org.apache.cocoon.transformation
Class CIncludeTransformer

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.CIncludeTransformer
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 CIncludeTransformer
extends org.apache.cocoon.transformation.AbstractSAXTransformer
implements org.apache.cocoon.caching.CacheableProcessingComponent

This transformer processes include elements in the http://apache.org/cocoon/include/1.0 namespace. The src attribute contains the url which points to an xml resource which is included instead of the element. With the attributes element, ns and prefix it is possible to specify an element which surrounds the included content.

This transformer also supports a more verbose but flexible version:

 <ci:includexml xmlns:ci="http://apache.org/cocoon/include/1.0" ignoreErrors="false">
   <ci:src>THE SRC URI</ci:src>
   <!-- This is an optional configuration block -->
   <ci:configuration>
     <!-- For example if you want to make a HTTP POST -->
     <ci:parameter>
       <ci:name>method</ci:name>
       <ci:value>POST</ci:value>
     </ci:parameter>
   </ci:configuration>
   <!-- The following are optional parameters appended to the URI -->
   <ci:parameters>
     <ci:parameter>
       <ci:name>a name</ci:name>
       <ci:value>a value</ci:value>
     </ci:parameter>
     <!-- more can follow -->
   </ci:parameters>
 </ci:includexml>
 

This transformer also supports caching of the included content. Caching is performed only when cached-include element in the http://apache.org/cocoon/include/1.0 namespace is used. The src attribute contains the url which points to an xml resource which is include instead of the element. First, it works like the usual include command. But it can be configured with various parameters: The most important one is the expires parameter. If (and only if) this is set to a value greater than zero, all included content is cached for the given period of time. So if any other request includes the same URI, the content is fetched from the cache. The expires value is in seconds. Usually the content is cached in the usual store, but you can also define a writeable source with the source parameter, e.g. "file:/c:/temp". Then the cached content is written into this directory. With the optional purge set to true the cache is purged which means the cached content is regarded as invalid nevertheless if it has expired or not. With the optional parameter parallel the various included contents are processed (included) in parallel rather than in a series. With the optional parameter preemptive set to true a pre-emptive caching is activated. When a resource is requested with pre-emptive caching, this transformer always attempts to get the content from the cache. If the content is not in the cache, it is of course retrieved from the original source and cached. If the cached resource has expired, it is still provided. The cache is updated by a background task. This task has to be started beforehand.

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

Field Summary
protected  IncludeCacheManager cacheManager
           
protected  IncludeCacheManagerSession cachingSession
           
static String CINCLUDE_CACHED_INCLUDE_ELEMENT
           
protected static String CINCLUDE_CACHED_INCLUDE_PLACEHOLDER_ELEMENT
           
static String CINCLUDE_CONFIGURATION_ELEMENT
           
static String CINCLUDE_INCLUDE_ELEMENT
           
static String CINCLUDE_INCLUDE_ELEMENT_ELEMENT_ATTRIBUTE
           
static String CINCLUDE_INCLUDE_ELEMENT_NS_ATTRIBUTE
           
static String CINCLUDE_INCLUDE_ELEMENT_PREFIX_ATTRIBUTE
           
static String CINCLUDE_INCLUDE_ELEMENT_SELECT_ATTRIBUTE
           
static String CINCLUDE_INCLUDE_ELEMENT_SRC_ATTRIBUTE
           
static String CINCLUDE_INCLUDE_ELEMENT_STRIP_ROOT_ATTRIBUTE
           
static String CINCLUDE_INCLUDEXML_ELEMENT
           
static String CINCLUDE_INCLUDEXML_ELEMENT_IGNORE_ERRORS_ATTRIBUTE
           
static String CINCLUDE_NAME_ELEMENT
           
static String CINCLUDE_NAMESPACE_URI
           
static String CINCLUDE_PARAMETER_ELEMENT
           
static String CINCLUDE_PARAMETERS_ELEMENT
           
static String CINCLUDE_SRC_ELEMENT
           
static String CINCLUDE_VALUE_ELEMENT
           
protected  boolean compiling
           
protected  Parameters configurationParameters
          The configuration of includexml
protected  org.apache.cocoon.xml.IncludeXMLConsumer filter
           
protected  SourceParameters resourceParameters
          The parameters for includexml
protected  AttributesImpl srcAttributes
           
protected  long startTime
          Remember the start time of the request for profiling
protected  int state
          The current state: STATE_
protected  boolean supportCaching
           
 
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
CIncludeTransformer()
          Constructor Set the namespace
 
Method Summary
 void dispose()
           
protected  Object endCompiledXMLRecording()
          Stop recording of compiled XML.
 void endDocument()
           
 void endTransformingElement(String uri, String name, String raw)
           
 Serializable getKey()
           
 SourceValidity getValidity()
           
protected  String processCIncludeElement(String src, String element, String select, String ns, String prefix, boolean stripRoot, boolean cache)
           
 void recycle()
          Recycle the component
 void service(ServiceManager manager)
           
 void setup(org.apache.cocoon.environment.SourceResolver resolver, Map objectModel, String source, Parameters parameters)
          Setup the component.
protected  void startCompiledXMLRecording()
          Start recording of compiled xml.
 void startDocument()
           
 void startTransformingElement(String uri, String name, String raw, Attributes attr)
           
 
Methods inherited from class org.apache.cocoon.transformation.AbstractSAXTransformer
addRecorder, characters, comment, configure, endCDATA, endDTD, endElement, endEntity, endParametersRecording, endParametersRecording, endPrefixMapping, endRecording, endSAXRecording, endSerializedXMLRecording, endTextRecording, findPrefixMapping, getMutableAttributes, ignorableWhitespace, processingInstruction, removeRecorder, sendEndElementEvent, sendEndElementEventNS, sendEndPrefixMapping, sendEvents, sendParametersEvents, sendStartElementEvent, sendStartElementEvent, sendStartElementEventNS, sendStartElementEventNS, sendStartPrefixMapping, sendTextEvent, setDocumentLocator, setupTransforming, skippedEntity, startCDATA, startDTD, startElement, startEntity, startParametersRecording, startPrefixMapping, startRecording, startSAXRecording, startSerializedXMLRecording, startTextRecording
 
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
 

Field Detail

CINCLUDE_NAMESPACE_URI

public static final String CINCLUDE_NAMESPACE_URI
See Also:
Constant Field Values

CINCLUDE_INCLUDE_ELEMENT

public static final String CINCLUDE_INCLUDE_ELEMENT
See Also:
Constant Field Values

CINCLUDE_INCLUDE_ELEMENT_SRC_ATTRIBUTE

public static final String CINCLUDE_INCLUDE_ELEMENT_SRC_ATTRIBUTE
See Also:
Constant Field Values

CINCLUDE_INCLUDE_ELEMENT_ELEMENT_ATTRIBUTE

public static final String CINCLUDE_INCLUDE_ELEMENT_ELEMENT_ATTRIBUTE
See Also:
Constant Field Values

CINCLUDE_INCLUDE_ELEMENT_SELECT_ATTRIBUTE

public static final String CINCLUDE_INCLUDE_ELEMENT_SELECT_ATTRIBUTE
See Also:
Constant Field Values

CINCLUDE_INCLUDE_ELEMENT_NS_ATTRIBUTE

public static final String CINCLUDE_INCLUDE_ELEMENT_NS_ATTRIBUTE
See Also:
Constant Field Values

CINCLUDE_INCLUDE_ELEMENT_PREFIX_ATTRIBUTE

public static final String CINCLUDE_INCLUDE_ELEMENT_PREFIX_ATTRIBUTE
See Also:
Constant Field Values

CINCLUDE_INCLUDE_ELEMENT_STRIP_ROOT_ATTRIBUTE

public static final String CINCLUDE_INCLUDE_ELEMENT_STRIP_ROOT_ATTRIBUTE
See Also:
Constant Field Values

CINCLUDE_INCLUDEXML_ELEMENT

public static final String CINCLUDE_INCLUDEXML_ELEMENT
See Also:
Constant Field Values

CINCLUDE_INCLUDEXML_ELEMENT_IGNORE_ERRORS_ATTRIBUTE

public static final String CINCLUDE_INCLUDEXML_ELEMENT_IGNORE_ERRORS_ATTRIBUTE
See Also:
Constant Field Values

CINCLUDE_SRC_ELEMENT

public static final String CINCLUDE_SRC_ELEMENT
See Also:
Constant Field Values

CINCLUDE_CONFIGURATION_ELEMENT

