Class CustomTag

java.lang.Object
com.opensymphony.module.sitemesh.html.CustomTag
All Implemented Interfaces:
Tag

public class CustomTag extends Object implements Tag
A CustomTag provides a mechanism to manipulate the contents of a Tag. The standard Tag implementations are immutable, however CustomTag allows a copy to be taken of an immutable Tag that can then be manipulated.
Author:
Joe Walnes
See Also:
  • Constructor Details

    • CustomTag

      public CustomTag(String name, int type)
      Type of tag:
      <blah> - Tag.OPEN
      </blah> - Tag.CLOSE
      <blah/> - Tag.EMPTY
      Parameters:
      name - the name
      type - the type
    • CustomTag

      public CustomTag(Tag tag)
      Create a CustomTag based on an existing Tag - this takes a copy of the Tag.
      Parameters:
      tag - the tag
  • Method Details

    • getContents

      public String getContents()
      Description copied from interface: Tag
      Get the complete tag in its original form, preserving original formatting. This has a slight overhead in that it needs to construct a String. For improved performance, use writeTo() instead.
      Specified by:
      getContents in interface Tag
      Returns:
      the contents
    • writeTo

      public void writeTo(SitemeshBufferFragment.Builder buffer, int position)
      Description copied from interface: Tag
      Write out the complete tag in its original form, preserving original formatting.
      Specified by:
      writeTo in interface Tag
      Parameters:
      buffer - the fragment
      position - the position
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getAttributeCount

      public int getAttributeCount()
      Description copied from interface: Tag
      Number of attributes in tag.
      Specified by:
      getAttributeCount in interface Tag
      Returns:
      the attribute count
    • getAttributeIndex

      public int getAttributeIndex(String name, boolean caseSensitive)
      Description copied from interface: Tag
      Determine which attribute has the specified name.
      Specified by:
      getAttributeIndex in interface Tag
      Parameters:
      name - the name
      caseSensitive - the case sensitive
      Returns:
      the attribute index
    • getAttributeName

      public String getAttributeName(int index)
      Description copied from interface: Tag
      Get name of attribute.
      Specified by:
      getAttributeName in interface Tag
      Parameters:
      index - the index
      Returns:
      the attribute name
    • getAttributeValue

      public String getAttributeValue(int index)
      Description copied from interface: Tag
      Get value of an attribute. If this is an empty attribute (i.e. just a name, without a value), null is returned.
      Specified by:
      getAttributeValue in interface Tag
      Parameters:
      index - the index
      Returns:
      the attribute value
    • getAttributeValue

      public String getAttributeValue(String name, boolean caseSensitive)
      Description copied from interface: Tag
      Get value of an attribute. If this is an empty attribute (i.e. just a name, without a value), null is returned.
      Specified by:
      getAttributeValue in interface Tag
      Parameters:
      name - the name
      caseSensitive - the case sensitive
      Returns:
      the attribute value
    • hasAttribute

      public boolean hasAttribute(String name, boolean caseSensitive)
      Description copied from interface: Tag
      Determine if an attribute is present.
      Specified by:
      hasAttribute in interface Tag
      Parameters:
      name - the name
      caseSensitive - the case sensitive
      Returns:
      true, if successful
    • getName

      public String getName()
      Description copied from interface: Tag
      Name of tag (ie. element name).
      Specified by:
      getName in interface Tag
      Returns:
      the name
    • getType

      public int getType()
      Type of tag:
      <blah> - Tag.OPEN
      </blah> - Tag.CLOSE
      <blah/> - Tag.EMPTY
      Specified by:
      getType in interface Tag
      Returns:
      the type
    • setName

      public void setName(String name)
      Change the name of the attribute.
      Parameters:
      name - the new name
    • setType

      public void setType(int type)
      Change the type of the tag. Type of tag:
      <blah> - Tag.OPEN
      </blah> - Tag.CLOSE
      <blah/> - Tag.EMPTY
      Parameters:
      type - the new type
    • addAttribute

      public int addAttribute(String name, String value)
      Add a new attribute. This does not check for the existence of an attribute with the same name, thus allowing duplicate attributes.
      Parameters:
      name - Name of attribute to change.
      value - New value of attribute or null for an HTML style empty attribute.
      Returns:
      Index of new attribute.
    • setAttributeValue

      public void setAttributeValue(String name, boolean caseSensitive, String value)
      Change the value of an attribute, or add an attribute if it does not already exist.
      Parameters:
      name - Name of attribute to change.
      caseSensitive - Whether the name should be treated as case sensitive when searching for an existing value.
      value - New value of attribute or null for an HTML style empty attribute.
    • setAttributeName

      public void setAttributeName(int attributeIndex, String name)
      Change the name of an existing attribute.
      Parameters:
      attributeIndex - the attribute index
      name - the name
    • setAttributeValue

      public void setAttributeValue(int attributeIndex, String value)
      Change the value of an existing attribute. The value may be null for an HTML style empty attribute.
      Parameters:
      attributeIndex - the attribute index
      value - the value
    • removeAttribute

      public void removeAttribute(int attributeIndex)
      Remove an attribute.
      Parameters:
      attributeIndex - the attribute index
    • removeAttribute

      public void removeAttribute(String name, boolean caseSensitive)
      Change the value of an attribute, or add an attribute if it does not already exist.
      Parameters:
      name - Name of attribute to remove.
      caseSensitive - Whether the name should be treated as case sensitive.
    • getPosition

      public int getPosition()
      Description copied from interface: Tag
      The position of the tag.
      Specified by:
      getPosition in interface Tag
      Returns:
      the position
    • getLength

      public int getLength()
      Description copied from interface: Tag
      The length of the tag.
      Specified by:
      getLength in interface Tag
      Returns:
      the length