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:
Tag
-
-
Field Summary
Fields Modifier and Type Field Description private intattributeCountprivate String[]attributesprivate Stringnameprivate inttype-
Fields inherited from interface com.opensymphony.module.sitemesh.html.Tag
CLOSE, CLOSE_MAGIC_COMMENT, EMPTY, OPEN, OPEN_MAGIC_COMMENT
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intaddAttribute(String name, String value)Add a new attribute.booleanequals(Object o)intgetAttributeCount()Number of attributes in tag.intgetAttributeIndex(String name, boolean caseSensitive)Determine which attribute has the specified name.StringgetAttributeName(int index)Get name of attribute.StringgetAttributeValue(int index)Get value of an attribute.StringgetAttributeValue(String name, boolean caseSensitive)Get value of an attribute.StringgetContents()Get the complete tag in its original form, preserving original formatting.StringgetName()Name of tag (ie.intgetType()Type of tag:
<blah> - Tag.OPEN
</blah> - Tag.CLOSE
<blah/> - Tag.EMPTYprivate voidgrowAttributes()booleanhasAttribute(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.voidsetName(String name)Change the name of the attribute.voidsetType(int type)Change the type of the tag.StringtoString()voidwriteTo(CharArray out)Write out the complete tag in its original form, preserving original formatting.
-
-
-
Method Detail
-
getContents
public String 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- See Also:
Tag.writeTo(com.opensymphony.module.sitemesh.html.util.CharArray)
-
writeTo
public void writeTo(CharArray out)
Description copied from interface:TagWrite out the complete tag in its original form, preserving original formatting.
-
getAttributeCount
public int getAttributeCount()
Description copied from interface:TagNumber of attributes in tag.- Specified by:
getAttributeCountin interfaceTag
-
getAttributeIndex
public int getAttributeIndex(String name, boolean caseSensitive)
Description copied from interface:TagDetermine which attribute has the specified name.- Specified by:
getAttributeIndexin interfaceTag
-
getAttributeName
public String getAttributeName(int index)
Description copied from interface:TagGet name of attribute.- Specified by:
getAttributeNamein interfaceTag
-
getAttributeValue
public String getAttributeValue(int index)
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
-
getAttributeValue
public String getAttributeValue(String name, boolean caseSensitive)
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
-
hasAttribute
public boolean hasAttribute(String name, boolean caseSensitive)
Description copied from interface:TagDetermine if an attribute is present.- Specified by:
hasAttributein interfaceTag
-
getName
public String 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
public void setName(String name)
Change the name of the attribute.
-
setType
public void setType(int type)
Change the type of the tag. Type of tag:
<blah> - Tag.OPEN
</blah> - Tag.CLOSE
<blah/> - Tag.EMPTY
-
growAttributes
private void growAttributes()
-
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.
-
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.
-
removeAttribute
public void removeAttribute(int attributeIndex)
Remove an attribute.
-
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.
-
-