net.sf.joost.stx
Class Emitter

java.lang.Object
  extended by net.sf.joost.stx.Emitter
All Implemented Interfaces:
Constants
Direct Known Subclasses:
DebugEmitter

public class Emitter
extends Object
implements Constants

Emitter acts as a filter between the Processor and the real SAX output handler. It maintains a stack of in-scope namespaces and sends corresponding events to the real output handler.

Version:
$Revision: 1.38 $ $Date: 2009/08/21 12:46:17 $
Author:
Oliver Becker

Field Summary
 ContentHandler contH
           
private  boolean dtdAllowed
           
private  ErrorHandlerImpl errorHandler
           
private  boolean insideCDATA
           
private  MutableAttributes lastAttrs
           
private  NodeBase lastInstruction
           
private  String lastLName
           
private  String lastQName
           
private  String lastUri
           
private  LexicalHandler lexH
           
private  String nsDefault
           
private  Stack nsStack
           
private  NamespaceSupport nsSupport
           
private  Stack openedElements
          Stack for emitted start events, allows well-formedness check
 Emitter prev
          Previous emitter.
 
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
protected Emitter(Emitter prev, StxEmitter handler)
          Called from pushEmitter(StxEmitter)
  Emitter(ErrorHandlerImpl errorHandler)
           
 
Method Summary
 void addAttribute(String uri, String qName, String lName, String value, NodeBase instruction)
          Adds a dynamic created attribute (via stx:attribute)
 void characters(char[] ch, int start, int length, NodeBase instruction)
          Emits characters.
 void comment(char[] ch, int start, int length, NodeBase instruction)
          Creates a comment.
 void createDTD(NodeBase instruction, String name, String publicId, String systemId)
           
 void endCDATA()
           
 void endDocument(AbstractInstruction instruction)
          Closes a document.
 void endElement(String uri, String lName, String qName, AbstractInstruction instruction)
          Closes an element.
 Writer getResultWriter(String href, String encoding, String publicId, String systemId, int lineNo, int colNo, boolean append)
          Provides a Writer object that will be used for stx:result-document instructions.
 boolean isEmitterActive(StxEmitter emitter)
           
 void processingInstruction(String target, String data, NodeBase instruction)
          Creates a processing instruction.
private  void processLastElement()
          Process a stored element start tag (from startElement)
 Emitter pushEmitter(StxEmitter handler)
          Put the current emitter object on a stack and return a new emitter, which uses the given handler.
 void setContentHandler(ContentHandler handler)
           
 void setLexicalHandler(LexicalHandler handler)
           
 void startCDATA(NodeBase instruction)
          Creates a CDATA section.
 void startDocument()
           
 void startElement(String uri, String lName, String qName, Attributes attrs, Hashtable namespaces, NodeBase instruction)
          Opens a new element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

contH

public ContentHandler contH

lexH

private LexicalHandler lexH

errorHandler

private ErrorHandlerImpl errorHandler

nsSupport

private NamespaceSupport nsSupport

nsStack

private Stack nsStack

nsDefault

private String nsDefault

openedElements

private Stack openedElements
Stack for emitted start events, allows well-formedness check


prev

public Emitter prev
Previous emitter. A new one will be created for each new result event stream.


lastUri

private String lastUri

lastLName

private String lastLName

lastQName

private String lastQName

lastAttrs

private MutableAttributes lastAttrs

lastInstruction

private NodeBase lastInstruction

insideCDATA

private boolean insideCDATA

dtdAllowed

private boolean dtdAllowed
Constructor Detail

Emitter

public Emitter(ErrorHandlerImpl errorHandler)

Emitter

protected Emitter(Emitter prev,
                  StxEmitter handler)
Called from pushEmitter(StxEmitter)

Method Detail

pushEmitter

public Emitter pushEmitter(StxEmitter handler)
Put the current emitter object on a stack and return a new emitter, which uses the given handler. This method may be overridden.

Parameters:
handler - the STX handler for the new emitter
Returns:
a new emitter object

setContentHandler

public void setContentHandler(ContentHandler handler)

setLexicalHandler

public void setLexicalHandler(LexicalHandler handler)

processLastElement

private void processLastElement()
                         throws SAXException
Process a stored element start tag (from startElement)

Throws:
SAXException

addAttribute

public void addAttribute(String uri,
                         String qName,
                         String lName,
                         String value,
                         NodeBase instruction)
                  throws SAXException
Adds a dynamic created attribute (via stx:attribute)

Parameters:
instruction - the instruction that causes this method invocation
Throws:
SAXException

startDocument

public void startDocument()
                   throws SAXException
Throws:
SAXException

endDocument

public void endDocument(AbstractInstruction instruction)
                 throws SAXException
Closes a document.

Parameters:
instruction - the instruction that causes this method invocation
Throws:
SAXException

startElement

public void startElement(String uri,
                         String lName,
                         String qName,
                         Attributes attrs,
                         Hashtable namespaces,
                         NodeBase instruction)
                  throws SAXException
Opens a new element.

Parameters:
instruction - the instruction that causes this method invocation
Throws:
SAXException

endElement

public void endElement(String uri,
                       String lName,
                       String qName,
                       AbstractInstruction instruction)
                throws SAXException
Closes an element.

Parameters:
instruction - the instruction that causes this method invocation
Throws:
SAXException

characters

public void characters(char[] ch,
                       int start,
                       int length,
                       NodeBase instruction)
                throws SAXException
Emits characters.

Parameters:
instruction - the instruction that causes this method invocation
Throws:
SAXException

processingInstruction

public void processingInstruction(String target,
                                  String data,
                                  NodeBase instruction)
                           throws SAXException
Creates a processing instruction.

Parameters:
instruction - the instruction that causes this method invocation
Throws:
SAXException

comment

public void comment(char[] ch,
                    int start,
                    int length,
                    NodeBase instruction)
             throws SAXException
Creates a comment.

Parameters:
instruction - the instruction that causes this method invocation
Throws:
SAXException

startCDATA

public void startCDATA(NodeBase instruction)
                throws SAXException
Creates a CDATA section.

Parameters:
instruction - the instruction that causes this method invocation
Throws:
SAXException

endCDATA

public void endCDATA()
              throws SAXException
Throws:
SAXException

createDTD

public void createDTD(NodeBase instruction,
                      String name,
                      String publicId,
                      String systemId)
               throws SAXException
Throws:
SAXException

isEmitterActive

public boolean isEmitterActive(StxEmitter emitter)
Returns:
true if this emitter is in use or on the stack

getResultWriter

public Writer getResultWriter(String href,
                              String encoding,
                              String publicId,
                              String systemId,
                              int lineNo,
                              int colNo,
                              boolean append)
                       throws IOException,
                              SAXException,
                              URISyntaxException
Provides a Writer object that will be used for stx:result-document instructions.

Parameters:
href - the filename
encoding - the requested encoding
publicId - public ID of the transformation sheet
systemId - system ID of the transformation sheet
lineNo - line number of the stx:result-document instruction
colNo - column number of the stx:result-document instruction
append - flag that determines, whether the new XML should be appended to an existing file
Throws:
IOException
SAXException
URISyntaxException