Package org.exoplatform.container.util
Class TemplateConfigurationHelper
- java.lang.Object
-
- org.exoplatform.container.util.TemplateConfigurationHelper
-
public class TemplateConfigurationHelper extends Object
Builds configuration from template using map of template-variables -- value. Class provides extra functionality for filtering parameters by pattern, excluding unnecessary parameters.- Version:
- $Id: TemplateConfigurationHelper.java 34360 2009-07-22 23:58:59Z nzamosenchuk $
- Author:
- Nikolay Zamosenchuk
-
-
Constructor Summary
Constructors Constructor Description TemplateConfigurationHelper(String[] includes, String[] excludes, ConfigurationManager cfm)Creates instance of template configuration helper with given lists of filtering patterns.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description InputStreamfillTemplate(InputStream inputStream, Map<String,String> parameters)Reads configuration file from a stream and replaces all the occurrences of template-variables (like : "${parameter.name}") with values provided in the map.InputStreamfillTemplate(String filename, Map<String,String> parameters)Reads configuration file from a stream and replaces all the occurrences of template-variables (like : "${parameter.name}") with values provided in the map.static InputStreamgetInputStream(ConfigurationManager cfm, String filename)Tries first to get the file content using the configuration manager, if it cannot be found it will then try to get it from the context class loader of the current thread, if it cannot be found it will try to get it from the class loader of the current class and finally it still cannot be found it will try to use the file name as a file path.protected Map<String,String>prepareParameters(Map<String,String> parameters)Filters the map of parameters, leaving only those than matches filtering regular expressions.
-
-
-
Constructor Detail
-
TemplateConfigurationHelper
public TemplateConfigurationHelper(String[] includes, String[] excludes, ConfigurationManager cfm)
Creates instance of template configuration helper with given lists of filtering patterns. Parameter will be included only if it matches any include-pattern and doesn't match any exclude-pattern. I.e. You can include "extended-*" and exclude "extended-type". Please refer to Java regexp documentation. Filtering for this example, should be defined as following: include: "^extended-.*" exclude: "^extended-type"- Parameters:
includes- Array with string representation of include reg-exp patternsexcludes- Array with string representation of exclude reg-exp patternscfm- instance for looking up resources
-
-
Method Detail
-
fillTemplate
public InputStream fillTemplate(InputStream inputStream, Map<String,String> parameters) throws IOException
Reads configuration file from a stream and replaces all the occurrences of template-variables (like : "${parameter.name}") with values provided in the map.- Parameters:
inputStream-parameters-- Returns:
- Throws:
IOException
-
fillTemplate
public InputStream fillTemplate(String filename, Map<String,String> parameters) throws IOException
Reads configuration file from a stream and replaces all the occurrences of template-variables (like : "${parameter.name}") with values provided in the map.- Parameters:
filename-parameters-- Returns:
- Throws:
IOException
-
getInputStream
public static InputStream getInputStream(ConfigurationManager cfm, String filename)
Tries first to get the file content using the configuration manager, if it cannot be found it will then try to get it from the context class loader of the current thread, if it cannot be found it will try to get it from the class loader of the current class and finally it still cannot be found it will try to use the file name as a file path.- Parameters:
cfm- the configuration manager from which we want to try to find the file contentfilename- the name of the file to found- Returns:
- the
InputStreamcorresponding to the file content if it can be foundnullotherwise
-
prepareParameters
protected Map<String,String> prepareParameters(Map<String,String> parameters)
Filters the map of parameters, leaving only those than matches filtering regular expressions. Also adds "${}" to the parameter key:
I.e. such map provided on input: "foo-cache.loader":"org.exoplatform" "foo-configuration":"/conf/test.xml" "max-volatile-size":"100Kb" the output will be like: "${foo-cache.loader}":"org.exoplatform" Other will be ignored (depending on includes/excludes lists provided in constructor).- Parameters:
parameters-- Returns:
-
-