|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectgroovy.lang.GroovyObjectSupport
groovy.util.BuilderSupport
groovy.xml.MarkupBuilder
public class MarkupBuilder
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>Note that
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(IndentPrinter out)
Sends markup to the given IndentPrinter. |
|
MarkupBuilder(PrintWriter pw)
Sends markup to the given PrintWriter |
|
MarkupBuilder(Writer writer)
Sends markup to the given Writer but first wrapping it in a PrintWriter |
Method Summary | |
---|---|
protected Object |
createNode(Object name)
|
protected Object |
createNode(Object name,
Map attributes)
|
protected Object |
createNode(Object name,
Map attributes,
Object value)
|
protected Object |
createNode(Object name,
Object value)
|
boolean |
getDoubleQuotes()
Returns true if attribute values are output with
double quotes; false if single quotes are used. |
Object |
getMkp()
Property that may be called from within your builder closure to access helper methods, namely MarkupBuilderHelper.yield(String) ,
MarkupBuilderHelper.yieldUnescaped(String) ,
MarkupBuilderHelper.pi(Map) ,
MarkupBuilderHelper.xmlDeclaration(Map) and
MarkupBuilderHelper.comment(String) . |
protected Object |
getName(String methodName)
A hook to allow names to be converted into some other object such as a QName in XML or ObjectName in JMX. |
protected IndentPrinter |
getPrinter()
|
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(Object parent,
Object node)
A hook to allow nodes to be processed once they have had all of their children applied. |
protected void |
print(Object node)
|
void |
setDoubleQuotes(boolean useDoubleQuotes)
Sets whether the builder outputs attribute values in double quotes or single quotes. |
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(Object parent,
Object child)
|
protected String |
transformValue(String value)
Deprecated. |
Methods inherited from class groovy.util.BuilderSupport |
---|
doInvokeMethod, getCurrent, invokeMethod, invokeMethod, postNodeCompletion, setClosureDelegate, setCurrent |
Methods inherited from class groovy.lang.GroovyObjectSupport |
---|
getMetaClass, getProperty, setMetaClass, setProperty |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public MarkupBuilder()
IndentPrinter.IndentPrinter()
public MarkupBuilder(PrintWriter pw)
pw
- the PrintWriter to useIndentPrinter.IndentPrinter(PrintWriter)
public MarkupBuilder(Writer writer)
writer
- the writer to useIndentPrinter.IndentPrinter(PrintWriter)
public MarkupBuilder(IndentPrinter out)
out
- the IndentPrinter to useMethod Detail |
---|
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 void setDoubleQuotes(boolean useDoubleQuotes)
useDoubleQuotes
- If this parameter is true
,
double quotes are used; otherwise, single quotes are.public boolean isOmitNullAttributes()
true
, if null attributes will be
removed from the resulting markup.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
.public boolean isOmitEmptyAttributes()
true
, if empty attributes will be
removed from the resulting markup.public void setOmitEmptyAttributes(boolean omitEmptyAttributes)
omitEmptyAttributes
- if true
, empty
attributes will not be included in the resulting markup.
Defaults to false
.protected IndentPrinter getPrinter()
protected void setParent(Object parent, Object child)
setParent
in class BuilderSupport
public Object getMkp()
MarkupBuilderHelper.yield(String)
,
MarkupBuilderHelper.yieldUnescaped(String)
,
MarkupBuilderHelper.pi(Map)
,
MarkupBuilderHelper.xmlDeclaration(Map)
and
MarkupBuilderHelper.comment(String)
.
protected Object createNode(Object name)
createNode
in class BuilderSupport
protected Object createNode(Object name, Object value)
createNode
in class BuilderSupport
protected Object createNode(Object name, Map attributes, Object value)
createNode
in class BuilderSupport
protected Object createNode(Object name, Map attributes)
createNode
in class BuilderSupport
protected void nodeCompleted(Object parent, Object node)
BuilderSupport
nodeCompleted
in class BuilderSupport
parent
- the parent of the node being processednode
- the current node being processedprotected void print(Object node)
protected Object getName(String methodName)
BuilderSupport
getName
in class BuilderSupport
methodName
- the name of the desired method
protected String transformValue(String value)
value
- to be searched and replaced for XML special characters.
escapeXmlValue(String, boolean)
|
Copyright © 2003-2009 The Codehaus. All rights reserved. | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |