eXo Kernel :: Container 2.4.4-CLD

org.exoplatform.container.util
Class TemplateConfigurationHelper

java.lang.Object
  extended by 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
TemplateConfigurationHelper(String[] includes, String[] excludes, ConfigurationManager cfm)
          Creates instance of template configuration helper with given lists of filtering patterns.
 
Method Summary
 InputStream fillTemplate(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.
 InputStream fillTemplate(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 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.
protected  Map<String,String> prepareParameters(Map<String,String> parameters)
          Filters the map of parameters, leaving only those than matches filtering regular expressions.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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 patterns
excludes - Array with string representation of exclude reg-exp patterns
ConfigurationManager - 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 content
filename - the name of the file to found
Returns:
the InputStream corresponding to the file content if it can be found null otherwise

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: "jbosscache-cache.loader":"org.exoplatform" "jbosscache-configuration":"/conf/test.xml" "max-volatile-size":"100Kb" the output will be like: "${jbosscache-cache.loader}":"org.exoplatform" Other will be ignored (depending on includes/excludes lists provided in constructor).

Parameters:
parameters -
Returns:

eXo Kernel :: Container 2.4.4-CLD

Copyright © 2013 eXo Platform SAS. All Rights Reserved.