public void loadAllProperties(String propertiesFilesString, String rootPath) { // load mgnl-beans.properties first loadBeanProperties(); loadAllModuleProperties(); // complete or override with WEB-INF properties files loadPropertiesFiles(propertiesFilesString, rootPath); // complete or override with JVM system properties overloadWithSystemProperties(); // resolve nested properties resolveNestedProperties(); }
public void loadAllModuleProperties() { // complete or override with modules' properties final List<ModuleDefinition> moduleDefinitions = moduleRegistry.getModuleDefinitions(); loadModuleProperties(moduleDefinitions); }
private void resolveNestedProperties() { Properties sysProps = SystemProperty.getProperties(); for (Iterator<Object> it = sysProps.keySet().iterator(); it.hasNext(); ) { String key = (String) it.next(); String oldValue = (String) sysProps.get(key); String value = parseStringValue(oldValue, new HashSet<String>()); SystemProperty.getProperties().put(key, value.trim()); } }
public void loadPropertiesFiles(String propertiesLocationString, String rootPath) { String[] propertiesLocation = StringUtils.split(propertiesLocationString, ','); boolean found = false; // attempt to load each properties file at the given locations in reverse order: first files in the list // override the later ones for (int j = propertiesLocation.length - 1; j >= 0; j--) { String location = StringUtils.trim(propertiesLocation[j]); if (loadPropertiesFile(rootPath, location)) { found = true; } } if (!found) { final String msg = MessageFormat.format("No configuration found using location list {0}. Base path is [{1}]", ArrayUtils.toString(propertiesLocation), rootPath); log.error(msg); throw new ConfigurationException(msg); } }
@Inject public DefaultMagnoliaPropertiesResolver(ServletContext context, MagnoliaInitPaths initPaths) { this.context = context; String propertiesFilesString = getInitParameter(context, MAGNOLIA_INITIALIZATION_FILE, DEFAULT_INITIALIZATION_PARAMETER); // Use ROOT for the default (root) context, otherwise trim the leading slash to prevent double slashes String contextPath = initPaths.getContextPath(); if (contextPath.length() == 0) { contextPath = "ROOT"; } else { contextPath = contextPath.substring(1); } final String propertiesLocationString = processPropertyFilesString(context, initPaths.getServerName(), initPaths.getWebappFolderName(), propertiesFilesString, contextPath); final String[] propertiesLocation = propertiesLocationString.trim().split("[,]+", 0); this.locations = new ArrayList<String>(propertiesLocation.length); // TODO - order ? // trim all: for (String loc : propertiesLocation) { locations.add(loc.trim()); } }
String[] contextAttributeNames = getNamesBetweenPlaceholders(propertiesFilesString, CONTEXT_ATTRIBUTE_PLACEHOLDER_PREFIX); if (contextAttributeNames != null) { for (String ctxAttrName : contextAttributeNames) { String[] contextParamNames = getNamesBetweenPlaceholders(propertiesFilesString, CONTEXT_PARAM_PLACEHOLDER_PREFIX); if (contextParamNames != null) { for (String ctxParamName : contextParamNames) { String[] systemPropertiesNames = getNamesBetweenPlaceholders(propertiesFilesString, SYSTEM_PROPERTY_PLACEHOLDER_PREFIX); if (systemPropertiesNames != null) { for (String sysPropName : systemPropertiesNames) { String[] envPropertiesNames = getNamesBetweenPlaceholders(propertiesFilesString, ENV_PROPERTY_PLACEHOLDER_PREFIX); if (envPropertiesNames != null) { for (String envPropName : envPropertiesNames) {
placeholder = parseStringValue(placeholder, visitedPlaceholders); propVal = parseStringValue(propVal, visitedPlaceholders); buf.replace(startIndex, endIndex + PLACEHOLDER_SUFFIX.length(), propVal); startIndex = buf.indexOf(PLACEHOLDER_PREFIX, startIndex + propVal.length());