public class Tag extends Object
| Constructor and Description |
|---|
Tag(String name,
Map<String,String> attributes) |
Tag(String name,
Map<String,String> attributes,
Object... contents) |
Tag(String name,
Map<String,String> attributes,
Object content)
Construct a new Tag with a name.
|
Tag(String name,
Object... contents) |
Tag(String name,
Object content)
Construct a new Tag with a name.
|
Tag(String name,
String[] attributes) |
Tag(String name,
String[] attributes,
Object... contents) |
Tag(String name,
String[] attributes,
Object content)
Construct a new Tag with a name and a set of attributes.
|
Tag(Tag parent,
String name,
Object... contents) |
Tag(Tag parent,
String name,
Object content) |
| Modifier and Type | Method and Description |
|---|---|
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(Map<String,?> map)
Add a new content tags.
|
Tag |
addContent(String string)
Add a new content string.
|
Tag |
addContent(Tag tag)
Add a new content tag.
|
String |
compact() |
static String |
escape(String s)
Escape a string, do entity conversion.
|
String |
findRecursiveAttribute(String name) |
static Tag |
fromDTO(String rootName,
Object dto)
Convert the DTO object in arguments to a Tag object with
rootName
as name. |
static Tag |
fromDTO(String rootName,
String arrayElementName,
Object dto)
Convert the DTO object in arguments to a Tag object with
rootName
as 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(StringBuilder sb)
convenient method to get the contents in a StringBuilder.
|
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.
|
String |
validate() |
public static final Pattern NAME_P
public Tag(String name, Map<String,String> attributes, Object content)
public Tag(String name, String[] attributes, Object content)
public Tag addAttribute(String key, Date value)
public static Tag fromDTO(String rootName, String arrayElementName, Object dto)
rootName
as name.
Keys in Map and public fields' name are used to name tags.
Objects in Collection or array are converted to
XML elements and tags names are computed as follow:
arrayElementName will be used.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)
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.
rootName - the name of the root tag, may be null.arrayElementName - a generic name for elements in lists, if
null or empty, the default value "element" will be
used.dto - the DTO to convert, if null an empty element is
returned.null.public static Tag fromDTO(String rootName, Object dto)
rootName
as name.
Keys in Map and public fields' name are used to name tags.
Objects in Collection or array are converted to
XML elements and tags names are computed as follow:
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.
rootName - the name of the root tag, may be null.dto - the DTO to convert, if null an empty element is
returned.null.public String getName()
public String getAttribute(String key, String deflt)
public Map<String,String> getAttributes()
public String toString()
public List<Object> getContents(String tag)
public String getContentsAsString()
public void getContentsAsString(StringBuilder sb)
public Tag print(int indent, PrintWriter pw)
public Collection<Tag> select(String path)
public Collection<Tag> select(String path, Tag mapping)
public String getStringContent()
public String getNameSpace()
public String getLocalName()
public void rename(String string)
public void setCDATA()
public String compact()
public String validate()
Copyright © 2021. All rights reserved.