Class ConfigLoader
- java.lang.Object
-
- com.opensymphony.module.sitemesh.mapper.ConfigLoader
-
public final class ConfigLoader extends java.lang.ObjectThe ConfigLoader reads a configuration XML file that contains Decorator definitions (name, url, init-params) and path-mappings (pattern, name).These can then be accessed by the getDecoratorByName() methods and getMappedName() methods respectively.
The DTD for the configuration file in old (deprecated) format is located at http://www.opensymphony.com/dtds/sitemesh_1_0_decorators.dtd .
The DTD for the configuration file in new format is located at http://www.opensymphony.com/dtds/sitemesh_1_5_decorators.dtd .
Editing the config file will cause it to be auto-reloaded.
This class is used by ConfigDecoratorMapper, and uses PathMapper for pattern matching.
- Version:
- $Revision: 1.4 $
- Author:
- Joe Walnes, Mathias Bogaert
- See Also:
ConfigDecoratorMapper,PathMapper
-
-
Field Summary
Fields Modifier and Type Field Description private Configconfigprivate java.io.FileconfigFileprivate java.lang.StringconfigFileNameprivate longconfigLastModifiedprivate java.util.Mapdecoratorsprivate PathMapperpathMapper
-
Constructor Summary
Constructors Constructor Description ConfigLoader(java.io.File configFile)Create new ConfigLoader using supplied File.ConfigLoader(java.lang.String configFileName, Config config)Create new ConfigLoader using supplied filename and config.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static java.lang.StringgetAttribute(org.w3c.dom.Element element, java.lang.String name)Override default behavior of element.getAttribute (returns the empty string) to return null.private static java.lang.StringgetContainedText(org.w3c.dom.Node parent, java.lang.String childTagName)With a given parent XML Element, find the text contents of the child element with supplied name.DecoratorgetDecoratorByName(java.lang.String name)Retrieve Decorator based on name specified in configuration file.java.lang.StringgetMappedName(java.lang.String path)Get name of Decorator mapped to given path.private voidloadConfig()Load configuration from file.private voidparseConfig(org.w3c.dom.Document document)Parse configuration from XML document.private voidpopulatePathMapper(org.w3c.dom.NodeList patternNodes, java.lang.String role, java.lang.String name)Extracts each URL pattern and adds it to the pathMapper map.private voidrefresh()Check if configuration file has been updated, and if so, reload.private voidstoreDecorator(Decorator d)Store Decorator in Map
-
-
-
Field Detail
-
decorators
private java.util.Map decorators
-
configLastModified
private long configLastModified
-
configFile
private java.io.File configFile
-
configFileName
private java.lang.String configFileName
-
pathMapper
private PathMapper pathMapper
-
config
private Config config
-
-
Constructor Detail
-
ConfigLoader
public ConfigLoader(java.io.File configFile) throws jakarta.servlet.ServletExceptionCreate new ConfigLoader using supplied File.- Throws:
jakarta.servlet.ServletException
-
ConfigLoader
public ConfigLoader(java.lang.String configFileName, Config config) throws jakarta.servlet.ServletExceptionCreate new ConfigLoader using supplied filename and config.- Throws:
jakarta.servlet.ServletException
-
-
Method Detail
-
getDecoratorByName
public Decorator getDecoratorByName(java.lang.String name) throws jakarta.servlet.ServletException
Retrieve Decorator based on name specified in configuration file.- Throws:
jakarta.servlet.ServletException
-
getMappedName
public java.lang.String getMappedName(java.lang.String path) throws jakarta.servlet.ServletExceptionGet name of Decorator mapped to given path.- Throws:
jakarta.servlet.ServletException
-
loadConfig
private void loadConfig() throws jakarta.servlet.ServletExceptionLoad configuration from file.- Throws:
jakarta.servlet.ServletException
-
parseConfig
private void parseConfig(org.w3c.dom.Document document)
Parse configuration from XML document.
-
populatePathMapper
private void populatePathMapper(org.w3c.dom.NodeList patternNodes, java.lang.String role, java.lang.String name)Extracts each URL pattern and adds it to the pathMapper map.
-
getAttribute
private static java.lang.String getAttribute(org.w3c.dom.Element element, java.lang.String name)Override default behavior of element.getAttribute (returns the empty string) to return null.
-
getContainedText
private static java.lang.String getContainedText(org.w3c.dom.Node parent, java.lang.String childTagName)With a given parent XML Element, find the text contents of the child element with supplied name.
-
storeDecorator
private void storeDecorator(Decorator d)
Store Decorator in Map
-
refresh
private void refresh() throws jakarta.servlet.ServletExceptionCheck if configuration file has been updated, and if so, reload.- Throws:
jakarta.servlet.ServletException
-
-