|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.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
org.apache.cocoon.transformation.CleanupTransformer
public class CleanupTransformer
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.
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 | |
---|---|
CleanupTransformer()
|
Method Summary | |
---|---|
void |
characters(char[] ch,
int start,
int length)
Process the SAX event. |
void |
configure(Configuration conf)
|
void |
endElement(String uri,
String qName,
String lName)
Process the SAX event. |
void |
endPrefixMapping(String prefix)
Process the SAX event. |
Serializable |
getKey()
Generate the unique key. |
SourceValidity |
getValidity()
Generate the validity object. |
void |
ignorableWhitespace(char[] ch,
int start,
int length)
Process the SAX event. |
void |
recycle()
Recycle the producer by removing references, and resetting handlers to null (empty) implementations. |
void |
setup(SourceResolver resolver,
Map objectModel,
String src,
Parameters par)
Set the SourceResolver , objectModel Map ,
the source and sitemap Parameters used to process the request. |
void |
startElement(String uri,
String qName,
String lName,
Attributes attrs)
Process the SAX event. |
void |
startPrefixMapping(String prefix,
String uri)
Process the SAX event. |
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 |
---|
public CleanupTransformer()
Method Detail |
---|
public void configure(Configuration conf) throws ConfigurationException
configure
in interface Configurable
configure
in class AbstractSAXTransformer
ConfigurationException
AbstractSAXTransformer.configure(org.apache.avalon.framework.configuration.Configuration)
public void setup(SourceResolver resolver, Map objectModel, String src, Parameters par) throws ProcessingException, SAXException, IOException
SitemapModelComponent
SourceResolver
, objectModel Map
,
the source and sitemap Parameters
used to process the request.
setup
in interface SitemapModelComponent
setup
in class AbstractSAXTransformer
ProcessingException
SAXException
IOException
AbstractSAXTransformer.setup(org.apache.cocoon.environment.SourceResolver, java.util.Map, java.lang.String, org.apache.avalon.framework.parameters.Parameters)
public void recycle()
AbstractXMLProducer
recycle
in interface Recyclable
recycle
in class AbstractSAXTransformer
AbstractSAXTransformer.recycle()
public Serializable getKey()
CacheableProcessingComponent
getKey
in interface CacheableProcessingComponent
null
if the component
is currently not cacheable.CacheableProcessingComponent.getKey()
public SourceValidity getValidity()
CacheableProcessingComponent
getValidity
in interface CacheableProcessingComponent
null
if the
component is currently not cacheable.CacheableProcessingComponent.getValidity()
public void startPrefixMapping(String prefix, String uri) throws SAXException
AbstractSAXTransformer
startPrefixMapping
in interface ContentHandler
startPrefixMapping
in class AbstractSAXTransformer
prefix
- The Namespace prefix being declared.uri
- The Namespace URI the prefix is mapped to.
SAXException
AbstractSAXTransformer.startPrefixMapping(java.lang.String, java.lang.String)
public void endPrefixMapping(String prefix) throws SAXException
AbstractSAXTransformer
endPrefixMapping
in interface ContentHandler
endPrefixMapping
in class AbstractSAXTransformer
prefix
- The prefix that was being mapping.
SAXException
AbstractSAXTransformer.endPrefixMapping(java.lang.String)
public void startElement(String uri, String qName, String lName, Attributes attrs) throws SAXException
AbstractSAXTransformer
AbstractSAXTransformer.startTransformingElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
hook is called.
startElement
in interface ContentHandler
startElement
in class AbstractSAXTransformer
uri
- The Namespace URI, or the empty string if the element has no
Namespace URI or if Namespace
processing is not being performed.qName
- The local name (without prefix), or the empty string if
Namespace processing is not being performed.lName
- The raw XML 1.0 name (with prefix), or the empty string if
raw names are not available.attrs
- The attributes attached to the element. If there are no
attributes, it shall be an empty Attributes object.
SAXException
AbstractSAXTransformer.startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
public void endElement(String uri, String qName, String lName) throws SAXException
AbstractSAXTransformer
AbstractSAXTransformer.endTransformingElement(java.lang.String, java.lang.String, java.lang.String)
hook is called.
endElement
in interface ContentHandler
endElement
in class AbstractSAXTransformer
uri
- The Namespace URI, or the empty string if the element has no
Namespace URI or if Namespace
processing is not being performed.qName
- The local name (without prefix), or the empty string if
Namespace processing is not being performed.lName
- The raw XML 1.0 name (with prefix), or the empty string if
raw names are not available.
SAXException
AbstractSAXTransformer.endElement(java.lang.String, java.lang.String, java.lang.String)
public void characters(char[] ch, int start, int length) throws SAXException
AbstractSAXTransformer
characters
in interface ContentHandler
characters
in class AbstractSAXTransformer
ch
- The characters from the XML document.start
- The start position in the array.length
- The number of characters to read from the array.
SAXException
AbstractSAXTransformer.characters(char[], int, int)
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException
AbstractSAXTransformer
ignorableWhitespace
in interface ContentHandler
ignorableWhitespace
in class AbstractSAXTransformer
ch
- The characters from the XML document.start
- The start position in the array.length
- The number of characters to read from the array.
SAXException
AbstractSAXTransformer.ignorableWhitespace(char[], int, int)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |