public class DomToGroovy
extends Object
A SAX handler for turning XML into Groovy scripts
| Modifiers | Name | Description |
|---|---|---|
protected boolean |
inMixed |
Whether the current element contains mixed text and element content. |
protected Collection<String> |
keywords |
Groovy keywords that must be quoted when emitted as method-style element names. |
protected IndentPrinter |
out |
Destination printer for the generated Groovy source. |
protected String |
qt |
Quote delimiter used for generated Groovy string literals. |
| Constructor and description |
|---|
DomToGroovy(PrintWriter out)Creates a converter that writes generated Groovy code to the supplied writer. |
DomToGroovy(IndentPrinter out)Creates a converter that writes generated Groovy code with the supplied indent printer. |
| Type Params | Return Type | Name and description |
|---|---|---|
|
protected boolean |
checkEscaping(String localName)Returns whether a generated Groovy name must be quoted. |
|
protected void |
defineNamespace(Map namespaces, String prefix, String uri)Records a namespace mapping and emits mkp.declareNamespace when needed. |
|
protected Map |
defineNamespaces(Element element, Map namespaces)Returns the namespace map extended with any newly encountered element or attribute prefixes. |
|
protected String |
escapeQuote(String text)Escapes backslashes and the active quote delimiter for generated Groovy strings. |
|
protected String |
getAttributeValue(Attr attribute)Returns the attribute value used when emitting the Groovy builder call. |
|
protected String |
getLocalName(Node node)Returns the trimmed local name for a DOM node, falling back to Node.getNodeName. |
|
protected String |
getTextNodeData(Text node)Returns the trimmed text content used when emitting a DOM text node. |
|
public static void |
main(String[] args)Command-line entry point that converts an XML file into a Groovy builder script. |
|
protected boolean |
mixedContent(NodeList list)Detects whether a node list contains both non-empty text and element children. |
|
protected static Document |
parse(String fileName)Parses the given XML file name into a DOM document. |
|
public static Document |
parse(File file)Parses the given XML file into a DOM document. |
|
public static Document |
parse(Reader input)Parses XML read from the supplied reader into a DOM document. |
|
public static Document |
parse(InputStream input)Parses XML read from the supplied stream into a DOM document. |
|
public void |
print(Document document)Writes the Groovy builder form of the supplied DOM document. |
|
protected void |
print(Node node, Map namespaces, boolean endWithComma)Dispatches a DOM node to the appropriate Groovy emission helper. |
|
protected void |
print(String text)Writes text through the configured indent printer. |
|
protected void |
printAttributeWithPrefix(Attr attribute, StringBuffer buffer)Appends a prefixed attribute representation to the deferred attribute buffer. |
|
protected boolean |
printAttributeWithoutPrefix(Attr attribute, boolean hasAttribute)Emits an unprefixed attribute and updates the separator state. |
|
protected boolean |
printAttributes(Element element)Emits the attributes for the supplied element. |
|
protected void |
printChildren(Node parent, Map namespaces)Emits all children of the supplied parent node. |
|
protected void |
printComment(Comment comment, boolean endWithComma)Emits a Groovy block comment for a non-empty DOM comment node. |
|
protected void |
printElement(Element element, Map namespaces, boolean endWithComma)Emits Groovy markup for a DOM element, including namespaces, attributes, and children. |
|
protected void |
printEnd(String text, boolean endWithComma)Finishes the current emitted fragment and optionally appends a comma. |
|
protected void |
printIndent()Writes the current indentation through the configured indent printer. |
|
protected void |
printPI(ProcessingInstruction instruction, boolean endWithComma)Emits a processing instruction as an mkp.pi call. |
|
protected void |
printQuoted(String text)Writes text as a Groovy string literal, using triple quotes for multi-line content. |
|
protected void |
printText(Text node, boolean endWithComma)Emits a text node, using mkp.yield when nested in mixed content. |
|
protected void |
println(String text)Writes a line through the configured indent printer. |
Whether the current element contains mixed text and element content.
Groovy keywords that must be quoted when emitted as method-style element names.
Destination printer for the generated Groovy source.
Quote delimiter used for generated Groovy string literals.
Creates a converter that writes generated Groovy code to the supplied writer.
out - destination writerCreates a converter that writes generated Groovy code with the supplied indent printer.
out - destination printerReturns whether a generated Groovy name must be quoted.
localName - candidate element or attribute nametrue if the name requires quoting Records a namespace mapping and emits mkp.declareNamespace when needed.
namespaces - mutable namespace mapprefix - namespace prefixuri - namespace URIReturns the namespace map extended with any newly encountered element or attribute prefixes.
element - element whose namespaces should be inspectednamespaces - namespaces currently in scopeEscapes backslashes and the active quote delimiter for generated Groovy strings.
text - raw textReturns the attribute value used when emitting the Groovy builder call.
attribute - attribute to inspectReturns the trimmed local name for a DOM node, falling back to Node.getNodeName.
node - DOM nodeReturns the trimmed text content used when emitting a DOM text node.
node - text nodeCommand-line entry point that converts an XML file into a Groovy builder script.
args - infilename [outfilename]Detects whether a node list contains both non-empty text and element children.
list - child nodes to inspecttrue for mixed contentParses the given XML file name into a DOM document.
fileName - XML file pathParses the given XML file into a DOM document.
file - XML fileParses XML read from the supplied reader into a DOM document.
input - XML readerParses XML read from the supplied stream into a DOM document.
input - XML streamWrites the Groovy builder form of the supplied DOM document.
document - source DOM documentDispatches a DOM node to the appropriate Groovy emission helper.
node - DOM node to emitnamespaces - namespaces currently in scopeendWithComma - whether to terminate the emitted fragment with a commaWrites text through the configured indent printer.
text - text to printAppends a prefixed attribute representation to the deferred attribute buffer.
attribute - attribute to renderbuffer - buffer collecting prefixed attributesEmits an unprefixed attribute and updates the separator state.
attribute - attribute to renderhasAttribute - whether a previous attribute has already been writtenEmits the attributes for the supplied element.
element - element whose attributes should be emittedtrue if any attributes were writtenEmits all children of the supplied parent node.
parent - DOM parent nodenamespaces - namespaces currently in scopeEmits a Groovy block comment for a non-empty DOM comment node.
comment - comment to emitendWithComma - whether to terminate the emitted fragment with a commaEmits Groovy markup for a DOM element, including namespaces, attributes, and children.
element - element to emitnamespaces - namespaces currently in scopeendWithComma - whether to terminate the emitted fragment with a commaFinishes the current emitted fragment and optionally appends a comma.
text - trailing text to emit before line terminationendWithComma - whether to append a commaWrites the current indentation through the configured indent printer.
Emits a processing instruction as an mkp.pi call.
instruction - processing instruction to emitendWithComma - whether to terminate the emitted fragment with a commaWrites text as a Groovy string literal, using triple quotes for multi-line content.
text - text to quote Emits a text node, using mkp.yield when nested in mixed content.
node - text node to emitendWithComma - whether to terminate the emitted fragment with a commaWrites a line through the configured indent printer.
text - line textCopyright © 2003-2026 The Apache Software Foundation. All rights reserved.