Package org.codehaus.plexus.util.xml
Class PrettyPrintXMLWriter
java.lang.Object
org.codehaus.plexus.util.xml.PrettyPrintXMLWriter
- All Implemented Interfaces:
XMLWriter
- Direct Known Subclasses:
CompactXMLWriter
Implementation of XMLWriter which emits nicely formatted documents.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Pattern
private static final Pattern
private static final String
private int
private String
private static final Pattern
private LinkedList
<String> private String
private static final Pattern
private String
private String
private static final Pattern
protected static final String
Line separator ("\n" on UNIX)private static final Pattern
private boolean
private static final Pattern
private boolean
private boolean
private PrintWriter
-
Constructor Summary
ConstructorsConstructorDescriptionPrettyPrintXMLWriter
(PrintWriter writer) PrettyPrintXMLWriter
(PrintWriter writer, String lineIndenter) PrettyPrintXMLWriter
(PrintWriter writer, String encoding, String doctype) PrettyPrintXMLWriter
(PrintWriter writer, String lineIndenter, String encoding, String doctype) PrettyPrintXMLWriter
(PrintWriter writer, String lineIndenter, String lineSeparator, String encoding, String doctype) PrettyPrintXMLWriter
(Writer writer) PrettyPrintXMLWriter
(Writer writer, String lineIndenter) PrettyPrintXMLWriter
(Writer writer, String encoding, String doctype) PrettyPrintXMLWriter
(Writer writer, String lineIndenter, String encoding, String doctype) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAttribute
(String key, String value) void
protected void
Write the end of line character (using specified line separator) and start new line with indentationprivate static String
private static String
escapeXmlAttribute
(String text) private void
protected int
getDepth()
Get the current depth in the xml indentationprotected String
Get the docType in the xmlprotected LinkedList
<String> protected String
Get the current encoding in the xmlprotected String
Get the string used as line indenterprotected String
Get the string used as line separator or LS if not set.protected PrintWriter
Get the underlying writerprotected void
setDepth
(int depth) Set the depth in the xml indentationprotected void
setDocType
(String docType) Set the docType in the xmlprotected void
setEncoding
(String encoding) Set the encoding in the xmlprotected void
setLineIndenter
(String lineIndenter) Set the string used as line indenterprotected void
setLineSeparator
(String lineSeparator) Set the string used as line separatorprotected void
setWriter
(PrintWriter writer) Set the underlying writervoid
startElement
(String name) private void
Write a string to the underlying writerprivate void
void
writeMarkup
(String text) void
private void
-
Field Details
-
LS
Line separator ("\n" on UNIX) -
writer
-
elementStack
-
tagInProgress
private boolean tagInProgress -
depth
private int depth -
lineIndenter
-
lineSeparator
-
encoding
-
docType
-
readyForNewLine
private boolean readyForNewLine -
tagIsEmpty
private boolean tagIsEmpty -
amp
-
lt
-
gt
-
dqoute
-
sqoute
-
crlf_str
- See Also:
-
crlf
-
lowers
-
-
Constructor Details
-
PrettyPrintXMLWriter
- Parameters:
writer
- not nulllineIndenter
- could be null, but the normal way is some spaces.
-
PrettyPrintXMLWriter
- Parameters:
writer
- not nulllineIndenter
- could be null, but the normal way is some spaces.
-
PrettyPrintXMLWriter
- Parameters:
writer
- not null
-
PrettyPrintXMLWriter
- Parameters:
writer
- not null
-
PrettyPrintXMLWriter
public PrettyPrintXMLWriter(PrintWriter writer, String lineIndenter, String encoding, String doctype) - Parameters:
writer
- not nulllineIndenter
- could be null, but the normal way is some spaces.encoding
- could be null or invalid.doctype
- could be null.
-
PrettyPrintXMLWriter
- Parameters:
writer
- not nulllineIndenter
- could be null, but the normal way is some spaces.encoding
- could be null or invalid.doctype
- could be null.
-
PrettyPrintXMLWriter
- Parameters:
writer
- not nullencoding
- could be null or invalid.doctype
- could be null.
-
PrettyPrintXMLWriter
- Parameters:
writer
- not nullencoding
- could be null or invalid.doctype
- could be null.
-
PrettyPrintXMLWriter
public PrettyPrintXMLWriter(PrintWriter writer, String lineIndenter, String lineSeparator, String encoding, String doctype) - Parameters:
writer
- not nulllineIndenter
- could be null, but the normal way is some spaces.lineSeparator
- could be null, but the normal way is valid line separator ("\n" on UNIX).encoding
- could be null or invalid.doctype
- could be null.
-
-
Method Details
-
startElement
- Specified by:
startElement
in interfaceXMLWriter
-
writeText
-
writeMarkup
- Specified by:
writeMarkup
in interfaceXMLWriter
-
writeText
-
escapeXml
-
escapeXmlAttribute
-
addAttribute
- Specified by:
addAttribute
in interfaceXMLWriter
-
endElement
public void endElement()- Specified by:
endElement
in interfaceXMLWriter
-
write
Write a string to the underlying writer- Parameters:
str
-
-
finishTag
private void finishTag() -
getLineIndenter
Get the string used as line indenter- Returns:
- the line indenter
-
setLineIndenter
Set the string used as line indenter- Parameters:
lineIndenter
- new line indenter, could be null, but the normal way is some spaces.
-
getLineSeparator
Get the string used as line separator or LS if not set.- Returns:
- the line separator
- See Also:
-
setLineSeparator
Set the string used as line separator- Parameters:
lineSeparator
- new line separator, could be null but the normal way is valid line separator ("\n" on UNIX).
-
endOfLine
protected void endOfLine()Write the end of line character (using specified line separator) and start new line with indentation- See Also:
-
writeDocumentHeaders
private void writeDocumentHeaders() -
setWriter
Set the underlying writer- Parameters:
writer
- not null writer
-
getWriter
Get the underlying writer- Returns:
- the underlying writer
-
setDepth
protected void setDepth(int depth) Set the depth in the xml indentation- Parameters:
depth
- new depth
-
getDepth
protected int getDepth()Get the current depth in the xml indentation- Returns:
- the current depth
-
setEncoding
Set the encoding in the xml- Parameters:
encoding
- new encoding
-
getEncoding
Get the current encoding in the xml- Returns:
- the current encoding
-
setDocType
Set the docType in the xml- Parameters:
docType
- new docType
-
getDocType
Get the docType in the xml- Returns:
- the current docType
-
getElementStack
- Returns:
- the current elementStack;
-