com.opensymphony.module.sitemesh.mapper
Class ConfigLoader

java.lang.Object
  extended by com.opensymphony.module.sitemesh.mapper.ConfigLoader

public final class ConfigLoader
extends 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
private  Config config
           
private  File configFile
           
private  String configFileName
           
private  long configLastModified
           
private  Map decorators
           
private  PathMapper pathMapper
           
 
Constructor Summary
ConfigLoader(File configFile)
          Create new ConfigLoader using supplied File.
ConfigLoader(String configFileName, Config config)
          Create new ConfigLoader using supplied filename and config.
 
Method Summary
private static String getAttribute(Element element, String name)
          Override default behavior of element.getAttribute (returns the empty string) to return null.
private static String getContainedText(Node parent, String childTagName)
          With a given parent XML Element, find the text contents of the child element with supplied name.
 Decorator getDecoratorByName(String name)
          Retrieve Decorator based on name specified in configuration file.
 String getMappedName(String path)
          Get name of Decorator mapped to given path.
private  void loadConfig()
          Load configuration from file.
private  void parseConfig(Document document)
          Parse configuration from XML document.
private  void populatePathMapper(NodeList patternNodes, String role, 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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

decorators

private Map decorators

configLastModified

private long configLastModified

configFile

private File configFile

configFileName

private String configFileName

pathMapper

private PathMapper pathMapper

config

private Config config
Constructor Detail

ConfigLoader

public ConfigLoader(File configFile)
             throws ServletException
Create new ConfigLoader using supplied File.

Throws:
ServletException

ConfigLoader

public ConfigLoader(String configFileName,
                    Config config)
             throws ServletException
Create new ConfigLoader using supplied filename and config.

Throws:
ServletException
Method Detail

getDecoratorByName

public Decorator getDecoratorByName(String name)
                             throws ServletException
Retrieve Decorator based on name specified in configuration file.

Throws:
ServletException

getMappedName

public String getMappedName(String path)
                     throws ServletException
Get name of Decorator mapped to given path.

Throws:
ServletException

loadConfig

private void loadConfig()
                 throws ServletException
Load configuration from file.

Throws:
ServletException

parseConfig

private void parseConfig(Document document)
Parse configuration from XML document.


populatePathMapper

private void populatePathMapper(NodeList patternNodes,
                                String role,
                                String name)
Extracts each URL pattern and adds it to the pathMapper map.


getAttribute

private static String getAttribute(Element element,
                                   String name)
Override default behavior of element.getAttribute (returns the empty string) to return null.


getContainedText

private static String getContainedText(Node parent,
                                       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 ServletException
Check if configuration file has been updated, and if so, reload.

Throws:
ServletException

www.opensymphony.com/sitemesh/