001: /*
002: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005:
006: package com.sun.portal.rewriter.services.ids;
007:
008: import com.sun.portal.rewriter.rom.DataRule;
009: import com.sun.portal.rewriter.rom.DataRuleCollection;
010: import com.sun.portal.rewriter.rom.Rule;
011: import com.sun.portal.rewriter.rom.common.Attribute;
012: import com.sun.portal.rewriter.rom.common.AttributeRule;
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.Arrays;
018: import java.util.List;
019:
020: final class IDSRuleCollectionBuilder {
021: static DataRuleCollection getHTMLAppletRuleCollection(
022: final DataSource aDataSource) {
023: final String[] appletStrings = aDataSource.getHTMLAppletData();
024: final ArrayList list = new ArrayList(appletStrings.length);
025: for (int i = 0; i < appletStrings.length; i++) {
026: DataRule applet = IDSRuleBuilder
027: .buildAppletRule(appletStrings[i]);
028: list.add(applet);
029: }
030: final DataRule[] appletRules = (DataRule[]) list
031: .toArray(new DataRule[0]);
032: return new DataRuleCollection(Rule.APPLET, appletRules);
033: }//createAppletRules()
034:
035: static DataRuleCollection getHTMLFormRuleCollection(
036: final DataSource aDataSource) {
037: final String[] formStrings = aDataSource.getHTMLFormData();
038: final ArrayList list = new ArrayList(formStrings.length);
039: for (int i = 0; i < formStrings.length; i++) {
040: DataRule formRule = IDSRuleBuilder
041: .buildFormRule(formStrings[i]);
042: list.add(formRule);
043: }
044: final DataRule[] formRules = (DataRule[]) list
045: .toArray(new DataRule[0]);
046: return new DataRuleCollection(Rule.FORM, formRules);
047: }//getHTMLFormRuleCollection()
048:
049: static DataRuleCollection getHTMLAttributeRuleCollection(
050: DataSource aDataSource) {
051:
052: String[] attrStrings = aDataSource.getHTMLAttributeData();
053:
054: ArrayList list = new ArrayList(attrStrings.length);
055: for (int i = 0; i < attrStrings.length; i++) {
056: DataRule attr = IDSRuleBuilder
057: .buildAttributeRule(attrStrings[i]);
058: list.add(attr);
059: }
060:
061: list.addAll(getHTMLJSTokenRules(aDataSource));
062: DataRule[] attrRules = (DataRule[]) list
063: .toArray(new DataRule[0]);
064: return new DataRuleCollection(Rule.ATTRIBUTE, attrRules);
065: }
066:
067: private static List getHTMLJSTokenRules(final DataSource aDataSource) {
068: final String[] jsTokens = aDataSource.getHTMLJSTokenData();
069: final List lList = new ArrayList();
070: for (int i = 0; i < jsTokens.length; i++) {
071: lList.add(new AttributeRule(new Attribute(jsTokens[i],
072: null, null, Rule.DJS, null)));
073: }
074:
075: return lList;
076: }//getHTMLJSTokenRules()
077:
078: //Variables
079: static DataRuleCollection getJSVariableRuleCollection(
080: final DataSource aDataSource) {
081: final List allVariables = new ArrayList();
082:
083: {
084: final List urlDataRules = Arrays.asList(buildVariables(
085: aDataSource.getJSURLVariablesData(), Rule.URL));
086: allVariables.addAll(urlDataRules);
087: }
088:
089: {
090: final List expressionDataRules = Arrays
091: .asList(buildVariables(aDataSource
092: .getJSExpressionVariablesData(),
093: Rule.EXPRESSION));
094: allVariables.addAll(expressionDataRules);
095: }
096:
097: {
098: final List dhtmlDataRules = Arrays.asList(buildVariables(
099: aDataSource.getJSDHTMLVariablesData(), Rule.DHTML));
100: allVariables.addAll(dhtmlDataRules);
101: }
102:
103: {
104: final List djsDataRules = Arrays.asList(buildVariables(
105: aDataSource.getJSDJSVariablesData(), Rule.DJS));
106: allVariables.addAll(djsDataRules);
107: }
108:
109: {
110: final List systemDataRules = Arrays
111: .asList(buildVariables(aDataSource
112: .getJSSystemVariablesData(), Rule.SYSTEM));
113: allVariables.addAll(systemDataRules);
114: }
115:
116: final DataRule[] allRules = (DataRule[]) allVariables
117: .toArray(new DataRule[0]);
118: return new DataRuleCollection(Rule.VARIABLE, allRules);
119: }//getJSVariableRuleCollection()
120:
121: //Function
122: static DataRuleCollection getJSFunctionRuleCollection(
123: final DataSource aDataSource) {
124: final List allFunctions = new ArrayList();
125:
126: {
127: final List urlDataRules = Arrays.asList(buildFunctions(
128: aDataSource.getJSURLFunctionData(), Rule.URL));
129: allFunctions.addAll(urlDataRules);
130: }
131:
132: {
133: final List expressionDataRules = Arrays
134: .asList(buildFunctions(aDataSource
135: .getJSExpressionFunctionData(),
136: Rule.EXPRESSION));
137: allFunctions.addAll(expressionDataRules);
138:
139: }
140:
141: {
142: final List dhtmlDataRules = Arrays.asList(buildFunctions(
143: aDataSource.getJSDHTMLFunctionData(), Rule.DHTML));
144: allFunctions.addAll(dhtmlDataRules);
145: }
146:
147: {
148: final List djsDataRules = Arrays.asList(buildFunctions(
149: aDataSource.getJSDJSFunctionData(), Rule.DJS));
150: allFunctions.addAll(djsDataRules);
151: }
152:
153: final DataRule[] allRules = (DataRule[]) allFunctions
154: .toArray(new DataRule[0]);
155: return new DataRuleCollection(Rule.FUNCTION, allRules);
156: }//getJSFunctionRuleCollection()
157:
158: private static DataRule[] buildVariables(final String[] variables,
159: final String type) {
160: final ArrayList list = new ArrayList(variables.length);
161: for (int i = 0; i < variables.length; i++) {
162: DataRule dataRule = new VariableRule(new Variable(
163: variables[i], type, null));
164: list.add(dataRule);
165: }
166: return (DataRule[]) list.toArray(new DataRule[0]);
167: }//buildVariables()
168:
169: private static DataRule[] buildFunctions(final String[] variables,
170: final String type) {
171: final ArrayList list = new ArrayList(variables.length);
172: for (int i = 0; i < variables.length; i++) {
173: DataRule dataRule = IDSRuleBuilder.buildFunctionRule(
174: variables[i], type);
175: list.add(dataRule);
176: }
177: return (DataRule[]) list.toArray(new DataRule[0]);
178: }//buildFunctions()
179:
180: static DataRuleCollection getXMLAttributeRuleCollection(
181: DataSource aDataSource) {
182: int length = 0;
183: String[] xmlAttrs = aDataSource.getXMLAttributeData();
184: if (xmlAttrs != null) {
185: length = xmlAttrs.length;
186: }
187:
188: List list = new ArrayList(length);
189: for (int i = 0; i < length; i++) {
190: DataRule xAttr = IDSRuleBuilder
191: .buildAttributeRule(xmlAttrs[i]);
192: list.add(xAttr);
193: }
194:
195: DataRule[] dataRules = (DataRule[]) list
196: .toArray(new DataRule[0]);
197: return new DataRuleCollection(Rule.ATTRIBUTE, dataRules);
198: }//getXMLAttributeRuleCollection()
199:
200: static DataRuleCollection getXMLTagTextRuleCollection(
201: DataSource aDataSource) {
202: int length = 0;
203: String[] xmlTS = aDataSource.getXMLTagTextData();
204:
205: if (xmlTS != null) {
206: length = xmlTS.length;
207: }
208:
209: List list = new ArrayList(length);
210: for (int i = 0; i < length; i++) {
211: DataRule xTS = IDSRuleBuilder.buildTagTextRule(xmlTS[i]);
212: list.add(xTS);
213: }
214:
215: DataRule[] dataRules = (DataRule[]) list
216: .toArray(new DataRule[0]);
217: return new DataRuleCollection(Rule.TAGTEXT, dataRules);
218: }//getXMLTagTextRuleCollection()
219:
220: }//class IDSRuleCollectionBuilder
|