Home » cocoon-2.1.11-src » org.apache.cocoon.transformation » [javadoc | source]
org.apache.cocoon.transformation
abstract public class: AbstractSAXTransformer [javadoc | source]
java.lang.Object
   org.apache.avalon.framework.logger.AbstractLogEnabled
      org.apache.cocoon.xml.AbstractXMLProducer
         org.apache.cocoon.xml.AbstractXMLPipe
            org.apache.cocoon.transformation.AbstractTransformer
               org.apache.cocoon.transformation.AbstractSAXTransformer

All Implemented Interfaces:
    org.apache.avalon.framework.activity.Disposable, org.apache.avalon.framework.service.Serviceable, org.apache.avalon.framework.configuration.Configurable, Transformer, XMLPipe, org.apache.avalon.excalibur.pool.Recyclable, XMLProducer

Direct Known Subclasses:
    SimpleFormTransformer, SunShinePostTransformer, JPathTransformer, SourceWritingTransformer, SQLTransformer, SessionPreTransformer, HTMLTransformer, AbstractSessionTransformer, CopletTransformer, RSSTransformer, SessionTransformer, PortalToolsLayoutTransformer, InsertTransformer, SourcePropsWritingTransformer, NekoHTMLTransformer, VariableRewriterTransformer, TeeTransformer, EventLinkTransformer, HTMLEventLinkTransformer, SunShineConnectTransformer, LinkRewriterTransformer, CheckAccessTransformer, FolderTransformer, CIncludeTransformer, NewEventLinkTransformer, SessionPostTransformer, DASLTransformer, CleanupTransformer, SendMailTransformer, AbstractBasketTransformer, AbstractSunShineTransformer, SunShineTransformer, AbstractCopletTransformer, BasketTransformer, WebDAVTransformer, SunShinePreTransformer

This class is the basis for all transformers. It provides various useful methods and hooks for implementing own custom transformers.

The basic behaviour of each transformer consists of the following four parts:

For all these four purposes the AbstractSAXTransformer offers some powerful methods and hooks:

Namespace handling

By setting the instance variable namespaceURI to the namespace the events are filtered and only events with this namespace are send to the two hooks: startTransformingElement and endTransformingElement. It is possible to override the default namespace for the transformer by specifying the parameter "namespaceURI" in the pipeline. This avoids possible namespace collisions.

Recording of information

There are several methods for recording information, e.g. startRecording(), startTextRecording() etc. These methods collect information from the xml stream for further processing.

Creating new events

New events can be easily created with the sendEvents() method, the sendStartElementEvent() methods, the sendEndElementEvent() method or the sendTextEvent() method.

Initialization

