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.common;
006:
007: import com.sun.portal.rewriter.rom.Data;
008: import com.sun.portal.rewriter.rom.DataRule;
009: import com.sun.portal.rewriter.rom.Rule;
010: import com.sun.portal.rewriter.util.Debug;
011: import com.sun.portal.rewriter.util.re.Pattern;
012: import com.sun.portal.rewriter.util.xml.Node;
013:
014: /**
015: * Attribute tag of RuleSet, used by both HTMLRules and XMLRules
016: *
017: * @version 1.0 12/15/2001
018: * @author Raja Nagendra Kumar, Nagendra.Raja@sun.com
019: * @see com.sun.portal.rewriter.rom.html.HTMLRules,com.sun.portal.rewriter.rom.xml.XMLRules
020: */
021: public final class AttributeRule extends DataRule {
022: public static final String JSTOKEN = "JSToken";
023:
024: private final Attribute attribute;
025: private final Pattern[] nameSpec;
026: private final Pattern[] tagSpec;
027: private final Pattern[] valuePatternSpec;
028:
029: public AttributeRule(final Attribute aAttribute) {
030: this (aAttribute, true);
031: }//constructor
032:
033: public AttributeRule(final Attribute aAttribute,
034: final boolean aIgnoreCase) {
035: super (aAttribute);
036: attribute = aAttribute;
037: nameSpec = createAttributeSpec(attribute.getName(), aIgnoreCase);
038:
039: tagSpec = createAttributeSpec(attribute.getTag(), aIgnoreCase);
040:
041: valuePatternSpec = createValuePatternSpec(attribute
042: .getValuePatterns());
043: }//constructor
044:
045: public AttributeRule(final Node aNode, final boolean aIgnoreCase) {
046: this (createAttribute(aNode), aIgnoreCase);
047: }//constructor
048:
049: private static final Attribute createAttribute(final Node aNode) {
050: //Start:Read JSToken Value - Compatability Code
051: if (aNode.getName().equals(JSTOKEN)) {
052: return new Attribute(aNode.getPCData(), null, null,
053: Rule.DJS, null);
054: }
055: //End:Read JSToken Value - Compatability Code
056:
057: return new Attribute(aNode.getAttributeValue(NAME), aNode
058: .getAttributeValue(TAG), aNode
059: .getAttributeValue(VALUE_PATTERNS), aNode
060: .getAttributeValue(TYPE), aNode
061: .getAttributeValue(SOURCE));
062: }//createAttribute()
063:
064: public Pattern[] getParsedPatterns() {
065: return valuePatternSpec;
066: }//getParsedValuePatterns()
067:
068: public boolean plugableMatch(final Data aMache) {
069: if (!(aMache instanceof Attribute)) {
070: return false;
071: }
072:
073: Attribute valueObject = (Attribute) aMache;
074: //if ( attribute.getType().equals( valueObject.getType() ) )
075: {
076: if (match(nameSpec, valueObject.getName())) {
077: if (match(tagSpec, valueObject.getTag())) {
078: return true;
079: }
080: }
081: }
082:
083: return false;
084: }//matchs()
085:
086: public boolean isValid() {
087: return doBasicValidation(new String[] { attribute.getName() });
088: }//isValid()
089:
090: public static final AttributeRule[] createAttributeRules(
091: final Node[] aNodeList, final boolean aIgnoreCase) {
092: AttributeRule[] lResult = new AttributeRule[aNodeList.length];
093: for (int i = 0; i < aNodeList.length; i++) {
094: lResult[i] = new AttributeRule(aNodeList[i], aIgnoreCase);
095: }
096:
097: return lResult;
098: }//createAttributeRules()
099:
100: public static void main(String[] args) {
101: AttributeRule[] attributes = com.sun.portal.rewriter.test.util.SampleRuleObjects.defaultHTMLAttributes;
102: for (int i = 0; i < attributes.length; i++) {
103: Debug.println(attributes[i].toXML());
104: }//for loop
105: }//main()
106: }//class Attribute
|