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:it.grid.storm.authz.sa.conf.FileAuthzDBReader.java

public void onChangeAuthzDB(String authzDBName) throws AuthzDBReaderException {

    // Parsing of Authz DB.
    try {// w ww. ja  va  2s. com
        PropertiesConfiguration authzdb = new PropertiesConfiguration(authzDBName);
        FileAuthzDB fileAuthzDB = new FileAuthzDB(authzdb);
        authzDBs.put(authzDBName, fileAuthzDB);
        long pTime = System.currentTimeMillis();
        parsedTime.put(authzDBName, new Long(pTime));
        log.debug("Bound FileAuthzDBReader with {}", authzDBName);
    } catch (ConfigurationException ex) {
        ex.printStackTrace();
        throw new AuthzDBReaderException("Unable to parse the AuthzDB '" + authzDBName + "'.");
    }
    // Notify the watcher the accomplished parsing
    authzDBWatcher.authzDBParsed(authzDBName);
}

From source file:eu.abc4trust.guice.configuration.ConfigurationParserTest.java

@Test
public void testPropertiesConfiguration() throws IOException {
    File tmp = TemporaryFileFactory.createTemporaryFile();
    String filename = tmp.getAbsolutePath();

    String credentialFilename = "credentials.file";
    String keystorageFilename = "keystorage.file";
    String tokensFilename = "tokens.file";
    String pseudonymsFilename = "pseudonyms.file";
    String defaultImagePath = "default.jpg";
    String imageCacheDir = "image_cache_dir";

    FileWriter writer = new FileWriter(tmp);
    writer.write(" credentialstorage_file" + "=" + credentialFilename + "\n");
    writer.write("keystorage_file" + " = " + keystorageFilename + "\n\n");
    writer.write("  pseudonyms_file" + "   =    " + pseudonymsFilename + "    \n");
    writer.write("tokenstorage_file" + "=" + tokensFilename + "\n");
    writer.write("default_image_path" + "=" + defaultImagePath + "\n");
    writer.write("image_cache_dir" + "=" + imageCacheDir + "\n");
    writer.close();/*from  w ww .  jav a2  s.co  m*/

    PropertiesConfiguration config;
    try {
        config = new PropertiesConfiguration(filename);

        config.setReloadingStrategy(new FileChangedReloadingStrategy());

        ConfigurationParser configurationParser = new ConfigurationParser(config);
        AbceConfigurationImpl abceConfiguration = new AbceConfigurationImpl();
        configurationParser.loadConfiguration(abceConfiguration);
        assertEquals(abceConfiguration.getCredentialFile().getName(), credentialFilename);
        assertEquals(abceConfiguration.getKeyStorageFile().getName(), keystorageFilename);
        assertEquals(abceConfiguration.getPseudonymsFile().getName(), pseudonymsFilename);
        assertEquals(abceConfiguration.getTokensFile().getName(), tokensFilename);
        assertEquals(abceConfiguration.getDefaultImagePath(), defaultImagePath);
        assertEquals(abceConfiguration.getImageCacheDir().getName(), imageCacheDir);
    } catch (ConfigurationException e) {
        throw new RuntimeException("Could not load property configuration", e);
    }
}

From source file:net.orpiske.ssps.common.repository.RepositorySettings.java

private static void addUserConfig(final RepositoryInfo repositoryInfo) throws RepositorySetupException {
    String repositoryPath = RepositoryUtils.getUserRepository();

    String path = repositoryPath + File.separator + repositoryInfo.getName() + File.separator + "user.conf";

    File file = new File(path);

    if (!file.exists()) {
        try {/*from   w  ww. j a  v  a 2s .c o  m*/
            file.createNewFile();
        } catch (IOException e) {
            throw new RepositorySetupException("Unable to create user configuration " + "file", e);
        }
    } else {
        throw new RepositorySetupException("This user already exists");
    }

    PropertiesConfiguration userConfig;
    try {
        userConfig = new PropertiesConfiguration(path);

        userConfig.addProperty(repositoryInfo.getName() + ".auth.user", repositoryInfo.getUserName());
        userConfig.addProperty(repositoryInfo.getName() + ".auth.password", repositoryInfo.getPassword());
        userConfig.save();
    } catch (ConfigurationException e) {
        throw new RepositorySetupException(
                "Unable to save user configuration to " + path + ":" + e.getMessage(), e);
    }

}

From source file:es.usc.citius.composit.transformer.wsc.wscxml.WSCTransformer.java

/**
 * The WSC specification does not define the ontology URI of the concepts.
 * Thus, the real URI of the ontology should be provided using the wsc-tranformer.properties
 *//*  w  w  w .j  a  v  a2s  . c  om*/
public WSCTransformer() throws Exception {
    // NOTE: The inputs and outputs of the services should be automatically translated from instances to
    // concepts using the XML Reasoner
    PropertiesConfiguration props = new PropertiesConfiguration("wsc-transformer.properties");
    this.taxonomyFile = (String) props.getProperty("taxonomy");
    // Name of the taxonomy.xml file (it will be localized automatically)
    log.info("Taxonomy file name {}", this.taxonomyFile);
    // Name of the ontology.owl file (it will be localized automatically)
    this.ontologyFile = (String) props.getProperty("ontology");
    log.info("Ontology file name {}", this.ontologyFile);
}

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

public CommonsConfigurationReader(ConfigGroupIF group, String config, CompositeConfiguration _cconfig) {
    this.cconfig = _cconfig;

    try {/*from w  w  w  .  jav  a 2 s. c o m*/
        String path = group.getPath() + config;
        ClassLoader loader = CommonsConfigurationReader.class.getClassLoader();
        URL clPath = loader.getResource(path);

        if (clPath == null) {
            throw new RunwayConfigurationException(
                    "The configuration resource [" + path + "] does not exist on the classpath.");
        }

        cconfig.addConfiguration(new PropertiesConfiguration(clPath));
        interpolate();
        CommonsConfigurationResolver.getInMemoryConfigurator().addInterpolateDependency(this);
    } catch (ConfigurationException e) {
        throw new RunwayConfigurationException(e);
    }
}

