org.apache.cocoon.portal.transformation
Class HTMLRootTransformer

java.lang.Object
  extended byorg.apache.avalon.framework.logger.AbstractLogEnabled
      extended byorg.apache.cocoon.xml.AbstractXMLProducer
          extended byorg.apache.cocoon.xml.AbstractXMLPipe
              extended byorg.apache.cocoon.transformation.AbstractTransformer
                  extended byorg.apache.cocoon.portal.transformation.HTMLRootTransformer
All Implemented Interfaces:
CacheableProcessingComponent, ContentHandler, LexicalHandler, LogEnabled, Poolable, Recyclable, SitemapModelComponent, Transformer, XMLConsumer, XMLConsumer, XMLPipe, XMLProducer

public class HTMLRootTransformer
extends AbstractTransformer
implements CacheableProcessingComponent

This transformer is an utility transformer for dealing with (x)html content. It has two operating modes: Add Mode (default): The transformer simply adds an html and a body element around the sax stream. Remove Mode: The transformer removes all surrounding elements like html and body and only passes everything on to the next pipeline component that's contained in a body element.

Version:
$Id: HTMLRootTransformer.java 322475 2005-10-16 14:26:44Z cziegeler $

Field Summary
protected  boolean addMode
          the operating mode: true means adding the root elements, false means removing them
protected  boolean ignoreRootElement
          do we remove the root tag?
protected  int ignoreRootElementCount
           
protected  boolean insideBodyTag
           
 
Fields inherited from class org.apache.cocoon.xml.AbstractXMLProducer
contentHandler, EMPTY_CONTENT_HANDLER, lexicalHandler, xmlConsumer
 
Fields inherited from interface org.apache.cocoon.transformation.Transformer
ROLE
 
Constructor Summary
HTMLRootTransformer()
           
 
Method Summary
 void characters(char[] c, int start, int len)
          Receive notification of character data.
 void endDocument()
          Receive notification of the end of a document.
 void endElement(String uri, String local, String qName)
          Receive notification of the end of an element.
 Serializable getKey()
          Generate the unique key for the resource being rendered.
 SourceValidity getValidity()
          Generate the validity object.
 void setup(SourceResolver resolver, Map objectModel, String src, Parameters par)
          The Sitemap will call the setup() method to prepare the component for use.
 void startDocument()
          Receive notification of the beginning of a document.
 void startElement(String uri, String local, String qName, Attributes attr)
          Receive notification of the beginning of an element.
 
Methods inherited from class org.apache.cocoon.xml.AbstractXMLPipe
comment, endCDATA, endDTD, endEntity, endPrefixMapping, ignorableWhitespace, processingInstruction, setDocumentLocator, skippedEntity, startCDATA, startDTD, startEntity, startPrefixMapping
 
Methods inherited from class org.apache.cocoon.xml.AbstractXMLProducer
recycle, setConsumer, setContentHandler, setLexicalHandler
 
Methods inherited from class org.apache.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
 
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
endPrefixMapping, ignorableWhitespace, processingInstruction, setDocumentLocator, skippedEntity, startPrefixMapping
 
Methods inherited from interface org.xml.sax.ext.LexicalHandler
comment, endCDATA, endDTD, endEntity, startCDATA, startDTD, startEntity
 
Methods inherited from interface org.apache.cocoon.xml.XMLProducer
setConsumer
 

Field Detail

addMode

protected boolean addMode
the operating mode: true means adding the root elements, false means removing them


ignoreRootElement

protected boolean ignoreRootElement
do we remove the root tag?


ignoreRootElementCount

protected int ignoreRootElementCount

insideBodyTag

protected boolean insideBodyTag
Constructor Detail

HTMLRootTransformer

public HTMLRootTransformer()
Method Detail

setup

public void setup(SourceResolver resolver,
                  Map objectModel,
                  String src,
                  Parameters par)
           throws ProcessingException,
                  SAXException,
                  IOException
