net.sf.joost.emitter
Class XmlEmitter

java.lang.Object
  extended by net.sf.joost.emitter.StxEmitterBase
      extended by net.sf.joost.emitter.StreamEmitter
          extended by net.sf.joost.emitter.XmlEmitter
All Implemented Interfaces:
Constants, StxEmitter, ContentHandler, LexicalHandler
Direct Known Subclasses:
HttpPostHandler

public class XmlEmitter
extends StreamEmitter

This class implements an emitter that uses the xml output method for byte or character streams.

Version:
$Revision: 1.9 $ $Date: 2008/10/06 13:31:41 $
Author:
Oliver Becker, Anatolij Zubow

Field Summary
private  boolean disabledOutputEscaping
          flag indicating if disabled output escaping is active
private  boolean insideCDATA
          flag indicating if we're within a CDATA section
private  Attributes lastAttrs
          attributes of the previous element
private  String lastQName
          qName of the previous element
private static org.apache.commons.logging.Log log
           
private  StringBuffer nsDeclarations
          string buffer for namespace declarations
private  boolean propOmitXmlDeclaration
          output property: omit-xml-declaration
private  boolean propStandalone
          output property: standalone
private  String propVersion
          output property: version
private  boolean supportDisableOutputEscaping
          flag indicating if disable output escaping will be supported
 
Fields inherited from class net.sf.joost.emitter.StreamEmitter
charsetEncoder, encoding, writer
 
Fields inherited from interface net.sf.joost.Constants
DEBUG, DEFAULT_ENCODING, FEAT_NS, FEAT_NSPREFIX, FEATURE_URI_PREFIX, FUNC_NS, JOOST_EXT_NS, PR_ATTRIBUTES, PR_BUFFER, PR_CHILDREN, PR_CONTINUE, PR_ERROR, PR_SELF, PR_SIBLINGS, STX_NS
 
Constructor Summary
XmlEmitter(Writer writer, String encoding, Properties outputProperties)
          Constructor
 
Method Summary
 void characters(char[] ch, int start, int length)
          SAX2-Callback - Constructs characters.
 void comment(char[] ch, int start, int length)
          SAX2-Callback - Outputs a comment
 void endCDATA()
          SAX2-Callback - Notify the end of a CDATA section
 void endDocument()
          SAX2-Callback - Flushes the output writer
 void endElement(String uri, String lName, String qName)
          SAX2-Callback - Outputs the element-tag.
 void processingInstruction(String target, String data)
          SAX2-Callback - Outputs a PI
private  boolean processLastElement(boolean end)
          Outputs a start or empty element tag if there is one stored.
 void setOmitXmlDeclaration(boolean flag)
          Defines whether the XML declaration should be omitted, default is false.
 void setSupportDisableOutputEscaping(boolean flag)
          Defines whether disable-output-escaping will be supported (means whether the corresponding processing instructions Result.PI_DISABLE_OUTPUT_ESCAPING and Result.PI_ENABLE_OUTPUT_ESCAPING will be interpreted).
 void startCDATA()
          SAX2-Callback - Notify the start of a CDATA section
 void startDocument()
          SAX2-Callback - Outputs XML-Deklaration with encoding.
 void startDTD(String name, String publicId, String systemId)
          SAX2-Callback - Outputs a document type declaration
 void startElement(String uri, String lName, String qName, Attributes attrs)
          SAX2-Callback
 void startPrefixMapping(String prefix, String uri)
          SAX2-Callback
 
Methods inherited from class net.sf.joost.emitter.StreamEmitter
encodeCharacters, endDTD, endEntity, endPrefixMapping, ignorableWhitespace, newEmitter, newEmitter, newEmitter, newXMLEmitter, setDocumentLocator, skippedEntity, startEntity
 
Methods inherited from class net.sf.joost.emitter.StxEmitterBase
getSystemId, setSystemId
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static org.apache.commons.logging.Log log

propOmitXmlDeclaration

private boolean propOmitXmlDeclaration
output property: omit-xml-declaration


propStandalone

private boolean propStandalone
output property: standalone


propVersion

