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

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

Introduction

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

Prototype

String getString(String key, String defaultValue);

Source Link

Document

Get a string associated with the given configuration key.

Usage

From source file:io.servicecomb.serviceregistry.api.registry.MicroserviceInstance.java

public static MicroserviceInstance createFromDefinition(Configuration configuration) {
    MicroserviceInstance microserviceInstance = new MicroserviceInstance();
    // default hard coded values
    microserviceInstance.setStage(DEFAULT_STAGE);
    microserviceInstance.setEnvironment(
            configuration.getString(CONFIG_QUALIFIED_INSTANCE_ENVIRONMENT_KEY, DEFAULT_INSTANCE_ENVIRONMENT));
    HealthCheck healthCheck = new HealthCheck();
    healthCheck.setMode(HealthCheckMode.HEARTBEAT);
    microserviceInstance.setHealthCheck(healthCheck);

    // load properties
    Map<String, String> propertiesMap = InstancePropertiesLoader.INSTANCE.loadProperties(configuration);
    microserviceInstance.setProperties(propertiesMap);

    // load data center information
    loadDatacenterInfo(microserviceInstance);
    return microserviceInstance;
}

From source file:com.comcast.viper.flume2storm.spout.FlumeSpoutConfiguration.java

/**
 * Builds a new {@link FlumeSpoutConfiguration} based on a Configuration
 * //from  w w  w .j  a  v a2 s  . c  o m
 * @param config
 *          The configuration to use
 * @return The newly created {@link F2SConfiguration}
 * @throws F2SConfigurationException
 *           If the class is not found in the class path
 */
public static FlumeSpoutConfiguration from(Configuration config) throws F2SConfigurationException {
    FlumeSpoutConfiguration result = new FlumeSpoutConfiguration();
    try {
        result.setLocationServiceFactoryClassName(
                config.getString(LOCATION_SERVICE_FACTORY_CLASS, LOCATION_SERVICE_FACTORY_CLASS_DEFAULT));
    } catch (Exception e) {
        throw F2SConfigurationException.with(config, LOCATION_SERVICE_FACTORY_CLASS, e);
    }
    try {
        result.setServiceProviderSerializationClassName(config.getString(SERVICE_PROVIDER_SERIALIZATION_CLASS,
                SERVICE_PROVIDER_SERIALIZATION_CLASS_DEFAULT));
    } catch (Exception e) {
        throw F2SConfigurationException.with(config, SERVICE_PROVIDER_SERIALIZATION_CLASS, e);
    }
    try {
        result.setEventReceptorFactoryClassName(
                config.getString(EVENT_RECEPTOR_FACTORY_CLASS, EVENT_RECEPTOR_FACTORY_CLASS_DEFAULT));
    } catch (Exception e) {
        throw F2SConfigurationException.with(config, EVENT_RECEPTOR_FACTORY_CLASS, e);
    }
    result.configuration = getMapFromConfiguration(config);
    return result;
}

From source file:de.tudarmstadt.ukp.dariah.pipeline.RunPipeline.java

public static Class<? extends AnalysisComponent> getClassFromConfig(Configuration config, String key)
        throws ClassNotFoundException {

    String entry = config.getString(key, "null");

    if (entry.toLowerCase().equals("null")) {
        return NoOpAnnotator.class;
    }//from  w w w.ja  v a2s .com

    return (Class<? extends AnalysisComponent>) Class.forName(entry);

}

From source file:com.comcast.viper.flume2storm.sink.StormSinkConfiguration.java

/**
 * @param config//from w  w w  .ja va2 s . c o m
 *          The configuration to use
 * @return The newly built {@link StormSinkConfiguration} based on the
 *         configuration specified
 * @throws F2SConfigurationException
 *           If the configuration is invalid
 */
public static StormSinkConfiguration from(Configuration config) throws F2SConfigurationException {
    StormSinkConfiguration result = new StormSinkConfiguration();
    try {
        result.setBatchSize(config.getInteger(BATCH_SIZE, BATCH_SIZE_DEFAULT));
    } catch (Exception e) {
        throw F2SConfigurationException.with(config, BATCH_SIZE, e);
    }
    try {
        result.setLocationServiceFactoryClassName(
                config.getString(LOCATION_SERVICE_FACTORY_CLASS, LOCATION_SERVICE_FACTORY_CLASS_DEFAULT));
    } catch (Exception e) {
        throw F2SConfigurationException.with(config, LOCATION_SERVICE_FACTORY_CLASS, e);
    }
    try {
        result.setServiceProviderSerializationClassName(config.getString(SERVICE_PROVIDER_SERIALIZATION_CLASS,
                SERVICE_PROVIDER_SERIALIZATION_CLASS_DEFAULT));
    } catch (Exception e) {
        throw F2SConfigurationException.with(config, SERVICE_PROVIDER_SERIALIZATION_CLASS, e);
    }
    try {
        result.setEventSenderFactoryClassName(
                config.getString(EVENT_SENDER_FACTORY_CLASS, EVENT_SENDER_FACTORY_CLASS_DEFAULT));
    } catch (Exception e) {
        throw F2SConfigurationException.with(config, EVENT_SENDER_FACTORY_CLASS, e);
    }
    try {
        result.setConnectionParametersFactoryClassName(config.getString(CONNECTION_PARAMETERS_FACTORY_CLASS,
                CONNECTION_PARAMETERS_FACTORY_CLASS_DEFAULT));
    } catch (Exception e) {
        throw F2SConfigurationException.with(config, CONNECTION_PARAMETERS_FACTORY_CLASS, e);
    }
    result.configuration = config;
    return result;
}

From source file:com.salesmanager.core.util.LocaleUtil.java

