Class XmlTag


  • public class XmlTag
    extends java.lang.Object
    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

      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)  
      java.lang.CharSequence getAttribute​(java.lang.String key)
      Get a string attribute.
      org.apache.wicket.util.value.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'.
      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.
      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.
      java.lang.Object put​(java.lang.String key, boolean value)
      Puts a boolean attribute.
      java.lang.Object put​(java.lang.String key, int value)
      Puts an int 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, org.apache.wicket.util.string.StringValue value)
      Puts a StringValueattribute.
      void putAll​(java.util.Map<java.lang.String,​java.lang.Object> 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.TagType 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()
      String representation with line and column number
      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 java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • 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 org.apache.wicket.util.value.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
      • 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)
      • getAttribute

        public java.lang.CharSequence getAttribute​(java.lang.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 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,
                                    org.apache.wicket.util.string.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<java.lang.String,​java.lang.Object> 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.TagType 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()
        Returns:
        The string representation of the tag
      • toUserDebugString

        public java.lang.String toUserDebugString()
        String representation with line and column number
        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