Class Tag
java.lang.Object
aQute.lib.tag.Tag
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 -
Constructor Summary
ConstructorsConstructorDescriptionConstruct a new Tag with a name.Construct a new Tag with a name and a set of attributes.Construct a new Tag with a name. -
Method Summary
Modifier and TypeMethodDescriptionaddAttribute(String key, int value) Add a new attribute.addAttribute(String key, Object value) Add a new attribute.addAttribute(String key, String value) Add a new attribute.addAttribute(String key, Date value) Add a new date attribute.addContent(Tag tag) Add a new content tag.addContent(String string) Add a new content string.addContent(Map<String, ?> map) Add a new content tags.compact()static StringEscape a string, do entity conversion.findRecursiveAttribute(String name) static TagConvert the DTO object in arguments to a Tag object withrootNameas name.static TagConvert the DTO object in arguments to a Tag object withrootNameas name.getAttribute(String key) Return the attribute value.getAttribute(String key, String deflt) Return the attribute value or a default if not defined.Answer the attributes as a Dictionary object.Return the contents.getContents(String tag) Return only the tags of the first level of descendants that match the name.Return the whole contents as a String (no tag info and attributes).voidconvenient method to get the contents in a StringBuilder.getName()Return the name of the tag.getNameSpace(String name) booleanprint(int indent, PrintWriter pw) Print the tag formatted to a PrintWriter.voidroot/preferences/native/osvoidsetCDATA()toString()Return a string representation of this Tag and all its children recursively.validate()
-
Field Details
-
NAME_P
-
-
Constructor Details
-
Tag
-
Tag
-
Tag
-
Tag
-
Tag
-
Tag
-
Tag
-
Tag
-
Tag
-
Tag
-
-
Method Details
-
addAttribute
-
addAttribute
-
addAttribute
-
addAttribute
-
addContent
-
addContent
-
addContent
-
fromDTO
Convert the DTO object in arguments to a Tag object withrootNameas name.Keys in
Mapand public fields' name are used to name tags.
Objects inCollectionorarrayare converted toXMLelements and tags names are computed as follow:- If the parent element tag does not have a defined name,
arrayElementNamewill be used. - If the parent element tag name ends with a 's' or 'S', the depluralized version will be used.
- Otherwise, the first letter of
arrayElementNameis capitalized and appended to the parent element tag name to name the tag (If the parent element tag name does not end with a lowercase letter,arrayElementNameis entirely capitalized and an '_' is first appended to to it)
Example:
fromDTO("things", "element", `[{"FRIEND": ["Amy"]},{"children": ["Emily"]},["Bob", "Bill"]]`)gives<things> <thing> <FRIEND> <FRIEND_ELEMENT>Amy</FRIEND_ELEMENT> </FRIEND> <children> <childrenElement>Emily</childrenElement> </children> </thing> <thing> <element>Bob</element> <element>Bill</element> </thing> </things>nullvalues are ignored.- Parameters:
rootName- the name of the root tag, may benull.arrayElementName- a generic name for elements in lists, ifnullor empty, the default value "element" will be used.dto- the DTO to convert, ifnullan empty element is returned.- Returns:
- the corresponding Tag, never
null.
- If the parent element tag does not have a defined name,
-
fromDTO
Convert the DTO object in arguments to a Tag object withrootNameas name.Keys in
Mapand public fields' name are used to name tags.
Objects inCollectionorarrayare converted toXMLelements and tags names are computed as follow:- If the parent element tag does not have a defined name, "element" will be used.
- If the parent element tag name ends with a 's' or 'S', the depluralized version will be used.
- Otherwise, the first letter of "element" is capitalized and appended to the parent element tag name to name the tag (If the parent element tag name does not end with a lowercase letter, "element" is entirely capitalized and an '_' is first appended to to it)
Example:
fromDTO("things", "element", `[{"FRIEND": ["Amy"]},{"children": ["Emily"]},["Bob", "Bill"]]`)gives<things> <thing> <FRIEND> <FRIEND_ELEMENT>Amy</FRIEND_ELEMENT> </FRIEND> <children> <childrenElement>Emily</childrenElement> </children> </thing> <thing> <element>Bob</element> <element>Bill</element> </thing> </things>nullvalues are ignored.- Parameters:
rootName- the name of the root tag, may benull.dto- the DTO to convert, ifnullan empty element is returned.- Returns:
- the corresponding Tag, never
null.
-
getName
Return the name of the tag. -
getAttribute
-
getAttribute
-
getAttributes
-
getContents
-
toString
-
getContents
-
getContentsAsString
Return the whole contents as a String (no tag info and attributes). -
getContentsAsString
convenient method to get the contents in a StringBuilder. -
print
Print the tag formatted to a PrintWriter. -
escape
-
select
root/preferences/native/os -
select
-
match
-
getString
-
getStringContent
-
getNameSpace
-
getNameSpace
-
findRecursiveAttribute
-
getLocalName
-
rename
-
setCDATA
public void setCDATA() -
compact
-
validate
-