Class PrettyPrintXMLWriter
java.lang.Object
org.apache.maven.shared.utils.xml.PrettyPrintXMLWriter
- All Implemented Interfaces:
XMLWriter
XMLWriter with nice indentation.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final char[]private static final char[]private static final char[]private intprivate Stringprivate booleanprivate Stringprivate booleanprivate char[]private char[]private booleanprivate PrintWriter -
Constructor Summary
ConstructorsModifierConstructorDescriptionPrettyPrintXMLWriter(PrintWriter writer) privatePrettyPrintXMLWriter(PrintWriter writer, char[] lineIndent, char[] lineSeparator, String encoding, String doctype) PrettyPrintXMLWriter(PrintWriter writer, String lineIndent) PrettyPrintXMLWriter(PrintWriter writer, String encoding, String doctype) PrettyPrintXMLWriter(PrintWriter writer, String lineIndent, String encoding, String doctype) PrettyPrintXMLWriter(PrintWriter writer, String lineIndent, String lineSeparator, String encoding, String doctype) PrettyPrintXMLWriter(Writer writer) PrettyPrintXMLWriter(Writer writer, String lineIndent) PrettyPrintXMLWriter(Writer writer, String encoding, String doctype) PrettyPrintXMLWriter(Writer writer, String lineIndent, String encoding, String doctype) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAttribute(String key, String value) Add a XML attribute to the current XML Element.private voidvoidEnd the previously opened element.private booleanWrite the document if not already done.private voidnewLine()voidsetDocType(String docType) Sets the DOCTYPE of the document.voidsetEncoding(String encoding) Sets the encoding of the document.voidsetLineIndenter(String lineIndentParameter) voidsetLineSeparator(String lineSeparator) voidstartElement(String elementName) Start an XML Element tag.private voidvoidwriteMarkup(String markup) Add preformatted markup to the current element tag.voidAdd text to the current element tag.
-
Field Details
-
CLOSE_1
private static final char[] CLOSE_1 -
CLOSE_2
private static final char[] CLOSE_2 -
DEFAULT_LINE_INDENT
private static final char[] DEFAULT_LINE_INDENT -
writer
-
elementStack
-
processingElement
private boolean processingElement -
documentStarted
private boolean documentStarted -
endOnSameLine
private boolean endOnSameLine -
depth
private int depth -
lineIndent
private char[] lineIndent -
lineSeparator
private char[] lineSeparator -
encoding
-
docType
-
-
Constructor Details
-
PrettyPrintXMLWriter
- Parameters:
writer- not nulllineIndent- can be null, but the normal way is some spaces
-
PrettyPrintXMLWriter
- Parameters:
writer- not nulllineIndent- can be null, but the normal way is some spaces.
-
PrettyPrintXMLWriter
- Parameters:
writer- not null
-
PrettyPrintXMLWriter
- Parameters:
writer- not null
-
PrettyPrintXMLWriter
- Parameters:
writer- not nulllineIndent- can be null, but the normal way is some spacesencoding- can be null or invaliddoctype- can be null
-
PrettyPrintXMLWriter
- Parameters:
writer- not nulllineIndent- can be null, but the normal way is some spacesencoding- can be null or invaliddoctype- can be null
-
PrettyPrintXMLWriter
- Parameters:
writer- not nullencoding- can be null or invaliddoctype- can be null
-
PrettyPrintXMLWriter
- Parameters:
writer- not nullencoding- can be null or invaliddoctype- can be null
-
PrettyPrintXMLWriter
public PrettyPrintXMLWriter(PrintWriter writer, String lineIndent, String lineSeparator, String encoding, String doctype) - Parameters:
writer- not nulllineIndent- can be null, but the normal way is some spaces.lineSeparator- can be null, but the normal way is valid line separatorencoding- can be null or the encoding to use.doctype- can be null
-
PrettyPrintXMLWriter
private PrettyPrintXMLWriter(PrintWriter writer, char[] lineIndent, char[] lineSeparator, String encoding, String doctype) - Parameters:
writer- not nulllineIndent- can be null, but the normal way is some spaceslineSeparator- can be null, but the normal way is valid line separatorencoding- can be null or the encoding to usedoctype- can be null
-
-
Method Details
-
addAttribute
Add a XML attribute to the current XML Element. This method must get called immediately afterXMLWriter.startElement(String).- Specified by:
addAttributein interfaceXMLWriter- Parameters:
key- The key of the attribute.value- The value of the attribute.- Throws:
IOException- if adding the attribute fails.
-
setEncoding
Sets the encoding of the document. If not set, UTF-8 is used.- Specified by:
setEncodingin interfaceXMLWriter- Parameters:
encoding- the encoding
-
setDocType
Sets the DOCTYPE of the document.- Specified by:
setDocTypein interfaceXMLWriter- Parameters:
docType- the docType
-
setLineSeparator
- Parameters:
lineSeparator- the line separator to be output
-
setLineIndenter
- Parameters:
lineIndentParameter- the line indent parameter
-
startElement
Start an XML Element tag.- Specified by:
startElementin interfaceXMLWriter- Parameters:
elementName- the name of the tag- Throws:
IOException- if starting the element fails
-
writeText
Add text to the current element tag. This performs XML escaping to guarantee well-formed content.- Specified by:
writeTextin interfaceXMLWriter- Parameters:
text- The text which should be written.- Throws:
IOException- if writing the text fails.
-
writeMarkup
Add preformatted markup to the current element tag.- Specified by:
writeMarkupin interfaceXMLWriter- Parameters:
markup- the text which should be written- Throws:
IOException- if writing the markup fails
-
endElement
End the previously opened element.- Specified by:
endElementin interfaceXMLWriter- Throws:
IOException- if ending the element fails.- See Also:
-
ensureDocumentStarted
private boolean ensureDocumentStarted()Write the document if not already done.- Returns:
trueif the document headers have freshly been written.
-
writeDocumentHeader
private void writeDocumentHeader() -
newLine
private void newLine() -
completePreviouslyOpenedElement
private void completePreviouslyOpenedElement()
-