Class ConfigLoader
- java.lang.Object
-
- com.opensymphony.module.sitemesh.mapper.ConfigLoader
-
public final class ConfigLoader extends java.lang.Object
The 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 Config
config
private java.io.File
configFile
private java.lang.String
configFileName
private long
configLastModified
private java.util.Map
decorators
private PathMapper
pathMapper
-
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.String
getAttribute(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.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.Decorator
getDecoratorByName(java.lang.String name)
Retrieve Decorator based on name specified in configuration file.java.lang.String
getMappedName(java.lang.String path)
Get name of Decorator mapped to given path.private void
loadConfig()
Load configuration from file.private void
parseConfig(org.w3c.dom.Document document)
Parse configuration from XML document.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.private void
refresh()
Check if configuration file has been updated, and if so, reload.private void
storeDecorator(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 javax.servlet.ServletException
Create new ConfigLoader using supplied File.- Throws:
javax.servlet.ServletException
-
ConfigLoader
public ConfigLoader(java.lang.String configFileName, Config config) throws javax.servlet.ServletException
Create new ConfigLoader using supplied filename and config.- Throws:
javax.servlet.ServletException
-
-
Method Detail
-
getDecoratorByName
public Decorator getDecoratorByName(java.lang.String name) throws javax.servlet.ServletException
Retrieve Decorator based on name specified in configuration file.- Throws:
javax.servlet.ServletException
-
getMappedName
public java.lang.String getMappedName(java.lang.String path) throws javax.servlet.ServletException
Get name of Decorator mapped to given path.- Throws:
javax.servlet.ServletException
-
loadConfig
private void loadConfig() throws javax.servlet.ServletException
Load configuration from file.- Throws:
javax.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 javax.servlet.ServletException
Check if configuration file has been updated, and if so, reload.- Throws:
javax.servlet.ServletException
-
-