Package org.apache.velocity.tools.config
Class ConfigurationUtils
- java.lang.Object
-
- org.apache.velocity.tools.config.ConfigurationUtils
-
public class ConfigurationUtils extends java.lang.ObjectUtility methods for handling tool configurations.- Version:
- $Id: ConfigurationUtils.java 511959 2007-02-26 19:24:39Z nbubna $
- Author:
- Nathan Bubna
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringAUTOLOADED_PROPS_PATHstatic java.lang.StringAUTOLOADED_XML_PATHstatic java.lang.StringCONFIG_FACTORY_METHODstatic java.lang.StringGENERIC_DEFAULTS_PATHstatic ConfigurationUtilsINSTANCEstatic java.lang.StringSYSTEM_PROPERTY_KEYstatic java.lang.StringVIEW_DEFAULTS_PATH
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidclean(Configuration config)Convenience method that automatically creates a newConfigurationCleanerand applies it to the specifiedConfiguration.static ToolboxFactorycreateFactory()Returns a new, standardToolboxFactoryconfigured with the results offindFromSystemProperty().static FactoryConfigurationfind(java.lang.String path)Searches for a configuration file at the specified path and returns it in the form of aFactoryConfiguration.static FactoryConfigurationfindFromSystemProperty()Returns aFactoryConfigurationloaded from the path specified in the "org.apache.velocity.tools" system property (if any).static FactoryConfigurationfindInClasspath(java.lang.String path)static FactoryConfigurationfindInClasspath(java.lang.String path, java.lang.Object caller)Searches the classpath for a configuration file matching the specified path.static FactoryConfigurationfindInFileSystem(java.lang.String path)Searches the file system for a configuration file matching the specified path.static FactoryConfigurationgetDefaultTools()Returns the "default"FactoryConfiguration.static FactoryConfigurationgetFromClass(java.lang.Class factory)static FactoryConfigurationgetFromClass(java.lang.String classname)Get a specificFactoryConfigurationclassstatic FactoryConfigurationgetGenericTools()Returns aFactoryConfigurationincluding all default "GenericTools" available and no others.ConfigurationUtilsgetInstance()static org.slf4j.LoggergetLog(org.apache.velocity.app.VelocityEngine engine, java.lang.String childNamespace)static FactoryConfigurationgetVelocityView()Returns aFactoryConfigurationincluding all default "velocity-tools-view" tools available as well as the default "GenericTools".static FactoryConfigurationload(java.lang.String path)Returns aFactoryConfigurationloaded from a configuration file at the specified path.static FactoryConfigurationread(java.net.URL url)Returns aFactoryConfigurationread from a known configuration file type at the specifiedURL.
-
-
-
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
-
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
-
-
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.- Returns:
- the default
FactoryConfiguration
-
getGenericTools
public static FactoryConfiguration getGenericTools()
Returns aFactoryConfigurationincluding all default "GenericTools" available and no others.- Returns:
- the generic tools default
FactoryConfiguration
-
getVelocityView
public static FactoryConfiguration getVelocityView()
Returns a
FactoryConfigurationincluding all default "velocity-tools-view" tools available as well as the default "GenericTools".- Returns:
- all default tools
FactoryConfiguration - Throws:
ConfigurationException- if a tools.xml is not found at theVIEW_DEFAULTS_PATH.
-
findFromSystemProperty
public static FactoryConfiguration findFromSystemProperty()
Returns aFactoryConfigurationloaded from the path specified in the "org.apache.velocity.tools" system property (if any). If no such property has been setnullwill be returned.- Returns:
- system property defined
FactoryConfiguration - 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, standardToolboxFactoryconfigured with the results offindFromSystemProperty().- Returns:
- new
ToolboxFactory
-
clean
public static void clean(Configuration config)
Convenience method that automatically creates a newConfigurationCleanerand applies it to the specifiedConfiguration.- Parameters:
config-Configuration
-
load
public static FactoryConfiguration load(java.lang.String path)
Returns aFactoryConfigurationloaded from a configuration file at the specified path. If no such file is found at that path, this will throw aResourceNotFoundException.- Parameters:
path- configuration path- Returns:
- new
FactoryConfiguration - 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 aFactoryConfiguration. 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 returnnull.- Parameters:
path- configuration classpath or filesystem path- Returns:
- new
FactoryConfigurationfor the given path
-
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 aFactoryConfiguration. If not found, this will returnnull.- Parameters:
path- filesystem path- Returns:
- new
FactoryConfigurationfor the given path - 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)
- Parameters:
path- configuration classpath- Returns:
- new
FactoryConfigurationfor the given classpath - 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 aFactoryConfiguration. If not found, this will returnnull. 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).- Parameters:
path- configuration classpathcaller- classloader context- Returns:
- new
FactoryConfigurationfor the given classpath - See Also:
ClassUtils.getResources(String path, Object caller)
-
read
public static FactoryConfiguration read(java.net.URL url)
Returns aFactoryConfigurationread from a known configuration file type at the specifiedURL. If the file is missing or unreadable, this will simply returnnull(i.e. if an IOException is thrown).- Parameters:
url- configuration URL- Returns:
- new
FactoryConfigurationfor the given URL - 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)
Get a specificFactoryConfigurationclass- Parameters:
classname- FacotyConfiguration class- Returns:
- new FactoryConfiguration instance
-
getFromClass
public static FactoryConfiguration getFromClass(java.lang.Class factory)
-
getLog
public static org.slf4j.Logger getLog(org.apache.velocity.app.VelocityEngine engine, java.lang.String childNamespace)
-
-