net.ontopia.xml
Class PrettyPrinter

java.lang.Object
  extended by net.ontopia.xml.PrettyPrinter
All Implemented Interfaces:
org.xml.sax.DocumentHandler

public class PrettyPrinter
extends java.lang.Object
implements org.xml.sax.DocumentHandler

INTERNAL: SAX document handler that writes pretty-printed XML to a Writer.


Field Summary
protected  boolean dropControlChars
           
protected  int encodeCharsFrom
           
protected  java.lang.String encoding
           
protected  int level
           
protected  int offset
           
protected  char[] startline
           
protected  boolean[] subelements
           
protected  java.io.Writer writer
           
 
Constructor Summary
PrettyPrinter(java.io.OutputStream stream)
          Creates a PrettyPrinter that writes to the given OutputStream.
PrettyPrinter(java.io.OutputStream stream, java.lang.String encoding)
          Creates a PrettyPrinter that writes to the given OutputStream in the requested character encoding.
PrettyPrinter(java.io.Writer writer, java.lang.String encoding)
          Creates a PrettyPrinter that writes to the given Writer.
 
Method Summary
 void addUnescaped(java.lang.String content)
          INTERNAL: Add given text unmodified and unescaped to the output.
 void characters(char[] ch, int start, int length)
           
 void endDocument()
           
 void endElement(java.lang.String name)
           
protected  void escapeAttrValue(java.lang.String attrval, java.io.Writer writer)
           
protected  void flush(java.io.Writer writer)
           
 void ignorableWhitespace(char[] ch, int start, int length)
           
protected  void indent()
           
static void main(java.lang.String[] args)
          Main method to allow PrettyPrinter to be used from the command-line.
protected  void makeStartLineBuffer(int size)
           
protected  void makeSubelements(int size)
           
 void processingInstruction(java.lang.String target, java.lang.String data)
           
 void setDocumentLocator(org.xml.sax.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 startDocument()
           
 void startElement(java.lang.String name, org.xml.sax.AttributeList atts)
           
protected  void write(java.io.Writer writer, char c)
           
protected  void write(java.io.Writer writer, char[] c, int off, int len)
           
protected  void write(java.io.Writer writer, java.lang.String s)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

writer

protected java.io.Writer writer

encoding

protected java.lang.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(java.io.OutputStream stream)
              throws java.io.UnsupportedEncodingException
Creates a PrettyPrinter that writes to the given OutputStream. The encoding used is always utf-8.

Throws:
java.io.UnsupportedEncodingException

PrettyPrinter

public PrettyPrinter(java.io.OutputStream stream,
                     java.lang.String encoding)
              throws java.io.UnsupportedEncodingException
Creates a PrettyPrinter that writes to the given OutputStream in the requested character encoding.

Throws:
java.io.UnsupportedEncodingException

PrettyPrinter

public PrettyPrinter(java.io.Writer writer,
                     java.lang.String encoding)
Creates a PrettyPrinter that writes to the given Writer.

Parameters:
encoding - The encoding to report in the XML declaration. If null, no XML declaration will be output.
Method Detail

main

public static void main(java.lang.String[] args)
                 throws java.lang.Exception
Main method to allow PrettyPrinter to be used from the command-line.

Throws:
java.lang.Exception

startDocument

public void startDocument()
Specified by:
startDocument in interface org.xml.sax.DocumentHandler

startElement

public void startElement(java.lang.String name,
                         org.xml.sax.AttributeList atts)
Specified by:
startElement in interface org.xml.sax.DocumentHandler

endElement

public void endElement(java.lang.String name)
Specified by:
endElement in interface org.xml.sax.DocumentHandler

characters

public void characters(char[] ch,
                       int start,
                       int length)
Specified by:
characters in interface org.xml.sax.DocumentHandler

ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int start,
                                int length)
Specified by:
ignorableWhitespace in interface org.xml.sax.DocumentHandler

processingInstruction

public void processingInstruction(java.lang.String target,
                                  java.lang.String data)
Specified by:
processingInstruction in interface org.xml.sax.DocumentHandler

endDocument

public void endDocument()
Specified by:
endDocument in interface org.xml.sax.DocumentHandler

setDocumentLocator

public void setDocumentLocator(org.xml.sax.Locator locator)
Specified by:
setDocumentLocator in interface org.xml.sax.DocumentHandler

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(java.lang.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(java.io.Writer writer,
                     java.lang.String s)

write

protected void write(java.io.Writer writer,
                     char c)

write

protected void write(java.io.Writer writer,
                     char[] c,
                     int off,
                     int len)

flush

protected void flush(java.io.Writer writer)

indent

protected void indent()

escapeAttrValue

protected void escapeAttrValue(java.lang.String attrval,
                               java.io.Writer writer)

makeStartLineBuffer

protected void makeStartLineBuffer(int size)

makeSubelements

protected void makeSubelements(int size)


Copyright © 2000-2012 Ontopia.