com.novell.xml.sax
Class SAXWriter

java.lang.Object
  extended bycom.novell.xml.sax.SAXWriter
All Implemented Interfaces:
DocumentCommentHandler, DocumentHandler, XmlWriter

public class SAXWriter
extends Object
implements XmlWriter, DocumentCommentHandler

Class to serialize SAX events.


Field Summary
protected  boolean children
           
protected  boolean firstElement
           
protected  int indentLevel
           
protected  int lastNode
           
protected  NamespaceStack namespaceStack
           
protected  boolean startTagOpen
           
protected  Stack stateStack
           
protected static int XML_SPACE_DEFAULT
           
protected static int XML_SPACE_PRESERVE
           
protected  int xmlSpace
           
protected static Integer xmlSpaceDefault
           
protected static Integer xmlSpacePreserve
           
 
Constructor Summary
SAXWriter(Parser parser, InputSource inputSource, OutputStream outputStream, String encoding)
          Construct a SAXWriter for the passed OutputStream, using the passed encoding, if possible.
SAXWriter(Parser parser, InputSource inputSource, Writer writer)
          Construct a SAXWriter object for a given java.io.Writer object.
 
Method Summary
 void characters(char[] ch, int start, int length)
          Receive notification of character data.
protected  void closeStartTag()
          Close any open element start tag
 void comment(String data)
          Handle a comment
 void endDocument()
          Receive notification of the end of a document.
 void endElement(String name)
          Receive notification of the end of an element.
 void flush()
          Flush the underlying writer attached to this SAXWriter
 Collection getCdataSectionElements()
          Get the list of element tag names whose text content should be output as CDATA sections.
 boolean getDisableTextEscaping()
          Return non-zero if XML text escaping is disabled for this XmlWriter.
 String getDoctypePublic()
          Return the DOCTYPE PUBLIC id to use for the DTD declaration
 String getDoctypeSystem()
          Return the DOCTYPE SYSTEM id to use for the XML-declaration
 String getEncoding()
          Get the encoding string that will be specified in the XML declaration, if a declaration is output
 boolean getIndent()
          Return if this object will inject whitespace to "pretty print" the serialization of a DOM tree
 boolean getStandalone()
          Return if this object will write a "standalone=yes" declaration in the XML-declaration.
 boolean getWriteDeclaration()
          Return if this object will write an XML-declaration when it serializes a DOM tree
 void ignorableWhitespace(char[] ch, int start, int length)
          Receive notification of ignorable whitespace in element content.
protected  void injectWhitespace(int nodeType)
          Optionally inject whitespace into the serialization stream
protected  void popState()
           
 void processingInstruction(String target, String data)
          Receive notification of a processing instruction.
protected  void pushState()
           
 void setCdataSectionElements(Collection cdataSectionElements)
          Set the list of element tag names whose text content should be output as CDATA sections.
 void setDisableTextEscaping(boolean disableTextEscaping)
          Set if XML text escaping is to be disabled for this XmlWriter.
 void setDoctypePublic(String doctypePublic)
          Set the DOCTYPE PUBLIC id to use in the DTD declaration Note that this will only be used if the DOCTYPE SYSTEM id is not null and non-empty (see setDoctypeSystem()), and that the public id overrides the system id.
 void setDoctypeSystem(String doctypeSystem)
          Set the DOCTYPE SYSTEM id to use in the DTD declaration Note that this will be overridden by the DOCTYPE PUBLIC id (see setDoctypePublic()), but must be set to use the public id.
 void setDocumentLocator(Locator locator)
          Receive an object for locating the origin of SAX document events.
 void setEncoding(String encoding)
          Set the encoding string that will be specified in the XML declaration, if a declaration is output.
 void setIndent(boolean indent)
          Set whether this object should inject whitespace to "pretty print" the serialization of a DOM tree.
 void setStandalone(boolean standalone)
          Set whether this object should write a "standalone=yes" declaration in the XML-declaration
 void setWriteDeclaration(boolean writeDeclaration)
          Set whether this object should output an XML-declaration when it serializes a DOM tree
 void startDocument()
          Receive notification of the beginning of a document.
 void startElement(String name, AttributeList atts)
          Receive notification of the beginning of an element.
protected  boolean useCdataOutput(String elementName)
          Return whether or not CDATA section output should be used for text children of the passed element name
 void write()
          Serialize a series of SAX events as XML
protected  void writeDeclaration()
          Write an XML declaration based on XmlWriter settings
protected  void writeDTD(String name)
          Write a DTD based on XmlWriter parameters
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

indentLevel

protected int indentLevel

firstElement

protected boolean firstElement

lastNode

protected int lastNode

startTagOpen

protected boolean startTagOpen

children

protected boolean children

stateStack

protected Stack stateStack

