org.apache.cocoon.transformation
Class HTMLTransformer

java.lang.Object
  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.cocoon.xml.AbstractXMLProducer
          extended by org.apache.cocoon.xml.AbstractXMLPipe
              extended by org.apache.cocoon.transformation.AbstractTransformer
                  extended by org.apache.cocoon.transformation.AbstractSAXTransformer
                      extended by org.apache.cocoon.transformation.HTMLTransformer
All Implemented Interfaces:
Poolable, Recyclable, Disposable, Component, Configurable, LogEnabled, Serviceable, SitemapModelComponent, Transformer, XMLPipe, XMLProducer, XMLConsumer, ContentHandler, LexicalHandler

public class HTMLTransformer
extends AbstractSAXTransformer
implements Configurable

Converts (escaped) HTML snippets into JTidied HTML. This transformer expects a list of elements, passed as comma separated values of the "tags" parameter. It records the text enclosed in such elements and pass it thru JTidy to obtain valid XHTML.

TODO: Add namespace support.

WARNING: This transformer should be considered unstable.

Version:
CVS $Id: HTMLTransformer.html 1304258 2012-03-23 10:09:27Z ilgrosso $
Author:
Daniele Madama, Gianugo Rabellino

Field Summary
 
Fields inherited from class org.apache.cocoon.transformation.AbstractSAXTransformer
context, defaultNamespaceURI, EMPTY_ATTRIBUTES, emptyAttributes, ignoreEmptyCharacters, ignoreEventsCount, ignoreHooksCount, ignoreWhitespaces, manager, namespaceURI, objectModel, parameters, recorderStack, request, resolver, response, source, stack
 
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
HTMLTransformer()
           
 
Method Summary
 void configure(Configuration config)
          Configure this transformer, possibly passing to it a jtidy configuration file location.
 void endElement(String uri, String name, String raw)
          React on endElement calls that contain a tag to be tidied and run Jtidy on it, otherwise passthru.
 void setup(SourceResolver resolver, Map objectModel, String src, Parameters par)
          Setup this component, passing the tag names to be tidied.
 void startElement(String uri, String name, String raw, Attributes attr)
          Start buffering text if inside a tag to be normalized, passthru otherwise.
 
Methods inherited from class org.apache.cocoon.transformation.AbstractSAXTransformer
addRecorder, characters, comment, dispose, endCDATA, endDocument, endDTD, 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, setupTransforming, skippedEntity, startCDATA, startDocument, startDTD, startEntity, startParametersRecording, startPrefixMapping, startRecording, startSAXRecording, startSerializedXMLRecording, startTextRecording, startTransformingElement
 
Methods inherited from class org.apache.cocoon.xml.AbstractXMLProducer
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.apache.cocoon.xml.XMLProducer
setConsumer
 

Constructor Detail

HTMLTransformer

public HTMLTransformer()
Method Detail

endElement

public void endElement(String uri,
                       String name,
                       String raw)
                throws SAXException
React on endElement calls that contain a tag to be tidied and run Jtidy on it, otherwise passthru.

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

startElement

public void startElement(String uri,
                         String name,
                         String raw,
                         Attributes attr)
                  throws SAXException
Start buffering text if inside a tag to be normalized, passthru otherwise.

Specified by:
startElement in interface ContentHandler
Overrides:
startElement in class AbstractSAXTransformer
Parameters:
uri - The Namespace URI, or the empty string if the element has no Namespace URI or if Namespace processing is not being performed.
name - The local name (without prefix), or the empty string if Namespace processing is not being performed.
raw - 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
See Also:
ContentHandler.startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)

configure

public void configure(Configuration config)
               throws ConfigurationException
Configure this transformer, possibly passing to it a jtidy configuration file location.

Specified by:
configure in interface Configurable
Overrides:
configure in class AbstractSAXTransformer
Throws:
ConfigurationException

setup

public void setup(SourceResolver resolver,
                  Map objectModel,
                  String src,
                  Parameters par)
           throws ProcessingException,
                  SAXException,
                  IOException
Setup this component, passing the tag names to be tidied.

Specified by:
setup in interface SitemapModelComponent
Overrides:
setup in class AbstractSAXTransformer
Throws:
ProcessingException
SAXException
IOException


Copyright © 1999-2010 The Apache Software Foundation. All Rights Reserved.