public static final String CINCLUDE_CONFIGURATION_ELEMENT
See Also:
Constant Field Values

CINCLUDE_PARAMETERS_ELEMENT

public static final String CINCLUDE_PARAMETERS_ELEMENT
See Also:
Constant Field Values

CINCLUDE_PARAMETER_ELEMENT

public static final String CINCLUDE_PARAMETER_ELEMENT
See Also:
Constant Field Values

CINCLUDE_NAME_ELEMENT

public static final String CINCLUDE_NAME_ELEMENT
See Also:
Constant Field Values

CINCLUDE_VALUE_ELEMENT

public static final String CINCLUDE_VALUE_ELEMENT
See Also:
Constant Field Values

CINCLUDE_CACHED_INCLUDE_ELEMENT

public static final String CINCLUDE_CACHED_INCLUDE_ELEMENT
See Also:
Constant Field Values

CINCLUDE_CACHED_INCLUDE_PLACEHOLDER_ELEMENT

protected static final String CINCLUDE_CACHED_INCLUDE_PLACEHOLDER_ELEMENT
See Also:
Constant Field Values

configurationParameters

protected Parameters configurationParameters
The configuration of includexml


resourceParameters

protected SourceParameters resourceParameters
The parameters for includexml


state

protected int state
The current state: STATE_


cacheManager

protected IncludeCacheManager cacheManager

cachingSession

protected IncludeCacheManagerSession cachingSession

compiling

protected boolean compiling

filter

protected org.apache.cocoon.xml.IncludeXMLConsumer filter

srcAttributes

protected AttributesImpl srcAttributes

supportCaching

protected boolean supportCaching

startTime

protected long startTime
Remember the start time of the request for profiling

Constructor Detail

CIncludeTransformer

public CIncludeTransformer()
Constructor Set the namespace

Method Detail

setup

public void setup(org.apache.cocoon.environment.SourceResolver resolver,
                  Map objectModel,
                  String source,
                  Parameters parameters)
           throws org.apache.cocoon.ProcessingException,
                  SAXException,
                  IOException
Setup the component.

Specified by:
setup in interface org.apache.cocoon.sitemap.SitemapModelComponent
Throws:
org.apache.cocoon.ProcessingException
SAXException
IOException

service

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

dispose

public void dispose()
Specified by:
dispose in interface Disposable
See Also:
Disposable.dispose()

recycle

public void recycle()
Recycle the component

Specified by:
recycle in interface Recyclable

startTransformingElement

public void startTransformingElement(String uri,
                                     String name,
                                     String raw,
                                     Attributes attr)
                              throws org.apache.cocoon.ProcessingException,
                                     IOException,
                                     SAXException
Throws:
org.apache.cocoon.ProcessingException
IOException
SAXException
See Also:
AbstractSAXTransformer.startTransformingElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)

endTransformingElement

public void endTransformingElement(String uri,
                                   String name,
                                   String raw)
                            throws org.apache.cocoon.ProcessingException,
                                   IOException,
                                   SAXException
Throws:
org.apache.cocoon.ProcessingException
IOException
SAXException
See Also:
AbstractSAXTransformer.endTransformingElement(java.lang.String, java.lang.String, java.lang.String)

processCIncludeElement

protected String processCIncludeElement(String src,
                                        String element,
                                        String select,
                                        String ns,
                                        String prefix,
                                        boolean stripRoot,
                                        boolean cache)
                                 throws SAXException,
                                        IOException
Throws:
SAXException
IOException

startCompiledXMLRecording

protected void startCompiledXMLRecording()
                                  throws SAXException
Start recording of compiled xml. The incomming SAX events are recorded and a compiled representation is created. These events are not forwarded to the next component in the pipeline.

Throws:
SAXException

endCompiledXMLRecording

protected Object endCompiledXMLRecording()
                                  throws SAXException
Stop recording of compiled XML.

Returns:
The compiled XML.
Throws:
SAXException

startDocument

public void startDocument()
                   throws SAXException
Specified by:
startDocument in interface ContentHandler
Throws:
SAXException
See Also:
ContentHandler.startDocument()

endDocument

public void endDocument()
                 throws SAXException
Specified by:
endDocument in interface ContentHandler
Throws:
SAXException
See Also:
ContentHandler.endDocument()

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()


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