namespaceStack

protected NamespaceStack namespaceStack

XML_SPACE_DEFAULT

protected static final int XML_SPACE_DEFAULT
See Also:
Constant Field Values

XML_SPACE_PRESERVE

protected static final int XML_SPACE_PRESERVE
See Also:
Constant Field Values

xmlSpaceDefault

protected static final Integer xmlSpaceDefault

xmlSpacePreserve

protected static final Integer xmlSpacePreserve

xmlSpace

protected int xmlSpace
Constructor Detail

SAXWriter

public SAXWriter(Parser parser,
                 InputSource inputSource,
                 Writer writer)
Construct a SAXWriter object for a given java.io.Writer object. Use a com.novell.xml.util.XMLWriter for character encoding. Note that using a buffered writer will result in maximum efficiency.

Parameters:
parser - The SAX Parser from which to get the SAX events
inputSource - The SAX InputSource to pass to the parser's parse() method
writer - The writer object to use.

SAXWriter

public SAXWriter(Parser parser,
                 InputSource inputSource,
                 OutputStream outputStream,
                 String encoding)
          throws UnsupportedEncodingException
Construct a SAXWriter for the passed OutputStream, using the passed encoding, if possible.

Parameters:
parser - The SAX Parser from which to get the SAX events
inputSource - The SAX InputSource to pass to the parser's parse() method
outputStream - The OutputStream to which to write
encoding - The name of the character encoding to use
Method Detail

flush

public void flush()
           throws IOException
Flush the underlying writer attached to this SAXWriter

Throws:
IOException

write

public void write()
           throws IOException
Serialize a series of SAX events as XML

Specified by:
write in interface XmlWriter
Throws:
IOException

getWriteDeclaration

public boolean getWriteDeclaration()
Return if this object will write an XML-declaration when it serializes a DOM tree

Specified by:
getWriteDeclaration in interface XmlWriter
Returns:
True if an XML-declaration will be written

setWriteDeclaration

public void setWriteDeclaration(boolean writeDeclaration)
Set whether this object should output an XML-declaration when it serializes a DOM tree

Specified by:
setWriteDeclaration in interface XmlWriter
Parameters:
writeDeclaration - True if an XML-declaration should be written

getEncoding

public String getEncoding()
Get the encoding string that will be specified in the XML declaration, if a declaration is output

Specified by:
getEncoding in interface XmlWriter
Returns:
The encoding string

setEncoding

public void setEncoding(String encoding)
Set the encoding string that will be specified in the XML declaration, if a declaration is output. Note that it is the caller's responsibility to set up the Writer object passed to the DOMWriter constructor so that it actually outputs using the correct encoding.

Specified by:
setEncoding in interface XmlWriter
Parameters:
encoding - The encoding string to place in the xml declaration

getIndent

public boolean getIndent()
Return if this object will inject whitespace to "pretty print" the serialization of a DOM tree

Specified by:
getIndent in interface XmlWriter
Returns:
True if whitespace will be injected

setIndent

public void setIndent(boolean indent)
Set whether this object should inject whitespace to "pretty print" the serialization of a DOM tree.

Specified by:
setIndent in interface XmlWriter
Parameters:
indent - True if whitespace should be injected to "pretty print" the XML serialization of a DOM tree.

getStandalone

public boolean getStandalone()
Return if this object will write a "standalone=yes" declaration in the XML-declaration.

Specified by:
getStandalone in interface XmlWriter
Returns:
True if standalone="yes" will be written in the XML-declaration

setStandalone

public void setStandalone(boolean standalone)
Set whether this object should write a "standalone=yes" declaration in the XML-declaration

Specified by:
setStandalone in interface XmlWriter
Parameters:
standalone - True if a standalone="yes" declaration should be written in the XML-declaration

getDoctypePublic

public String getDoctypePublic()
Return the DOCTYPE PUBLIC id to use for the DTD declaration

Specified by:
getDoctypePublic in interface XmlWriter
Returns:
The DOCTYPE PUBLIC id to use for the DTD declaration, or null if none will be used.

setDoctypePublic

public void setDoctypePublic(String doctypePublic)
Set the DOCTYPE PUBLIC id to use in the DTD declaration Note that this will only be used if the DOCTYPE SYSTEM id is not null and non-empty (see setDoctypeSystem()), and that the public id overrides the system id.

Specified by:
setDoctypePublic in interface XmlWriter
Parameters:
doctypePublic - The DOCTYPE PUBLIC id to use in the DTD declaration or null if none should be used.

getDoctypeSystem

public String getDoctypeSystem()
Return the DOCTYPE SYSTEM id to use for the XML-declaration

Specified by:
getDoctypeSystem in interface XmlWriter
Returns:
The DOCTYPE SYSTEM id to use for the XML-declaration, or null if none will be used.

