org.apache.wicket.markup.parser
Class XmlTag

java.lang.Object
  extended by org.apache.wicket.markup.MarkupElement
      extended by org.apache.wicket.markup.parser.XmlTag

public class XmlTag
extends MarkupElement

A subclass of MarkupElement which represents a tag including namespace and its optional attributes. XmlTags are returned by the XML parser.

Author:
Jonathan Locke

Nested Class Summary
static class XmlTag.Type
          Enumerated type for different kinds of component tags.
 
Field Summary
static XmlTag.Type CLOSE
          A close tag, like </TAG>.
static XmlTag.Type OPEN
          An open tag, like <TAG componentId = "xyz">.
static XmlTag.Type OPEN_CLOSE
          An open/close tag, like <TAG componentId = "xyz"/>.
 
Constructor Summary
XmlTag()
          Construct.
 
Method Summary
 boolean closes(XmlTag open)
          Gets whether this tag closes the provided open tag.
 boolean equalTo(MarkupElement element)
          This is not an implementation of equals because we don't care about hashCodes for MarkupElements yet.
 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.
 java.lang.String getName()
          Gets the name of the tag, for example the tag <b>'s name would be 'b'.
 boolean getNameChanged()
          Get whether the name of this component tag was changed.
 java.lang.String getNamespace()
          Namespace of the tag, if available.
 XmlTag getOpenTag()
          Assuming this is a close tag, return the corresponding open tag
 int getPos()
          Gets the location of the tag in the input string.
 java.lang.CharSequence getString(java.lang.String key)
          Get a string attribute.
 XmlTag.Type getType()
          Get the tag type.
 boolean hasAttributes()
           
 boolean hasEqualTagName(XmlTag tag)
          Compare tag name including namespace
 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.
 void 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.
 java.lang.Object put(java.lang.String key, boolean value)
          Puts a boolean attribute.
 java.lang.Object put(java.lang.String key, java.lang.CharSequence value)
          Puts a string attribute.
 java.lang.Object put(java.lang.String key, int value)
          Puts an int attribute.
 java.lang.Object put(java.lang.String key, StringValue value)
          Puts a StringValueattribute.
 void putAll(java.util.Map map)
          Puts all attributes in map
 void remove(java.lang.String key)
          Removes an attribute.
 void setName(java.lang.String name)
          Sets the tag name.
 void setNamespace(java.lang.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.Type type)
          Sets type of this tag if it is not immutable.
 java.lang.CharSequence toCharSequence()
           
 java.lang.String toDebugString()
          Converts this object to a string representation.
 java.lang.String toString()
          Converts this object to a string representation.
 java.lang.String toUserDebugString()
          Converts this object to a string representation.
 java.lang.CharSequence toXmlString(java.lang.String attributeToBeIgnored)
          Assuming some attributes have been changed, toXmlString() rebuilds the String on based on the tags informations.
 
Methods inherited from class org.apache.wicket.markup.MarkupElement
closes
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CLOSE

public static final XmlTag.Type CLOSE
A close tag, like </TAG>.


OPEN

public static final XmlTag.Type OPEN
An open tag, like <TAG componentId = "xyz">.


OPEN_CLOSE

public static final XmlTag.Type OPEN_CLOSE
An open/close tag, like <TAG componentId = "xyz"/>.

Constructor Detail

XmlTag

public XmlTag()
Construct.

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(MarkupElement element)
Description copied from class: MarkupElement
This is not an implementation of equals because we don't care about hashCodes for MarkupElements yet. Also, this method only compares the namespace, name and attributes of the given MarkupElements.

Specified by:
equalTo in class MarkupElement
Parameters:
element - The markup element to compare with
Returns:
True if the other element equals this one
See Also:
MarkupElement.equalTo(org.apache.wicket.markup.MarkupElement)

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 java.lang.String getName()
Gets the name of the tag, for example the tag <b>'s name would be 'b'.

Returns:
The tag's name

getNameChanged

public boolean getNameChanged()
Get whether the name of this component tag was changed.

Returns:
Returns true if the name of this component tag was changed

getNamespace

public java.lang.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)

getString

public java.lang.CharSequence getString(java.lang.String key)
Get a string attribute.

Parameters:
key - The key
Returns:
The string value

getType

public XmlTag.Type 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

hasEqualTagName

public boolean hasEqualTagName(XmlTag tag)
Compare tag name including namespace

Parameters:
tag -
Returns:
true if name and namespace are equal

makeImmutable

public void 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.


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 java.lang.Object put(java.lang.String key,
                            boolean value)
Puts a boolean attribute.

Parameters:
key - The key
value - 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 java.lang.Object put(java.lang.String key,
                            int value)
Puts an int attribute.

Parameters:
key - The key
value - 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 java.lang.Object put(java.lang.String key,
                            java.lang.CharSequence value)
Puts a string attribute.

Parameters:
key - The key
value - 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 java.lang.Object put(java.lang.String key,
                            StringValue value)
Puts a StringValueattribute.

Parameters:
key - The key
value - 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(java.util.Map map)
Puts all attributes in map

Parameters:
map - A key/value map

remove

public void remove(java.lang.String key)
Removes an attribute.

Parameters:
key - The key to remove

setName

public void setName(java.lang.String name)
Sets the tag name.

Parameters:
name - New tag name

setNamespace

public void setNamespace(java.lang.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:
java.lang.RuntimeException - if 'this' is not a close tag

setType

public void setType(XmlTag.Type type)
Sets type of this tag if it is not immutable.

Parameters:
type - The new type

toDebugString

public java.lang.String toDebugString()
Converts this object to a string representation.

Returns:
String version of this object

toString

public java.lang.String toString()
Converts this object to a string representation.

Overrides:
toString in class java.lang.Object
Returns:
String version of this object

toCharSequence

public java.lang.CharSequence toCharSequence()
Specified by:
toCharSequence in class MarkupElement
Returns:
Gets the charsequence representation of this element
See Also:
MarkupElement.toCharSequence()

toUserDebugString

public java.lang.String toUserDebugString()
Converts this object to a string representation.

Specified by:
toUserDebugString in class MarkupElement
Returns:
String version of this object

toXmlString

public java.lang.CharSequence toXmlString(java.lang.String attributeToBeIgnored)
Assuming some attributes have been changed, toXmlString() rebuilds the String on based on the tags informations.

Parameters:
attributeToBeIgnored -
Returns:
A xml string matching the tag


Copyright © 2004-2010 Apache Software Foundation. All Rights Reserved.