org.apache.cocoon.transformation
Class CleanupTransformer

java.lang.Object
  extended byorg.apache.cocoon.util.AbstractLogEnabled
      extended byorg.apache.cocoon.xml.AbstractXMLProducer
          extended byorg.apache.cocoon.xml.AbstractXMLPipe
              extended byorg.apache.cocoon.transformation.AbstractTransformer
                  extended byorg.apache.cocoon.transformation.AbstractSAXTransformer
                      extended byorg.apache.cocoon.transformation.CleanupTransformer
All Implemented Interfaces:
org.apache.cocoon.caching.CacheableProcessingComponent, Configurable, ContentHandler, Disposable, LexicalHandler, Poolable, Recyclable, Serviceable, org.apache.cocoon.sitemap.SitemapModelComponent, org.apache.cocoon.transformation.Transformer, XMLConsumer, org.apache.cocoon.xml.XMLConsumer, org.apache.cocoon.xml.XMLPipe, org.apache.cocoon.xml.XMLProducer

public class CleanupTransformer
extends org.apache.cocoon.transformation.AbstractSAXTransformer
implements org.apache.cocoon.caching.CacheableProcessingComponent

Cleanup transformer: Removes excess whitespace while adding some where needed for legibility. Strips unwanted namespace declarations.

The cleanup transformer can be used for basically any document as-is or customized by schema (inline vs. block elements) for easier reading.

Transformer declaration: <map:components> <map:transformers> <map:transformer name="htmlcleanup" src="org.apache.cocoon.transformation.CleanupTransformer"> <preserve-uri>*</preserve-uri> </map:transformer> <map:transformer name="xhtmlcleanup" src="org.apache.cocoon.transformation.CleanupTransformer"> <inline-elements>a,abbr,acronym,b,br,font,i,u,img</inline-elements> <preserve-uri>http://www.w3.org/1999/xhtml</preserve-uri> </map:transformer> </map:transformers> </map:components>

The "inline-elements" configuration element refers to a list of element names that are not to be indented. The "preserve-uri" configuration element specifies a namespace uri mapping that is meant for output. All other namespace declarations are stripped from the output. The "preserve-uri" element may appear more than once. If "preserve-uri" is omitted, all namespaces/prefixes are removed from the output.

Transformer usage: <transform type="xhtmlcleanup"> <map:parameter name="indent-size" value="4"/> </transform>

The optional parameter "indent-size" specifies the number of additional space characters appearing at each level of the output document. The default value is 2.

Bugs: Nested namespace declarations with the same namespace prefix will break the code.

Version:
$Id: CleanupTransformer.html 1304280 2012-03-23 11:18:01Z ilgrosso $

Field Summary
 
Fields inherited from class org.apache.cocoon.transformation.AbstractSAXTransformer
context, defaultNamespaceURI, EMPTY_ATTRIBUTES, ignoreEmptyCharacters, ignoreEventsCount, ignoreHooksCount, ignoreWhitespaces, manager, namespaceURI, objectModel, parameters, recorderStack, removeOurNamespacePrefixes, 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
CleanupTransformer()
           
 
Method Summary
 void characters(char[] ch, int start, int length)
           
 void configure(Configuration conf)
           
 void endElement(String uri, String qName, String lName)
           
 void endPrefixMapping(String prefix)
           
 Serializable getKey()
           
 SourceValidity getValidity()
           
 void ignorableWhitespace(char[] ch, int start, int length)
           
 void recycle()
           
 void setup(org.apache.cocoon.environment.SourceResolver resolver, Map objectModel, String src, Parameters par)
           
 void startElement(String uri, String qName, String lName, Attributes attrs)
           
 void startPrefixMapping(String prefix, String uri)
           
 
