AttributeRule.java :  » Portal » Open-Portal » com » sun » portal » rewriter » rom » common » Java Open Source

Java Open Source » Portal » Open Portal 
Open Portal » com » sun » portal » rewriter » rom » common » AttributeRule.java
/*
 * Copyright 2001 Sun Microsystems, Inc.  All rights reserved.
 * PROPRIETARY/CONFIDENTIAL.  Use of this product is subject to license terms.
 */
package com.sun.portal.rewriter.rom.common;

import com.sun.portal.rewriter.rom.Data;
import com.sun.portal.rewriter.rom.DataRule;
import com.sun.portal.rewriter.rom.Rule;
import com.sun.portal.rewriter.util.Debug;
import com.sun.portal.rewriter.util.re.Pattern;
import com.sun.portal.rewriter.util.xml.Node;

/**
 * Attribute tag of RuleSet, used by both HTMLRules and XMLRules
 *
 * @version 1.0 12/15/2001
 * @author Raja Nagendra Kumar, Nagendra.Raja@sun.com
 * @see com.sun.portal.rewriter.rom.html.HTMLRules,com.sun.portal.rewriter.rom.xml.XMLRules
 */
public final class AttributeRule extends DataRule
{
    public static final String JSTOKEN = "JSToken";

    private final Attribute attribute;
    private final Pattern[] nameSpec;
    private final Pattern[] tagSpec;
    private final Pattern[] valuePatternSpec;

    public AttributeRule( final Attribute aAttribute )
    {
  this( aAttribute, true );
    }//constructor

    public AttributeRule( final Attribute aAttribute,
        final boolean aIgnoreCase )
    {
  super( aAttribute );
  attribute = aAttribute;
  nameSpec = createAttributeSpec( attribute.getName(),
          aIgnoreCase );

  tagSpec = createAttributeSpec( attribute.getTag(),
               aIgnoreCase );

  valuePatternSpec = createValuePatternSpec( attribute.getValuePatterns() );
    }//constructor

    public AttributeRule( final Node aNode,
        final boolean aIgnoreCase )
    {
  this( createAttribute( aNode ), aIgnoreCase );
    }//constructor

    private static final Attribute createAttribute( final Node aNode )
    {
  //Start:Read JSToken Value - Compatability Code
  if ( aNode.getName().equals( JSTOKEN ) )
  {
      return new Attribute( aNode.getPCData(),
          null,
          null,
          Rule.DJS,
          null );
  }
  //End:Read JSToken Value - Compatability Code

  return new Attribute( aNode.getAttributeValue( NAME ),
            aNode.getAttributeValue( TAG ),
            aNode.getAttributeValue( VALUE_PATTERNS ),
            aNode.getAttributeValue( TYPE ),
            aNode.getAttributeValue( SOURCE ) );
    }//createAttribute()

    public Pattern[] getParsedPatterns()
    {
  return valuePatternSpec;
    }//getParsedValuePatterns()

    public boolean plugableMatch( final Data aMache )
    {
  if ( !( aMache instanceof Attribute ) )
  {
      return false;
  }

  Attribute valueObject = (Attribute) aMache;
  //if ( attribute.getType().equals( valueObject.getType() ) )
  {
      if ( match( nameSpec, valueObject.getName() ) )
      {
    if ( match( tagSpec, valueObject.getTag() ) )
    {
        return true;
    }
      }
  }

  return false;
    }//matchs()

    public boolean isValid()
    {
  return doBasicValidation( new String[]{attribute.getName()} );
    }//isValid()

    public static final AttributeRule[] createAttributeRules( final Node[] aNodeList,
                    final boolean aIgnoreCase )
    {
  AttributeRule[] lResult = new AttributeRule[aNodeList.length];
  for ( int i = 0; i < aNodeList.length; i++ )
  {
      lResult[i] = new AttributeRule( aNodeList[i], aIgnoreCase );
  }

  return lResult;
    }//createAttributeRules()

    public static void main( String[] args )
    {
  AttributeRule[] attributes =
    com.sun.portal.rewriter.test.util.SampleRuleObjects.defaultHTMLAttributes;
  for ( int i = 0; i < attributes.length; i++ )
  {
      Debug.println( attributes[i].toXML() );
  }//for loop
    }//main()
}//class Attribute
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.