Class Tag

  • All Implemented Interfaces:
    java.lang.Iterable<Tag>

    public class Tag
    extends java.lang.Object
    implements java.lang.Iterable<Tag>
    Represents an encountered tag.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Map<java.lang.String,​java.lang.String> attributes  
      private java.util.List<Tag> children  
      private java.util.Map<java.lang.String,​java.lang.String> css  
      private java.lang.Object lastMarginBottom  
      private java.lang.String ns  
      private Tag parent  
      private java.lang.String tag  
    • Constructor Summary

      Constructors 
      Constructor Description
      Tag​(java.lang.String tag)  
      Tag​(java.lang.String tag, java.lang.String ns)
      Create a new tag object.
      Tag​(java.lang.String tag, java.util.Map<java.lang.String,​java.lang.String> attr)
      Construct a tag.
      Tag​(java.lang.String tag, java.util.Map<java.lang.String,​java.lang.String> attr, java.lang.String ns)
      Create a new tag object.
      Tag​(java.lang.String tag, java.util.Map<java.lang.String,​java.lang.String> attr, java.util.Map<java.lang.String,​java.lang.String> css, java.lang.String ns)  
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      void addChild​(Tag t)
      Add a child tag to this tag.
      boolean compareTag​(Tag t)
      Compare this tag with t for namespace and name equality.
      java.util.Map<java.lang.String,​java.lang.String> getAttributes()  
      Tag getChild​(java.lang.String name, java.lang.String ns)
      Finds the first child that matches the given name and namespace.
      Tag getChild​(java.lang.String name, java.lang.String ns, boolean recursive)
      Finds the first child that matches the given name and ns.
      java.util.List<Tag> getChildren()
      Returns all children of this tag.
      java.util.List<Tag> getChildren​(java.lang.String name)
      Returns all children of this tag with the given name.
      java.util.Map<java.lang.String,​java.lang.String> getCSS()
      Returns a Map of css property, value.
      java.lang.Object getLastMarginBottom()  
      java.lang.String getName()
      Returns the name of the tag.
      (Actually the same as getTag method, but after using XMLWorker for a while we caught ourself always trying to call Tag#getName() instead of Tag#getTag())
      java.lang.String getNameSpace()  
      Tag getParent()
      Returns the parent tag for this tag.
      java.lang.String getTag()
      Deprecated.
      marked as deprecated in favor for getName, we won't remove it yet.
      boolean hasChild​(java.lang.String name, java.lang.String ns)
      Check if this tag has a child with the given name and namespace.
      boolean hasChild​(java.lang.String name, java.lang.String ns, boolean recursive)
      Check if this tag has a child with the given name and namespace.
      boolean hasChildren()
      Whether or not this tag has children.
      boolean hasParent()
      Whether or not this tag has a parent.
      java.util.Iterator<Tag> iterator()  
      private Tag recursiveGetChild​(Tag tag, java.lang.String name, java.lang.String ns, boolean recursive)  
      private boolean recursiveHasChild​(Tag tag, java.lang.String name, java.lang.String ns, boolean recursive)  
      void setCSS​(java.util.Map<java.lang.String,​java.lang.String> css)
      Set the css map.
      void setLastMarginBottom​(java.lang.Object lastMarginBottom)  
      void setParent​(Tag parent)
      Set the tags parent tag.
      java.lang.String toString()
      Print the tag
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface java.lang.Iterable

        forEach, spliterator
    • Field Detail

      • parent

        private Tag parent
      • tag

        private final java.lang.String tag
      • attributes

        private final java.util.Map<java.lang.String,​java.lang.String> attributes
      • css

        private java.util.Map<java.lang.String,​java.lang.String> css
      • children

        private final java.util.List<Tag> children
      • ns

        private final java.lang.String ns
      • lastMarginBottom

        private java.lang.Object lastMarginBottom
    • Constructor Detail

      • Tag

        public Tag​(java.lang.String tag,
                   java.util.Map<java.lang.String,​java.lang.String> attr)
        Construct a tag.
        Parameters:
        tag - the tag name
        attr - the attributes in the tag
      • Tag

        public Tag​(java.lang.String tag)
        Parameters:
        tag - the tag name
      • Tag

        public Tag​(java.lang.String tag,
                   java.util.Map<java.lang.String,​java.lang.String> attr,
                   java.util.Map<java.lang.String,​java.lang.String> css,
                   java.lang.String ns)
        Parameters:
        tag - the tag name
        attr - the attributes
        css - a map with CSS
        ns - the namespace
      • Tag

        public Tag​(java.lang.String tag,
                   java.util.Map<java.lang.String,​java.lang.String> attr,
                   java.lang.String ns)
        Create a new tag object.
        Parameters:
        tag - the tag name
        attr - the attributes
        ns - the namespace
      • Tag

        public Tag​(java.lang.String tag,
                   java.lang.String ns)
        Create a new tag object.
        Parameters:
        tag - the name of the tag
        ns - the namespace of the tag (do not set null, set an empty String)
    • Method Detail

      • setParent

        public void setParent​(Tag parent)
        Set the tags parent tag.
        Parameters:
        parent - the parent tag of this tag
      • getParent

        public Tag getParent()
        Returns the parent tag for this tag.
        Returns:
        the parent tag or null if none
      • getTag

        @Deprecated
        public java.lang.String getTag()
        Deprecated.
        marked as deprecated in favor for getName, we won't remove it yet.
        The tags name.
        Returns:
        the tag name
      • getCSS

        public java.util.Map<java.lang.String,​java.lang.String> getCSS()
        Returns a Map of css property, value.
        Returns:
        the css, never null but can be an empty map.
      • setCSS

        public void setCSS​(java.util.Map<java.lang.String,​java.lang.String> css)
        Set the css map. If null is given the css is cleared.
        Parameters:
        css - set css properties
      • getAttributes

        public java.util.Map<java.lang.String,​java.lang.String> getAttributes()
        Returns:
        the attributes of the tag
      • addChild

        public void addChild​(Tag t)
        Add a child tag to this tag. The given tags parent is set to this tag.
        Parameters:
        t - the tag
      • getChildren

        public java.util.List<Tag> getChildren()
        Returns all children of this tag.
        Returns:
        the children tags of this tag.
      • getChildren

        public java.util.List<Tag> getChildren​(java.lang.String name)
        Returns all children of this tag with the given name.
        Parameters:
        name - the name of the tags to look for
        Returns:
        the children tags of this tag with the given name.
      • getNameSpace

        public java.lang.String getNameSpace()
        Returns:
        the ns
      • toString

        public java.lang.String toString()
        Print the tag
        Overrides:
        toString in class java.lang.Object
      • compareTag

        public boolean compareTag​(Tag t)
        Compare this tag with t for namespace and name equality.
        Parameters:
        t - the tag to compare with
        Returns:
        true if the namespace and tag are the same.
      • iterator

        public java.util.Iterator<Tag> iterator()
        Specified by:
        iterator in interface java.lang.Iterable<Tag>
        Returns:
        the child iterator.
      • getChild

        public Tag getChild​(java.lang.String name,
                            java.lang.String ns)
        Finds the first child that matches the given name and namespace.
        Parameters:
        name - the name of the tag
        ns - the namespace
        Returns:
        the child
      • getChild

        public Tag getChild​(java.lang.String name,
                            java.lang.String ns,
                            boolean recursive)
        Finds the first child that matches the given name and ns. Optionally look in the whole tree (in children of children of children ...)
        Parameters:
        name - name of the tag
        ns - the namespace
        recursive - true if the tree should be fully inwards inspected.
        Returns:
        the child if found
      • hasChildren

        public boolean hasChildren()
        Whether or not this tag has children.
        Returns:
        true if there are children
      • hasParent

        public boolean hasParent()
        Whether or not this tag has a parent.
        Returns:
        true if parent is not null
      • hasChild

        public boolean hasChild​(java.lang.String name,
                                java.lang.String ns)
        Check if this tag has a child with the given name and namespace.
        Parameters:
        name - the name of the tag to look for
        ns - the namespace (if no namespace, set an empty String)
        Returns:
        true if a child with given name and ns is found
      • hasChild

        public boolean hasChild​(java.lang.String name,
                                java.lang.String ns,
                                boolean recursive)
        Check if this tag has a child with the given name and namespace.
        Parameters:
        name - the name of the tag to look for
        ns - the namespace (if no namespace, set an empty String)
        recursive - true if children's children children children ... should be inspected too.
        Returns:
        true if a child with the given name and ns is found.
      • recursiveHasChild

        private boolean recursiveHasChild​(Tag tag,
                                          java.lang.String name,
                                          java.lang.String ns,
                                          boolean recursive)
        Parameters:
        tag -
        name -
        ns -
        recursive -
        Returns:
        true if the child is found in the child tree
      • recursiveGetChild

        private Tag recursiveGetChild​(Tag tag,
                                      java.lang.String name,
                                      java.lang.String ns,
                                      boolean recursive)
        Parameters:
        tag -
        name -
        ns -
        recursive -
        Returns:
        the child tag
      • getName

        public java.lang.String getName()
        Returns the name of the tag.
        (Actually the same as getTag method, but after using XMLWorker for a while we caught ourself always trying to call Tag#getName() instead of Tag#getTag())
        Returns:
        the name of the tag.
      • getLastMarginBottom

        public java.lang.Object getLastMarginBottom()
      • setLastMarginBottom

        public void setLastMarginBottom​(java.lang.Object lastMarginBottom)