public static class WebUtils.Tag extends Object
WebUtils.Tag results = new WebUtils.Tag("results"); for (Record r: someResultsSet()) { WebUtils.Tag result = new WebUtils.Tag("result") .attr("id", r.getId()) .attr("status", r.getStatus()); results.addContent(result); } ...Invoking
results.toString()
might produce something like...
<results> <result id="11" status="normal" /> <result id="12" status="normal" /> <result id="13" status="unreachable" /> </results>
Note that this class is not intended as a replacement for more complete XML utilities such as JAXB.
Another example, this time HTML...
WebUtils.Tag table = new WebUtils.Tag("table").attr("width", "100%"); WebUtils.Tag tr = new WebUtils.Tag("tr"); table.addContent(tr); WebUtils.Tag td = new WebUtils.Tag("td").addContent("First Cell"); tr.addContent(td); td = new WebUtils.Tag("td").addContent("Second Cell"); tr.addContent(td);Invoking
table.toString()
will produce...
<table width="100%"> <tr> <td> First Cell </td> <td> Second Cell </td> </tr> </table>
Constructor and Description |
---|
WebUtils.Tag(String id)
Constructs a tag with the given id.
|
Modifier and Type | Method and Description |
---|---|
WebUtils.Tag |
addCData(String data)
Adds the specified string as content of this tag, but wrapped in a CDATA construct.
|
WebUtils.Tag |
addContent(String s)
Adds the specified string as verbatim content of this tag.
|
WebUtils.Tag |
addContent(String s,
boolean textInlining)
Adds the specified string as content of this tag.
|
WebUtils.Tag |
addContent(String s,
boolean textInlining,
boolean verbatim)
Adds the specified string as content of this tag.
|
WebUtils.Tag |
addContent(WebUtils.Tag tag)
Adds the specified tag as a child to this tag.
|
WebUtils.Tag |
attr(String name,
Object value)
Adds an attribute with the given name and value.
|
boolean |
hasContent()
Returns an indication whether or not the given tag has any content.
|
WebUtils.Tag |
noShorthand() |
String |
toString() |
public WebUtils.Tag(String id)
id
- the idpublic WebUtils.Tag attr(String name, Object value)
name
- the attribute namevalue
- the attribute valuepublic WebUtils.Tag noShorthand()
public WebUtils.Tag addContent(WebUtils.Tag tag)
shorthand
setting of this tag.tag
- the child tag to be added as contentpublic WebUtils.Tag addContent(String s, boolean textInlining)
<tag>content</tag>
s
- the string to be added as content.textInlining
- if true, the text content will be rendered on the same line as the tag/endtagpublic WebUtils.Tag addContent(String s, boolean textInlining, boolean verbatim)
<tag>content</tag>
s
- the string to be added as content.textInlining
- if true, the text content will be rendered on the same line as the tag/endtagverbatim
- if true, the text content will be inserted without any protective encodingpublic WebUtils.Tag addContent(String s)
s
- the string to be added as content.public WebUtils.Tag addCData(String data)
WebUtils.Tag tag = new WebUtils.Tag("record") .addCData("Some arbitrary data");This will result in the following...
<record> <![CDATA[Some arbitrary data]]> </record>
data
- the data to be inserted into a CDATA constructpublic boolean hasContent()
Copyright © 2015. All Rights Reserved.