org.apache.cocoon.components.modules.input
Class XMLFileModule

java.lang.Object
  extended byorg.apache.cocoon.util.AbstractLogEnabled
      extended byorg.apache.cocoon.components.modules.input.AbstractInputModule
          extended byorg.apache.cocoon.components.modules.input.AbstractJXPathModule
              extended byorg.apache.cocoon.components.modules.input.XMLFileModule
All Implemented Interfaces:
Configurable, Disposable, org.apache.cocoon.components.modules.input.InputModule, Serviceable, ThreadSafe

public class XMLFileModule
extends org.apache.cocoon.components.modules.input.AbstractJXPathModule
implements Serviceable, ThreadSafe

This module provides an Input Module interface to any XML document, by using XPath expressions as attribute keys. The XML can be obtained from any Cocoon Source (e.g., cocoon:/..., context://.., and regular URLs). Sources can be held in memory for better performance and reloaded if changed.

Caching and reloading can be turned on / off (default: caching on, reloading off) through <reloadable>false</reloadable> and <cacheable>false</cacheable>. The file (source) to use is specified through <file src="protocol:path/to/file.xml" reloadable="true" cacheable="true"/> optionally overriding defaults for caching and/or reloading.

In addition, xpath expressions are cached for higher performance. Thus, if an expression has been evaluated for a file, the result is cached and will be reused, the expression is not evaluated a second time. This can be turned off using the cache-expressions configuration option.

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

Nested Class Summary
protected  class XMLFileModule.DocumentHelper
          Takes care of (re-)loading and caching of sources.
 
Field Summary
 
Fields inherited from class org.apache.cocoon.components.modules.input.AbstractJXPathModule
configuration, parameter
 
Fields inherited from class org.apache.cocoon.components.modules.input.AbstractInputModule
settings
 
Fields inherited from interface org.apache.cocoon.components.modules.input.InputModule
ROLE
 
Constructor Summary
XMLFileModule()
           
 
Method Summary
 void configure(Configuration config)
          Static (cocoon.xconf) configuration.
 void dispose()
          Dispose this component
protected  void flushCache()
           
 Object getAttribute(String name, Configuration modeConf, Map objectModel)
           
 Object[] getAttributeValues(String name, Configuration modeConf, Map objectModel)
           
protected  Object getContextObject(Configuration modeConf, Map objectModel)
          Get the DOM object that JXPath will operate on when evaluating attributes.
 void service(ServiceManager manager)
           
 
Methods inherited from class org.apache.cocoon.components.modules.input.AbstractJXPathModule
getAttributeNames
 
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
 

Constructor Detail

XMLFileModule

public XMLFileModule()
Method Detail

service

public void service(ServiceManager manager)
             throws ServiceException
Specified by:
service in interface Serviceable
Throws:
ServiceException

configure

public void configure(Configuration config)
               throws ConfigurationException
Static (cocoon.xconf) configuration. Configuration is expected to be of the form: <...> <reloadable>true|false</reloadable> <cacheable>true|false</cacheable> <file src="src1" reloadable="true|false" cacheable="true|false"/> <file src="src2" reloadable="true|false" cacheable="true|false"/> ... </...> Each <file/> element pre-loads an XML DOM for querying. Typically only one <file> is specified, and its src is used as a default if not overridden in the getContextObject(Configuration, Map)

Specified by:
configure in interface Configurable
Parameters:
config - a Configuration value, as described above.
Throws:
ConfigurationException - if an error occurs

dispose

public void dispose()
Dispose this component

Specified by:
dispose in interface Disposable

getContextObject

protected Object getContextObject(Configuration modeConf,
                                  Map objectModel)
                           throws ConfigurationException
Get the DOM object that JXPath will operate on when evaluating attributes. This DOM is loaded from a Source, specified in the modeConf, or (if modeConf is null) from the configure(Configuration).

Parameters:
modeConf - The dynamic configuration for the current operation. May be null, in which case static (cocoon.xconf) configuration is used. Configuration is expected to have a <file> child node, and be of the form: <...> <file src="..." reloadable="true|false"/> </...>
objectModel - Object Model for the current module operation.
Throws:
ConfigurationException

getAttribute

public Object getAttribute(String name,
                           Configuration modeConf,
                           Map objectModel)
                    throws ConfigurationException
Specified by:
getAttribute in interface org.apache.cocoon.components.modules.input.InputModule
Throws:
ConfigurationException

getAttributeValues

public Object[] getAttributeValues(String name,
                                   Configuration modeConf,
                                   Map objectModel)
                            throws ConfigurationException
Specified by:
getAttributeValues in interface org.apache.cocoon.components.modules.input.InputModule
Throws:
ConfigurationException

flushCache

protected void flushCache()


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