Before the document is processed the setupTransforming hook is invoked.
Field Summary
protected static final  Attributes EMPTY_ATTRIBUTES    Empty immutable attributes (for performance). Use them whenever creating an element with no attributes. 
protected  boolean ignoreWhitespaces    Controlls SAX event handling. If set to true all whitespace events are ignored. 
protected  boolean ignoreEmptyCharacters    Controlls SAX event handling. If set to true all characters events containing only whitespaces are ignored. 
protected  int ignoreEventsCount    Controlls SAX event handling. If this is incremented all events are not forwarded to the next pipeline component, but the hooks are still called. 
protected  int ignoreHooksCount    Controlls SAX event handling. If this is greater than zero, the hooks are not called. Attention, make sure, that you decrement this counter properly as your hooks are not called anymore! 
protected  String namespaceURI    The namespace used by the transformer for the SAX events filtering. This either equals to the #defaultNamespaceURI or to the value set by the namespaceURI sitemap parameter for the pipeline. Must never be null. 
protected  String defaultNamespaceURI    This is the default namespace used by the transformer. Implementations should set its value in the constructor. Must never be null. 
protected final  Stack stack    A stack for collecting information. The stack is important for collection information especially when the tags can be nested. 
protected final  Stack recorderStack    The stack of current used recorders 
protected  Request request    The current Request object 
protected  Response response    The current Response object 
protected  Context context    The current Context object 
protected  Map objectModel    The current objectModel of the environment 
protected  Parameters parameters    The parameters specified in the sitemap 
protected  String source    The source attribute specified in the sitemap 
protected  ServiceManager manager    The Avalon ServiceManager for getting Components 
protected  SourceResolver resolver    The SourceResolver for this request 
protected  Attributes emptyAttributes    Empty attributes (for performance). This can be used do create own attributes, but make sure to clean them afterwords.
     
    Fields inherited from org.apache.cocoon.xml.AbstractXMLProducer:
    EMPTY_CONTENT_HANDLER,  xmlConsumer,  contentHandler,  lexicalHandler
    Method from org.apache.cocoon.transformation.AbstractSAXTransformer Summary:
    addRecorder,   characters,   comment,   configure,   dispose,   endCDATA,   endDTD,   endDocument,   endElement,   endEntity,   endParametersRecording,   endParametersRecording,   endPrefixMapping,   endRecording,   endSAXRecording,   endSerializedXMLRecording,   endTextRecording,   endTransformingElement,   findPrefixMapping,   getMutableAttributes,   ignorableWhitespace,   processingInstruction,   recycle,   removeRecorder,   sendEndElementEvent,   sendEndElementEventNS,   sendEndPrefixMapping,   sendEvents,   sendParametersEvents,   sendStartElementEvent,   sendStartElementEvent,   sendStartElementEventNS,   sendStartElementEventNS,   sendStartPrefixMapping,   sendTextEvent,   service,   setDocumentLocator,   setup,   setupTransforming,   skippedEntity,   startCDATA,   startDTD,   startDocument,   startElement,   startEntity,   startParametersRecording,   startPrefixMapping,   startRecording,   startSAXRecording,   startSerializedXMLRecording,   startTextRecording,   startTransformingElement
    Methods from org.apache.cocoon.xml.AbstractXMLPipe:
    characters,   comment,   endCDATA,   endDTD,   endDocument,   endElement,   endEntity,   endPrefixMapping,   ignorableWhitespace,   processingInstruction,   setDocumentLocator,   skippedEntity,   startCDATA,   startDTD,   startDocument,   startElement,   startEntity,   startPrefixMapping
    Methods from org.apache.cocoon.xml.AbstractXMLProducer:
    recycle,   setConsumer,   setContentHandler,   setLexicalHandler
    Methods from java.lang.Object:
    equals,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
    Method from org.apache.cocoon.transformation.AbstractSAXTransformer Detail:
     protected  void addRecorder(XMLConsumer recorder) 
      Add a new recorder to the recording chain. Do not invoke this method directly.
     public  void characters(char[] p0,
        int p1,
        int p2) throws SAXException 
      Process the SAX event.
     public  void comment(char[] ary,
        int start,
        int length) throws SAXException 
     public  void configure(Configuration configuration) throws ConfigurationException 
     public  void dispose() 
     public  void endCDATA() throws SAXException 
     public  void endDTD() throws SAXException 
     public  void endDocument() throws SAXException 
      Process the SAX event. The processing of the document is finished.
     public  void endElement(String uri,
        String name,
        String raw) throws SAXException 
      Process the SAX event. The namespace of the event is checked. If it is the defined namespace for this transformer, the #endTransformingElement hook is called.
     public  void endEntity(String name) throws SAXException 
     public SourceParameters endParametersRecording(Parameters source) throws SAXException 
      End recording of parameters If source is null a new parameters object is created, otherwise the parameters are added to this object.
     public SourceParameters endParametersRecording(SourceParameters source) throws SAXException 
      End recording of parameters If source is null a new parameters object is created, otherwise the parameters are added to this object.
     public  void endPrefixMapping(String prefix) throws SAXException 
      Process the SAX event.
     public DocumentFragment endRecording() throws SAXException 
      Stop DOM DocumentFragment recording. This method returns the resulting DocumentFragment, normalized.
     public XMLizable endSAXRecording() throws SAXException 
      Stop recording of SAX events. This method returns the resulting XMLizable.
     public String endSerializedXMLRecording() throws SAXException, ProcessingException 
      Return the serialized xml string.
     public String endTextRecording() throws SAXException 
      Stop recording of text and return the recorded information.
     public  void endTransformingElement(String uri,
        String name,
        String raw) throws IOException, SAXException, ProcessingException 
      Start processing elements of our namespace. This hook is invoked for each sax event with our namespace.
     protected String findPrefixMapping(String uri) 
      Find prefix mapping for the given namespace URI.
     protected AttributesImpl getMutableAttributes(Attributes a) 
      Helper method to get a modifiable attribute set.
     public  void ignorableWhitespace(char[] p0,
        int p1,
        int p2) throws SAXException 
      Process the SAX event.
     public  void processingInstruction(String target,
        String data) throws SAXException 
      Process the SAX event.
     public  void recycle() 
     protected Object removeRecorder() 
      Remove a recorder from the recording chain. Do not invoke this method directly.
     public  void sendEndElementEvent(String localname) throws SAXException 
      Send SAX events to the next pipeline component. The endElement event for the given element is send to the next component in the current pipeline. The element has no namespace.
     public  void sendEndElementEventNS(String localname) throws SAXException 
      Send SAX events to the next pipeline component. The endElement event for the given element is send to the next component in the current pipeline. The element has the namespace of the transformer.
     protected  void sendEndPrefixMapping() throws SAXException 
      Send all end prefix mapping events to the current content handler
     public  void sendEvents(Node node) throws SAXException 
      Send SAX events to the next pipeline component. The node is parsed and the events are send to the next component in the pipeline.
     public  void sendParametersEvents(SourceParameters pars) throws SAXException 
      Send SAX events for the SourceParameters. For each parametername/value pair an element is created with the name of the parameter and the content of this element is the value.
     public  void sendStartElementEvent(String localname) throws SAXException 
      Send SAX events to the next pipeline component. The startElement event for the given element is send to the next component in the current pipeline. The element has no namespace and no attributes
     public  void sendStartElementEvent(String localname,
        Attributes attr) throws SAXException 
      Send SAX events to the next pipeline component. The startElement event for the given element is send to the next component in the current pipeline. The element has no namespace.
     public  void sendStartElementEventNS(String localname) throws SAXException 
      Send SAX events to the next pipeline component. The startElement event for the given element is send to the next component in the current pipeline. The element has the namespace of the transformer, but not attributes
     public  void sendStartElementEventNS(String localname,
        Attributes attr) throws SAXException 
      Send SAX events to the next pipeline component. The startElement event for the given element is send to the next component in the current pipeline. The element has the namespace of the transformer.
     protected  void sendStartPrefixMapping() throws SAXException 
      Send all start prefix mapping events to the current content handler
     public  void sendTextEvent(String text) throws SAXException 
      Send SAX events to the next pipeline component. The characters event for the given text is send to the next component in the current pipeline.
     public  void service(ServiceManager manager) throws ServiceException 
     public  void setDocumentLocator(Locator locator) 
      Process the SAX event.
     public  void setup(SourceResolver resolver,
        Map objectModel,
        String src,
        Parameters params) throws IOException, SAXException, ProcessingException 
     public  void setupTransforming() throws IOException, SAXException, ProcessingException 
      Setup the transformation of an xml document. This method is called just before the transformation (sending of sax events) starts. It should be used to initialize setup parameter depending on the object modell.
     public  void skippedEntity(String name) throws SAXException 
      Process the SAX event.
     public  void startCDATA() throws SAXException 
     public  void startDTD(String name,
        String public_id,
        String system_id) throws SAXException 
     public  void startDocument() throws SAXException 
      Process the SAX event. A new document is processed. The hook method #setupTransforming is invoked.
     public  void startElement(String uri,
        String name,
        String raw,
        Attributes attr) throws SAXException 
      Process the SAX event. The namespace of the event is checked. If it is the defined namespace for this transformer, the #startTransformingElement hook is called.
     public  void startEntity(String name) throws SAXException 
     public  void startParametersRecording() throws SAXException 
      Start recording of parameters. All events are not forwarded and the incoming xml is converted to parameters. Each toplevel node is a parameter and its text subnodes form the value. The Parameters can eiter be retrieved by endParametersRecording().
     public  void startPrefixMapping(String prefix,
        String uri) throws SAXException 
      Process the SAX event.
     public  void startRecording() throws SAXException 
      Start DOM DocumentFragment recording. All incoming events are recorded and not forwarded. The resulting DocumentFragment can be obtained by the matching #endRecording call.
     public  void startSAXRecording() throws SAXException 
      Start recording of SAX events. All incoming events are recorded and not forwarded. The resulting XMLizable can be obtained by the matching #endSAXRecording call.
     public  void startSerializedXMLRecording(Properties format) throws SAXException 
      Start recording of serialized xml All events are converted to an xml string which can be retrieved by endSerializedXMLRecording.
     public  void startTextRecording() throws SAXException 
      Start recording of a text. No events forwarded, and all characters events are collected into a string.
     public  void startTransformingElement(String uri,
        String name,
        String raw,
        Attributes attr) throws IOException, SAXException, ProcessingException 
      Start processing elements of our namespace. This hook is invoked for each sax event with our namespace.