Class Tag

java.lang.Object
com.itextpdf.tool.xml.Tag
All Implemented Interfaces:
Iterable<Tag>

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

  • Constructor Details

    • Tag

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

      public Tag(String tag)
      Parameters:
      tag - the tag name
    • Tag

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

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

      public Tag(String tag, 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 Details

    • 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 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 Map<String,String> getCSS()
      Returns a Map of css property, value.
      Returns:
      the css, never null but can be an empty map.
    • setCSS

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

      public Map<String,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 List<Tag> getChildren()
      Returns all children of this tag.
      Returns:
      the children tags of this tag.
    • getChildren

      public List<Tag> getChildren(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 String getNameSpace()
      Returns:
      the ns
    • toString

      public String toString()
      Print the tag
      Overrides:
      toString in class 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 Iterator<Tag> iterator()
      Specified by:
      iterator in interface Iterable<Tag>
      Returns:
      the child iterator.
    • getChild

      public Tag getChild(String name, 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(String name, 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(String name, 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(String name, 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, String name, 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, String name, String ns, boolean recursive)
      Parameters:
      tag -
      name -
      ns -
      recursive -
      Returns:
      the child tag
    • getName

      public 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 Object getLastMarginBottom()
    • setLastMarginBottom

      public void setLastMarginBottom(Object lastMarginBottom)