groovy.xml
Class MarkupBuilder

java.lang.Object
  extended by groovy.lang.GroovyObjectSupport
      extended by groovy.util.BuilderSupport
          extended by groovy.xml.MarkupBuilder
All Implemented Interfaces:
GroovyObject

public class MarkupBuilder
extends BuilderSupport

A helper class for creating XML or HTML markup

Version:
$Revision: 14219 $
Author:
James Strachan, Stefan Matthias Aust, Scott Stirling, Paul King

Field Summary
private  boolean nodeIsEmpty
           
private  boolean nospace
           
private  boolean omitEmptyAttributes
           
private  boolean omitNullAttributes
           
private  IndentPrinter out
           
private  int state
           
private  boolean useDoubleQuotes
           
 
Constructor Summary
MarkupBuilder()
           
MarkupBuilder(IndentPrinter out)
           
MarkupBuilder(java.io.PrintWriter writer)
           
MarkupBuilder(java.io.Writer writer)
           
 
Method Summary
protected  java.lang.Object createNode(java.lang.Object name)
           
protected  java.lang.Object createNode(java.lang.Object name, java.util.Map attributes)
           
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.lang.Object value)
           
private  java.lang.String escapeAttributeValue(java.lang.String value)
          Escapes a string so that it can be used directly as an XML attribute value.
private  java.lang.String escapeElementContent(java.lang.String value)
          Escapes a string so that it can be used directly in XML element content.
private  java.lang.String escapeXmlValue(java.lang.String value, boolean isAttrValue)
          Escapes a string so that it can be used in XML text successfully.
 boolean getDoubleQuotes()
          Returns true if attribute values are output with double quotes; false if single quotes are used.
 java.lang.Object getMkp()
           
private  java.lang.Object getName(java.lang.Object name)
           
