org.apache.struts.plugins

Class DigestingPlugIn

public class DigestingPlugIn extends Object implements PlugIn

An implementation of PlugIn which can be configured to instantiate a graph of objects using the Commons Digester and place the root object of that graph into the Application context.

Since: Struts 1.2

Version: $Rev: 164530 $

See Also: PlugIn

Field Summary
protected StringconfigPath
protected StringconfigSource
protected StringdigesterPath
protected StringdigesterSource
protected Stringkey
static Loglog
Commons Logging instance.
protected ModuleConfigmoduleConfig
protected booleanpush
protected Stringrulesets
protected ActionServletservlet
protected static StringSOURCE_CLASSPATH
protected static StringSOURCE_FILE
protected static StringSOURCE_SERVLET
Constructor Summary
DigestingPlugIn()
Constructor for DigestingPlugIn.
Method Summary
protected voidapplyRuleSets(Digester digester)
Instantiate any RuleSet classes defined in the rulesets property and use them to add rules to our Digester.
voiddestroy()
Receive notification that our owning module is being shut down.
protected DigesterdigesterFromXml(String path, String source)

Instantiate a Digester from an XML input stream using the Commons DigesterLoader.

protected URLgetClassPathURL(String path)
Given a string, return a URL to a classpath resource of that name.
StringgetConfigPath()
StringgetConfigSource()
protected URLgetConfigURL(String path, String source)

Look up a resource path using one of a set of known path resolution mechanisms and return a URL to the resource.

StringgetDigesterPath()
StringgetDigesterSource()
protected URLgetFileURL(String path)
Given a string, return a URL to a Filesystem resource of that name.
StringgetKey()
booleangetPush()
StringgetRulesets()
protected URLgetServletContextURL(String path)
Given a string, return a URL to a Servlet Context resource of that name.
voidinit(ActionServlet servlet, ModuleConfig config)

Initialize a Digester and use it to parse a configuration file, resulting in a root object which will be placed into the ServletContext.

protected DigesterinitializeDigester()
Initialize the Digester which will be used to process the main configuration.
protected DigesternewDigesterInstance()

Instantiate a Digester.

Subclasses may wish to override this to provide a subclass of Digester, or to configure the Digester using object methods.

voidsetConfigPath(String configPath)
voidsetConfigSource(String configSource)
Set the source of the config file.
voidsetDigesterPath(String digesterPath)

The path to a Digester XML configuration file, relative to the digesterSource property.

voidsetDigesterSource(String digesterSource)

The lookup mechanism to be used to resolve digesterPath (optional).

voidsetKey(String key)
voidsetPush(boolean push)

If set to true, this PlugIn will be pushed onto the Digester stack before the digester parse method is called.

Defaults to false

voidsetRulesets(String ruleSets)

A comma-delimited list of one or more classes which implement org.apache.commons.digester.RuleSet.

protected voidstoreGeneratedObject(Object obj)
This method is called after the Digester runs to store the generated object somewhere.

Field Detail

configPath

protected String configPath

configSource

protected String configSource

digesterPath

protected String digesterPath

digesterSource

protected String digesterSource

key

protected String key

log

private static Log log
Commons Logging instance.

moduleConfig

protected ModuleConfig moduleConfig

push

protected boolean push

rulesets

protected String rulesets

servlet

protected ActionServlet servlet

SOURCE_CLASSPATH

protected static final String SOURCE_CLASSPATH

SOURCE_FILE

protected static final String SOURCE_FILE

SOURCE_SERVLET

protected static final String SOURCE_SERVLET

Constructor Detail

DigestingPlugIn

public DigestingPlugIn()
Constructor for DigestingPlugIn.

Method Detail

applyRuleSets

protected void applyRuleSets(Digester digester)
Instantiate any RuleSet classes defined in the rulesets property and use them to add rules to our Digester.

Parameters: digester the Digester instance to add RuleSet objects to.

Throws: ServletException

destroy

public void destroy()
Receive notification that our owning module is being shut down.

digesterFromXml

protected Digester digesterFromXml(String path, String source)

Instantiate a Digester from an XML input stream using the Commons DigesterLoader.

Parameters: path the path to the digester rules XML to be found using source source a string indicating the lookup method to be used with path

