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.| Modifier and Type | Class and Description |
|---|---|
| public static enum | |
| public static class |
| Modifier and Type | Field and Description |
|---|---|
| private List | |
| private boolean | |
| private boolean | |
| private boolean | |
| private boolean | |
| private boolean | |
| private boolean | |
| private IndentPrinter | |
| private int | |
| private boolean |
| Access | Constructor and Description |
|---|---|
| public | |
| public | |
| public | MarkupBuilder(Writer
the writer to use writer)Sends markup to the given Writer but first wrapping it in a PrintWriter |
| public |
| Modifier and Type | Method and Description |
|---|---|
| protected Object | |
| protected Object | |
| protected Object | createNode(Object name, Map<K, V> attributes, Object value)
Implements abstract groovy. |
| protected Object | createNode(Object name, Map<K, V> attributes)
Implements abstract groovy. |
| private String | Returns: A new string in which all characters that require escaping have been replaced with the corresponding XML entities.The string to escape. value)Escapes a string so that it can be used directly as an XML attribute value. |
| private String | Returns: A new string in which all characters that require escaping have been replaced with the corresponding XML entities.The string to escape. value)Escapes a string so that it can be used directly in XML element content. |
| private String | Returns: A new string in which all characters that require escaping have been replaced with the corresponding XML entities.The string to escape. value, boolean true if the string is to be used
as an attribute value, otherwise false.Escapes a string so that it can be used in XML text successfully. |
| public List | |
| public boolean | Returns: true if double quotes are used for attributesReturns |
| public MarkupBuilderHelper | Returns: this MarkupBuilderProperty that may be called from within your builder closure to access
helper methods, namely |
| protected Object | getName(String
the name of the desired method methodName)Overrides groovy. |
| private static Object | |
| protected IndentPrinter | |
| public boolean | Returns: the escapeAttributes property valueReturns the escapeAttributes property value. |
| public boolean | Returns: true, if empty elements will be represented by an opening tag
followed immediately by a closing tag.Whether empty elements are expanded from <tagName/> to <tagName></tagName>. |
| public boolean | Returns: true, if empty attributes will be
removed from the resulting markup.Determine whether empty attributes will appear in the produced markup. |
| public boolean | Returns: true, if null attributes will be
removed from the resulting markup.Determine whether null attributes will appear in the produced markup. |
| protected void | nodeCompleted(Object
the parent of the node being processed parent, Object the current node being processed node)Overrides groovy. |
| pack-priv void | |
| protected void | |
| public void | |
| public void | setDoubleQuotes(boolean
If this parameter is useDoubleQuotes)true,
double quotes are used; otherwise, single quotes are.Sets whether the builder outputs attribute values in double quotes or single quotes. |
| public void | |
| public void | setExpandEmptyElements(boolean
if expandEmptyElements)true, empty
elements will be represented by an opening tag
followed immediately by a closing tag.
Defaults to false.Whether empty elements are expanded from <tagName/> to <tagName></tagName>. |
| public void | setOmitEmptyAttributes(boolean
if omitEmptyAttributes)true, empty
attributes will not be included in the resulting markup.
Defaults to false.Allows empty attributes to be removed from the generated markup. |
| public void | setOmitNullAttributes(boolean
if omitNullAttributes)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.Allows null attributes to be removed from the generated markup. |
| protected void | |
| private void | |
| pack-priv void |
| additionalFilters | back to summary |
|---|---|
| private List<Function<Character, Optional<String>>> additionalFilters | |
| escapeAttributes | back to summary |
|---|---|
| private boolean escapeAttributes | |
| expandEmptyElements | back to summary |
|---|---|
| private boolean expandEmptyElements | |
| nodeIsEmpty | back to summary |
|---|---|
| private boolean nodeIsEmpty | |
| nospace | back to summary |
|---|---|
| private boolean nospace | |
| omitEmptyAttributes | back to summary |
|---|---|
| private boolean omitEmptyAttributes | |
| omitNullAttributes | back to summary |
|---|---|
| private boolean omitNullAttributes | |
| out | back to summary |
|---|---|
| private IndentPrinter out | |
| state | back to summary |
|---|---|
| private int state | |
| useDoubleQuotes | back to summary |
|---|---|
| private boolean useDoubleQuotes | |
| MarkupBuilder | back to summary |
|---|---|
| public MarkupBuilder() Prints markup to System.out
| |
| MarkupBuilder | back to summary |
|---|---|
| public MarkupBuilder(PrintWriter pw) Sends markup to the given PrintWriter
| |
| MarkupBuilder | back to summary |
|---|---|
| public MarkupBuilder(Writer writer) Sends markup to the given Writer but first wrapping it in a PrintWriter
| |
| MarkupBuilder | back to summary |
|---|---|
| public MarkupBuilder(IndentPrinter out) Sends markup to the given IndentPrinter. Use this option if you want to customize the indent used or provide your own IndentPrinter.
| |
| createNode | back to summary |
|---|---|
| protected Object createNode(Object name) Implements abstract groovy. | |
| createNode | back to summary |
|---|---|
| protected Object createNode(Object name, Object value) Implements abstract groovy. | |
| createNode | back to summary |
|---|---|
| protected Object createNode(Object name, Map<K, V> attributes, Object value) Implements abstract groovy. | |
| createNode | back to summary |
|---|---|
| protected Object createNode(Object name, Map<K, V> attributes) Implements abstract groovy. | |
| escapeAttributeValue | back to summary |
|---|---|
| private String escapeAttributeValue(String value) Escapes a string so that it can be used directly as an XML attribute value.
| |
| escapeElementContent | back to summary |
|---|---|
| private String escapeElementContent(String value) Escapes a string so that it can be used directly in XML element content.
| |
| escapeXmlValue | back to summary |
|---|---|
| private String escapeXmlValue(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:
| |
| getAdditionalFilters | back to summary |
|---|---|
| public List | |
| getDoubleQuotes | back to summary |
|---|---|
| public boolean getDoubleQuotes() Returns
| |
| getMkp | back to summary |
|---|---|
| public MarkupBuilderHelper getMkp() Property that may be called from within your builder closure to access
helper methods, namely
| |
| getName | back to summary |
|---|---|
| protected Object getName(String methodName) Overrides groovy. Doc from groovy. A hook to allow names to be converted into some other object such as a QName in XML or ObjectName in JMX. | |
| getName | back to summary |
|---|---|
| private static Object getName(Object name) | |
| getPrinter | back to summary |
|---|---|
| protected IndentPrinter getPrinter() | |
| isEscapeAttributes | back to summary |
|---|---|
| public boolean isEscapeAttributes() Returns the escapeAttributes property value.
| |
| isExpandEmptyElements | back to summary |
|---|---|
| public boolean isExpandEmptyElements() Whether empty elements are expanded from <tagName/> to <tagName></tagName>.
| |
| isOmitEmptyAttributes | back to summary |
|---|---|
| public boolean isOmitEmptyAttributes() Determine whether empty attributes will appear in the produced markup.
| |
| isOmitNullAttributes | back to summary |
|---|---|
| public boolean isOmitNullAttributes() Determine whether null attributes will appear in the produced markup.
| |
| nodeCompleted | back to summary |
|---|---|
| protected void nodeCompleted(Object parent, Object node) Overrides groovy. Doc from groovy. A hook to allow nodes to be processed once they have had all of their children applied. | |
| pi | back to summary |
|---|---|
| pack-priv void pi(Map<String, Map<String, Object>> args) Produce an XML processing instruction in the output. For example:
mkp.pi("xml-stylesheet":[href:"mystyle.css", type:"text/css"])
| |
| back to summary | |
|---|---|
| protected void print(Object node) | |
| setAdditionalFilters | back to summary |
|---|---|
| public void setAdditionalFilters(List<Function<Character, Optional<String>>> additionalFilters) | |
| setDoubleQuotes | back to summary |
|---|---|
| public void setDoubleQuotes(boolean useDoubleQuotes) Sets whether the builder outputs attribute values in double quotes or single quotes.
| |
| setEscapeAttributes | back to summary |
|---|---|
| public void setEscapeAttributes(boolean escapeAttributes) Defaults to true. If set to false then you must escape any special characters within attribute values such as '&', '<', CR/LF, single and double quotes etc. manually as needed. The builder will not guard against producing invalid XML when in this mode and the output may not be able to be parsed/round-tripped but it does give you full control when producing for instance HTML output.
| |
| setExpandEmptyElements | back to summary |
|---|---|
| public void setExpandEmptyElements(boolean expandEmptyElements) Whether empty elements are expanded from <tagName/> to <tagName></tagName>.
| |
| setOmitEmptyAttributes | back to summary |
|---|---|
| public void setOmitEmptyAttributes(boolean omitEmptyAttributes) Allows empty attributes to be removed from the generated markup.
| |
| setOmitNullAttributes | back to summary |
|---|---|
| public void setOmitNullAttributes(boolean omitNullAttributes) Allows null attributes to be removed from the generated markup.
| |
| setParent | back to summary |
|---|---|
| protected void setParent(Object parent, Object child) Implements abstract groovy. | |
| toState | back to summary |
|---|---|
| private void toState(int next, Object name) | |
| yield | back to summary |
|---|---|
| pack-priv void yield(String value, boolean escaping) | |
| Modifier and Type | Field and Description |
|---|---|
| public static final MarkupBuilder. | |
| public static final MarkupBuilder. | |
| public static final MarkupBuilder. |
| Access | Constructor and Description |
|---|---|
| private |
| Modifier and Type | Method and Description |
|---|---|
| public static MarkupBuilder. | |
| public static MarkupBuilder. |
| NONE | back to summary |
|---|---|
| public static final MarkupBuilder. | |
| XML_ALL | back to summary |
|---|---|
| public static final MarkupBuilder. | |
| XML_STRICT | back to summary |
|---|---|
| public static final MarkupBuilder. | |
| CharFilter | back to summary |
|---|---|
| private CharFilter() | |
| valueOf | back to summary |
|---|---|
| public static MarkupBuilder. | |
| values | back to summary |
|---|---|
| public static MarkupBuilder. | |
| Modifier and Type | Field and Description |
|---|---|
| private final Function | |
| private final boolean | |
| private final Function | |
| private final Function |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public Optional | apply(Character
the function argument ch)Implements java. |
| attrFilter | back to summary |
|---|---|
| private final Function<Character, Optional<String>> attrFilter | |
| isAttrValue | back to summary |
|---|---|
| private final boolean isAttrValue | |
| quoteFilter | back to summary |
|---|---|
| private final Function<Character, Optional<String>> quoteFilter | |
| stdFilter | back to summary |
|---|---|
| private final Function<Character, Optional<String>> stdFilter | |
| DefaultXmlEscapingFunction | back to summary |
|---|---|
| public DefaultXmlEscapingFunction(boolean isAttrValue, boolean useDoubleQuotes) | |
| apply | back to summary |
|---|---|
| public Optional Implements java. Doc from java. Applies this function to the given argument. | |