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:com.continuent.tungsten.common.security.SecurityHelper.java

/**
 * Delete a user and password from a file
 * //from w ww  .ja  v  a2s  . c o  m
 * @param authenticationInfo containing password file location
 */
public static void deleteUserFromAuthenticationInfo(AuthenticationInfo authenticationInfo)
        throws ServerRuntimeException {
    String username = authenticationInfo.getUsername();
    String passwordFileLocation = authenticationInfo.getPasswordFileLocation();

    try {
        PropertiesConfiguration props = new PropertiesConfiguration(passwordFileLocation);

        // --- Check that the user exists ---
        String usernameInFile = props.getString(username);
        if (usernameInFile == null) {
            throw new ServerRuntimeException(MessageFormat.format("Username does not exist: {0}", username));
        }

        props.clearProperty(username);
        props.save();
    } catch (org.apache.commons.configuration.ConfigurationException ce) {
        logger.error("Error while saving properties for file:" + authenticationInfo.getPasswordFileLocation(),
                ce);
        throw new ServerRuntimeException("Error while saving Credentials: " + ce.getMessage());
    }
}

From source file:edu.lternet.pasta.datapackagemanager.dataserver.ConfigurationListener.java

/**
 * Configure logger and properties applications for non-servlet based
 * execution (e.g., main(String[] args)).
 *///from   w  w  w.  j a  va 2 s  .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/dataserver.properties";
    try {
        config = new PropertiesConfiguration(appConfigPath);
        config.setProperty("system.cwd", cwd);
        config.save();
    } catch (ConfigurationException e) {
        logger.error(e);
        e.printStackTrace();
    }

}

From source file:fr.insalyon.creatis.vip.ssha.ConfigFile.java

private ConfigFile() {
    try {//from w ww.j  ava2 s.  c  om
        config = new PropertiesConfiguration(new File(configFile));
        gridaHost = config.getString("ssha.grida.host", "kingkong.grid.creatis.insa-lyon.fr");
        gridaPort = config.getInt("ssha.grida.port", 9006);
        gridaProxy = config.getString("ssha.grida.proxy", "/root/.vip/proxies/x509up_server");
        LOCAL_TEMP = config.getString("ssha.tempdir", "/tmp/ssh");
        sleepTimeMillis = config.getInt("ssha.iteration.sleeptime", 5000);
        maxFilesIteration = config.getInt("ssha.iteration.maxfiles", 10);
        privKeyFile = config.getString("ssha.auth.privatekeyfile", "./id_rsa");
        privKeyPass = config.getString("ssha.auth.privatekeypass", "changeit");
        url = config.getString("ssha.db.jdbcurl", "jdbc:mysql://localhost:3306/vip");
        userName = config.getString("ssha.db.user", "vip");
        password = config.getString("ssha.db.password", "changeit");
        nbSecond = config.getDouble("ssha.exponentielBackOff.nbSecond", 5);

        config.setProperty("ssha.grida.host", gridaHost);
        config.setProperty("ssha.grida.port", gridaPort);
        config.setProperty("ssha.grida.proxy", gridaProxy);
        config.setProperty("ssha.tempdir", LOCAL_TEMP);
        config.setProperty("ssha.iteration.sleeptime", sleepTimeMillis);
        config.setProperty("ssha.iteration.maxfiles", maxFilesIteration);
        config.setProperty("ssha.auth.privatekeyfile", privKeyFile);
        config.setProperty("ssha.auth.privatekeypass", privKeyPass);
        config.setProperty("ssha.db.jdbcurl", url);
        config.setProperty("ssha.db.user", userName);
        config.setProperty("ssha.db.password", password);
        config.setProperty("ssha.exponentielBackOff.nbSecond", nbSecond);
        config.save();

    } catch (ConfigurationException ex) {
        System.out.println(ex.getMessage());
    }
}

From source file:com.runwaysdk.configuration.FlattenedProfileConfigurationTest.java

@Test
public void testActuallyUsingFlattenedProfile() {
    // Change a property so we know we're actually using the flattened ones and
    // not the unflattened
    try {/*from  w ww  . ja v  a 2 s .  c o  m*/
        PropertiesConfiguration tprops = new PropertiesConfiguration(
                new File(baseDir + "/target/test-classes/flat/terraframe.properties"));
        String oldValue = tprops.getString("deploy.appname");

        tprops.setProperty("deploy.appname", "Actually Using Flattened Profile");
        tprops.save();

        try {
            CommonProperties.dumpInstance();
            String appName = CommonProperties.getDeployAppName();

            assertEquals("Actually Using Flattened Profile", appName);
        } finally {
            tprops.setProperty("deploy.appname", oldValue);
            tprops.save();

        }
    } catch (ConfigurationException e) {
        throw new RunwayConfigurationException(e);
    }

    CommonProperties.dumpInstance();
}

