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 int
private String
private boolean
private String
private boolean
private char[]
private char[]
private boolean
private PrintWriter
-
Constructor Summary
ConstructorsModifierConstructorDescriptionPrettyPrintXMLWriter
(PrintWriter writer) private
PrettyPrintXMLWriter
(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 TypeMethodDescriptionvoid
addAttribute
(String key, String value) Add a XML attribute to the current XML Element.private void
void
End the previously opened element.private boolean
Write the document if not already done.private void
newLine()
void
setDocType
(String docType) Sets the DOCTYPE of the document.void
setEncoding
(String encoding) Sets the encoding of the document.void
setLineIndenter
(String lineIndentParameter) void
setLineSeparator
(String lineSeparator) void
startElement
(String elementName) Start an XML Element tag.private void
void
writeMarkup
(String markup) Add preformatted markup to the current element tag.void
Add 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:
addAttribute
in 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:
setEncoding
in interfaceXMLWriter
- Parameters:
encoding
- the encoding
-
setDocType
Sets the DOCTYPE of the document.- Specified by:
setDocType
in 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:
startElement
in 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:
writeText
in 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:
writeMarkup
in interfaceXMLWriter
- Parameters:
markup
- the text which should be written- Throws:
IOException
- if writing the markup fails
-
endElement
End the previously opened element.- Specified by:
endElement
in interfaceXMLWriter
- Throws:
IOException
- if ending the element fails.- See Also:
-
ensureDocumentStarted
private boolean ensureDocumentStarted()Write the document if not already done.- Returns:
true
if the document headers have freshly been written.
-
writeDocumentHeader
private void writeDocumentHeader() -
newLine
private void newLine() -
completePreviouslyOpenedElement
private void completePreviouslyOpenedElement()
-