public class PrettySerializingContentHandler extends Object implements ContentHandler
Writer
.The GNU Lesser General Public License for details.
Modifier and Type | Field and Description |
---|---|
private int |
depth
The depth is incremented on each startElement and decremented on each
endElement.
|
private FormatType |
formatting |
private static char[] |
indentation
This allows for rapid output of whitespace.
|
private boolean |
lookingForChars
It is possible that characters(...) will be called for adjacent pieces of
text.
|
private boolean |
pendingEndTag
One of the difficulties in SAX parsing is that it does not retain state.
|
private Writer |
writer |
Constructor and Description |
---|
PrettySerializingContentHandler()
A formatting serializer that does not add whitespace to the document.
|
PrettySerializingContentHandler(FormatType theFormat)
A formatting serializer that adds whitespace to the document according to
the specified
FormatType . |
PrettySerializingContentHandler(FormatType theFormat,
Writer theWriter)
A formatting serializer that adds whitespace to the document according to
the specified
FormatType . |
Modifier and Type | Method and Description |
---|---|
void |
characters(char[] chars,
int start,
int length) |
protected String |
decorateAttributeName(String attrName) |
protected String |
decorateAttributeValue(String attrValue) |
protected String |
decorateCharacters(String characters) |
protected String |
decorateIndent(int indentLevel) |
protected String |
decorateTagName(String tagName) |
private void |
emitWhitespace(int indentLevel) |
void |
endDocument() |
void |
endElement(String uri,
String localname,
String qname) |
void |
endPrefixMapping(String prefix) |
protected String |
getEmptyTagEnd() |
protected String |
getEndTagStart() |
protected String |
getNewline() |
protected String |
getPIEnd() |
protected String |
getPIStart() |
protected String |
getTagEnd() |
protected String |
getTagStart() |
private void |
handlePending() |
void |
ignorableWhitespace(char[] chars,
int start,
int length) |
void |
processingInstruction(String target,
String data) |
void |
setDocumentLocator(Locator locator) |
void |
skippedEntity(String name) |
void |
startDocument() |
void |
startElement(String uri,
String localname,
String qname,
Attributes attrs) |
void |
startPrefixMapping(String prefix,
String uri) |
String |
toString() |
protected void |
write(char obj) |
protected void |
write(String obj) |
private static char[] indentation
private int depth
private boolean lookingForChars
private boolean pendingEndTag
private FormatType formatting
private Writer writer
public PrettySerializingContentHandler()
public PrettySerializingContentHandler(FormatType theFormat)
FormatType
. This uses a StringWriter and the
toString method will return its content.theFormat
- the formatting to usepublic PrettySerializingContentHandler(FormatType theFormat, Writer theWriter)
FormatType
. As the document is serialized it
is written to the provided Writer
.theFormat
- the formatting to usetheWriter
- the writer to usepublic void setDocumentLocator(Locator locator)
setDocumentLocator
in interface ContentHandler
public void startDocument()
startDocument
in interface ContentHandler
public void endDocument()
endDocument
in interface ContentHandler
public void startPrefixMapping(String prefix, String uri)
startPrefixMapping
in interface ContentHandler
public void endPrefixMapping(String prefix)
endPrefixMapping
in interface ContentHandler
public void startElement(String uri, String localname, String qname, Attributes attrs)
startElement
in interface ContentHandler
public void endElement(String uri, String localname, String qname)
endElement
in interface ContentHandler
public void characters(char[] chars, int start, int length)
characters
in interface ContentHandler
public void ignorableWhitespace(char[] chars, int start, int length)
ignorableWhitespace
in interface ContentHandler
public void processingInstruction(String target, String data)
processingInstruction
in interface ContentHandler
public void skippedEntity(String name)
skippedEntity
in interface ContentHandler
protected String getTagStart()
protected String getTagEnd()
protected String getEmptyTagEnd()
protected String getEndTagStart()
protected String getPIStart()
protected String getPIEnd()
protected String getNewline()
protected String decorateIndent(int indentLevel)
protected void write(String obj)
protected void write(char obj)
private void handlePending()
private void emitWhitespace(int indentLevel)