setDoctypeSystem

public void setDoctypeSystem(String doctypeSystem)
Set the DOCTYPE SYSTEM id to use in the DTD declaration Note that this will be overridden by the DOCTYPE PUBLIC id (see setDoctypePublic()), but must be set to use the public id.

Specified by:
setDoctypeSystem in interface XmlWriter
Parameters:
doctypeSystem - The DOCTYPE SYSTEM id to use in the DTD declaration or null if none should be used.

getDisableTextEscaping

public boolean getDisableTextEscaping()
Return non-zero if XML text escaping is disabled for this XmlWriter. Disabling text escaping means that no character references or entity references will be output for text nodes.

Specified by:
getDisableTextEscaping in interface XmlWriter
Returns:
True if text escaping is disabled

setDisableTextEscaping

public void setDisableTextEscaping(boolean disableTextEscaping)
Set if XML text escaping is to be disabled for this XmlWriter. Disabling text escaping means that no character references or entity references will be output for text nodes.

Specified by:
setDisableTextEscaping in interface XmlWriter
Parameters:
disableTextEscaping - True if text escaping is disabled

getCdataSectionElements

public Collection getCdataSectionElements()
Get the list of element tag names whose text content should be output as CDATA sections.

Specified by:
getCdataSectionElements in interface XmlWriter
Returns:
A Collection of element tag names, each represented by an ExpandedQName object.

setCdataSectionElements

public void setCdataSectionElements(Collection cdataSectionElements)
Set the list of element tag names whose text content should be output as CDATA sections.

Specified by:
setCdataSectionElements in interface XmlWriter
Parameters:
cdataSectionElements - A Collection of ExpandedQName objects, each of which represents an element tag name.

setDocumentLocator

public void setDocumentLocator(Locator locator)
Receive an object for locating the origin of SAX document events.

Specified by:
setDocumentLocator in interface DocumentHandler
Parameters:
locator - An object that can return the location of any SAX document event.
See Also:
Locator

startDocument

public void startDocument()
                   throws SAXException
Receive notification of the beginning of a document.

Specified by:
startDocument in interface DocumentHandler
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.

endDocument

public void endDocument()
                 throws SAXException
Receive notification of the end of a document.

Specified by:
endDocument in interface DocumentHandler
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.

startElement

public void startElement(String name,
                         AttributeList atts)
                  throws SAXException
Receive notification of the beginning of an element.

Specified by:
startElement in interface DocumentHandler
Parameters:
name - The element type name.
atts - The attributes attached to the element, if any.
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
endElement(java.lang.String), AttributeList

endElement

public void endElement(String name)
                throws SAXException
Receive notification of the end of an element.

Specified by:
endElement in interface DocumentHandler
Parameters:
name - The element type name
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws SAXException
Receive notification of character data.

Specified by:
characters in interface DocumentHandler
Parameters:
ch - The characters from the XML document.
start - The start position in the array.
length - The number of characters to read from the array.
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
ignorableWhitespace(char[], int, int), Locator

ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int start,
                                int length)
                         throws SAXException
Receive notification of ignorable whitespace in element content.

Specified by:
ignorableWhitespace in interface DocumentHandler
Parameters:
ch - The characters from the XML document.
start - The start position in the array.
length - The number of characters to read from the array.
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.
See Also:
characters(char[], int, int)

processingInstruction

public void processingInstruction(String target,
                                  String data)
                           throws SAXException
Receive notification of a processing instruction.

Specified by:
processingInstruction in interface DocumentHandler
Parameters:
target - The processing instruction target.
data - The processing instruction data, or null if none was supplied.
Throws:
SAXException - Any SAX exception, possibly wrapping another exception.

comment

public void comment(String data)
             throws SAXException
Handle a comment

Specified by:
comment in interface DocumentCommentHandler
Parameters:
data - The comment data, that is, everything between the tags.
Throws:
SAXException

writeDeclaration

protected void writeDeclaration()
                         throws IOException
Write an XML declaration based on XmlWriter settings

Throws:
IOException

writeDTD

protected void writeDTD(String name)
                 throws IOException
Write a DTD based on XmlWriter parameters

Parameters:
name - The name of the document element
Throws:
IOException

injectWhitespace

protected void injectWhitespace(int nodeType)
                         throws IOException
Optionally inject whitespace into the serialization stream

Parameters:
nodeType - The current node type
Throws:
IOException

closeStartTag

protected void closeStartTag()
                      throws IOException
Close any open element start tag

Throws:
IOException

useCdataOutput

protected boolean useCdataOutput(String elementName)
Return whether or not CDATA section output should be used for text children of the passed element name

Parameters:
elementName - The element name to check

pushState

protected void pushState()

popState

protected void popState()