protected  java.lang.Object getName(java.lang.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(java.lang.Object parent, java.lang.Object node)
          A hook to allow nodes to be processed once they have had all of their children applied.
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 setOmitEmptyAttributes(boolean omitEmptyAttributes)
          Allows empty attributes to be removed the produced markup.
 void setOmitNullAttributes(boolean omitNullAttributes)
          Allows null attributes to be removed the produced markup.
protected  void setParent(java.lang.Object parent, java.lang.Object child)
           
private  void toState(int next, java.lang.Object name)
           
protected  java.lang.String transformValue(java.lang.String value)
          Deprecated.  
 void yield(java.lang.String value)
           
private  void yield(java.lang.String value, boolean escaping)
           
 void yieldUnescaped(java.lang.String value)
           
 
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
 

Field Detail

out

private IndentPrinter out

nospace

private boolean nospace

state

private int state

nodeIsEmpty

private boolean nodeIsEmpty

useDoubleQuotes

private boolean useDoubleQuotes

omitNullAttributes

private boolean omitNullAttributes

omitEmptyAttributes

private boolean omitEmptyAttributes
Constructor Detail

MarkupBuilder

public MarkupBuilder()

MarkupBuilder

public MarkupBuilder(java.io.PrintWriter writer)

MarkupBuilder

public MarkupBuilder(java.io.Writer writer)

MarkupBuilder

public MarkupBuilder(IndentPrinter out)
Method Detail

getDoubleQuotes

public boolean getDoubleQuotes()
Returns true if attribute values are output with double quotes; false if single quotes are used. By default, single quotes are used.

Returns:
true if double quotes are used for attributes

setDoubleQuotes

public void setDoubleQuotes(boolean useDoubleQuotes)
Sets whether the builder outputs attribute values in double quotes or single quotes.

Parameters:
useDoubleQuotes - If this parameter is true, double quotes are used; otherwise, single quotes are.

isOmitNullAttributes

public boolean isOmitNullAttributes()
Determine whether null attributes will appear in the produced markup.

Returns:
true, if null attributes will be removed from the resulting markup.

setOmitNullAttributes

public void setOmitNullAttributes(boolean omitNullAttributes)
Allows null attributes to be removed the produced markup.

Parameters:
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.

isOmitEmptyAttributes

public boolean isOmitEmptyAttributes()
Determine whether empty attributes will appear in the produced markup.

Returns:
true, if empty attributes will be removed from the resulting markup.

setOmitEmptyAttributes

public void setOmitEmptyAttributes(boolean omitEmptyAttributes)
Allows empty attributes to be removed the produced markup.

Parameters:
omitEmptyAttributes - if true, empty attributes will not be included in the resulting markup. Defaults to false.

getPrinter

protected IndentPrinter getPrinter()

setParent

protected void setParent(java.lang.Object parent,
                         java.lang.Object child)
Specified by:
setParent in class BuilderSupport

getMkp

public java.lang.Object getMkp()

yield

public void yield(java.lang.String value)

yieldUnescaped

public void yieldUnescaped(java.lang.String value)

yield

private void yield(java.lang.String value,
                   boolean escaping)

createNode

protected java.lang.Object createNode(java.lang.Object name)
Specified by:
createNode in class BuilderSupport

createNode

protected java.lang.Object createNode(java.lang.Object name,
                                      java.lang.Object value)
Specified by:
createNode in class BuilderSupport

createNode

protected java.lang.Object createNode(java.lang.Object name,
                                      java.util.Map attributes,
                                      java.lang.Object value)
Specified by:
createNode in class BuilderSupport

createNode

protected java.lang.Object createNode(java.lang.Object name,
                                      java.util.Map attributes)
Specified by:
createNode in class BuilderSupport

nodeCompleted

protected void nodeCompleted(java.lang.Object parent,
                             java.lang.Object node)
Description copied from class: BuilderSupport
A hook to allow nodes to be processed once they have had all of their children applied.

Overrides:
nodeCompleted in class BuilderSupport
Parameters:
parent - the parent of the node being processed
node - the current node being processed

print

protected void print(java.lang.Object node)

getName

protected java.lang.Object getName(java.lang.String methodName)
Description copied from class: BuilderSupport
A hook to allow names to be converted into some other object such as a QName in XML or ObjectName in JMX.

Overrides:
getName in class BuilderSupport
Parameters:
methodName - the name of the desired method
Returns:
the object representing the name

transformValue

protected java.lang.String transformValue(java.lang.String value)
Deprecated. 

Returns a String with special XML characters escaped as entities so that output XML is valid. Escapes the following characters as corresponding entities:

Parameters:
value - to be searched and replaced for XML special characters.
Returns:
value with XML characters escaped
See Also:
escapeXmlValue(String, boolean)

escapeAttributeValue

private java.lang.String escapeAttributeValue(java.lang.String value)
Escapes a string so that it can be used directly as an XML attribute value.

Parameters:
value - The string to escape.
Returns:
A new string in which all characters that require escaping have been replaced with the corresponding XML entities.
See Also:
escapeXmlValue(String, boolean)

escapeElementContent

private java.lang.String escapeElementContent(java.lang.String value)
Escapes a string so that it can be used directly in XML element content.

Parameters:
value - The string to escape.
Returns:
A new string in which all characters that require escaping have been replaced with the corresponding XML entities.
See Also:
escapeXmlValue(String, boolean)

escapeXmlValue

private java.lang.String escapeXmlValue(java.lang.String value,
                                        boolean isAttrValue)
Escapes a string so that it can be used in XML text successfully. It replaces the following characters with the corresponding XML entities: If the string is to be added as an attribute value, these characters are also escaped:

Parameters:
value - The string to escape.
isAttrValue - true if the string is to be used as an attribute value, otherwise false.
Returns:
A new string in which all characters that require escaping have been replaced with the corresponding XML entities.

toState

private void toState(int next,
                     java.lang.Object name)

getName

private java.lang.Object getName(java.lang.Object name)


Copyright © ${year} The Codehaus. All Rights Reserved.