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
public class PrettyPrintXMLWriter extends java.lang.Object implements XMLWriter
Implementation of XMLWriter which emits nicely formatted documents.- Version:
- $Id$
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.regex.Patternampprivate static java.util.regex.Patterncrlfprivate static java.lang.Stringcrlf_strprivate intdepthprivate java.lang.StringdocTypeprivate static java.util.regex.Patterndqouteprivate java.util.LinkedList<java.lang.String>elementStackprivate java.lang.Stringencodingprivate static java.util.regex.Patterngtprivate java.lang.StringlineIndenterprivate java.lang.StringlineSeparatorprivate static java.util.regex.Patternlowersprotected static java.lang.StringLSLine separator ("\n" on UNIX)private static java.util.regex.Patternltprivate booleanreadyForNewLineprivate static java.util.regex.Patternsqouteprivate booleantagInProgressprivate booleantagIsEmptyprivate java.io.PrintWriterwriter
-
Constructor Summary
Constructors Constructor Description PrettyPrintXMLWriter(java.io.PrintWriter writer)PrettyPrintXMLWriter(java.io.PrintWriter writer, java.lang.String lineIndenter)PrettyPrintXMLWriter(java.io.PrintWriter writer, java.lang.String encoding, java.lang.String doctype)PrettyPrintXMLWriter(java.io.PrintWriter writer, java.lang.String lineIndenter, java.lang.String encoding, java.lang.String doctype)PrettyPrintXMLWriter(java.io.PrintWriter writer, java.lang.String lineIndenter, java.lang.String lineSeparator, java.lang.String encoding, java.lang.String doctype)PrettyPrintXMLWriter(java.io.Writer writer)PrettyPrintXMLWriter(java.io.Writer writer, java.lang.String lineIndenter)PrettyPrintXMLWriter(java.io.Writer writer, java.lang.String encoding, java.lang.String doctype)PrettyPrintXMLWriter(java.io.Writer writer, java.lang.String lineIndenter, java.lang.String encoding, java.lang.String doctype)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAttribute(java.lang.String key, java.lang.String value)voidendElement()protected voidendOfLine()Write the end of line character (using specified line separator) and start new line with indentationprivate static java.lang.StringescapeXml(java.lang.String text)private static java.lang.StringescapeXmlAttribute(java.lang.String text)private voidfinishTag()protected intgetDepth()Get the current depth in the xml indentationprotected java.lang.StringgetDocType()Get the docType in the xmlprotected java.util.LinkedList<java.lang.String>getElementStack()protected java.lang.StringgetEncoding()Get the current encoding in the xmlprotected java.lang.StringgetLineIndenter()Get the string used as line indenterprotected java.lang.StringgetLineSeparator()Get the string used as line separator or LS if not set.protected java.io.PrintWritergetWriter()Get the underlying writerprotected voidsetDepth(int depth)Set the depth in the xml indentationprotected voidsetDocType(java.lang.String docType)Set the docType in the xmlprotected voidsetEncoding(java.lang.String encoding)Set the encoding in the xmlprotected voidsetLineIndenter(java.lang.String lineIndenter)Set the string used as line indenterprotected voidsetLineSeparator(java.lang.String lineSeparator)Set the string used as line separatorprotected voidsetWriter(java.io.PrintWriter writer)Set the underlying writervoidstartElement(java.lang.String name)private voidwrite(java.lang.String str)Write a string to the underlying writerprivate voidwriteDocumentHeaders()voidwriteMarkup(java.lang.String text)voidwriteText(java.lang.String text)private voidwriteText(java.lang.String text, boolean escapeXml)
-
-
-
Field Detail
-
LS
protected static final java.lang.String LS
Line separator ("\n" on UNIX)
-
writer
private java.io.PrintWriter writer
-
elementStack
private java.util.LinkedList<java.lang.String> elementStack
-
tagInProgress
private boolean tagInProgress
-
depth
private int depth
-
lineIndenter
private java.lang.String lineIndenter
-
lineSeparator
private java.lang.String lineSeparator
-
encoding
private java.lang.String encoding
-
docType
private java.lang.String docType
-
readyForNewLine
private boolean readyForNewLine
-
tagIsEmpty
private boolean tagIsEmpty
-
amp
private static final java.util.regex.Pattern amp
-
lt
private static final java.util.regex.Pattern lt
-
gt
private static final java.util.regex.Pattern gt
-
dqoute
private static final java.util.regex.Pattern dqoute
-
sqoute
private static final java.util.regex.Pattern sqoute
-
crlf_str
private static final java.lang.String crlf_str
- See Also:
- Constant Field Values
-
crlf
private static final java.util.regex.Pattern crlf
-
lowers
private static final java.util.regex.Pattern lowers
-
-
Constructor Detail
-
PrettyPrintXMLWriter
public PrettyPrintXMLWriter(java.io.PrintWriter writer, java.lang.String lineIndenter)- Parameters:
writer- not nulllineIndenter- could be null, but the normal way is some spaces.
-
PrettyPrintXMLWriter
public PrettyPrintXMLWriter(java.io.Writer writer, java.lang.String lineIndenter)- Parameters:
writer- not nulllineIndenter- could be null, but the normal way is some spaces.
-
PrettyPrintXMLWriter
public PrettyPrintXMLWriter(java.io.PrintWriter writer)
- Parameters:
writer- not null
-
PrettyPrintXMLWriter
public PrettyPrintXMLWriter(java.io.Writer writer)
- Parameters:
writer- not null
-
PrettyPrintXMLWriter
public PrettyPrintXMLWriter(java.io.PrintWriter writer, java.lang.String lineIndenter, java.lang.String encoding, java.lang.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
public PrettyPrintXMLWriter(java.io.Writer writer, java.lang.String lineIndenter, java.lang.String encoding, java.lang.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
public PrettyPrintXMLWriter(java.io.PrintWriter writer, java.lang.String encoding, java.lang.String doctype)- Parameters:
writer- not nullencoding- could be null or invalid.doctype- could be null.
-
PrettyPrintXMLWriter
public PrettyPrintXMLWriter(java.io.Writer writer, java.lang.String encoding, java.lang.String doctype)- Parameters:
writer- not nullencoding- could be null or invalid.doctype- could be null.
-
PrettyPrintXMLWriter
public PrettyPrintXMLWriter(java.io.PrintWriter writer, java.lang.String lineIndenter, java.lang.String lineSeparator, java.lang.String encoding, java.lang.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 Detail
-
startElement
public void startElement(java.lang.String name)
- Specified by:
startElementin interfaceXMLWriter
-
writeText
public void writeText(java.lang.String text)
-
writeMarkup
public void writeMarkup(java.lang.String text)
- Specified by:
writeMarkupin interfaceXMLWriter
-
writeText
private void writeText(java.lang.String text, boolean escapeXml)
-
escapeXml
private static java.lang.String escapeXml(java.lang.String text)
-
escapeXmlAttribute
private static java.lang.String escapeXmlAttribute(java.lang.String text)
-
addAttribute
public void addAttribute(java.lang.String key, java.lang.String value)- Specified by:
addAttributein interfaceXMLWriter
-
endElement
public void endElement()
- Specified by:
endElementin interfaceXMLWriter
-
write
private void write(java.lang.String str)
Write a string to the underlying writer- Parameters:
str-
-
finishTag
private void finishTag()
-
getLineIndenter
protected java.lang.String getLineIndenter()
Get the string used as line indenter- Returns:
- the line indenter
-
setLineIndenter
protected void setLineIndenter(java.lang.String lineIndenter)
Set the string used as line indenter- Parameters:
lineIndenter- new line indenter, could be null, but the normal way is some spaces.
-
getLineSeparator
protected java.lang.String getLineSeparator()
Get the string used as line separator or LS if not set.- Returns:
- the line separator
- See Also:
LS
-
setLineSeparator
protected void setLineSeparator(java.lang.String lineSeparator)
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:
getLineIndenter(),getLineSeparator()
-
writeDocumentHeaders
private void writeDocumentHeaders()
-
setWriter
protected void setWriter(java.io.PrintWriter writer)
Set the underlying writer- Parameters:
writer- not null writer
-
getWriter
protected java.io.PrintWriter 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
protected void setEncoding(java.lang.String encoding)
Set the encoding in the xml- Parameters:
encoding- new encoding
-
getEncoding
protected java.lang.String getEncoding()
Get the current encoding in the xml- Returns:
- the current encoding
-
setDocType
protected void setDocType(java.lang.String docType)
Set the docType in the xml- Parameters:
docType- new docType
-
getDocType
protected java.lang.String getDocType()
Get the docType in the xml- Returns:
- the current docType
-
getElementStack
protected java.util.LinkedList<java.lang.String> getElementStack()
- Returns:
- the current elementStack;
-
-