From source file:net.orpiske.ssps.common.repository.utils.RepositoryUtils.java

private static void readPackageProperties(final File file, final PackageInfo packageInfo) {
    File settingsFile = new File(file.getPath() + File.separator + "package.properties");

    if (logger.isDebugEnabled()) {
        logger.debug("Reading package properties for " + file.getPath());
        logger.debug("Trying to open package.properties at " + settingsFile.getPath());
    }//from  w  w w  .  j  a  va  2 s  .c  o m

    if (settingsFile.exists() && settingsFile.canRead()) {
        PropertiesConfiguration packageSettings;
        try {
            packageSettings = new PropertiesConfiguration(settingsFile);

            String slot = packageSettings.getString("package.default.slot", SlotComparatorFactory.DEFAULT_SLOT);

            packageInfo.setSlot(slot);
        } catch (ConfigurationException e) {
            logger.warn("Unable to read package configuration file at " + settingsFile.getPath());

            if (logger.isDebugEnabled()) {
                logger.debug(e.getMessage(), e);
            }
        }
    } else {
        packageInfo.setSlot(SlotComparatorFactory.DEFAULT_SLOT);
    }

}

From source file:com.boozallen.cognition.accumulo.config.CognitionConfiguration.java

/**
 * Load the CognitionConfiguration from the given AccumuloConfiguration object
 * and any other configurations from the given properties file.
 * @param filePath -- the path to the properties file
 *///from   w w  w . ja v a  2s  .  c o  m
public CognitionConfiguration(AccumuloConfiguration accumuloConfig, String filePath) {
    try {
        this.config = new PropertiesConfiguration(filePath);
    } catch (ConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    this.accumuloConfig = accumuloConfig;
}

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

/**
 * Run initialization code when at web application start-up.
 * /*w  w w. j av a2 s. c  om*/
 * 
 * @param  servletContextEvent     The ServletContextEvent object
 * @throws ResourceNotFoundException
 *                 if the properties file can not be found
 * @throws IllegalStateException
 *                 if an {@link IOException} is thrown while reading the 
 *                 properties file
 */
public void contextInitialized(ServletContextEvent servletContextEvent) {
    ServletContext servletContext = servletContextEvent.getServletContext();

    // Create an absolute path for accessing configuration properties
    String cwd = servletContext.getRealPath(".");

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

    // Initialize commons configuration
    String appConfigPath = cwd + "/WEB-INF/conf/datapackagemanager.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.xpn.xwiki.internal.skin.EnvironmentSkin.java

public Configuration getProperties() {
    if (this.properties == null) {
        URL url = this.environment.getResource(getSkinFolder() + "skin.properties");
        if (url != null) {
            try {
                this.properties = new PropertiesConfiguration(url);
            } catch (ConfigurationException e) {
                LOGGER.error("Failed to load skin [{}] properties file ([])", this.id, url,
                        ExceptionUtils.getRootCauseMessage(e));

                this.properties = new BaseConfiguration();
            }// w w w. j a  va 2s .c o  m
        } else {
            LOGGER.debug("No properties found for skin [{}]", this.id);

            this.properties = new BaseConfiguration();
        }
    }

    return this.properties;
}

From source file:eu.optimis.elasticityengine.config.ConfigurationManager.java

/**
 * Load configuration file as specified in the system property, and fall
 * back on the default file if required.
 *//*from ww  w  .j  a v  a  2s  . co  m*/
private void loadConfigurationFile(String defaultConfigFilePath, String defaultConfigFileName)
        throws ConfigurationException {
    String configFilePath = System.getProperty("configuration.file.path");
    String configFileName = System.getProperty("configuration.file.name");
    String filePath = configFilePath == null ? defaultConfigFilePath : configFilePath;
    String fileName = configFileName == null ? defaultConfigFileName : configFileName;

    URL configURL;

    if (!filePath.endsWith(File.pathSeparator)) {
        filePath += File.pathSeparatorChar;
    }

    // Check if the file exists on the system, else try reading it from the
    // classpath
    File configFile = new File(filePath + fileName);
    if (configFile.exists()) {
        try {
            configURL = new URL(filePath + fileName);
        } catch (MalformedURLException e) {
            throw new ConfigurationException(e);
        }
    } else {
        configURL = this.getClass().getClassLoader().getResource(fileName);
    }

    PropertiesConfiguration config = null;
    try {
        config = new PropertiesConfiguration(configURL);
    } catch (ConfigurationException e) {
        if (configFileName.equals(defaultConfigFileName) && configFilePath.equals(defaultConfigFilePath)) {
            log.fatal("Could not find default configuration file: '" + defaultConfigFilePath + "'", e);
            throw e;
        } else {
            // Try default file too
            try {
                config = new PropertiesConfiguration(defaultConfigFilePath);
            } catch (ConfigurationException e2) {
                log.fatal("Could not find specified " + "configuration file: '" + configFilePath
                        + File.pathSeparator + configFileName + "', and could not find default "
                        + "configuration file: '" + defaultConfigFilePath + "'", e2);
                throw e2;
            }

            log.warn("Could not find specified " + "configuration file: '" + configFilePath + File.pathSeparator
                    + configFileName + "', using default configuration at : '" + defaultConfigFilePath
                    + File.pathSeparator + defaultConfigFileName + "'");
        }
    }
    config.setThrowExceptionOnMissing(true);
    this.configuration = config;
}