public static Locale getDefaultLocale() {
    Configuration conf = PropertiesUtil.getConfiguration();
    int defaultCountryId = conf.getInt("core.system.defaultcountryid", 38);

    Map countriesMap = RefCache.getAllcountriesmap(Constants.ENGLISH);

    if (countriesMap == null) {
        log.error("Cannot get object from database, check your database configuration");
    }/*from ww w  .j a  v a 2s .  c om*/

    Country country = (Country) countriesMap.get(defaultCountryId);
    Locale locale = new Locale(conf.getString("core.system.defaultlanguage", Constants.ENGLISH_CODE),
            country.getCountryIsoCode2());
    return locale;
}

From source file:com.salesmanager.core.util.FileUtil.java

public static String getInvoiceUrl(Order order, Customer customer) throws Exception {

    Configuration conf = PropertiesUtil.getConfiguration();

    MerchantService mservice = (MerchantService) ServiceFactory.getService(ServiceFactory.MerchantService);
    MerchantStore store = mservice.getMerchantStore(order.getMerchantId());

    // ***build fileid***
    StringBuffer urlconstruct = new StringBuffer();
    StringBuffer invoiceurl = new StringBuffer();

    // order id and, expiration date and language
    urlconstruct.append(order.getOrderId()).append("|").append(customer.getCustomerId());

    String lang = conf.getString("core.system.defaultlanguage", "en");
    if (customer != null) {
        lang = customer.getCustomerLang();
    }/*from   www.j a  v  a 2  s .  com*/

    String file = EncryptionUtil.encrypt(EncryptionUtil.generatekey(SecurityConstants.idConstant),
            urlconstruct.toString());

    invoiceurl.append(ReferenceUtil.buildCartUri(store))
            .append(conf.getString("core.salesmanager.core.viewInvoiceAction")).append("?fileId=").append(file);

    return invoiceurl.toString();

}

From source file:com.salesmanager.core.util.FileUtil.java

public static String getAdminPasswordResetUrl(MerchantUserInformation information, MerchantStore store)
        throws Exception {

    Configuration conf = PropertiesUtil.getConfiguration();

    StringBuffer urlconstruct = new StringBuffer();
    StringBuffer downloadurl = new StringBuffer();
    Calendar endDate = Calendar.getInstance();
    endDate.add(Calendar.DATE, conf.getInt("core.product.file.downloadmaxdays", 2)); // add 2 days
    Date denddate = endDate.getTime();
    String sedate = DateUtil.formatDate(denddate);

    // order id and, expiration date and language
    urlconstruct.append(information.getMerchantUserId()).append("|").append(sedate);

    String lang = conf.getString("core.system.defaultlanguage", "en");
    if (information != null) {
        lang = information.getUserlang();
    }/* w  w  w. j a  va  2s  .  c om*/

    String file = EncryptionUtil.encrypt(EncryptionUtil.generatekey(SecurityConstants.idConstant),
            urlconstruct.toString());

    downloadurl.append(ReferenceUtil.buildCentralUri(store))
            .append("/anonymous" + conf.getString("core.salesmanager.core.resetPasswordAction"))
            .append("?urlId=").append(file).append("&lang=").append(lang);

    return downloadurl.toString();

}

From source file:com.germinus.easyconf.ComponentProperties.java

protected static Object getTypedPropertyWithDefault(String key, Class theClass, Configuration properties,
        Object defaultValue) {/*ww  w  .  ja v a2  s  .  c  o m*/
    if (theClass.equals(Float.class)) {
        return properties.getFloat(key, (Float) defaultValue);

    } else if (theClass.equals(Integer.class)) {
        return properties.getInteger(key, (Integer) defaultValue);

    } else if (theClass.equals(String.class)) {
        return properties.getString(key, (String) defaultValue);

    } else if (theClass.equals(Double.class)) {
        return properties.getDouble(key, (Double) defaultValue);

    } else if (theClass.equals(Long.class)) {
        return properties.getLong(key, (Long) defaultValue);

    } else if (theClass.equals(Boolean.class)) {
        return properties.getBoolean(key, (Boolean) defaultValue);

    } else if (theClass.equals(List.class)) {
        return properties.getList(key, (List) defaultValue);

    } else if (theClass.equals(BigInteger.class)) {
        return properties.getBigInteger(key, (BigInteger) defaultValue);

    } else if (theClass.equals(BigDecimal.class)) {
        return properties.getBigDecimal(key, (BigDecimal) defaultValue);

    } else if (theClass.equals(Byte.class)) {
        return properties.getByte(key, (Byte) defaultValue);

    } else if (theClass.equals(Short.class)) {
        return properties.getShort(key, (Short) defaultValue);
    }
    throw new IllegalArgumentException("Class " + theClass + " is not" + "supported for properties");
}

From source file:com.caricah.iotracah.datastore.ignitecache.internal.impl.ClientHandler.java

@Override
public void configure(Configuration configuration) {

    String cacheName = configuration.getString(CONFIG_IGNITECACHE_CLIENT_CACHE_NAME,
            CONFIG_IGNITECACHE_CLIENT_CACHE_NAME_VALUE_DEFAULT);
    setCacheName(cacheName);/*from   w  w  w . j  a  v  a 2  s.  c  o m*/

}

From source file:com.caricah.iotracah.datastore.ignitecache.internal.impl.SubscriptionHandler.java

@Override
public void configure(Configuration configuration) {

    String cacheName = configuration.getString(CONFIG_IGNITECACHE_SUBSCRIPTION_CACHE_NAME,
            CONFIG_IGNITECACHE_SUBSCRIPTION_CACHE_NAME_VALUE_DEFAULT);
    setCacheName(cacheName);//from ww  w  . j  a v  a2  s  .c o m

}