org.apache.velocity.tools.config
Class ConfigurationUtils

java.lang.Object
  extended by org.apache.velocity.tools.config.ConfigurationUtils

public class ConfigurationUtils
extends java.lang.Object

Utility methods for handling tool configurations.

Version:
$Id: ConfigurationUtils.java 511959 2007-02-26 19:24:39Z nbubna $
Author:
Nathan Bubna

Field Summary
static java.lang.String AUTOLOADED_PROPS_PATH
           
static java.lang.String AUTOLOADED_XML_PATH
           
static java.lang.String CONFIG_FACTORY_METHOD
           
static java.lang.String GENERIC_DEFAULTS_PATH
           
static ConfigurationUtils INSTANCE
           
static java.lang.String STRUTS_DEFAULTS_PATH
           
static java.lang.String SYSTEM_PROPERTY_KEY
           
static java.lang.String VIEW_DEFAULTS_PATH
           
 
Constructor Summary
private ConfigurationUtils()
           
 
Method Summary
static void clean(Configuration config)
          Convenience method that automatically creates a new ConfigurationCleaner and applies it to the specified Configuration.
static ToolboxFactory createFactory()
          Returns a new, standard ToolboxFactory configured with the results of both getAutoLoaded() and findFromSystemProperty().
static FactoryConfiguration find(java.lang.String path)
          Searches for a configuration file at the specified path and returns it in the form of a FactoryConfiguration.
static FactoryConfiguration findFromSystemProperty()
          Returns a FactoryConfiguration loaded from the path specified in the "org.apache.velocity.tools" system property (if any).
static FactoryConfiguration findInClasspath(java.lang.String path)
           
static FactoryConfiguration findInClasspath(java.lang.String path, java.lang.Object caller)
          Searches the classpath for a configuration file matching the specified path.
static FactoryConfiguration findInFileSystem(java.lang.String path)
          Searches the file system for a configuration file matching the specified path.
static FactoryConfiguration getAutoLoaded()
          Returns a FactoryConfiguration including all getDefaultTools() as well as any tools that can be automatically loaded from "tools.xml" or "tools.properties" found at the root of the classpath or in the current directory.
static FactoryConfiguration getAutoLoaded(boolean includeDefaults)
          Returns a FactoryConfiguration composed, in order of the following configurations: getDefaultTools() (only if includeDefaults is true) All "tools.xml" configurations found in the classpath root, in the order found All "tools.properties" configurations found in the classpath root, in the order found The "tools.xml" file in the current directory (if any) The "tools.properties" file in the current directory (if any) If the includeDefaults parameter is null and no such files described above can be found, then the configuration returned by this method will be empty, but it should never be null.
static FactoryConfiguration getDefaultTools()
          Returns the "default" FactoryConfiguration.
static FactoryConfiguration getFromClass(java.lang.Class factory)
           
static FactoryConfiguration getFromClass(java.lang.String classname)
           
static FactoryConfiguration getGenericTools()
          Returns a FactoryConfiguration including all default "GenericTools" available and no others.
 ConfigurationUtils getInstance()
           
static FactoryConfiguration getVelocityStruts()
          Returns a FactoryConfiguration including all default "VelocityStruts" tools available as well as the default "VelocityView" tools and "GenericTools".
static FactoryConfiguration getVelocityView()
          Returns a FactoryConfiguration including all default "VelocityView" tools available as well as the default "GenericTools".
static FactoryConfiguration load(java.lang.String path)
          Returns a FactoryConfiguration loaded from a configuration file at the specified path.
static FactoryConfiguration read(java.net.URL url)
          Returns a FactoryConfiguration read from a known configuration file type at the specified URL.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GENERIC_DEFAULTS_PATH

public static final java.lang.String GENERIC_DEFAULTS_PATH
See Also:
Constant Field Values

VIEW_DEFAULTS_PATH

public static final java.lang.String VIEW_DEFAULTS_PATH
See Also:
Constant Field Values

STRUTS_DEFAULTS_PATH

public static final java.lang.String STRUTS_DEFAULTS_PATH
See Also:
Constant Field Values

AUTOLOADED_XML_PATH

public static final java.lang.String AUTOLOADED_XML_PATH
See Also:
Constant Field Values

AUTOLOADED_PROPS_PATH

public static final java.lang.String AUTOLOADED_PROPS_PATH
See Also:
Constant Field Values

SYSTEM_PROPERTY_KEY

public static final java.lang.String SYSTEM_PROPERTY_KEY
See Also:
Constant Field Values

INSTANCE

public static final ConfigurationUtils INSTANCE

CONFIG_FACTORY_METHOD

public static final java.lang.String CONFIG_FACTORY_METHOD
See Also:
Constant Field Values
Constructor Detail

