Class CustomTag
java.lang.Object
com.opensymphony.module.sitemesh.html.CustomTag
- All Implemented Interfaces:
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:
-
Field Summary
Fields inherited from interface com.opensymphony.module.sitemesh.html.Tag
CLOSE, CLOSE_MAGIC_COMMENT, EMPTY, OPEN, OPEN_MAGIC_COMMENT -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintaddAttribute(String name, String value) Add a new attribute.booleanintNumber of attributes in tag.intgetAttributeIndex(String name, boolean caseSensitive) Determine which attribute has the specified name.getAttributeName(int index) Get name of attribute.getAttributeValue(int index) Get value of an attribute.getAttributeValue(String name, boolean caseSensitive) Get value of an attribute.Get the complete tag in its original form, preserving original formatting.intThe length of the tag.getName()Name of tag (ie.intThe position of the tag.intgetType()Type of tag:
<blah> - Tag.OPEN
</blah> - Tag.CLOSE
<blah/> - Tag.EMPTYbooleanhasAttribute(String name, boolean caseSensitive) Determine if an attribute is present.inthashCode()voidremoveAttribute(int attributeIndex) Remove an attribute.voidremoveAttribute(String name, boolean caseSensitive) Change the value of an attribute, or add an attribute if it does not already exist.voidsetAttributeName(int attributeIndex, String name) Change the name of an existing attribute.voidsetAttributeValue(int attributeIndex, String value) Change the value of an existing attribute.voidsetAttributeValue(String name, boolean caseSensitive, String value) Change the value of an attribute, or add an attribute if it does not already exist.voidChange the name of the attribute.voidsetType(int type) Change the type of the tag.toString()voidwriteTo(SitemeshBufferFragment.Builder buffer, int position) Write out the complete tag in its original form, preserving original formatting.
-
Constructor Details
-
CustomTag
Type of tag:
<blah> - Tag.OPEN
</blah> - Tag.CLOSE
<blah/> - Tag.EMPTY- Parameters:
name- the nametype- the type
-
CustomTag
Create a CustomTag based on an existing Tag - this takes a copy of the Tag.- Parameters:
tag- the tag
-
-
Method Details
-
getContents
Description copied from interface:TagGet 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:
getContentsin interfaceTag- Returns:
- the contents
-
writeTo
Description copied from interface:TagWrite out the complete tag in its original form, preserving original formatting. -
equals
-
hashCode
public int hashCode() -
toString
-
getAttributeCount
public int getAttributeCount()Description copied from interface:TagNumber of attributes in tag.- Specified by:
getAttributeCountin interfaceTag- Returns:
- the attribute count
-
getAttributeIndex
Description copied from interface:TagDetermine which attribute has the specified name.- Specified by:
getAttributeIndexin interfaceTag- Parameters:
name- the namecaseSensitive- the case sensitive- Returns:
- the attribute index
-
getAttributeName
Description copied from interface:TagGet name of attribute.- Specified by:
getAttributeNamein interfaceTag- Parameters:
index- the index- Returns:
- the attribute name
-
getAttributeValue
Description copied from interface:TagGet value of an attribute. If this is an empty attribute (i.e. just a name, without a value), null is returned.- Specified by:
getAttributeValuein interfaceTag- Parameters:
index- the index- Returns:
- the attribute value
-
getAttributeValue
Description copied from interface:TagGet value of an attribute. If this is an empty attribute (i.e. just a name, without a value), null is returned.- Specified by:
getAttributeValuein interfaceTag- Parameters:
name- the namecaseSensitive- the case sensitive- Returns:
- the attribute value
-
hasAttribute
Description copied from interface:TagDetermine if an attribute is present.- Specified by:
hasAttributein interfaceTag- Parameters:
name- the namecaseSensitive- the case sensitive- Returns:
- true, if successful
-
getName
Description copied from interface:TagName of tag (ie. element name). -
getType
public int getType()Type of tag:
<blah> - Tag.OPEN
</blah> - Tag.CLOSE
<blah/> - Tag.EMPTY -
setName
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
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
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
Change the name of an existing attribute.- Parameters:
attributeIndex- the attribute indexname- the name
-
setAttributeValue
Change the value of an existing attribute. The value may be null for an HTML style empty attribute.- Parameters:
attributeIndex- the attribute indexvalue- the value
-
removeAttribute
public void removeAttribute(int attributeIndex) Remove an attribute.- Parameters:
attributeIndex- the attribute index
-
removeAttribute
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:TagThe position of the tag.- Specified by:
getPositionin interfaceTag- Returns:
- the position
-
getLength
public int getLength()Description copied from interface:TagThe length of the tag.
-