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:fr.jetoile.hadoopunit.test.hdfs.HdfsUtils.java

private void loadConfig() throws ConfigException {
    try {//from  www.java  2 s. c o m
        configuration = new PropertiesConfiguration(HadoopUnitConfig.DEFAULT_PROPS_FILE);
    } catch (ConfigurationException e) {
        throw new ConfigException("bad config", e);
    }

    port = configuration.getInt(HadoopUnitConfig.HDFS_NAMENODE_PORT_KEY);
    httpPort = configuration.getInt(HadoopUnitConfig.HDFS_NAMENODE_HTTP_PORT_KEY);
}

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

/**
 * Load the CognitionConfiguration from the given properties file.
 * //w ww .j a v  a2  s .c  om
 * @param filePath -- the path to the properties file
 */
public CognitionConfiguration(String filePath) {
    try {
        this.config = new PropertiesConfiguration(filePath);
        this.accumuloConfig = new AccumuloConfiguration(config.getString("zookeeper.instance.name"),
                config.getString("zookeeper.instance.hosts"), config.getString("accumulo.user"),
                config.getString("accumulo.password"));
    } catch (ConfigurationException | AccumuloSecurityException | IOException e) {
        throw new RuntimeException("Unable to load configuration or configuration is invalid: " + filePath);
    }
}

From source file:eu.planetdata.srbench.oracle.configuration.Config.java

private Config() {
    converter = new JsonConverter();
    try {//w  w  w . j a v a  2 s  .com
        config = new PropertiesConfiguration("setup.properties");
    } catch (ConfigurationException e) {
        logger.error("Error while reading the configuration file", e);
    }
}

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

/**
 * Edits the conf value.//from ww w .  j  a  v a2s  .  c o  m
 * 
 * @param file
 *            the file
 * @param propertyName
 *            the property name
 * @param newPropertyValue
 *            the new property value
 * @return true, if successful
 */
@Override
public boolean editConfValue(String file, String propertyName, String newPropertyValue) {
    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.setProperty(propertyName, newPropertyValue);
        props.getLayout().setSeparator(propertyName, "=");
        props.save();
        status = true;
    } catch (Exception e) {
        System.err.println(e.getMessage());
    }
    return status;
}

From source file:com.norconex.jefmon.about.AboutDialog.java

private PropertiesConfiguration getAboutProperties() {
    try {//from  ww  w . j ava 2  s.  c om
        URL resource = new DefaultClassResolver().getClassLoader().getResource("about.properties");
        return new PropertiesConfiguration(resource);
    } catch (ConfigurationException e) {
        throw new JEFMonException("Exception while reading about.properties", e);
    }
}

From source file:at.newmedialab.ldpath.backend.linkeddata.AbstractLDBackend.java

/**
 * Initialise a new sesame backend. Repository needs to be set using setRepository.
 *//*ww w  .j  a  v  a 2  s  . co  m*/
protected AbstractLDBackend() {
    ldCache = new LDCache(this);

    try {
        Configuration config = new PropertiesConfiguration("endpoints.properties");

        HashSet<String> endpointNames = new HashSet<String>();
        for (Iterator<String> it = config.getKeys(); it.hasNext();) {
            String key = it.next();
            String[] components = key.split("\\.");
            if (components.length > 1) {
                endpointNames.add(components[0]);
            }
        }
        for (String endpointName : endpointNames) {
            String prefix = config.getString(endpointName + ".prefix", "");
            String kind = config.getString(endpointName + ".kind", "");
            String endpointUrl = config.getString(endpointName + ".endpoint", "");
            String mimetype = config.getString(endpointName + ".mimetype", "");
            long expiry = config.getLong(endpointName + ".expiry", (long) 86400);

            Endpoint.EndpointType type;
            try {
                type = Endpoint.EndpointType.valueOf(kind.toUpperCase());
            } catch (Exception e) {
                type = Endpoint.EndpointType.LINKEDDATA;
            }

            if (prefix != null && prefix.startsWith(Endpoint.REGEX_INDICATOR)) {
                // Check for valid Regex
                try {
                    Pattern.compile(prefix.substring(Endpoint.REGEX_INDICATOR.length()));
                } catch (PatternSyntaxException pse) {
                    log.error("invalid regexp pattern in endpoint '{}' prefix definition: {}", endpointName,
                            prefix);
                }
            }
            if (endpointUrl != null) {
                endpointUrl = endpointUrl.replace('<', '{').replace('>', '}');
            } else {
                endpointUrl = "";
            }
            Endpoint endpoint = new Endpoint(endpointName, type, prefix, endpointUrl, mimetype, expiry);
            log.info("Registering LD Cache Endpoint \"{}\"", endpointName);
            registerEndpoint(endpoint);
        }

    } catch (ConfigurationException e) {
        log.warn(
                "could not load configuration file endpoints.properties from current directory, home directory, or classpath");
    }

}

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

