info.magnolia.cms.beans.config
Class PropertiesInitializer

java.lang.Object
  extended by info.magnolia.cms.beans.config.PropertiesInitializer

public class PropertiesInitializer
extends java.lang.Object

This class is responsible for loading the various "magnolia.properties" files, merging them, and substituting variables in their values.

Author:
pbracher, fgiust

Field Summary
static java.lang.String CONTEXT_ATTRIBUTE_PLACEHOLDER_PREFIX
          Context attribute prefix, to obtain a property definition like ${contextAttribute/property}, that can refer to any context attribute.
static java.lang.String CONTEXT_PARAM_PLACEHOLDER_PREFIX
          Context parameter prefix, to obtain a property definition like ${contextParam/property}, that can refer to any context parameter.
static java.lang.String DEFAULT_INITIALIZATION_PARAMETER
          Default value for the MAGNOLIA_INITIALIZATION_FILE parameter.
static java.lang.String PLACEHOLDER_PREFIX
          Placeholder prefix: "${".
static java.lang.String PLACEHOLDER_SUFFIX
          Placeholder suffix: "}".
 
Constructor Summary
PropertiesInitializer()
           
 
Method Summary
static PropertiesInitializer getInstance()
           
 void loadAllModuleProperties()
           
 void loadAllProperties(java.lang.String propertiesFilesString, java.lang.String rootPath)
           
 void loadBeanProperties()
           
protected  void loadModuleProperties(java.util.List<ModuleDefinition> moduleDefinitions)
          Load the properties defined in the module descriptors.
 boolean loadPropertiesFile(java.lang.String rootPath, java.lang.String location)
          Try to load a magnolia.properties file.
 void loadPropertiesFiles(java.lang.String propertiesLocationString, java.lang.String rootPath)
           
 void overloadWithSystemProperties()
          Overload the properties with set system properties.
protected  java.lang.String parseStringValue(java.lang.String strVal, java.util.Set<java.lang.String> visitedPlaceholders)
          Parse the given String value recursively, to be able to resolve nested placeholders.
static java.lang.String processPropertyFilesString(javax.servlet.ServletContext context, java.lang.String servername, java.lang.String webapp, java.lang.String propertiesFilesString)
          Returns the property files configuration string passed, replacing all the needed values: ${servername} will be reaplced with the name of the server, ${webapp} will be replaced with webapp name, and ${contextAttribute/*} and ${contextParam/*} will be replaced with the corresponding attributes or parameters taken from servlet context.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PLACEHOLDER_PREFIX

public static final java.lang.String PLACEHOLDER_PREFIX
Placeholder prefix: "${".

See Also:
Constant Field Values

PLACEHOLDER_SUFFIX

public static final java.lang.String PLACEHOLDER_SUFFIX
Placeholder suffix: "}".

See Also:
Constant Field Values

CONTEXT_ATTRIBUTE_PLACEHOLDER_PREFIX

public static final java.lang.String CONTEXT_ATTRIBUTE_PLACEHOLDER_PREFIX
Context attribute prefix, to obtain a property definition like ${contextAttribute/property}, that can refer to any context attribute.

See Also:
Constant Field Values

CONTEXT_PARAM_PLACEHOLDER_PREFIX

public static final java.lang.String CONTEXT_PARAM_PLACEHOLDER_PREFIX
Context parameter prefix, to obtain a property definition like ${contextParam/property}, that can refer to any context parameter.

See Also:
Constant Field Values

DEFAULT_INITIALIZATION_PARAMETER

public static final java.lang.String DEFAULT_INITIALIZATION_PARAMETER
Default value for the MAGNOLIA_INITIALIZATION_FILE parameter.

See Also:
Constant Field Values
Constructor Detail

PropertiesInitializer

public PropertiesInitializer()
Method Detail

getInstance

public static PropertiesInitializer getInstance()

loadAllProperties

public void loadAllProperties(java.lang.String propertiesFilesString,
                              java.lang.String rootPath)

loadAllModuleProperties

public void loadAllModuleProperties()

loadModuleProperties

protected void loadModuleProperties(java.util.List<ModuleDefinition> moduleDefinitions)
Load the properties defined in the module descriptors. They can get overridden later in the properties files in WEB-INF


loadPropertiesFiles

public void loadPropertiesFiles(java.lang.String propertiesLocationString,
                                java.lang.String rootPath)

loadBeanProperties

public void loadBeanProperties()

loadPropertiesFile

public boolean loadPropertiesFile(java.lang.String rootPath,
                                  java.lang.String location)
Try to load a magnolia.properties file.

Parameters:
rootPath -
location -
Returns:

overloadWithSystemProperties

public void overloadWithSystemProperties()
Overload the properties with set system properties.


processPropertyFilesString

public static java.lang.String processPropertyFilesString(javax.servlet.ServletContext context,
                                                          java.lang.String servername,
                                                          java.lang.String webapp,
                                                          java.lang.String propertiesFilesString)
Returns the property files configuration string passed, replacing all the needed values: ${servername} will be reaplced with the name of the server, ${webapp} will be replaced with webapp name, and ${contextAttribute/*} and ${contextParam/*} will be replaced with the corresponding attributes or parameters taken from servlet context. This can be very useful for all those application servers that has multiple instances on the same server, like WebSphere. Typical usage in this case: WEB-INF/config/${servername}/${contextAttribute/com.ibm.websphere.servlet.application.host}/magnolia.properties

Parameters:
context - Servlet context
servername - Server name
webapp - Webapp name
propertiesFilesString - Property file configuration string.
Returns:
Property file configuration string with everything replaced.

parseStringValue

protected java.lang.String parseStringValue(java.lang.String strVal,
                                            java.util.Set<java.lang.String> visitedPlaceholders)
Parse the given String value recursively, to be able to resolve nested placeholders. Partly borrowed from org.springframework.beans.factory.config.PropertyPlaceholderConfigurer (original author: Juergen Hoeller)



Copyright © 2003-2011 Magnolia International Ltd.. All Rights Reserved.