From source file:com.rapid7.diskstorage.dynamodb.TestGraphUtil.java

public static Configuration loadProperties() {
    ClassLoader classLoader = Client.class.getClassLoader();
    URL resource = classLoader.getResource("META-INF/dynamodb_store_manager_test.properties");
    PropertiesConfiguration storageConfig;
    try {//w  w w  .j  a  v  a2 s  .  c o  m
        storageConfig = new PropertiesConfiguration(resource.getFile());
    } catch (ConfigurationException e) {
        throw new RuntimeException(e);
    }
    return storageConfig;
}

From source file:de.iai.ilcd.configuration.ConfigurationService.java

ConfigurationService() {
    try {/*w  w  w . ja va  2 s . c o  m*/
        this.appConfig = new PropertiesConfiguration("app.properties");
    } catch (ConfigurationException e) {
        throw new RuntimeException("FATAL ERROR: application properties could not be initialized", e);
    }

    // log application version message
    this.versionTag = this.appConfig.getString("version.tag");
    this.logger.info(this.versionTag);

    // validate/migrate database schema
    this.migrateDatabaseSchema();

    URL resourceUrl = Thread.currentThread().getContextClassLoader().getResource("log4j.properties");
    String decodedPath = "";
    // now extract path and decode it
    try {
        // note, that URLs getPath() method does not work, because it don't
        // decode encoded Urls, but URI's does this
        decodedPath = resourceUrl.toURI().getPath();
    } catch (URISyntaxException ex) {
        this.logger.error("Cannot extract base path from resource files", ex);
    }

    // base path it relative to web application root directory
    this.basePath = decodedPath.replace("/WEB-INF/classes/log4j.properties", "");
    this.logger.info("base path of web application: {}", this.basePath);

    // Obtain our environment naming context
    Context initCtx;
    Context envCtx;
    String propertiesFilePath = null;
    try {
        initCtx = new InitialContext();
        envCtx = (Context) initCtx.lookup("java:comp/env");
        propertiesFilePath = (String) envCtx.lookup("soda4LCAProperties");
    } catch (NamingException e1) {
        this.logger.error(e1.getMessage());
    }

    if (propertiesFilePath == null) {
        this.logger.info("using default application properties at {}", this.defaultPropertiesFile);
        propertiesFilePath = this.defaultPropertiesFile;
    } else {
        this.logger.info("reading application configuration properties from {}", propertiesFilePath);
    }

    try {
        // OK, now load configuration file
        this.fileConfig = new PropertiesConfiguration(propertiesFilePath);
        this.featureNetworking = this.fileConfig.getString("feature.networking");
        configureLanguages();
    } catch (ConfigurationException ex) {
        this.logger.error(
                "Cannot find application configuration properties file under {}, either put it there or set soda4LCAProperties environment entry via JNDI.",
                propertiesFilePath, ex);
        throw new RuntimeException("application configuration properties not found", ex);
    }

}

From source file:TestExtractor.java

