org.apache.cocoon.serialization
Class AbstractTextSerializer

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.serialization.AbstractSerializer
                  extended byorg.apache.cocoon.serialization.AbstractTextSerializer
All Implemented Interfaces:
org.apache.cocoon.caching.CacheableProcessingComponent, Configurable, ContentHandler, LexicalHandler, Poolable, Recyclable, org.apache.cocoon.serialization.Serializer, Serviceable, org.apache.cocoon.sitemap.SitemapOutputComponent, XMLConsumer, org.apache.cocoon.xml.XMLConsumer, org.apache.cocoon.xml.XMLPipe, org.apache.cocoon.xml.XMLProducer

public abstract class AbstractTextSerializer
extends AbstractSerializer
implements Configurable, Serviceable, org.apache.cocoon.caching.CacheableProcessingComponent

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

Nested Class Summary
static class AbstractTextSerializer.NamespaceAsAttributes
          A pipe that ensures that all namespace prefixes are also present as 'xmlns:' attributes.
 
Field Summary
protected  Properties format
          The Properties used by this serializer.
 
Fields inherited from class org.apache.cocoon.serialization.AbstractSerializer
output
 
Fields inherited from class org.apache.cocoon.xml.AbstractXMLProducer
contentHandler, EMPTY_CONTENT_HANDLER, lexicalHandler, xmlConsumer
 
Fields inherited from interface org.apache.cocoon.serialization.Serializer
ROLE
 
Constructor Summary
AbstractTextSerializer()
           
 
Method Summary
 void configure(Configuration conf)
          Deprecated. use property injection instead
protected static String createCachingKey(Properties format)
          Create the caching key from the formating properties used by the transformer handler that is used for serialization.
 Serializable getKey()
          Generate the unique key.
protected  SAXTransformerFactory getTransformerFactory()
          Helper for TransformerFactory.
protected  TransformerHandler getTransformerHandler()
          Helper for TransformerHandler.
 SourceValidity getValidity()
          Generate the validity object.
 void init()
          Initialize logger, caching key, transformer handler and namespace pipe
protected  boolean needsNamespacesAsAttributes()
          Checks if the used Trax implementation correctly handles namespaces set using startPrefixMapping(), but wants them also as 'xmlns:' attributes.
 void recycle()
          Recycle serializer by removing references
 void service(ServiceManager manager)
          Deprecated. use property injection instead
 void setConsumer(org.apache.cocoon.xml.XMLConsumer consumer)
          Interpose namespace pipe if needed.
 void setContentHandler(ContentHandler handler)
          Interpose namespace pipe if needed.
 void setDefaultEncoding(String defaultEncoding)
          Set the default encoding.
 void setFormat(Properties format)
          Set the properties used for transformer handler used by the serializer see OutputKeys for possible settings.
 void setLexicalHandler(LexicalHandler handler)
          Interpose namespace pipe if needed.
 void setTransformerFactory(String transformerFactoryClass)
          Optionally set the transformer factory used for creating the transformer handler that is used for serialization.
 
Methods inherited from class org.apache.cocoon.serialization.AbstractSerializer
getMimeType, setOutputStream, shouldSetContentLength
 
Methods inherited from class org.apache.cocoon.xml.AbstractXMLPipe
characters, comment, endCDATA, endDocument, endDTD, endElement, endEntity, endPrefixMapping, ignorableWhitespace, processingInstruction, setDocumentLocator, skippedEntity, startCDATA, startDocument, startDTD, startElement, startEntity, startPrefixMapping
 
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.xml.sax.ContentHandler
characters, endDocument, endElement, endPrefixMapping, ignorableWhitespace, processingInstruction, setDocumentLocator, skippedEntity, startDocument, startElement, startPrefixMapping
 
Methods inherited from interface org.xml.sax.ext.LexicalHandler
comment, endCDATA, endDTD, endEntity, startCDATA, startDTD, startEntity
 

Field Detail

format

protected Properties format
The Properties used by this serializer.

Constructor Detail

AbstractTextSerializer

public AbstractTextSerializer()
Method Detail

setFormat

public void setFormat(Properties format)
Set the properties used for transformer handler used by the serializer see OutputKeys for possible settings.

Parameters:
format -

setDefaultEncoding

public void setDefaultEncoding(String defaultEncoding)
Set the default encoding. This will be overided if the encoding is set in the format properties. This is mainly useful together with Spring bean inheritance.

Parameters:
defaultEncoding -

init

public void init()
          throws Exception
Initialize logger, caching key, transformer handler and namespace pipe

Throws:
Exception

setTransformerFactory

public void setTransformerFactory(String transformerFactoryClass)
Optionally set the transformer factory used for creating the transformer handler that is used for serialization. Otherwise the standard transformer factory is used (TransformerFactory).

Parameters:
transformerFactoryClass - the name of the class

setConsumer

public void setConsumer(org.apache.cocoon.xml.XMLConsumer consumer)
Interpose namespace pipe if needed.

Specified by:
setConsumer in interface org.apache.cocoon.xml.XMLProducer
Overrides:
setConsumer in class AbstractXMLProducer
Parameters:
consumer - xml consumer, should never be null.

setContentHandler

public void setContentHandler(ContentHandler handler)
Interpose namespace pipe if needed.

Overrides:
setContentHandler in class AbstractXMLProducer
Parameters:
handler - content handler, should never be null.

setLexicalHandler

public void setLexicalHandler(LexicalHandler handler)
Interpose namespace pipe if needed.

Overrides:
setLexicalHandler in class AbstractXMLProducer
Parameters:
handler - lexical handler, should never be null.

getTransformerFactory

protected SAXTransformerFactory getTransformerFactory()
Helper for TransformerFactory.


getTransformerHandler

protected TransformerHandler getTransformerHandler()
                                            throws TransformerException
Helper for TransformerHandler.

Throws:
TransformerException

service

public void service(ServiceManager manager)
             throws ServiceException
Deprecated. use property injection instead

Specified by:
service in interface Serviceable
Throws:
ServiceException
See Also:
Serviceable.service(org.apache.avalon.framework.service.ServiceManager)

configure

public void configure(Configuration conf)
               throws ConfigurationException
Deprecated. use property injection instead

Set the configurations for this serializer.

Specified by:
configure in interface Configurable
Throws:
ConfigurationException

recycle

public void recycle()
Description copied from class: AbstractSerializer
Recycle serializer by removing references

Specified by:
recycle in interface Recyclable
Overrides:
recycle in class AbstractSerializer
See Also:
Recyclable.recycle()

createCachingKey

protected static String createCachingKey(Properties format)
Create the caching key from the formating properties used by the transformer handler that is used for serialization.

Parameters:
format -

getKey

public Serializable getKey()
Generate the unique key. This key must be unique inside the space of this component. This method must be invoked before the generateValidity() method.

Specified by:
getKey in interface org.apache.cocoon.caching.CacheableProcessingComponent
Returns:
The generated key or 0 if the component is currently not cacheable.

getValidity

public SourceValidity getValidity()
Generate the validity object. Before this method can be invoked the generateKey() method must be invoked.

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

needsNamespacesAsAttributes

protected boolean needsNamespacesAsAttributes()
                                       throws Exception
Checks if the used Trax implementation correctly handles namespaces set using startPrefixMapping(), but wants them also as 'xmlns:' attributes.

The check consists in sending SAX events representing a minimal namespaced document with namespaces defined only with calls to startPrefixMapping (no xmlns:xxx attributes) and check if they are present in the resulting text.

Throws:
Exception


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