Package net.ontopia.xml
Class PrettyPrinter
- java.lang.Object
-
- net.ontopia.xml.PrettyPrinter
-
- All Implemented Interfaces:
ContentHandler
public class PrettyPrinter extends Object implements ContentHandler
INTERNAL: SAX document handler that writes pretty-printed XML to a Writer.
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
dropControlChars
protected int
encodeCharsFrom
protected String
encoding
protected int
level
protected int
offset
protected char[]
startline
protected boolean[]
subelements
protected Writer
writer
-
Constructor Summary
Constructors Constructor Description PrettyPrinter(OutputStream stream)
Creates a PrettyPrinter that writes to the given OutputStream.PrettyPrinter(OutputStream stream, String encoding)
Creates a PrettyPrinter that writes to the given OutputStream in the requested character encoding.PrettyPrinter(Writer writer, String encoding)
Creates a PrettyPrinter that writes to the given Writer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addUnescaped(String content)
INTERNAL: Add given text unmodified and unescaped to the output.void
characters(char[] ch, int start, int length)
void
endDocument()
void
endElement(String uri, String localName, String qName)
void
endPrefixMapping(String prefix)
protected void
escapeAttrValue(String attrval, Writer writer)
protected void
flush(Writer writer)
void
ignorableWhitespace(char[] ch, int start, int length)
protected void
indent()
protected void
makeStartLineBuffer(int size)
protected void
makeSubelements(int size)
void
processingInstruction(String target, String data)
void
setDocumentLocator(Locator locator)
void
setDropControlCharacters(boolean dropControlChars)
INTERNAL: If this property is true control characters are being dropped from the resulting document.void
setEncodeCharactersFrom(int charnumber)
INTERNAL: Encodes element content as decimal character entitites for characters from the given character number.void
skippedEntity(String name)
void
startDocument()
void
startElement(String uri, String localName, String qName, Attributes atts)
void
startPrefixMapping(String prefix, String uri)
protected void
write(Writer writer, char c)
protected void
write(Writer writer, char[] c, int off, int len)
protected void
write(Writer writer, String s)
-
-
-
Field Detail
-
writer
protected Writer writer
-
encoding
protected String encoding
-
subelements
protected boolean[] subelements
-
startline
protected char[] startline
-
offset
protected int offset
-
level
protected int level
-
encodeCharsFrom
protected int encodeCharsFrom
-
dropControlChars
protected boolean dropControlChars
-
-
Constructor Detail
-
PrettyPrinter
public PrettyPrinter(OutputStream stream) throws UnsupportedEncodingException
Creates a PrettyPrinter that writes to the given OutputStream. The encoding used is always utf-8.- Throws:
UnsupportedEncodingException
-
PrettyPrinter
public PrettyPrinter(OutputStream stream, String encoding) throws UnsupportedEncodingException
Creates a PrettyPrinter that writes to the given OutputStream in the requested character encoding.- Throws:
UnsupportedEncodingException
-
-
Method Detail
-
startDocument
public void startDocument()
- Specified by:
startDocument
in interfaceContentHandler
-
startElement
public void startElement(String uri, String localName, String qName, Attributes atts)
- Specified by:
startElement
in interfaceContentHandler
-
endElement
public void endElement(String uri, String localName, String qName)
- Specified by:
endElement
in interfaceContentHandler
-
characters
public void characters(char[] ch, int start, int length)
- Specified by:
characters
in interfaceContentHandler
-
ignorableWhitespace
public void ignorableWhitespace(char[] ch, int start, int length)
- Specified by:
ignorableWhitespace
in interfaceContentHandler
-
processingInstruction
public void processingInstruction(String target, String data)
- Specified by:
processingInstruction
in interfaceContentHandler
-
endDocument
public void endDocument()
- Specified by:
endDocument
in interfaceContentHandler
-
setDocumentLocator
public void setDocumentLocator(Locator locator)
- Specified by:
setDocumentLocator
in interfaceContentHandler
-
setEncodeCharactersFrom
public void setEncodeCharactersFrom(int charnumber)
INTERNAL: Encodes element content as decimal character entitites for characters from the given character number.
-
setDropControlCharacters
public void setDropControlCharacters(boolean dropControlChars)
INTERNAL: If this property is true control characters are being dropped from the resulting document.
-
addUnescaped
public void addUnescaped(String content)
INTERNAL: Add given text unmodified and unescaped to the output. BEWARE: This makes it possible (even easy) to produce output that is not well-formed.
-
write
protected void write(Writer writer, char c)
-
write
protected void write(Writer writer, char[] c, int off, int len)
-
flush
protected void flush(Writer writer)
-
indent
protected void indent()
-
makeStartLineBuffer
protected void makeStartLineBuffer(int size)
-
makeSubelements
protected void makeSubelements(int size)
-
startPrefixMapping
public void startPrefixMapping(String prefix, String uri) throws SAXException
- Specified by:
startPrefixMapping
in interfaceContentHandler
- Throws:
SAXException
-
endPrefixMapping
public void endPrefixMapping(String prefix) throws SAXException
- Specified by:
endPrefixMapping
in interfaceContentHandler
- Throws:
SAXException
-
skippedEntity
public void skippedEntity(String name) throws SAXException
- Specified by:
skippedEntity
in interfaceContentHandler
- Throws:
SAXException
-
-