@Test
public void testValue() {

    try {//  w  w  w .  ja va2s  .  co  m
        Configuration conf = new PropertiesConfiguration(
                System.getProperty("user.dir") + "/src/test/resources/xwiki.cfg");
        String tmpldap_server = conf
                .getString("xwiki.authentication.trustedldap.remoteUserMapping.ldap_server");
        //String tmpldap_base_DN = conf.getString("xwiki.authentication.trustedldap.remoteUserMapping.ldap_base_DN");
        String tmpBinDN = conf.getString("xwiki.authentication.trustedldap.remoteUserMapping.ldap_bind_DN");
        String tmpldap_bind_pass = conf
                .getString("xwiki.authentication.trustedldap.remoteUserMapping.ldap_bind_pass");
        String[] ldap_server = StringUtils.split(tmpldap_server, "|");
        //String[] ldap_base_DN = StringUtils.split(tmpldap_base_DN,"|");
        String[] BinDN = StringUtils.split(tmpBinDN, "|");
        String[] ldap_bind_pass = StringUtils.split(tmpldap_bind_pass, "|");

        int i = 0;
        String userDomain = StringUtils.split(ldap_server[i], "=")[0];
        String userDomainLDAPServer = StringUtils.split(ldap_server[i], "=")[1];
        // never used String userDomainLDAPBaseDN = ldap_base_DN[i].split("=")[1];
        String userDomainBinDN = StringUtils.split(BinDN[i], "=")[1];
        String userDomainldap_bind_pass = StringUtils.split(ldap_bind_pass[i], "=")[1];
        assertEquals(userDomain, "ZOZO.AD");
        assertEquals(userDomainLDAPServer, "10.0.0.1");
        assertEquals(userDomainBinDN, "connecuserssosw@ZOZO.AD");
        assertEquals(userDomainldap_bind_pass, "secret001");

        i = 3;
        userDomain = ldap_server[i].split("=")[0];
        userDomainLDAPServer = ldap_server[i].split("=")[1];
        // never used String userDomainLDAPBaseDN = ldap_base_DN[i].split("=")[1];
        userDomainBinDN = BinDN[i].split("=")[1];
        userDomainldap_bind_pass = ldap_bind_pass[i].split("=")[1];
        assertEquals(userDomain, "SOMEWHERE.INTERNAL");
        assertEquals(userDomainLDAPServer, "10.0.0.4");
        assertEquals(userDomainBinDN, "connecuserssoau@SOMEWHERE.INTERNAL");
        assertEquals(userDomainldap_bind_pass, "secret004");
    } catch (ConfigurationException ex) {
        Logger.getLogger(TestExtractor.class.getName()).log(Level.SEVERE, null, ex);
        fail(ex.getLocalizedMessage());
    }

}

From source file:com.ibm.replication.iidr.utils.Bookmarks.java

/**
 * Load the bookmarks from the properties file
 *//*w  ww  .  ja v  a 2 s  . co m*/
private void loadBookmarks(String bookmarksFileName)
        throws ConfigurationException, FileNotFoundException, IOException {
    String bookmarkDirFullName = System.getProperty("user.dir") + File.separatorChar + "conf" + File.separator
            + "bookmarks";
    String bookmarkFullFileName = bookmarkDirFullName + File.separator + bookmarksFileName;
    File bookmarkFile = new File(bookmarkFullFileName);
    // Create the bookmark file if it doesn't exist
    if (!bookmarkFile.exists()) {
        new File(bookmarkDirFullName).mkdirs();
        new FileOutputStream(bookmarkFullFileName, true).close();
    }
    // Get bookmarks
    bookmarks = new PropertiesConfiguration(bookmarkFile);
    Iterator<String> bookmarkKeys = bookmarks.getKeys();
    while (bookmarkKeys.hasNext()) {
        String bookmarkKey = bookmarkKeys.next();
        logger.debug("Bookmark: " + bookmarkKey + " = " + (String) bookmarks.getProperty(bookmarkKey));
    }
    // Make sure that any updates to the bookmarks is automatically saved
    bookmarks.setAutoSave(true);
}

From source file:com.pinterest.terrapin.TerrapinUtil.java

public static PropertiesConfiguration readPropertiesExitOnFailure(String configFile) {
    PropertiesConfiguration configuration = null;
    if (configFile.isEmpty()) {
        LOG.error("Empty configuration file name. Please specify using -Dterrapin.config.");
        System.exit(1);//from   w  ww. ja v a 2s.c  o m
    }
    try {
        configuration = new PropertiesConfiguration(configFile);
    } catch (ConfigurationException e) {
        LOG.info("Invalid configuration file " + configFile);
        System.exit(1);
    }
    return configuration;
}

From source file:com.ripariandata.timberwolf.conf4j.ConfigFileParser.java

/**
 * Takes the values from the named configuration file and apply them to the
 * target class.  Assumes that the file is a java properties file, readable
 * by <a href="http://commons.apache.org/configuration/apidocs/org/apache/commons/configuration/PropertiesConfiguration.html">
 * org.apache.commons.configuration.PropertiesConfiguration</a>.
 *
 * @throws ConfigFileMissingException If the named configuration file does not exist.
 * @throws ConfigFileException If there was any other problem reading the configuration file.
 *//* ww  w. j ava 2  s .co  m*/
public void parseConfigFile(final String configFile) throws ConfigFileException {
    File f = new File(configFile);
    if (!f.exists()) {
        throw new ConfigFileMissingException(configFile, this);
    }

    Configuration config;
    try {
        config = new PropertiesConfiguration(configFile);
    } catch (ConfigurationException e) {
        throw new ConfigFileException("There was an error loading the configuration file at " + configFile, e,
                this);
    }
    parseConfiguration(config);
}