@Test
public void shouldCopyPropertyWithComments() throws IOException, ConfigurationException {
    // given//from   w w  w.j a v  a2  s.c o m
    File confFile1 = new File("src/test/data/conf1.properties");
    File confFile2 = new File("src/test/data/conf2.properties");
    File confFile3 = new File("src/test/data/conf3.properties");
    File outConfFile = new File(testConfDir, "outConf.properties");
    Files.copy(confFile1, outConfFile);
    PropertiesConfiguration conf2 = new PropertiesConfiguration(confFile2);
    PropertiesConfiguration outConf = new PropertiesConfiguration(outConfFile);

    // when
    Configurations.copyProperty("bar", conf2, outConf);
    outConf.save();

    // then
    assertThat(Files.equal(outConfFile, confFile3), is(true));
}

From source file:de.unibw.inf2.fishification.Launch.java

@Override
public void start(Stage primaryStage) {

    m_log.info("Fishification launched.");

    // Store JavaFx stage for thread-safe access
    StageSingleton.injectStage(primaryStage);

    boolean fullScreenMode = true;
    int serverPort = 8088;
    String serverEndpoint = "fishworld";
    try {//  w w w .  j av  a 2  s . co  m
        // Load configuration
        PropertiesConfiguration config = new PropertiesConfiguration("app.properties");

        // Assign properties
        m_serverMode = config.getBoolean("fishification.server.active");
        fullScreenMode = config.getBoolean("fishification.fullscreen");
        serverPort = config.getInt("fishification.server.port");
        serverEndpoint = config.getString("fishification.server.endpoint");

    } catch (ConfigurationException e) {
        m_log.warn(MarkerManager.getMarker("EXCEPTION"), "Error reading configuration.", e);
    }

    // Init Server ?
    if (!m_serverMode) {

        m_log.info(String.format("Starting in client mode with fullscreen: '%b'", fullScreenMode));

        // Create World
        m_world = new FishWorld();

        // Init World
        Rectangle2D screenBounds = Screen.getPrimary().getVisualBounds();
        m_world.initialize(screenBounds.getWidth(), screenBounds.getHeight());

        // Let's go
        m_world.launch();

    } else {

        // Launch Server
        m_log.info(String.format("Starting server with port: '%d' endpoint: '%s' fullscreen: '%b'", serverPort,
                serverEndpoint, fullScreenMode));

        try {
            // Set up server
            FishificationServer.launch(serverPort, serverEndpoint);

        } catch (Exception e) {
            m_log.error(MarkerManager.getMarker("EXCEPTION"), "Error launching the server. Exit application.",
                    e);
            Platform.exit();
        }
    }

    // Focus window
    primaryStage.show();

    // Full Screen mode
    if (fullScreenMode) {
        primaryStage.setFullScreen(true);
    }

}

From source file:it.grid.storm.config.ConfigReader.java