private String propVersion
output property: version


nsDeclarations

private StringBuffer nsDeclarations
string buffer for namespace declarations


lastQName

private String lastQName
qName of the previous element


lastAttrs

private Attributes lastAttrs
attributes of the previous element


insideCDATA

private boolean insideCDATA
flag indicating if we're within a CDATA section


supportDisableOutputEscaping

private boolean supportDisableOutputEscaping
flag indicating if disable output escaping will be supported


disabledOutputEscaping

private boolean disabledOutputEscaping
flag indicating if disabled output escaping is active

Constructor Detail

XmlEmitter

public XmlEmitter(Writer writer,
                  String encoding,
                  Properties outputProperties)
Constructor

Method Detail

setOmitXmlDeclaration

public void setOmitXmlDeclaration(boolean flag)
Defines whether the XML declaration should be omitted, default is false.

Overrides:
setOmitXmlDeclaration in class StreamEmitter
Parameters:
flag - true: the XML declaration will be omitted; false: the XML declaration will be output

setSupportDisableOutputEscaping

public void setSupportDisableOutputEscaping(boolean flag)
Defines whether disable-output-escaping will be supported (means whether the corresponding processing instructions Result.PI_DISABLE_OUTPUT_ESCAPING and Result.PI_ENABLE_OUTPUT_ESCAPING will be interpreted). The default is false

Overrides:
setSupportDisableOutputEscaping in class StreamEmitter
Parameters:
flag - true the PIs will be interpreted; false the PIs will be written literally

processLastElement

private boolean processLastElement(boolean end)
                            throws SAXException
Outputs a start or empty element tag if there is one stored.

Parameters:
end - true if this method was called due to an endElement event, i.e. an empty element tag has to be output.
Returns:
true if something was output (needed for endElement to determine, if a separate end tag must be output)
Throws:
SAXException

startDocument

public void startDocument()
                   throws SAXException
SAX2-Callback - Outputs XML-Deklaration with encoding.

Throws:
SAXException

endDocument

public void endDocument()
                 throws SAXException
SAX2-Callback - Flushes the output writer

Throws:
SAXException

startElement

public void startElement(String uri,
                         String lName,
                         String qName,
                         Attributes attrs)
                  throws SAXException
SAX2-Callback

Throws:
SAXException

endElement

public void endElement(String uri,
                       String lName,
                       String qName)
                throws SAXException
SAX2-Callback - Outputs the element-tag.

Throws:
SAXException

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws SAXException
SAX2-Callback - Constructs characters.

Throws:
SAXException

startPrefixMapping

public void startPrefixMapping(String prefix,
                               String uri)
                        throws SAXException
SAX2-Callback

Specified by:
startPrefixMapping in interface ContentHandler
Overrides:
startPrefixMapping in class StreamEmitter
Throws:
SAXException

processingInstruction

public void processingInstruction(String target,
                                  String data)
                           throws SAXException
SAX2-Callback - Outputs a PI

Specified by:
processingInstruction in interface ContentHandler
Overrides:
processingInstruction in class StreamEmitter
Throws:
SAXException

startCDATA

public void startCDATA()
                throws SAXException
SAX2-Callback - Notify the start of a CDATA section

Specified by:
startCDATA in interface LexicalHandler
Overrides:
startCDATA in class StreamEmitter
Throws:
SAXException

endCDATA

public void endCDATA()
              throws SAXException
SAX2-Callback - Notify the end of a CDATA section

Specified by:
endCDATA in interface LexicalHandler
Overrides:
endCDATA in class StreamEmitter
Throws:
SAXException

comment

public void comment(char[] ch,
                    int start,
                    int length)
             throws SAXException
SAX2-Callback - Outputs a comment

Specified by:
comment in interface LexicalHandler
Overrides:
comment in class StreamEmitter
Throws:
SAXException

startDTD

public void startDTD(String name,
                     String publicId,
                     String systemId)
              throws SAXException
SAX2-Callback - Outputs a document type declaration

Specified by:
startDTD in interface LexicalHandler
Overrides:
startDTD in class StreamEmitter
Throws:
SAXException