Package aQute.lib.tag
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
FieldsModifier and TypeFieldDescriptionprivate static final String
(package private) boolean
(package private) static final DateTimeFormatter
(package private) String
(package private) static final String
static final Pattern
(package private) static final String
(package private) static final String
(package private) Tag
-
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()
private static String
computeArrayElementName
(String name, String arrayElementName) private static Tag
convertDTO
(String rootName, String arrayElementName, Object dto, boolean suffix) static String
Escape a string, do entity conversion.findRecursiveAttribute
(String name) static Tag
Convert the DTO object in arguments to a Tag object withrootName
as name.static Tag
Convert the DTO object in arguments to a Tag object withrootName
as 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).void
convenient method to get the contents in a StringBuilder.getName()
Return the name of the tag.getNameSpace
(String name) private String
getPath()
(package private) boolean
private static boolean
boolean
print
(int indent, PrintWriter pw) Print the tag formatted to a PrintWriter.void
root/preferences/native/os(package private) void
void
setCDATA()
(package private) void
spaces
(PrintWriter pw, int n) Make spaces.toString()
Return a string representation of this Tag and all its children recursively.validate()
-
Field Details
-
Constructor Details
-
Tag
Construct a new Tag with a name. -
Tag
-
Tag
-
Tag
-
Tag
Construct a new Tag with a name. -
Tag
-
Tag
-
Tag
Construct a new Tag with a name and a set of attributes. The attributes are given as ( name, value ) ... -
Tag
-
Tag
-
-
Method Details
-
addAttribute
Add a new attribute. -
addAttribute
Add a new attribute. -
addAttribute
Add a new attribute. -
addAttribute
Add a new date attribute. The date is formatted by DATE_TIME_FORMATTER described at the top of this class. -
addContent
Add a new content string. -
addContent
Add a new content tag. -
addContent
Add a new content tags. -
fromDTO
Convert the DTO object in arguments to a Tag object withrootName
as name.Keys in
Map
and public fields' name are used to name tags.
Objects inCollection
orarray
are converted toXML
elements and tags names are computed as follow:- If the parent element tag does not have a defined name,
arrayElementName
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
arrayElementName
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,arrayElementName
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>
null
values are ignored.- Parameters:
rootName
- the name of the root tag, may benull
.arrayElementName
- a generic name for elements in lists, ifnull
or empty, the default value "element" will be used.dto
- the DTO to convert, ifnull
an 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 withrootName
as name.Keys in
Map
and public fields' name are used to name tags.
Objects inCollection
orarray
are converted toXML
elements 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>
null
values are ignored.- Parameters:
rootName
- the name of the root tag, may benull
.dto
- the DTO to convert, ifnull
an empty element is returned.- Returns:
- the corresponding Tag, never
null
.
-
convertDTO
-
computeArrayElementName
-
isComplex
-
getFields
-
getName
Return the name of the tag. -
getAttribute
Return the attribute value. -
getAttribute
Return the attribute value or a default if not defined. -
getAttributes
Answer the attributes as a Dictionary object. -
getContents
Return the contents. -
toString
Return a string representation of this Tag and all its children recursively. -
getContents
Return only the tags of the first level of descendants that match the name. -
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
Escape a string, do entity conversion. -
spaces
Make spaces. -
select
root/preferences/native/os -
select
-
select
-
match
-
getString
-
getStringContent
-
getNameSpace
-
getNameSpace
-
findRecursiveAttribute
-
getLocalName
-
rename
-
setCDATA
public void setCDATA() -
compact
-
validate
-
invalid
-
getPath
-