com.opensymphony.module.sitemesh.mapper
Class ConfigLoader

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

public 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.8 $
Author:
Joe Walnes, Mathias Bogaert
See Also:
ConfigDecoratorMapper, PathMapper

Nested Class Summary
private static class ConfigLoader.State
          State visibile across threads stored in a single container so that we can efficiently atomically access it with the guarantee that we wont see a partially loaded configuration in the face of one thread reloading the configuration while others are trying to read it.
 
Field Summary
private  Config config
           
private  File configFile
           
private  String configFileName
           
private  ConfigLoader.State state
          Mark volatile so that the installation of new versions is guaranteed to be visible across threads.
 
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)
           
private static String getContainedText(Node parent, String childTagName)
           
 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  ConfigLoader.State loadConfig()
          Load configuration from file.
private  void parseConfig(ConfigLoader.State newState, Document document)
           
private  void populatePathMapper(ConfigLoader.State newState, NodeList patternNodes, String role, String name)
           
private  ConfigLoader.State refresh()
          Check if configuration file has been updated, and if so, reload.
private  void storeDecorator(ConfigLoader.State newState, Decorator d)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

state

private volatile ConfigLoader.State state
Mark volatile so that the installation of new versions is guaranteed to be visible across threads.


configFile

private File configFile

configFileName

private String configFileName

config

private Config config
Constructor Detail

ConfigLoader

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

Throws:
javax.servlet.ServletException

ConfigLoader

public ConfigLoader(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(String name)
                             throws javax.servlet.ServletException
Retrieve Decorator based on name specified in configuration file.

Throws:
javax.servlet.ServletException

getMappedName

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

Throws:
javax.servlet.ServletException

loadConfig

private ConfigLoader.State loadConfig()
                               throws javax.servlet.ServletException
Load configuration from file.

Throws:
javax.servlet.ServletException

parseConfig

private void parseConfig(ConfigLoader.State newState,
                         Document document)

populatePathMapper

private void populatePathMapper(ConfigLoader.State newState,
                                NodeList patternNodes,
                                String role,
                                String name)

getAttribute

private static String getAttribute(Element element,
                                   String name)

getContainedText

private static String getContainedText(Node parent,
                                       String childTagName)

storeDecorator

private void storeDecorator(ConfigLoader.State newState,
                            Decorator d)

refresh

private ConfigLoader.State refresh()
                            throws javax.servlet.ServletException
Check if configuration file has been updated, and if so, reload.

Throws:
javax.servlet.ServletException

www.opensymphony.com/sitemesh/