Class ConfigLoader

java.lang.Object
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:
  • Field Details

    • 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 Details

    • ConfigLoader

      public ConfigLoader(File configFile) throws jakarta.servlet.ServletException
      Create new ConfigLoader using supplied File.
      Throws:
      jakarta.servlet.ServletException
    • ConfigLoader

      public ConfigLoader(String configFileName, Config config) throws jakarta.servlet.ServletException
      Create new ConfigLoader using supplied filename and config.
      Throws:
      jakarta.servlet.ServletException
  • Method Details

    • getDecoratorByName

      public Decorator getDecoratorByName(String name) throws jakarta.servlet.ServletException
      Retrieve Decorator based on name specified in configuration file.
      Throws:
      jakarta.servlet.ServletException
    • getMappedName

      public String getMappedName(String path) throws jakarta.servlet.ServletException
      Get name of Decorator mapped to given path.
      Throws:
      jakarta.servlet.ServletException
    • loadConfig

      private void loadConfig() throws jakarta.servlet.ServletException
      Load configuration from file.
      Throws:
      jakarta.servlet.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 jakarta.servlet.ServletException
      Check if configuration file has been updated, and if so, reload.
      Throws:
      jakarta.servlet.ServletException