Example usage for org.apache.commons.configuration PropertiesConfiguration PropertiesConfiguration

List of usage examples for org.apache.commons.configuration PropertiesConfiguration PropertiesConfiguration

Introduction

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

Prototype

public PropertiesConfiguration(URL url) throws ConfigurationException 

Source Link

Document

Creates and loads the extended properties from the specified URL.

Usage

From source file:eu.optimis.aggregator.test.AggregatorPushTest.java

public AggregatorPushTest() {
    try {//from w  w  w  . j a v a2s  .  c  o m
        PropertiesConfiguration config = new PropertiesConfiguration(
                AggregatorPushTest.class.getClassLoader().getResource(RESOURCE_FILE));
        AGGREGATOR_URL = config.getString("aggregator.url");
        DB_DRIVER = config.getString("db.driver");
        TABLE_URL = config.getString("db.table.url");
        DB_USER = config.getString("db.username");
        DB_PASSWORD = config.getString("db.password");
        logger.info("table url:" + TABLE_URL);
    } catch (Exception e) {
        System.err.println("Error: cannot find the resource bundle path.");
        throw new RuntimeException(e);
    }
}

From source file:info.halo9pan.word2vec.hadoop.conf.Parameters.java

public void initialize(String fileName) {
    try {/* w w w.j  a  v a 2  s  .c om*/
        if (fileName == null) {
            fileName = DEFAULT_CONFIGURATION_FILE;
        }
        this.configuration = new PropertiesConfiguration(fileName);
    } catch (ConfigurationException e) {
        logger.error("Can't initialize the properties configuration.");
        throw new IllegalArgumentException(e);
    }
}

From source file:fr.jetoile.hadoopunit.component.ZookeeperBootstrap.java

private void loadConfig() throws BootstrapException {
    HadoopUtils.setHadoopHome();/*from   w  ww . ja  va2 s  .  c  om*/
    try {
        configuration = new PropertiesConfiguration(HadoopUnitConfig.DEFAULT_PROPS_FILE);
    } catch (ConfigurationException e) {
        throw new BootstrapException("bad config", e);
    }
    port = configuration.getInt(HadoopUnitConfig.ZOOKEEPER_PORT_KEY);
    localDir = configuration.getString(HadoopUnitConfig.ZOOKEEPER_TEMP_DIR_KEY);
    host = configuration.getString(HadoopUnitConfig.ZOOKEEPER_HOST_KEY);

}

From source file:com.nesscomputing.config.util.FileConfigStrategy.java

@Override
public AbstractConfiguration load(final String configName, final String configPath)
        throws ConfigurationException {
    if (!(directoryLocation.exists() && directoryLocation.isDirectory() && directoryLocation.canRead())) {
        return null;
    }//from   w  ww .  j av  a 2s.  c  om
    // A property configuration lives in a configuration directory and is called
    // "config.properties"
    final File[] propertyFiles = new File[] {
            new File(directoryLocation, configPath + File.separator + "config.properties"),
            new File(directoryLocation, configName + ".properties") };

    for (final File propertyFile : propertyFiles) {
        if (propertyFile.exists() && propertyFile.isFile() && propertyFile.canRead()) {
            LOG.trace("Trying to load '%s'...", propertyFile);
            try {
                final AbstractConfiguration config = new PropertiesConfiguration(propertyFile);
                LOG.trace("... succeeded");
                return config;
            } catch (ConfigurationException ce) {
                LOG.trace("... failed", ce);
            }
        }
    }
    return null;
}

From source file:fr.jetoile.hadoopunit.component.CassandraBootstrap.java

private void loadConfig() throws BootstrapException {
    try {/*from w  ww.  j  a v a  2s .  co m*/
        configuration = new PropertiesConfiguration(HadoopUnitConfig.DEFAULT_PROPS_FILE);
    } catch (ConfigurationException e) {
        throw new BootstrapException("bad config", e);
    }

    port = configuration.getInt(HadoopUnitConfig.CASSANDRA_PORT_KEY);
    ip = configuration.getString(HadoopUnitConfig.CASSANDRA_IP_KEY);
}

From source file:mashups.eventpub.EventPublisherServlet.java

public EventPublisherServlet() throws Exception {
    super();
    config = new PropertiesConfiguration("EventPublisher.properties");
}

From source file:edu.lternet.pasta.portal.ConfigurationListener.java

/**
 * Configure logger and properties applications for non-servlet based
 * execution (e.g., main(String[] args)).
 *///from w ww  .java 2s .  c  o m
public static void configure() {

    String cwd = System.getProperty("user.dir");

    // Initialize log4j
    String log4jPropertiesPath = cwd + "/WebRoot/WEB-INF/conf/log4j.properties";
    PropertyConfigurator.configureAndWatch(log4jPropertiesPath);

    // Initialize commons configuration
    String appConfigPath = cwd + "/WebRoot/WEB-INF/conf/dataportal.properties";
    try {
        config = new PropertiesConfiguration(appConfigPath);
        config.setProperty("system.cwd", cwd);
        config.save();
    } catch (ConfigurationException e) {
        logger.error(e);
        e.printStackTrace();
    }

}

