public class XMLGeneratorVisitor extends AbstractDepthFirstVisitor
AbstractDepthFirstVisitor
which can generate XML out of a NodeElement
.
Accepts a PrintWriter
in the constructor and uses it to output the generated XML.
Output can be controlled by enabling/disabling the various options present in XMLGeneratorVisitor.OutputBehavior
by calling
enableOutputBehavior(OutputBehavior)
or disableOutputBehavior(OutputBehavior)
Modifier and Type | Class and Description |
---|---|
static class |
XMLGeneratorVisitor.OutputBehavior
Enum controlling the generated XML output
|
Modifier and Type | Field and Description |
---|---|
private java.util.Map<XMLGeneratorVisitor.OutputBehavior,java.lang.Boolean> |
enabledOutputBehaviors |
private int |
indent |
private java.io.PrintWriter |
out |
private NodeElement |
rootElement |
private static java.lang.String |
SPACER |
private boolean |
visitedFirstElement |
Constructor and Description |
---|
XMLGeneratorVisitor(java.io.PrintWriter out)
Constructor accepting the
PrintWriter . |
Modifier and Type | Method and Description |
---|---|
void |
disableAllOutputBehaviors()
Disables all output behaviors
|
void |
disableOutputBehavior(XMLGeneratorVisitor.OutputBehavior behavior)
Disables one particular
XMLGeneratorVisitor.OutputBehavior |
void |
enableAllOutputBehaviors()
Enables all output behaviors
|
void |
enableOutputBehavior(XMLGeneratorVisitor.OutputBehavior behavior)
Enables one particular
XMLGeneratorVisitor.OutputBehavior |
protected void |
endAttributes(NodeElement element)
Finish visiting attributes of the element.
|
protected void |
endChildren(NodeElement element)
Finish visiting children of the element.
|
protected void |
endElement(NodeElement element)
Finish visiting the element.
|
private void |
indentBackward() |
private void |
indentForward() |
boolean |
isOutputBehaviorEnabled(XMLGeneratorVisitor.OutputBehavior behavior)
Returns true if the output behavior is enabled
|
private void |
newLine() |
private void |
print(java.lang.String string) |
private void |
printWithoutSpacer(java.lang.String string) |
private java.lang.String |
spacer() |
protected void |
startAttributes(NodeElement element)
Starts visiting the attributes of the element.
|
protected void |
startChildren(NodeElement element)
Starts visiting children of the element.
|
protected void |
startElement(NodeElement element)
Starts visiting an element.
|
protected void |
visitAttribute(NodeElement element,
NodeAttribute attribute)
Visits an attribute.
|
protected void |
visitAttributes(NodeElement element,
java.util.List<NodeAttribute> attributes)
Visits the attributes of the element.
|
protected void |
visitElement(NodeElement element)
Visits the element.
|
visit
private static final java.lang.String SPACER
private final java.util.Map<XMLGeneratorVisitor.OutputBehavior,java.lang.Boolean> enabledOutputBehaviors
private final java.io.PrintWriter out
private int indent
private NodeElement rootElement
private boolean visitedFirstElement
public XMLGeneratorVisitor(java.io.PrintWriter out)
PrintWriter
. All output behaviors are enabled by default.out
- the PrintWriter
public void enableAllOutputBehaviors()
public void disableAllOutputBehaviors()
public void enableOutputBehavior(XMLGeneratorVisitor.OutputBehavior behavior)
XMLGeneratorVisitor.OutputBehavior
behavior
- public void disableOutputBehavior(XMLGeneratorVisitor.OutputBehavior behavior)
XMLGeneratorVisitor.OutputBehavior
behavior
- public boolean isOutputBehaviorEnabled(XMLGeneratorVisitor.OutputBehavior behavior)
behavior
- the output behavior to inspectprivate void print(java.lang.String string)
private void printWithoutSpacer(java.lang.String string)
private void newLine()
private java.lang.String spacer()
private void indentForward()
private void indentBackward()
protected void startElement(NodeElement element)
startElement
in class AbstractDepthFirstVisitor
element
- the elementprotected void startAttributes(NodeElement element)
startAttributes
in class AbstractDepthFirstVisitor
element
- the elementprotected void visitAttributes(NodeElement element, java.util.List<NodeAttribute> attributes)
visitAttributes
in class AbstractDepthFirstVisitor
element
- the elementattributes
- the attributesprotected void visitAttribute(NodeElement element, NodeAttribute attribute)
element
- attribute
- protected void endAttributes(NodeElement element)
endAttributes
in class AbstractDepthFirstVisitor
element
- the elementprotected void visitElement(NodeElement element)
visitElement
in class AbstractDepthFirstVisitor
element
- the elementprotected void startChildren(NodeElement element)
startChildren
in class AbstractDepthFirstVisitor
element
- the elementprotected void endChildren(NodeElement element)
endChildren
in class AbstractDepthFirstVisitor
element
- the elementprotected void endElement(NodeElement element)
endElement
in class AbstractDepthFirstVisitor
element
- the element