|
Groovy Documentation | |||||||
FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object groovy.lang.GroovyObjectSupport groovy.util.BuilderSupport groovy.xml.MarkupBuilder
public class MarkupBuilder extends BuilderSupport
A helper class for creating XML or HTML markup. The builder supports various 'pretty printed' formats.
Example:
new MarkupBuilder().root { a( a1:'one' ) { b { mkp.yield( '3 < 5' ) } c( a2:'two', 'blah' ) } }Will print the following to System.out:
<root> <a a1='one'> <b>3 < 5</b> <c a2='two'>blah</c> </a> </root>Notes:
mkp
is a special namespace used to escape
away from the normal building mode of the builder and get access
to helper markup methods such as 'yield' and 'yieldUnescaped'.
See the javadoc for getMkp() for further details.Constructor Summary | |
MarkupBuilder()
Prints markup to System.out |
|
MarkupBuilder(java.io.PrintWriter pw)
Sends markup to the given PrintWriter |
|
MarkupBuilder(java.io.Writer writer)
Sends markup to the given Writer but first wrapping it in a PrintWriter |
|
MarkupBuilder(IndentPrinter out)
Sends markup to the given IndentPrinter. |
Method Summary | |
---|---|
protected java.lang.Object
|
createNode(java.lang.Object name)
|
protected java.lang.Object
|
createNode(java.lang.Object name, java.lang.Object value)
|
protected java.lang.Object
|
createNode(java.lang.Object name, java.util.Map attributes, java.lang.Object value)
|
protected java.lang.Object
|
createNode(java.lang.Object name, java.util.Map attributes)
|
boolean
|
getDoubleQuotes()
Returns |
java.lang.Object
|
getMkp()
Property that may be called from within your builder closure to access helper methods, namely MarkupBuilderHelper.yield, MarkupBuilderHelper.yieldUnescaped, MarkupBuilderHelper.pi, MarkupBuilderHelper.xmlDeclaration and MarkupBuilderHelper.comment. |
protected java.lang.Object
|
getName(java.lang.String methodName)
|
protected IndentPrinter
|
getPrinter()
|
boolean
|
isEscapeAttributes()
Returns the escapeAttributes property value. |
boolean
|
isExpandEmptyElements()
Whether empty elements are expanded from <tagName/> to <tagName></tagName>. |
boolean
|
isOmitEmptyAttributes()
Determine whether empty attributes will appear in the produced markup. |
boolean
|
isOmitNullAttributes()
Determine whether null attributes will appear in the produced markup. |
protected void
|
nodeCompleted(java.lang.Object parent, java.lang.Object node)
|
protected void
|
print(java.lang.Object node)
|
void
|
setDoubleQuotes(boolean useDoubleQuotes)
Sets whether the builder outputs attribute values in double quotes or single quotes. |
void
|
setEscapeAttributes(boolean escapeAttributes)
Defaults to true. |
void
|
setExpandEmptyElements(boolean expandEmptyElements)
Whether empty elements are expanded from |
void
|
setOmitEmptyAttributes(boolean omitEmptyAttributes)
Allows empty attributes to be removed from the generated markup. |
void
|
setOmitNullAttributes(boolean omitNullAttributes)
Allows null attributes to be removed from the generated markup. |
protected void
|
setParent(java.lang.Object parent, java.lang.Object child)
|
Methods inherited from class BuilderSupport | |
---|---|
createNode, createNode, createNode, createNode, doInvokeMethod, getCurrent, getName, invokeMethod, invokeMethod, nodeCompleted, postNodeCompletion, setClosureDelegate, setCurrent, setParent |
Methods inherited from class GroovyObjectSupport | |
---|---|
getMetaClass, getProperty, invokeMethod, setMetaClass, setProperty |
Methods inherited from class java.lang.Object | |
---|---|
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
Constructor Detail |
---|
public MarkupBuilder()
public MarkupBuilder(java.io.PrintWriter pw)
pw
- the PrintWriter to use
public MarkupBuilder(java.io.Writer writer)
writer
- the writer to use
public MarkupBuilder(IndentPrinter out)
out
- the IndentPrinter to use
Method Detail |
---|
protected java.lang.Object createNode(java.lang.Object name)
protected java.lang.Object createNode(java.lang.Object name, java.lang.Object value)
protected java.lang.Object createNode(java.lang.Object name, java.util.Map attributes, java.lang.Object value)
protected java.lang.Object createNode(java.lang.Object name, java.util.Map attributes)
public boolean getDoubleQuotes()
true
if attribute values are output with
double quotes; false
if single quotes are used.
By default, single quotes are used.
public java.lang.Object getMkp()
protected java.lang.Object getName(java.lang.String methodName)
protected IndentPrinter getPrinter()
public boolean isEscapeAttributes()
public boolean isExpandEmptyElements()
true
, if empty elements will be represented by an opening tag
followed immediately by a closing tag.
public boolean isOmitEmptyAttributes()
true
, if empty attributes will be
removed from the resulting markup.
public boolean isOmitNullAttributes()
true
, if null attributes will be
removed from the resulting markup.
protected void nodeCompleted(java.lang.Object parent, java.lang.Object node)
protected void print(java.lang.Object node)
public void setDoubleQuotes(boolean useDoubleQuotes)
useDoubleQuotes
- If this parameter is true
,
double quotes are used; otherwise, single quotes are.
public void setEscapeAttributes(boolean escapeAttributes)
escapeAttributes
- the new value
public void setExpandEmptyElements(boolean expandEmptyElements)
expandEmptyElements
- if true
, empty
elements will be represented by an opening tag
followed immediately by a closing tag.
Defaults to false
.
public void setOmitEmptyAttributes(boolean omitEmptyAttributes)
omitEmptyAttributes
- if true
, empty
attributes will not be included in the resulting markup.
Defaults to false
.
public void setOmitNullAttributes(boolean omitNullAttributes)
omitNullAttributes
- if true
, null
attributes will not be included in the resulting markup.
If false
null attributes will be included in the
markup as empty strings regardless of the omitEmptyAttribute
setting. Defaults to false
.
protected void setParent(java.lang.Object parent, java.lang.Object child)
Groovy Documentation