Example usage for org.apache.commons.configuration SystemConfiguration getString

List of usage examples for org.apache.commons.configuration SystemConfiguration getString

Introduction

In this page you can find the example usage for org.apache.commons.configuration SystemConfiguration getString.

Prototype

public String getString(String key) 

Source Link

Usage

From source file:com.impetus.kundera.utils.KunderaCoreUtils.java

/**
 * Resolves variable in path given as string
 * /*www.j  a va  2s.c o m*/
 * @param input
 *            String input url Code inspired by
 *            :http://stackoverflow.com/questions/2263929/
 *            regarding-application-properties-file-and-environment-variable
 */
public static String resolvePath(String input) {
    if (null == input) {
        return input;
    }

    // matching for 2 groups match ${VAR_NAME} or $VAR_NAME
    Pattern pathPattern = Pattern.compile("\\$\\{(.+?)\\}");
    Matcher matcherPattern = pathPattern.matcher(input); // get a matcher
                                                         // object
    StringBuffer sb = new StringBuffer();
    EnvironmentConfiguration config = new EnvironmentConfiguration();
    SystemConfiguration sysConfig = new SystemConfiguration();

    while (matcherPattern.find()) {

        String confVarName = matcherPattern.group(1) != null ? matcherPattern.group(1)
                : matcherPattern.group(2);
        String envConfVarValue = config.getString(confVarName);
        String sysVarValue = sysConfig.getString(confVarName);

        if (envConfVarValue != null) {

            matcherPattern.appendReplacement(sb, envConfVarValue);

        } else if (sysVarValue != null) {

            matcherPattern.appendReplacement(sb, sysVarValue);

        } else {
            matcherPattern.appendReplacement(sb, "");
        }
    }
    matcherPattern.appendTail(sb);
    return sb.toString();
}

From source file:cc.kune.core.server.persist.DataSourceKunePersistModule.java

/**
 * Inits the./* w ww  .  j ava  2  s .  c om*/
 * 
 * @param settedProperties
 *          the setted properties
 */
private void init(final String settedProperties) {
    final SystemConfiguration sysConf = new SystemConfiguration();
    kuneConfig = settedProperties != null ? settedProperties : sysConf.getString("kune.server.config");
    kuneProperties = new KunePropertiesDefault(kuneConfig);
    log4Conf = sysConf.getString("log4j.configuration");
}