ConfigurationUtils

private ConfigurationUtils()
Method Detail

getInstance

public ConfigurationUtils getInstance()

getDefaultTools

public static FactoryConfiguration getDefaultTools()
Returns the "default" FactoryConfiguration. This includes all the standard tools developed by this project and available in the jar being used. In other words, if the velocity-tools-generic-2.x.jar is being used, then only the generic tools will be included. If the velocity-tools-struts-2.x.jar is being used, then all VelocityTools will be available. This also means that subclasses in the larger jars will override their superclasses. So, if you are using the VelocityStruts jar, then your $link reference will be a StrutsLinkTool. If you are using the VelocityView jar, it will be a standard LinkTool.


getGenericTools

public static FactoryConfiguration getGenericTools()
Returns a FactoryConfiguration including all default "GenericTools" available and no others.


getVelocityView

public static FactoryConfiguration getVelocityView()
Returns a FactoryConfiguration including all default "VelocityView" tools available as well as the default "GenericTools".

Throws:
{@link - ConfigurationException} if a tools.xml is not found at the VIEW_DEFAULTS_PATH.

getVelocityStruts

public static FactoryConfiguration getVelocityStruts()
Returns a FactoryConfiguration including all default "VelocityStruts" tools available as well as the default "VelocityView" tools and "GenericTools".

Throws:
{@link - ConfigurationException} if a tools.xml is not found at the VIEW_DEFAULTS_PATH or STRUTS_DEFAULTS_PATH.

getAutoLoaded

public static FactoryConfiguration getAutoLoaded()
Returns a FactoryConfiguration including all getDefaultTools() as well as any tools that can be automatically loaded from "tools.xml" or "tools.properties" found at the root of the classpath or in the current directory.

See Also:
getAutoLoaded(boolean includeDefaults)

getAutoLoaded

public static FactoryConfiguration getAutoLoaded(boolean includeDefaults)
Returns a FactoryConfiguration composed, in order of the following configurations: If the includeDefaults parameter is null and no such files described above can be found, then the configuration returned by this method will be empty, but it should never be null.


findFromSystemProperty

public static FactoryConfiguration findFromSystemProperty()
Returns a FactoryConfiguration loaded from the path specified in the "org.apache.velocity.tools" system property (if any). If no such property has been set null will be returned.

Throws:
org.apache.velocity.exception.ResourceNotFoundException - if the system property has a value but no configuration file was found at the specified location

createFactory

public static ToolboxFactory createFactory()
Returns a new, standard ToolboxFactory configured with the results of both getAutoLoaded() and findFromSystemProperty().


clean

public static void clean(Configuration config)
Convenience method that automatically creates a new ConfigurationCleaner and applies it to the specified Configuration.


load

public static FactoryConfiguration load(java.lang.String path)
Returns a FactoryConfiguration loaded from a configuration file at the specified path. If no such file is found at that path, this will throw a ResourceNotFoundException.

See Also:
find(String path)

find

public static FactoryConfiguration find(java.lang.String path)
Searches for a configuration file at the specified path and returns it in the form of a FactoryConfiguration. This method will look for a matching file in both the classpath and the file system. If perchance a match is found in both, then both are loaded and the configuration loaded from the file system is given precedence (i.e. it is added onto the other). If no match is found in either, then this will return null.


findInFileSystem

public static FactoryConfiguration findInFileSystem(java.lang.String path)
Searches the file system for a configuration file matching the specified path. If found, it will read and return it as a FactoryConfiguration. If not found, this will return null.

Throws:
java.lang.IllegalStateException - if the file exists, but its path could not be converted to a URL for reading.

findInClasspath

public static FactoryConfiguration findInClasspath(java.lang.String path)
See Also:
findInClasspath(String path, Object caller)

findInClasspath

public static FactoryConfiguration findInClasspath(java.lang.String path,
                                                   java.lang.Object caller)
Searches the classpath for a configuration file matching the specified path. If found, it will read and return it as a FactoryConfiguration. If not found, this will return null. If there are multiple matching resources in the classpath, then they will be added together in the order found (i.e. the last one will have precedence).

See Also:
ClassUtils.getResources(String path, Object caller)

read

public static FactoryConfiguration read(java.net.URL url)
Returns a FactoryConfiguration read from a known configuration file type at the specified URL. If the file is missing or unreadable, this will simply return null (i.e. if an IOException is thrown).

Throws:
java.lang.UnsupportedOperationException - if the file type (identified via suffix) is neither ".xml" or ".properties"

getFromClass

public static FactoryConfiguration getFromClass(java.lang.String classname)

getFromClass

public static FactoryConfiguration getFromClass(java.lang.Class factory)


Copyright (c) 2003-2007 Apache Software Foundation