001: /*
002: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005: package com.sun.portal.rewriter.rom;
006:
007: import com.sun.portal.rewriter.rom.common.Attribute;
008: import com.sun.portal.rewriter.rom.common.TagText;
009: import com.sun.portal.rewriter.rom.html.Applet;
010: import com.sun.portal.rewriter.rom.html.Form;
011: import com.sun.portal.rewriter.rom.js.Function;
012: import com.sun.portal.rewriter.rom.js.FunctionRule;
013: import com.sun.portal.rewriter.rom.js.Variable;
014: import com.sun.portal.rewriter.rom.js.VariableRule;
015:
016: import java.util.ArrayList;
017: import java.util.List;
018:
019: public class RuleSetHelper {
020: //HTML Rules
021: public static DataRule findHTMLFormMatch(RuleSet aRuleSet,
022: Form aMacherForm) {
023: DataRule lResult = aRuleSet.getHTMLRules().getForms()
024: .findMatch(aMacherForm);
025: RuleSet lParentRuleSet = aRuleSet.getParentRuleSet();
026: if (lResult == null && lParentRuleSet != null) {
027: lResult = findHTMLFormMatch(lParentRuleSet, aMacherForm);
028: }
029:
030: return lResult;
031: }//findHTMLFormMatch()
032:
033: public static DataRule findHTMLAppletMatch(RuleSet aRuleSet,
034: Applet aMacherApplet) {
035: DataRule lResult = aRuleSet.getHTMLRules().getApplets()
036: .findMatch(aMacherApplet);
037: RuleSet lParentRuleSet = aRuleSet.getParentRuleSet();
038: if (lResult == null && lParentRuleSet != null) {
039: lResult = findHTMLAppletMatch(lParentRuleSet, aMacherApplet);
040: }
041:
042: return lResult;
043: }//findHTMLAppletMatch()
044:
045: public static DataRule findHTMLAttributeMatch(RuleSet aRuleSet,
046: Attribute aMacherAttribute) {
047: DataRule lResult = aRuleSet.getHTMLRules().getAttributes()
048: .findMatch(aMacherAttribute);
049: RuleSet lParentRuleSet = aRuleSet.getParentRuleSet();
050: if (lResult == null && lParentRuleSet != null) {
051: lResult = findHTMLAttributeMatch(lParentRuleSet,
052: aMacherAttribute);
053: }
054:
055: return lResult;
056: }//findHTMLAttributeMatch()
057:
058: //JS Rules
059: public static VariableRule findJSNonSystemVariableMatch(
060: RuleSet aRuleSet, Variable aMacherNonSystemVariable) {
061: DataRule lResult = aRuleSet.getJSRules()
062: .getNonSystemVariables().findMatch(
063: aMacherNonSystemVariable);
064: RuleSet lParentRuleSet = aRuleSet.getParentRuleSet();
065: if (lResult == null && lParentRuleSet != null) {
066: lResult = findJSNonSystemVariableMatch(lParentRuleSet,
067: aMacherNonSystemVariable);
068: }
069:
070: return (VariableRule) lResult;
071: }//findJSNonSystemVariableMatch()
072:
073: public static VariableRule findJSSystemVariableMatch(
074: RuleSet aRuleSet, Variable aMacherSystemVariable) {
075: DataRule lResult = aRuleSet.getJSRules().getSystemVariables()
076: .findMatch(aMacherSystemVariable);
077: RuleSet lParentRuleSet = aRuleSet.getParentRuleSet();
078: if (lResult == null && lParentRuleSet != null) {
079: lResult = findJSSystemVariableMatch(lParentRuleSet,
080: aMacherSystemVariable);
081: }
082:
083: return (VariableRule) lResult;
084: }//findJSNonSystemVariableMatch()
085:
086: public static FunctionRule findJSFunctionMatch(RuleSet aRuleSet,
087: Function aMacherFunction) {
088: DataRule lResult = aRuleSet.getJSRules().getFunctions()
089: .findMatch(aMacherFunction);
090: RuleSet lParentRuleSet = aRuleSet.getParentRuleSet();
091: if (lResult == null && lParentRuleSet != null) {
092: lResult = findJSFunctionMatch(lParentRuleSet,
093: aMacherFunction);
094: }
095:
096: return (FunctionRule) lResult;
097: }//findJSFunctionMatch()
098:
099: //XML Rules
100: public static DataRule findXMLAttributeMatch(RuleSet aRuleSet,
101: Attribute aMacherAttribute) {
102: DataRule lResult = aRuleSet.getXMLRules().getAttributes()
103: .findMatch(aMacherAttribute);
104: RuleSet lParentRuleSet = aRuleSet.getParentRuleSet();
105: if (lResult == null && lParentRuleSet != null) {
106: lResult = findXMLAttributeMatch(lParentRuleSet,
107: aMacherAttribute);
108: }
109:
110: return lResult;
111: }//findXMLAttributeMatch()
112:
113: public static DataRule findXMLTagTextMatch(RuleSet aRuleSet,
114: TagText aMacherTagText) {
115: DataRule lResult = aRuleSet.getXMLRules().getTagTexts()
116: .findMatch(aMacherTagText);
117: RuleSet lParentRuleSet = aRuleSet.getParentRuleSet();
118: if (lResult == null && lParentRuleSet != null) {
119: lResult = findXMLTagTextMatch(lParentRuleSet,
120: aMacherTagText);
121: }
122:
123: return lResult;
124: }//findXMLTagTextMatch()
125:
126: public static DataRuleCollection getByType(
127: final DataRuleCollection aCollection, final String aType) {
128: return getByType(aCollection, aType, false);
129: }//getByType()
130:
131: public static DataRuleCollection getByType(
132: final DataRuleCollection aCollection, final String aType,
133: final boolean aISExclude) {
134: final ArrayList aList = new ArrayList();
135: final List lRuleCollection = aCollection.getCollection();
136: final int collectionLength = lRuleCollection.size();
137: for (int i = 0; i < collectionLength; i++) {
138: DataRule bDataRule = (DataRule) lRuleCollection.get(i);
139: TypedData bData = (TypedData) (bDataRule.getData());
140: String lType = bData.getType();
141:
142: boolean lInclude;
143: if (aISExclude == true) {
144: lInclude = !lType.equals(aType);
145: } else {
146: lInclude = lType.equals(aType);
147: }
148:
149: if (lInclude) {
150: aList.add(bDataRule);
151: }
152: }//for loop
153:
154: final DataRuleCollection subDataRuleCollection = new DataRuleCollection(
155: aCollection.getCollectionID(), (DataRule[]) aList
156: .toArray(DataRule.EMPTY_DATA_RULE_ARRAY));
157: return subDataRuleCollection;
158: }//getByType()
159: }//class RuleSetHelper
|