aQute.lib.tag
Class Tag

java.lang.Object
  extended by aQute.lib.tag.Tag

public class Tag
extends 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.


Constructor Summary
Tag(String name, Map<String,String> attributes)
           
Tag(String name, Map<String,String> attributes, Object... contents)
          Construct a new Tag with a name.
Tag(String name, Object... contents)
          Construct a new Tag with a name.
Tag(String name, String[] attributes)
           
Tag(String name, String[] attributes, Object... contents)
          Construct a new Tag with a name and a set of attributes.
Tag(Tag parent, String name, Object... contents)
           
 
Method Summary
 Tag addAttribute(String key, Date value)
          Add a new date attribute.
 Tag addAttribute(String key, int value)
          Add a new attribute.
 Tag addAttribute(String key, Object value)
          Add a new attribute.
 Tag addAttribute(String key, String value)
          Add a new attribute.
 Tag addContent(String string)
          Add a new content string.
 Tag addContent(Tag tag)
          Add a new content tag.
 String findRecursiveAttribute(String name)
           
 String getAttribute(String key)
          Return the attribute value.
 String getAttribute(String key, String deflt)
          Return the attribute value or a default if not defined.
 Map<String,String> getAttributes()
          Answer the attributes as a Dictionary object.
 List<Object> getContents()
          Return the contents.
 List<Object> getContents(String tag)
          Return only the tags of the first level of descendants that match the name.
 String getContentsAsString()
          Return the whole contents as a String (no tag info and attributes).
 void getContentsAsString(StringBuffer sb)
          convenient method to get the contents in a StringBuffer.
 String getLocalName()
           
 String getName()
          Return the name of the tag.
 String getNameSpace()
           
 String getNameSpace(String name)
           
 String getString(String path)
           
 String getStringContent()
           
 boolean match(String search, Tag child, Tag mapping)
           
 Tag print(int indent, PrintWriter pw)
          Print the tag formatted to a PrintWriter.
 void rename(String string)
           
 Collection<Tag> select(String path)
          root/preferences/native/os
 Collection<Tag> select(String path, Tag mapping)
           
 void setCDATA()
           
 String toString()
          Return a string representation of this Tag and all its children recursively.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Tag

public Tag(String name,
           Object... contents)
Construct a new Tag with a name.


Tag

public Tag(Tag parent,
           String name,
           Object... contents)

Tag

public Tag(String name,
           Map<String,String> attributes,
           Object... contents)
Construct a new Tag with a name.


Tag

public Tag(String name,
           Map<String,String> attributes)

Tag

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


Tag

public Tag(String name,
           String[] attributes)
Method Detail

addAttribute

public Tag addAttribute(String key,
                        String value)
Add a new attribute.


addAttribute

public Tag addAttribute(String key,
                        Object value)
Add a new attribute.


addAttribute

public Tag addAttribute(String key,
                        int value)
Add a new attribute.


addAttribute

public Tag addAttribute(String key,
                        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(String string)
Add a new content string.


addContent

public Tag addContent(Tag tag)
Add a new content tag.


getName

public String getName()
Return the name of the tag.


getAttribute

public String getAttribute(String key)
Return the attribute value.


getAttribute

public String getAttribute(String key,
                           String deflt)
Return the attribute value or a default if not defined.


getAttributes

public Map<String,String> getAttributes()
Answer the attributes as a Dictionary object.


getContents

public List<Object> getContents()
Return the contents.


toString

public String toString()
Return a string representation of this Tag and all its children recursively.

Overrides:
toString in class Object

getContents

public List<Object> getContents(String tag)
Return only the tags of the first level of descendants that match the name.


getContentsAsString

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


getContentsAsString

public void getContentsAsString(StringBuffer sb)
convenient method to get the contents in a StringBuffer.


print

public Tag print(int indent,
                 PrintWriter pw)
Print the tag formatted to a PrintWriter.


select

public Collection<Tag> select(String path)
root/preferences/native/os


select

public Collection<Tag> select(String path,
                              Tag mapping)

match

public boolean match(String search,
                     Tag child,
                     Tag mapping)

getString

public String getString(String path)

getStringContent

public String getStringContent()

getNameSpace

public String getNameSpace()

getNameSpace

public String getNameSpace(String name)

findRecursiveAttribute

public String findRecursiveAttribute(String name)

getLocalName

public String getLocalName()

rename

public void rename(String string)

setCDATA

public void setCDATA()


Copyright © 2012 aQute SARL. All Rights Reserved.