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.html;
006:
007: import com.sun.portal.rewriter.engines.LanguageConstants;
008: import com.sun.portal.rewriter.rom.DataRuleCollection;
009: import com.sun.portal.rewriter.rom.InvalidXMLException;
010: import com.sun.portal.rewriter.rom.RecursiveRuleCollection;
011: import com.sun.portal.rewriter.rom.RuleCollection;
012: import com.sun.portal.rewriter.rom.RuleSetHelper;
013: import com.sun.portal.rewriter.rom.common.AttributeRule;
014: import com.sun.portal.rewriter.util.Constants;
015: import com.sun.portal.rewriter.util.Debug;
016: import com.sun.portal.rewriter.util.xml.Node;
017:
018: import java.util.ArrayList;
019: import java.util.Arrays;
020: import java.util.Collection;
021: import java.util.List;
022:
023: /**
024: * Representation of HTMLRules tag of RuleSet
025: *
026: * @version 1.0 12/15/2001
027: * @author Raja Nagendra Kumar, Nagendra.Raja@sun.com
028: */
029: public final class HTMLRules extends RecursiveRuleCollection {
030: public HTMLRules(final RuleCollection[] aCollection)
031: throws InvalidXMLException {
032: super (HTMLRULES, aCollection);
033: setMIMEType(LanguageConstants.HTML_MIME);
034: }//constructor
035:
036: public HTMLRules(final Node aNode) throws InvalidXMLException {
037: this ((RuleCollection[]) null);
038:
039: DataRuleCollection tempCollection = DataRuleCollection.create(
040: FormRule.class, aNode.getChildren(FORM));
041: addRuleCollection(tempCollection);
042:
043: tempCollection = DataRuleCollection.create(AppletRule.class,
044: aNode.getChildren(APPLET));
045: addRuleCollection(tempCollection);
046:
047: Node[] attributeArray = scanAttributeJSTokenNodes(aNode);
048: tempCollection = new DataRuleCollection(ATTRIBUTE,
049: AttributeRule
050: .createAttributeRules(attributeArray, true));
051: addRuleCollection(tempCollection);
052: }//constructor
053:
054: private DataRuleCollection forms;
055: private DataRuleCollection applets;
056: private DataRuleCollection attributes;
057:
058: public DataRuleCollection getForms() {
059: if (forms == null) {
060: forms = (DataRuleCollection) getRuleCollection(FORM);
061: }
062:
063: return forms;
064: }//getForms()
065:
066: public DataRuleCollection getApplets() {
067: if (applets == null) {
068: applets = (DataRuleCollection) getRuleCollection(APPLET);
069: }
070:
071: return applets;
072: }//getApplets()
073:
074: public DataRuleCollection getAttributes() {
075: if (attributes == null) {
076: attributes = (DataRuleCollection) getRuleCollection(ATTRIBUTE);
077: }
078:
079: return attributes;
080: }//getAttributes()
081:
082: public DataRuleCollection getAttributes(final String aType) {
083: return RuleSetHelper.getByType(getAttributes(), aType);
084: }//getAttributes()
085:
086: private static Node[] scanAttributeJSTokenNodes(Node aNode) {
087: Node[] jsTokenRules = aNode.getChildren(AttributeRule.JSTOKEN);
088: Node[] attributeRules = aNode.getChildren(ATTRIBUTE);
089: if (jsTokenRules.length == 0) {
090: return attributeRules;
091: }
092:
093: Collection c = Arrays.asList(jsTokenRules);
094: List lList = new ArrayList(c);
095: lList.addAll(Arrays.asList(attributeRules));
096: return (Node[]) lList.toArray(Constants.EMPTY_NODE_ARRAY);
097: }//scanAttributeJSTokenNodes()
098:
099: public static void main(String[] args) {
100: String xmlString = com.sun.portal.rewriter.test.util.SampleRuleObjects.defaultHTMLRules
101: .toXML();
102: Debug.println(xmlString);
103: }//main()
104: }//class HTMLRules
|