Methods inherited from class org.apache.cocoon.transformation.AbstractSAXTransformer
addRecorder, comment, dispose, endCDATA, endDocument, endDTD, endEntity, endParametersRecording, endParametersRecording, endRecording, endSAXRecording, endSerializedXMLRecording, endTextRecording, endTransformingElement, findPrefixMapping, getMutableAttributes, processingInstruction, removeRecorder, sendEndElementEvent, sendEndElementEventNS, sendEndPrefixMapping, sendEvents, sendParametersEvents, sendStartElementEvent, sendStartElementEvent, sendStartElementEventNS, sendStartElementEventNS, sendStartPrefixMapping, sendTextEvent, service, setDocumentLocator, setupTransforming, skippedEntity, startCDATA, startDocument, startDTD, startEntity, startParametersRecording, startRecording, startSAXRecording, startSerializedXMLRecording, startTextRecording, startTransformingElement
 
Methods inherited from class org.apache.cocoon.xml.AbstractXMLProducer
setConsumer, setContentHandler, setLexicalHandler
 
Methods inherited from class org.apache.cocoon.util.AbstractLogEnabled
getLogger, setLogger
 
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

CleanupTransformer

public CleanupTransformer()
Method Detail

configure

public void configure(Configuration conf)
               throws ConfigurationException
Specified by:
configure in interface Configurable
Throws:
ConfigurationException
See Also:
AbstractSAXTransformer.configure(org.apache.avalon.framework.configuration.Configuration)

setup

public void setup(org.apache.cocoon.environment.SourceResolver resolver,
                  Map objectModel,
                  String src,
                  Parameters par)
           throws org.apache.cocoon.ProcessingException,
                  SAXException,
                  IOException
Specified by:
setup in interface org.apache.cocoon.sitemap.SitemapModelComponent
Throws:
org.apache.cocoon.ProcessingException
SAXException
IOException
See Also:
AbstractSAXTransformer.setup(org.apache.cocoon.environment.SourceResolver, java.util.Map, java.lang.String, org.apache.avalon.framework.parameters.Parameters)

recycle

public void recycle()
Specified by:
recycle in interface Recyclable
See Also:
AbstractSAXTransformer.recycle()

getKey

public Serializable getKey()
Specified by:
getKey in interface org.apache.cocoon.caching.CacheableProcessingComponent
See Also:
CacheableProcessingComponent.getKey()

getValidity

public SourceValidity getValidity()
Specified by:
getValidity in interface org.apache.cocoon.caching.CacheableProcessingComponent
See Also:
CacheableProcessingComponent.getValidity()

startPrefixMapping

public void startPrefixMapping(String prefix,
                               String uri)
                        throws SAXException
Specified by:
startPrefixMapping in interface ContentHandler
Throws:
SAXException
See Also:
AbstractSAXTransformer.startPrefixMapping(java.lang.String, java.lang.String)

endPrefixMapping

public void endPrefixMapping(String prefix)
                      throws SAXException
Specified by:
endPrefixMapping in interface ContentHandler
Throws:
SAXException
See Also:
AbstractSAXTransformer.endPrefixMapping(java.lang.String)

startElement

public void startElement(String uri,
                         String qName,
                         String lName,
                         Attributes attrs)
                  throws SAXException
Specified by:
startElement in interface ContentHandler
Throws:
SAXException
See Also:
AbstractSAXTransformer.startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)

endElement

public void endElement(String uri,
                       String qName,
                       String lName)
                throws SAXException
Specified by:
endElement in interface ContentHandler
Throws:
SAXException
See Also:
AbstractSAXTransformer.endElement(java.lang.String, java.lang.String, java.lang.String)

characters

public void characters(char[] ch,
                       int start,
                       int length)
                throws SAXException
Specified by:
characters in interface ContentHandler
Throws:
SAXException
See Also:
AbstractSAXTransformer.characters(char[], int, int)

ignorableWhitespace

public void ignorableWhitespace(char[] ch,
                                int start,
                                int length)
                         throws SAXException
Specified by:
ignorableWhitespace in interface ContentHandler
Throws:
SAXException
See Also:
AbstractSAXTransformer.ignorableWhitespace(char[], int, int)


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