net.sf.joost.emitter
Class StreamEmitter

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

public abstract class StreamEmitter
extends StxEmitterBase
implements Constants

Base class for emitter classes that produce a character stream.

Version:
$Revision: 1.32 $ $Date: 2008/10/06 13:31:41 $
Author:
Oliver Becker

Field Summary
protected  CharsetEncoder charsetEncoder
          Encoder for the chosen encoding
protected  String encoding
          The used output encoding
private static String HTML_METHOD
          Joost's HTML extension output method
private static org.apache.commons.logging.Log log
           
protected  Writer writer
          Writer for the resulting text
 
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
StreamEmitter(Writer writer, String encoding)
           
 
Method Summary
 void comment(char[] ch, int start, int length)
          Does nothing
protected  int encodeCharacters(char[] chars, int index, StringBuffer sb)
          Encode a character from a character array, respect surrogate pairs
 void endCDATA()
          Does nothing
 void endDTD()
          Does nothing
 void endEntity(String name)
          Won't be called
 void endPrefixMapping(String prefix)
          Does nothing
 void ignorableWhitespace(char[] p0, int p1, int p2)
          Won't be called
static StreamEmitter newEmitter(OutputStream out, Properties outputProperties)
          Creates an emitter using a given OutputStream and a set of output properties.
static StreamEmitter newEmitter(String filename, Properties outputProperties)
          Creates an emitter that writes to a given file, using a set of output properties.
static StreamEmitter newEmitter(Writer writer, String encoding, Properties outputProperties)
          Creates an emitter using a given Writer, an output encoding and a set of output properties.
static StreamEmitter newXMLEmitter(Writer writer)
          Creates an XML emitter using a given Writer and the default output encoding (Constants.DEFAULT_ENCODING).
 void processingInstruction(String target, String data)
          Does nothing
 void setDocumentLocator(Locator locator)
          Does nothing
 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 skippedEntity(String value)
          Won't be called
 void startCDATA()
          Does nothing
 void startDTD(String name, String publicId, String systemId)
          Does nothing
 void startEntity(String name)
          Won't be called
 void startPrefixMapping(String prefix, String uri)
          Does nothing
 
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
 
Methods inherited from interface org.xml.sax.ContentHandler
characters, endDocument, endElement, startDocument, startElement
 

Field Detail

log

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

HTML_METHOD

private static String HTML_METHOD
Joost's HTML extension output method


writer

protected Writer writer
Writer for the resulting text


encoding

protected String encoding
The used output encoding


charsetEncoder

protected CharsetEncoder charsetEncoder
Encoder for the chosen encoding

Constructor Detail

StreamEmitter

public StreamEmitter(Writer writer,
                     String encoding)
Method Detail

newEmitter

public static StreamEmitter newEmitter(Writer writer,
                                       String encoding,
                                       Properties outputProperties)
Creates an emitter using a given Writer, an output encoding and a set of output properties. The value of the OutputKeys.METHOD property determines the returned emitter object.

Parameters:
writer - A Writer for receiving the output.
encoding - the encoding used in the writer resp. that should be used for the encoding declaration
outputProperties - The set of output properties to be used.
Returns:
a proper stream emitter object

newEmitter

public static StreamEmitter newEmitter(OutputStream out,
                                       Properties outputProperties)
                                throws UnsupportedEncodingException
Creates an emitter using a given OutputStream and a set of output properties. The value of the OutputKeys.ENCODING property defines the encoding for to used. The value of the OutputKeys.METHOD property determines the returned emitter object.

Parameters:
out - An OutputStream for receiving the output.
outputProperties - The set of output properties to be used.
Returns:
a proper stream emitter object
Throws:
UnsupportedEncodingException - When outputProperties specifies an unsupported output encoding

newXMLEmitter

public static StreamEmitter newXMLEmitter(Writer writer)
Creates an XML emitter using a given Writer and the default output encoding (Constants.DEFAULT_ENCODING).

Parameters:
writer - A Writer for receiving the output.
Returns:
a proper XML emitter object

newEmitter

public static StreamEmitter newEmitter(String filename,
                                       Properties outputProperties)
                                throws IOException
Creates an emitter that writes to a given file, using a set of output properties. The value of the OutputKeys.ENCODING property defines the encoding for to used. The value of the OutputKeys.METHOD property determines the returned emitter object.

Parameters:
filename - The name of the output file.
outputProperties - The set of output properties to be used.
Returns:
a proper stream emitter object
Throws:
IOException - When an error occurs while opening the file.

setOmitXmlDeclaration

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

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

Parameters:
flag - true the PIs will be interpreted; false the PIs will be written literally

encodeCharacters

protected int encodeCharacters(char[] chars,
                               int index,
                               StringBuffer sb)
                        throws SAXException
Encode a character from a character array, respect surrogate pairs

Parameters:
chars - the character array
index - the current index
sb - the buffer to append the encoded character
Returns:
the new index (if a pair has been consumed)
Throws:
SAXException - when there's no low surrogate

startPrefixMapping

public void startPrefixMapping(String prefix,
                               String uri)
                        throws SAXException
Does nothing

Specified by:
startPrefixMapping in interface ContentHandler
Throws:
SAXException

endPrefixMapping

public void endPrefixMapping(String prefix)
Does nothing

Specified by:
endPrefixMapping in interface ContentHandler

processingInstruction

public void processingInstruction(String target,
                                  String data)
                           throws SAXException
Does nothing

Specified by:
processingInstruction in interface ContentHandler
Throws:
SAXException

skippedEntity

public void skippedEntity(String value)
Won't be called

Specified by:
skippedEntity in interface ContentHandler

ignorableWhitespace

public void ignorableWhitespace(char[] p0,
                                int p1,
                                int p2)
Won't be called

Specified by:
ignorableWhitespace in interface ContentHandler

setDocumentLocator

public void setDocumentLocator(Locator locator)
Does nothing

Specified by:
setDocumentLocator in interface ContentHandler

startDTD

public void startDTD(String name,
                     String publicId,
                     String systemId)
              throws SAXException
Does nothing

Specified by:
startDTD in interface LexicalHandler
Throws:
SAXException

endDTD

public void endDTD()
Does nothing

Specified by:
endDTD in interface LexicalHandler

startEntity

public void startEntity(String name)
Won't be called

Specified by:
startEntity in interface LexicalHandler

endEntity

public void endEntity(String name)
Won't be called

Specified by:
endEntity in interface LexicalHandler

startCDATA

public void startCDATA()
                throws SAXException
Does nothing

Specified by:
startCDATA in interface LexicalHandler
Throws:
SAXException

endCDATA

public void endCDATA()
              throws SAXException
Does nothing

Specified by:
endCDATA in interface LexicalHandler
Throws:
SAXException

comment

public void comment(char[] ch,
                    int start,
                    int length)
             throws SAXException
Does nothing

Specified by:
comment in interface LexicalHandler
Throws:
SAXException