Package aQute.lib.tag

Class Tag


  • public class Tag
    extends java.lang.Object
    The Tag class represents a minimal XML tree. It consist of a named element with a hashtable of named attributes. Methods are provided to walk the tree and get its constituents. The content of a Tag is a list that contains String objects or other Tag objects.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.util.regex.Pattern NAME_P  
    • Constructor Summary

      Constructors 
      Constructor Description
      Tag​(Tag parent, java.lang.String name, java.lang.Object... contents)  
      Tag​(java.lang.String name, java.lang.Object... contents)
      Construct a new Tag with a name.
      Tag​(java.lang.String name, java.lang.String[] attributes)  
      Tag​(java.lang.String name, java.lang.String[] attributes, java.lang.Object... contents)
      Construct a new Tag with a name and a set of attributes.
      Tag​(java.lang.String name, java.util.Map<java.lang.String,​java.lang.String> attributes)  
      Tag​(java.lang.String name, java.util.Map<java.lang.String,​java.lang.String> attributes, java.lang.Object... contents)
      Construct a new Tag with a name.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Tag addAttribute​(java.lang.String key, int value)
      Add a new attribute.
      Tag addAttribute​(java.lang.String key, java.lang.Object value)
      Add a new attribute.
      Tag addAttribute​(java.lang.String key, java.lang.String value)
      Add a new attribute.
      Tag addAttribute​(java.lang.String key, java.util.Date value)
      Add a new date attribute.
      Tag addContent​(Tag tag)
      Add a new content tag.
      Tag addContent​(java.lang.String string)
      Add a new content string.
      java.lang.String compact()  
      static java.lang.String escape​(java.lang.String s)
      Escape a string, do entity conversion.
      java.lang.String findRecursiveAttribute​(java.lang.String name)  
      java.lang.String getAttribute​(java.lang.String key)
      Return the attribute value.
      java.lang.String getAttribute​(java.lang.String key, java.lang.String deflt)
      Return the attribute value or a default if not defined.
      java.util.Map<java.lang.String,​java.lang.String> getAttributes()
      Answer the attributes as a Dictionary object.
      java.util.List<java.lang.Object> getContents()
      Return the contents.
      java.util.List<java.lang.Object> getContents​(java.lang.String tag)
      Return only the tags of the first level of descendants that match the name.
      java.lang.String getContentsAsString()
      Return the whole contents as a String (no tag info and attributes).
      void getContentsAsString​(java.lang.StringBuilder sb)
      convenient method to get the contents in a StringBuilder.
      java.lang.String getLocalName()  
      java.lang.String getName()
      Return the name of the tag.
      java.lang.String getNameSpace()  
      java.lang.String getNameSpace​(java.lang.String name)  
      java.lang.String getString​(java.lang.String path)  
      java.lang.String getStringContent()  
      boolean match​(java.lang.String search, Tag child, Tag mapping)  
      Tag print​(int indent, java.io.PrintWriter pw)
      Print the tag formatted to a PrintWriter.
      void rename​(java.lang.String string)  
      java.util.Collection<Tag> select​(java.lang.String path)
      root/preferences/native/os
      java.util.Collection<Tag> select​(java.lang.String path, Tag mapping)  
      void setCDATA()  
      java.lang.String toString()
      Return a string representation of this Tag and all its children recursively.
      java.lang.String validate()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • NAME_P

        public static final java.util.regex.Pattern NAME_P
    • Constructor Detail

      • Tag

        public Tag​(java.lang.String name,
                   java.lang.Object... contents)
        Construct a new Tag with a name.
      • Tag

        public Tag​(Tag parent,
                   java.lang.String name,
                   java.lang.Object... contents)
      • Tag

        public Tag​(java.lang.String name,
                   java.util.Map<java.lang.String,​java.lang.String> attributes,
                   java.lang.Object... contents)
        Construct a new Tag with a name.
      • Tag

        public Tag​(java.lang.String name,
                   java.util.Map<java.lang.String,​java.lang.String> attributes)
      • Tag

        public Tag​(java.lang.String name,
                   java.lang.String[] attributes,
                   java.lang.Object... contents)
        Construct a new Tag with a name and a set of attributes. The attributes are given as ( name, value ) ...
      • Tag

        public Tag​(java.lang.String name,
                   java.lang.String[] attributes)
    • Method Detail

      • addAttribute

        public Tag addAttribute​(java.lang.String key,
                                java.lang.String value)
        Add a new attribute.
      • addAttribute

        public Tag addAttribute​(java.lang.String key,
                                java.lang.Object value)
        Add a new attribute.
      • addAttribute

        public Tag addAttribute​(java.lang.String key,
                                int value)
        Add a new attribute.
      • addAttribute

        public Tag addAttribute​(java.lang.String key,
                                java.util.Date value)
        Add a new date attribute. The date is formatted as the SimpleDateFormat describes at the top of this class.
      • addContent

        public Tag addContent​(java.lang.String string)
        Add a new content string.
      • addContent

        public Tag addContent​(Tag tag)
        Add a new content tag.
      • getName

        public java.lang.String getName()
        Return the name of the tag.
      • getAttribute

        public java.lang.String getAttribute​(java.lang.String key)
        Return the attribute value.
      • getAttribute

        public java.lang.String getAttribute​(java.lang.String key,
                                             java.lang.String deflt)
        Return the attribute value or a default if not defined.
      • getAttributes

        public java.util.Map<java.lang.String,​java.lang.String> getAttributes()
        Answer the attributes as a Dictionary object.
      • getContents

        public java.util.List<java.lang.Object> getContents()
        Return the contents.
      • toString

        public java.lang.String toString()
        Return a string representation of this Tag and all its children recursively.
        Overrides:
        toString in class java.lang.Object
      • getContents

        public java.util.List<java.lang.Object> getContents​(java.lang.String tag)
        Return only the tags of the first level of descendants that match the name.
      • getContentsAsString

        public java.lang.String getContentsAsString()
        Return the whole contents as a String (no tag info and attributes).
      • getContentsAsString

        public void getContentsAsString​(java.lang.StringBuilder sb)
        convenient method to get the contents in a StringBuilder.
      • print

        public Tag print​(int indent,
                         java.io.PrintWriter pw)
        Print the tag formatted to a PrintWriter.
      • escape

        public static java.lang.String escape​(java.lang.String s)
        Escape a string, do entity conversion.
      • select

        public java.util.Collection<Tag> select​(java.lang.String path)
        root/preferences/native/os
      • select

        public java.util.Collection<Tag> select​(java.lang.String path,
                                                Tag mapping)
      • match

        public boolean match​(java.lang.String search,
                             Tag child,
                             Tag mapping)
      • getString

        public java.lang.String getString​(java.lang.String path)
      • getStringContent

        public java.lang.String getStringContent()
      • getNameSpace

        public java.lang.String getNameSpace()
      • getNameSpace

        public java.lang.String getNameSpace​(java.lang.String name)
      • findRecursiveAttribute

        public java.lang.String findRecursiveAttribute​(java.lang.String name)
      • getLocalName

        public java.lang.String getLocalName()
      • rename

        public void rename​(java.lang.String string)
      • setCDATA

        public void setCDATA()
      • compact

        public java.lang.String compact()
      • validate

        public java.lang.String validate()