public ConfigReader(String configurationPathname, int refresh) {

    if (configurationPathname != null) {
        if (refresh < 0)
            refresh = 0;/*from   ww w.j  av  a2  s .com*/
        this.refresh = refresh;
        this.configurationPathname = configurationPathname;
        log.info("Configuration file {}. Refresh rate: {} seconds", configurationPathname, refresh);

        try {
            FileChangedReloadingStrategy strategy = new FileChangedReloadingStrategy();
            strategy.setRefreshDelay(refresh);
            PropertiesConfiguration properties = new PropertiesConfiguration(configurationPathname);
            log.debug("Configuration properties:");
            String key;
            for (Iterator<?> i = properties.getKeys(); i.hasNext();) {
                key = (String) i.next();
                log.debug("{} = {}", key, properties.getProperty(key).toString());
            }
            properties.setReloadingStrategy(strategy);
            this.c = new CompositeConfiguration();
            ((CompositeConfiguration) this.c).addConfiguration(properties);
            log.info("Configuration read successfully.");
        } catch (ConfigurationException e) {
            this.c = makeEmptyConfiguration();
            log.error("Configuration parsing error: {}", e.getMessage(), e);
        }
    } else {
        throw new NullPointerException("Null configuration pathname.");
    }
}

From source file:eu.smartenit.sbox.main.SBox.java

/**
 * The method that reads and sets the configuration parameters from file. 
 * //from  w  w w.  jav a2 s .  c o m
 */
private static void readConfigurationProperties() {
    logger.debug("Reading configuration parameters.");
    PropertiesConfiguration config = null;

    try {
        config = new PropertiesConfiguration(SBoxProperties.PROPERTIES_FILE_NAME);
        SBoxProperties.CONNECTION_RETRIES = config.getInt("connection.retries");
        SBoxProperties.CONNECTION_TIMEOUT = config.getLong("connection.timeout");
        SBoxProperties.CORE_POOL_SIZE = config.getInt("core.pool.size");
        SBoxProperties.DB_FILE = config.getString("db.file");
        SBoxProperties.INTER_SBOX_PORT = config.getInt("inter.sbox.port");
        SBoxProperties.MAX_FETCHING_TIME = config.getLong("max.fetching.time");

        SBoxProperties.LOG_TRAFFIC_DETAILS = config.getBoolean("log.traffic.details");
        SBoxProperties.TRAFFIC_DETAILS_FILE_PATH = config.getString("traffic.details.file.path");
        SBoxProperties.TRAFFIC_DETAILS_FILE_NAME = config.getString("traffic.details.file.name");

        SBoxProperties.DEFAULT_REF_VECTOR_FILE = config.getString("default.ref.vector.file");

    } catch (ConfigurationException e) {
        logger.warn("Exception while loading configuration file " + SBoxProperties.PROPERTIES_FILE_NAME + ".");

    } catch (ConversionException e2) {
        logger.warn("Invalid format of configuration parameters, using default.");

    }

    logger.debug("Configuration parameters: \n" + "connection.retries: " + SBoxProperties.CONNECTION_RETRIES
            + "\n" + "connection.timeout: " + SBoxProperties.CONNECTION_TIMEOUT + "\n" + "core.pool.size: "
            + SBoxProperties.CORE_POOL_SIZE + "\n" + "db.file: " + SBoxProperties.DB_FILE + "\n"
            + "inter.sbox.port: " + SBoxProperties.INTER_SBOX_PORT + "\n" + "max.fetching.time: "
            + SBoxProperties.MAX_FETCHING_TIME + "\n" + "log.traffic.details: "
            + SBoxProperties.LOG_TRAFFIC_DETAILS + "\n" + "traffic.details.file.path: "
            + SBoxProperties.TRAFFIC_DETAILS_FILE_PATH + "\n" + "traffic.details.file.name: "
            + SBoxProperties.TRAFFIC_DETAILS_FILE_NAME + "\n" + "default.ref.vector.file: "
            + SBoxProperties.DEFAULT_REF_VECTOR_FILE);
}