Package aQute.lib.tag
Class Tag
- java.lang.Object
-
- aQute.lib.tag.Tag
-
public class Tag extends java.lang.ObjectThe 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.PatternNAME_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 TagaddAttribute(java.lang.String key, int value)Add a new attribute.TagaddAttribute(java.lang.String key, java.lang.Object value)Add a new attribute.TagaddAttribute(java.lang.String key, java.lang.String value)Add a new attribute.TagaddAttribute(java.lang.String key, java.util.Date value)Add a new date attribute.TagaddContent(Tag tag)Add a new content tag.TagaddContent(java.lang.String string)Add a new content string.java.lang.Stringcompact()static java.lang.Stringescape(java.lang.String s)Escape a string, do entity conversion.java.lang.StringfindRecursiveAttribute(java.lang.String name)java.lang.StringgetAttribute(java.lang.String key)Return the attribute value.java.lang.StringgetAttribute(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.StringgetContentsAsString()Return the whole contents as a String (no tag info and attributes).voidgetContentsAsString(java.lang.StringBuilder sb)convenient method to get the contents in a StringBuilder.java.lang.StringgetLocalName()java.lang.StringgetName()Return the name of the tag.java.lang.StringgetNameSpace()java.lang.StringgetNameSpace(java.lang.String name)java.lang.StringgetString(java.lang.String path)java.lang.StringgetStringContent()booleanmatch(java.lang.String search, Tag child, Tag mapping)Tagprint(int indent, java.io.PrintWriter pw)Print the tag formatted to a PrintWriter.voidrename(java.lang.String string)java.util.Collection<Tag>select(java.lang.String path)root/preferences/native/osjava.util.Collection<Tag>select(java.lang.String path, Tag mapping)voidsetCDATA()java.lang.StringtoString()Return a string representation of this Tag and all its children recursively.java.lang.Stringvalidate()
-
-
-
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.
-
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:
toStringin classjava.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
-
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()
-
-