Package org.apache.wicket.markup.parser
Class XmlTag
- java.lang.Object
-
- org.apache.wicket.markup.parser.XmlTag
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
XmlTag.TagType
Enumerated type for different kinds of component tags.
-
Constructor Summary
Constructors Constructor Description XmlTag()
Construct.XmlTag(org.apache.wicket.markup.parser.XmlTag.TextSegment text, XmlTag.TagType type)
Construct.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
closes(XmlTag open)
Gets whether this tag closes the provided open tag.boolean
equalTo(XmlTag element)
CharSequence
getAttribute(String key)
Get a string attribute.IValueMap
getAttributes()
Gets a hashmap of this tag's attributes.int
getColumnNumber()
Get the column number.int
getLength()
Gets the length of the tag in characters.int
getLineNumber()
Get the line number.String
getName()
Gets the name of the tag, for example the tag<b>
's name would be 'b'.String
getNamespace()
Namespace of the tag, if available.XmlTag
getOpenTag()
Assuming this is a close tag, return the corresponding open tagint
getPos()
Gets the location of the tag in the input string.XmlTag.TagType
getType()
Get the tag type.boolean
hasAttributes()
boolean
isClose()
Gets whether this is a close tag.boolean
isMutable()
boolean
isOpen()
Gets whether this is an open tag.boolean
isOpenClose()
Gets whether this tag is an open/ close tag.XmlTag
makeImmutable()
Makes this tag object immutable by making the attribute map unmodifiable.XmlTag
mutable()
Gets this tag if it is already mutable, or a mutable copy of this tag if it is immutable.Object
put(String key, boolean value)
Puts a boolean attribute.Object
put(String key, int value)
Puts an int attribute.Object
put(String key, CharSequence value)
Puts a string attribute.Object
put(String key, StringValue value)
Puts aStringValue
attribute.void
putAll(Map<String,Object> map)
Puts all attributes in mapvoid
remove(String key)
Removes an attribute.void
setName(String name)
Sets the tag name.void
setNamespace(String namespace)
Sets the tag namespace.void
setOpenTag(XmlTag tag)
Assuming this is a close tag, assign it's corresponding open tag.void
setType(XmlTag.TagType type)
Sets type of this tag if it is not immutable.CharSequence
toCharSequence()
String
toDebugString()
Converts this object to a string representation.String
toString()
Converts this object to a string representation.String
toUserDebugString()
String representation with line and column numberCharSequence
toXmlString()
Assuming some attributes have been changed, toXmlString() rebuilds the String on based on the tags informations.
-
-
-
Constructor Detail
-
XmlTag
public XmlTag()
Construct.
-
XmlTag
public XmlTag(org.apache.wicket.markup.parser.XmlTag.TextSegment text, XmlTag.TagType type)
Construct.- Parameters:
text
-type
-
-
-
Method Detail
-
closes
public final boolean closes(XmlTag open)
Gets whether this tag closes the provided open tag.- Parameters:
open
- The open tag- Returns:
- True if this tag closes the given open tag
-
equalTo
public final boolean equalTo(XmlTag element)
- Parameters:
element
-- Returns:
- true, if namespace, name and attributes are the same
-
getAttributes
public IValueMap getAttributes()
Gets a hashmap of this tag's attributes.- Returns:
- The tag's attributes
-
hasAttributes
public boolean hasAttributes()
- Returns:
- true if there 1 or more attributes.
-
getColumnNumber
public int getColumnNumber()
Get the column number.- Returns:
- Returns the columnNumber.
-
getLength
public int getLength()
Gets the length of the tag in characters.- Returns:
- The tag's length
-
getLineNumber
public int getLineNumber()
Get the line number.- Returns:
- Returns the lineNumber.
-
getName
public String getName()
Gets the name of the tag, for example the tag<b>
's name would be 'b'.- Returns:
- The tag's name
-
getNamespace
public String getNamespace()
Namespace of the tag, if available. For example, <wicket:link>.- Returns:
- The tag's namespace
-
getOpenTag
public final XmlTag getOpenTag()
Assuming this is a close tag, return the corresponding open tag- Returns:
- The open tag. Null, if no open tag available
-
getPos
public int getPos()
Gets the location of the tag in the input string.- Returns:
- Tag location (index in input string)
-
getAttribute
public CharSequence getAttribute(String key)
Get a string attribute.- Parameters:
key
- The key- Returns:
- The string value
-
getType
public XmlTag.TagType getType()
Get the tag type.- Returns:
- the tag type (OPEN, CLOSE or OPEN_CLOSE).
-
isClose
public boolean isClose()
Gets whether this is a close tag.- Returns:
- True if this tag is a close tag
-
isMutable
public final boolean isMutable()
- Returns:
- True, if tag is mutable
-
isOpen
public boolean isOpen()
Gets whether this is an open tag.- Returns:
- True if this tag is an open tag
-
isOpenClose
public boolean isOpenClose()
Gets whether this tag is an open/ close tag.- Returns:
- True if this tag is an open and a close tag
-
makeImmutable
public XmlTag makeImmutable()
Makes this tag object immutable by making the attribute map unmodifiable. Immutable tags cannot be made mutable again. They can only be copied into new mutable tag objects.- Returns:
- this
-
mutable
public XmlTag mutable()
Gets this tag if it is already mutable, or a mutable copy of this tag if it is immutable.- Returns:
- This tag if it is already mutable, or a mutable copy of this tag if it is immutable.
-
put
public Object put(String key, boolean value)
Puts a boolean attribute.- Parameters:
key
- The keyvalue
- The value- Returns:
- previous value associated with specified key, or null if there was no mapping for key. A null return can also indicate that the map previously associated null with the specified key, if the implementation supports null values.
-
put
public Object put(String key, int value)
Puts an int attribute.- Parameters:
key
- The keyvalue
- The value- Returns:
- previous value associated with specified key, or null if there was no mapping for key. A null return can also indicate that the map previously associated null with the specified key, if the implementation supports null values.
-
put
public Object put(String key, CharSequence value)
Puts a string attribute.- Parameters:
key
- The keyvalue
- The value- Returns:
- previous value associated with specified key, or null if there was no mapping for key. A null return can also indicate that the map previously associated null with the specified key, if the implementation supports null values.
-
put
public Object put(String key, StringValue value)
Puts aStringValue
attribute.- Parameters:
key
- The keyvalue
- The value- Returns:
- previous value associated with specified key, or null if there was no mapping for key. A null return can also indicate that the map previously associated null with the specified key, if the implementation supports null values.
-
putAll
public void putAll(Map<String,Object> map)
Puts all attributes in map- Parameters:
map
- A key/value map
-
setNamespace
public void setNamespace(String namespace)
Sets the tag namespace.- Parameters:
namespace
- New tag name
-
setOpenTag
public void setOpenTag(XmlTag tag)
Assuming this is a close tag, assign it's corresponding open tag.- Parameters:
tag
- the open-tag- Throws:
RuntimeException
- if 'this' is not a close tag
-
setType
public void setType(XmlTag.TagType type)
Sets type of this tag if it is not immutable.- Parameters:
type
- The new type
-
toDebugString
public String toDebugString()
Converts this object to a string representation.- Returns:
- String version of this object
-
toCharSequence
public CharSequence toCharSequence()
- Returns:
- The string representation of the tag
-
toUserDebugString
public String toUserDebugString()
String representation with line and column number- Returns:
- String version of this object
-
toXmlString
public CharSequence toXmlString()
Assuming some attributes have been changed, toXmlString() rebuilds the String on based on the tags informations.- Returns:
- A xml string matching the tag
-
-