From source file:com.dcsquare.fileauthplugin.utility.properties.FileAuthConfiguration.java

/**
 * Init is responsible for loading all properties of fileAuthConfiguration.properties
 *
 * @param pathname absolute path of the fileAuthConfiguration.properties
 * @throws ConfigurationException thrown if there is any problem with creating the credential file.
 * @throws IOException            is thrown when fileAuthConfiguration.properties is not found.
 *//*w  ww  .  j  a  v  a  2s .  co m*/
public void init(String pathname) throws ConfigurationException, IOException {
    final File configFile = new File(pathname);

    if (!configFile.exists() || !configFile.isFile()) {
        throw new FileNotFoundException("Configuration file not found");
    }
    propertiesConfiguration = new PropertiesConfiguration(configFile);

    credentialFileName = propertiesConfiguration.getString("filename");

    final File credentialFile = new File(configFile.getParent(), credentialFileName);

    if (!credentialFile.exists()) {
        credentialFile.createNewFile();
        LOG.warning("Credential file not found, new one created in " + credentialFile.getAbsolutePath());
    }

    isHashed = propertiesConfiguration.getBoolean("passwordHashing.enabled", true);
    iterations = propertiesConfiguration.getInt("passwordHashing.iterations", 1000000);
    algorithm = propertiesConfiguration.getString("passwordHashing.algorithm", "SHA-512");
    separationChar = propertiesConfiguration.getString("passwordHashingSalt.separationChar", "$");
    isSalted = propertiesConfiguration.getBoolean("passwordHashingSalt.enabled", true);
    isFirst = propertiesConfiguration.getBoolean("passwordHashingSalt.isFirst", true);
}

From source file:eu.sisob.uma.restserver.TheConfig.java

/**
 *
 * @param path/* w  w  w .  ja v  a  2  s.com*/
 * @throws ConfigurationException
 */
public static void createInstance(String path) throws ConfigurationException {
    if (instance == null) {
        String filepath = path + File.separator + "WEB-INF" + File.separator + "server.properties";
        File file = new File(filepath);
        instance = new PropertiesConfiguration(file);

        String debug = instance.getString(SERVER_DEBUG);

        if (debug.equals("true")) {
            ProjectLogger.LOGGER.info("Configuration in debug mode: " + filepath);
            instance.setProperty(TheConfig.SERVER_URL, instance.getString(SERVER_DEBUG_URL));
        } else {
            ProjectLogger.LOGGER.info("Configuration in production mode: " + filepath);
        }

        instance.setProperty(SERVER_REAL_PATH, path);

        ProjectLogger.LOGGER.info("Configuration object initialized from: " + filepath);
    }
}

From source file:com.ibm.replication.iidr.metadata.Settings.java

/**
 * Retrieve the settings from the given properties file.
 * //from  w w w .  ja  va2 s. co  m
 * @param propertiesFile
 * @throws ConfigurationException
 */
public Settings(String propertiesFile) throws ConfigurationException {
    PropertiesConfiguration config = new PropertiesConfiguration(propertiesFile);
    asHostName = config.getString("asHostName");
    asUserName = config.getString("asUserName");
    String encryptedAsPassword = config.getString("asPassword");
    asPort = config.getInt("asPort", 10101);

    isHostName = config.getString("isHostName");
    isUserName = config.getString("isUserName");
    String encryptedISPassword = config.getString("isPassword");
    isPort = config.getInt("isPort", 10101);

    bundleFilePath = config.getString("bundleFilePath");
    defaultDataPath = config.getString("defaultDataPath");

    trustSelfSignedCertificates = config.getBoolean("trustSelfSignedCertificates");

    // Check if the password has already been encrypted
    // If not, encrypt and save the properties
    try {
        asPassword = Encryptor.decodeAndDecrypt(encryptedAsPassword);
    } catch (EncryptedDataException e) {
        logger.debug("Encrypting asPassword");
        asPassword = encryptedAsPassword;
        encryptedAsPassword = Encryptor.encryptAndEncode(encryptedAsPassword);
        config.setProperty("asPassword", encryptedAsPassword);
        config.save();
    }

    try {
        isPassword = Encryptor.decodeAndDecrypt(encryptedISPassword);
    } catch (EncryptedDataException e) {
        logger.debug("Encrypting isPassword");
        isPassword = encryptedISPassword;
        encryptedISPassword = Encryptor.encryptAndEncode(encryptedISPassword);
        config.setProperty("isPassword", encryptedISPassword);
        config.save();
    }

    // Now log the settings
    logSettings(config);
}