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.tango.energymodeller.energypredictor.AveragePowerEnergyPredictor.java

/**
 * This creates a new average power energy predictor. The predictor when
 * running takes the last power reading and makes the assumption no change
 * will occur. An observation time window is used for taking the measurement,
 * which is set via a configuration file.
 *//*from  w w w.j  a va2 s . co m*/
public AveragePowerEnergyPredictor() {
    try {
        if (database == null) {
            database = new DefaultDatabaseConnector();
        }
        PropertiesConfiguration config;
        if (new File(CONFIG_FILE).exists()) {

            config = new PropertiesConfiguration(CONFIG_FILE);
        } else {
            config = new PropertiesConfiguration();
            config.setFile(new File(CONFIG_FILE));
        }
        config.setAutoSave(true); //This will save the configuration file back to disk. In case the defaults need setting.
        powerObservationTimeMin = config.getInt(
                "energy.modeller.energy.predictor.cpu.utilisation.observe_time.min", powerObservationTimeMin);
        config.setProperty("energy.modeller.energy.predictor.cpu.utilisation.observe_time.min",
                powerObservationTimeMin);
        powerObservationTimeSec = config.getInt(
                "energy.modeller.energy.predictor.cpu.utilisation.observe_time.sec", powerObservationTimeSec);
        config.setProperty("energy.modeller.energy.predictor.cpu.utilisation.observe_time.sec",
                powerObservationTimeSec);
        observationTime = powerObservationTimeSec + (int) TimeUnit.MINUTES.toSeconds(powerObservationTimeMin);
    } catch (ConfigurationException ex) {
        Logger.getLogger(AveragePowerEnergyPredictor.class.getName()).log(Level.SEVERE,
                "The average power energy predictor failed to initialise", ex);
    }
}

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

private void loadProperties(String fileName) {
    try {//w w  w .j a  va 2s. c o  m
        String path = ConfigGroup.COMMON.getPath() + fileName;

        // Read the configuration
        URL url = CommonsConfigurationReader.class.getClassLoader().getResource(path);

        if (url != null) {
            cconfig.addConfiguration(new PropertiesConfiguration(url));

            log.trace("Loading [" + fileName + "] configuration overrides.");
        } else {
            log.info("Did not find " + fileName + ". No overrides were loaded.");
        }
    } catch (ConfigurationException e) {
        log.error(e.getLocalizedMessage(), e);
    }
}

From source file:com.xemantic.tadedon.configuration.Configurations.java

public static PropertiesConfiguration newPropertiesConfiguration(URL confUrl) {
    try {//  w  w  w. j  av  a 2  s. c  o m
        return new PropertiesConfiguration(confUrl);
    } catch (ConfigurationException e) {
        throw new RuntimeException("Cannot create configuration", e);
    }
}

From source file:net.krotscheck.jersey2.configuration.Jersey2ToolkitConfig.java

/**
 * Builds the configuration object for our toolkit config.
 *
 * @return A Configuration object.//from www.  ja  v  a2  s  .c  om
 */
private Configuration buildToolkitConfig() {

    // The toolkit configuration file.
    try {
        File configFile = ResourceUtil.getFileForResource("jersey2-toolkit.properties");
        return new PropertiesConfiguration(configFile);
    } catch (ConfigurationException ce) {
        logger.error("jersey2-toolkit.properties not readable," + " some features may be misconfigured.");

        // Return a new, empty map configuration so we don't error out.
        return new MapConfiguration(new HashMap<String, String>());
    }
}

From source file:com.TersoSolutions.Jetstream.SDK.Application.User.JetstreamServiceClient.java

/**
 * Constructor for the JetstreamServiceClient. This client is the base
 * service for accessing the Jetstream REST endpoints. Reads information
 * from the provided file/*from   www  . j av  a  2 s. co  m*/
 * 
 * @param properties
 *            The properties file
 * @throws IllegalArgumentException
 */
public JetstreamServiceClient(File properties) {
    try {
        config = new PropertiesConfiguration(properties);

        String jetstreamAPIUrl = config.getString("jetstream.baseuri");
        String accessKey = config.getString("jetstream.accesskey");

        init(jetstreamAPIUrl, accessKey);

    } catch (ConfigurationException e) {
        e.printStackTrace();
    }
}

From source file:fr.inria.atlanmod.neoemf.graph.blueprints.neo4j.resources.BlueprintsNeo4jResourceSaveTest.java