Returns: a configured Digester

Throws: FileNotFoundException MalformedURLException

See Also: DigestingPlugIn

getClassPathURL

protected URL getClassPathURL(String path)
Given a string, return a URL to a classpath resource of that name.

Parameters: path a Classpath-relative string identifying a resource.

Returns: a URL identifying the resource on the classpath. TODO Do we need to be smarter about ClassLoaders?

getConfigPath

public String getConfigPath()

Returns: the configPath property

See Also: configSource

getConfigSource

public String getConfigSource()

Returns: the string describing which access method should be used to resolve configPath.

See Also: configPath

getConfigURL

protected URL getConfigURL(String path, String source)

Look up a resource path using one of a set of known path resolution mechanisms and return a URL to the resource.

Parameters: path a String which is meaningful to one of the known resolution mechanisms. source one of the known path resolution mechanisms:

Returns: a URL pointing to the given path in the given mechanism.

Throws: FileNotFoundException MalformedURLException

getDigesterPath

public String getDigesterPath()

Returns: the configured path to a Digester XML config file, or null.

See Also: digesterSource DigestingPlugIn

getDigesterSource

public String getDigesterSource()

Returns: the configured lookup mechanism for resolving digesterPath.

See Also: DigestingPlugIn

getFileURL

protected URL getFileURL(String path)
Given a string, return a URL to a Filesystem resource of that name.

Parameters: path a path to a file.

Returns: a URL identifying the resource in the in the file system.

Throws: MalformedURLException FileNotFoundException

getKey

public String getKey()

Returns: The ServletContext attribute name the generated object is stored under.

getPush

public boolean getPush()

Returns: Whether or not this PlugIn instance will be pushed onto the Digester stack before digester.parse() is called.

getRulesets

public String getRulesets()

Returns: The configured list of RuleSet classes.

getServletContextURL

protected URL getServletContextURL(String path)
Given a string, return a URL to a Servlet Context resource of that name.

Parameters: path a Classpath-relative string identifying a resource.

Returns: a URL identifying the resource in the Servlet Context

Throws: MalformedURLException

init

public void init(ActionServlet servlet, ModuleConfig config)

Initialize a Digester and use it to parse a configuration file, resulting in a root object which will be placed into the ServletContext.

Parameters: servlet ActionServlet that is managing all the modules in this web application config ModuleConfig for the module with which this plug-in is associated

Throws: ServletException if this PlugIn cannot be successfully initialized

initializeDigester

protected Digester initializeDigester()
Initialize the Digester which will be used to process the main configuration.

Returns: a Digester, ready to use.

Throws: ServletException

newDigesterInstance

protected Digester newDigesterInstance()

Instantiate a Digester.

Subclasses may wish to override this to provide a subclass of Digester, or to configure the Digester using object methods.

Returns: a basic instance of org.apache.commons.digester.Digester

setConfigPath

public void setConfigPath(String configPath)

Parameters: configPath the path to configuration information for this PlugIn.

See Also: configSource

setConfigSource

public void setConfigSource(String configSource)
Set the source of the config file. Should be one of the following:

Parameters: configSource the source (lookup method) for the config file.

See Also: configPath

setDigesterPath

public void setDigesterPath(String digesterPath)

The path to a Digester XML configuration file, relative to the digesterSource property. (Optional)

See Also: digesterSource DigestingPlugIn

setDigesterSource

public void setDigesterSource(String digesterSource)

The lookup mechanism to be used to resolve digesterPath (optional).

Parameters: digesterSource

See Also: DigestingPlugIn

setKey

public void setKey(String key)

Parameters: key The ServletContext attribute name to store the generated object under.

setPush

public void setPush(boolean push)

If set to true, this PlugIn will be pushed onto the Digester stack before the digester parse method is called.

Defaults to false

Parameters: push

setRulesets

public void setRulesets(String ruleSets)

A comma-delimited list of one or more classes which implement org.apache.commons.digester.RuleSet. (Optional)

storeGeneratedObject

protected void storeGeneratedObject(Object obj)
This method is called after the Digester runs to store the generated object somewhere. This implementation places the given object into the ServletContext under the attribute name as defined in key.

Parameters: obj The object to save.

Copyright B) 2000-2007 - The Apache Software Foundation