Description copied from interface: SitemapModelComponent
The Sitemap will call the setup() method to prepare the component for use. This is where you start the process of getting your information ready to generate your results. See ObjectModelHelper for help with the objectModel.

Specified by:
setup in interface SitemapModelComponent
Parameters:
resolver - The SourceResolver to find resources within your context.
objectModel - A java.util.Map that contains the request and session information.
src - The value of the "src" attribute in the sitemap.
par - The sitemap parameters passed into your component.
Throws:
ProcessingException - if there is any other unexpected problem.
IOException - if there is a problem reading files.
SAXException - if there is a problem reading a SAX stream.

endDocument

public void endDocument()
                 throws SAXException
Description copied from class: AbstractXMLPipe
Receive notification of the end of a document.

Specified by:
endDocument in interface ContentHandler
Overrides:
endDocument in class AbstractXMLPipe
Throws:
SAXException

startDocument

public void startDocument()
                   throws SAXException
Description copied from class: AbstractXMLPipe
Receive notification of the beginning of a document.

Specified by:
startDocument in interface ContentHandler
Overrides:
startDocument in class AbstractXMLPipe
Throws:
SAXException

startElement

public void startElement(String uri,
                         String local,
                         String qName,
                         Attributes attr)
                  throws SAXException
Description copied from class: AbstractXMLPipe
Receive notification of the beginning of an element.

Specified by:
startElement in interface ContentHandler
Overrides:
startElement in class AbstractXMLPipe
Parameters:
uri - The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.
local - The local name (without prefix), or the empty string if Namespace processing is not being performed.
qName - The raw XML 1.0 name (with prefix), or the empty string if raw names are not available.
attr - The attributes attached to the element. If there are no attributes, it shall be an empty Attributes object.
Throws:
SAXException

endElement

public void endElement(String uri,
                       String local,
                       String qName)
                throws SAXException
Description copied from class: AbstractXMLPipe
Receive notification of the end of an element.

Specified by:
endElement in interface ContentHandler
Overrides:
endElement in class AbstractXMLPipe
Parameters:
uri - The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.
local - The local name (without prefix), or the empty string if Namespace processing is not being performed.
qName - The raw XML 1.0 name (with prefix), or the empty string if raw names are not available.
Throws:
SAXException

characters

public void characters(char[] c,
                       int start,
                       int len)
                throws SAXException
Description copied from class: AbstractXMLPipe
Receive notification of character data.

Specified by:
characters in interface ContentHandler
Overrides:
characters in class AbstractXMLPipe
Parameters:
c - The characters from the XML document.
start - The start position in the array.
len - The number of characters to read from the array.
Throws:
SAXException

getKey

public Serializable getKey()
Description copied from interface: CacheableProcessingComponent
Generate the unique key for the resource being rendered.

The cache key is the single most important part of the caching implementation. If you don't get it right, you can introduce more load on the caching engine than is necessary. It is important that the cache key has the following attributes:

Thankfully there is a perfectly suitable object that satisfies these obligations from Java's core: java.lang.String. You can also use your own specific key objects provided they respect the above contracts.

Important:If the cache key is null then your component will not be cached at all. You can use this to your advantage to cache some things but not others.

Specified by:
getKey in interface CacheableProcessingComponent
Returns:
The generated key or null if the component is currently not cacheable.

getValidity

public SourceValidity getValidity()
Description copied from interface: CacheableProcessingComponent
Generate the validity object. This method is invoked after the getKey() method.

The caching contracts use the Excalibur SourceValidity interface to determine whether a resource is valid or not. The validity can be a compound check that incorporates time since creation, parameter values, etc. As long as the sitemap can determine whether the cached resource is valid or not. More information is available on the Apache Excalibur site. Alternatively you can use the built in CacheValidity objects in the org.apache.cocoon.caching package and then use the CacheValidityToSourceValidity adaptor object.

Specified by:
getValidity in interface CacheableProcessingComponent
Returns:
The generated validity object or null if the component is currently not cacheable.


Copyright ? 1999-2005 The Apache Software Foundation. All Rights Reserved.