@SuppressWarnings("unchecked")
@Test//from  w ww  . ja va2s.com
public void testSaveGraphNeo4jResourceNeo4jTypeOption() throws IOException, ConfigurationException {
    options.clear();
    options.put(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_GRAPH_TYPE,
            BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_TYPE_NEO4J);
    resource.save(options);
    File configFile = new File(testFilePath + configFileName);
    assert configFile.exists();
    PropertiesConfiguration configuration = new PropertiesConfiguration(configFile);
    assert configuration.containsKey(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_GRAPH_TYPE);
    assert configuration.getString(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_GRAPH_TYPE)
            .equals(BlueprintsNeo4jResourceOptions.OPTIONS_BLUEPRINTS_TYPE_NEO4J);
    /*
     * Check the configuration file contains the store_dir property (computed by
     * blueprints at graph creation)
     */
    assert configuration.containsKey(OPTIONS_GRAPH_NEO4J_STORE_DIR);
    assert configuration.getString(OPTIONS_GRAPH_NEO4J_STORE_DIR).equals(testFile.getAbsolutePath());
    assert getKeyCount(
            configuration) == defaultPropertyCount : "The number of properties in the configuration file is not consistent with the given options";
}

From source file:com.xtesy.core.internals.impl.Settings.java

/**
 * @author Wasiq B/*from   w  w  w  .  ja  v  a  2  s  .  c o m*/
 * @throws ConfigurationException
 * @throws FileNotFoundException
 * @since 04-Jul-2015 6:17:05 pm
 */
private void parseConfig() throws ConfigurationException, FileNotFoundException {
    String file = getString(Constants.TEST_CONFIG_FILE);
    if (file == null) {
        file = "test.properties";
    }
    final URL url = FileUtils.getResource(file);
    if (url == null)
        throw new FileNotFoundException(file);
    this.prop = new PropertiesConfiguration(url);
    this.prop.setAutoSave(true);
    this.prop.setReloadingStrategy(new FileChangedReloadingStrategy());
    addConfiguration(this.prop);
}

From source file:cz.cas.lib.proarc.common.process.GenericExternalProcessTest.java

@Test
public void testIMConvert() throws Exception {
    //        temp.setDeleteOnExit(false);
    String imageMagicExec = "/usr/bin/convert";
    Assume.assumeTrue(new File(imageMagicExec).exists());

    File confFile = temp.newFile("props.cfg");
    File root = temp.getRoot();/*from w w w .ja  va 2s  .c  o  m*/
    URL pdfaResource = TiffImporterTest.class.getResource("pdfa_test.pdf");
    File pdfa = new File(root, "pdfa_test.pdf");
    FileUtils.copyURLToFile(pdfaResource, pdfa);
    FileUtils.writeLines(confFile, Arrays.asList("input.file.name=RESOLVED", "exec=" + imageMagicExec,
            //                "arg=-verbose",
            "arg=-thumbnail", "arg=120x128", "arg=$${input.file}[0]", "arg=-flatten", "arg=$${output.file}",
            "id=test"));
    PropertiesConfiguration conf = new PropertiesConfiguration(confFile);
    GenericExternalProcess gep = new GenericExternalProcess(conf);
    gep.addInputFile(pdfa);
    File output = new File(root, "pdfa.jpg");
    gep.addOutputFile(output);
    gep.run();
    //        System.out.printf("#exit: %s, out: %s\nresults: %s\n",
    //                gep.getExitCode(), gep.getFullOutput(), gep.getResultParameters());
    assertEquals("exit code", 0, gep.getExitCode());
    assertTrue(output.toString(), output.exists());
    assertTrue("Not JPEG", InputUtils.isJpeg(output));
}

From source file:com.zavakid.mushroom.impl.MetricsConfig.java

/**
 * Load configuration from a list of files until the first successful load
 * /* ww w .  jav  a  2 s  .c o  m*/
 * @param conf the configuration object
 * @param files the list of filenames to try
 * @return the configuration object
 */
static MetricsConfig loadFirst(String prefix, String... fileNames) {
    for (String fname : fileNames) {
        try {
            Configuration cf = new PropertiesConfiguration(fname).interpolatedConfiguration();
            LOG.info("loaded properties from " + fname);
            return new MetricsConfig(cf, prefix);
        } catch (ConfigurationException e) {
            if (e.getMessage().startsWith("Cannot locate configuration")) {
                continue;
            }
            throw new MetricsConfigException(e);
        }
    }
    throw new MetricsConfigException("Cannot locate configuration: tried " + StringUtils.join(fileNames, ", "));
}

From source file:com.impetus.ankush.agent.action.impl.PropertyFileManipulator.java

/**
 * Delete conf value./*ww w  . j  a v a2s.c  o m*/
 * 
 * @param file
 *            the file
 * @param propertyName
 *            the property name
 * @return true, if successful
 */
@Override
public boolean deleteConfValue(String file, String propertyName) {
    boolean status = false;
    try {
        // read conf file
        File confFile = new File(file);

        if (!confFile.exists()) {
            System.err.println("File " + file + " does not exists.");
            status = false;
        }
        PropertiesConfiguration props = new PropertiesConfiguration(file);
        props.getLayout().setSeparator(propertyName, "=");
        if (props.getProperty(propertyName) != null) {
            props.clearProperty(propertyName);
            props.save();
            status = true;
        }
    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
    return status;

}