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

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

Introduction

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

Prototype

public Object getProperty(String key) 

Source Link

Usage

From source file:com.uber.stream.kafka.mirrormaker.manager.ManagerConf.java

public static ManagerConf getManagerConf(CommandLine cmd) {
    ManagerConf managerConf = new ManagerConf();
    if (cmd.hasOption("config")) {
        managerConf.setConfigFile(cmd.getOptionValue("config"));
    } else {//from   w w w  . ja  v  a  2s .  c  o m
        managerConf.setConfigFile("");
    }
    if (cmd.hasOption("srcClusters")) {
        managerConf.setSourceClusters(cmd.getOptionValue("srcClusters"));
    } else {
        managerConf.setSourceClusters("");
    }
    if (cmd.hasOption("destClusters")) {
        managerConf.setDestinationClusters(cmd.getOptionValue("destClusters"));
    } else {
        managerConf.setDestinationClusters("");
    }
    if (cmd.hasOption("enableRebalance")) {
        managerConf.setEnableRebalance(cmd.getOptionValue("enableRebalance"));
    } else {
        managerConf.setEnableRebalance(Boolean.toString(DEFAULT_ENABLE_REBALANCE));
    }
    if (cmd.hasOption("zookeeper")) {
        managerConf.setManagerZkStr(cmd.getOptionValue("zookeeper"));
    } else {
        throw new RuntimeException("Missing option: --zookeeper");
    }
    if (cmd.hasOption("managerPort")) {
        managerConf.setManagerPort(cmd.getOptionValue("managerPort"));
    } else {
        throw new RuntimeException("Missing option: --managerPort");
    }
    if (cmd.hasOption("deployment")) {
        managerConf.setManagerDeployment(cmd.getOptionValue("deployment"));
    } else {
        throw new RuntimeException("Missing option: --deployment");
    }
    if (cmd.hasOption("env")) {
        managerConf.setEnvironment(cmd.getOptionValue("env"));
    } else {
        throw new RuntimeException("Missing option: --env");
    }
    if (cmd.hasOption("instanceId")) {
        managerConf.setManagerInstanceId(cmd.getOptionValue("instanceId"));
    } else {
        try {
            managerConf.setManagerInstanceId(InetAddress.getLocalHost().getHostName());
        } catch (UnknownHostException e) {
            throw new RuntimeException("Missing option: --instanceId");
        }
    }
    if (cmd.hasOption("controllerPort")) {
        managerConf.setControllerPort(cmd.getOptionValue("controllerPort"));
    } else {
        throw new RuntimeException("Missing option: --controllerPort");
    }
    if (cmd.hasOption("graphiteHost")) {
        managerConf.setGraphiteHost(cmd.getOptionValue("graphiteHost"));
    }
    if (cmd.hasOption("graphitePort")) {
        managerConf.setGraphitePort(cmd.getOptionValue("graphitePort"));
    } else {
        managerConf.setGraphitePort("0");
    }
    if (cmd.hasOption("metricsPrefix")) {
        managerConf.setMetricsPrefix(cmd.getOptionValue("metricsPrefix"));
    } else {
        managerConf.setMetricsPrefix(DEFAULT_METRICS_PREFIX);
    }
    if (cmd.hasOption("c3Host")) {
        managerConf.setC3Host(cmd.getOptionValue("c3Host"));
    } else {
        managerConf.setC3Host(DEFAULT_C3_HOST);
    }
    if (cmd.hasOption("c3Port")) {
        managerConf.setC3Port(cmd.getOptionValue("c3Port"));
    } else {
        managerConf.setC3Port(Integer.toString(DEFAULT_C3_PORT));
    }
    if (cmd.hasOption("clusterPrefixLength")) {
        managerConf.setClusterPrefixLength(cmd.getOptionValue("clusterPrefixLength"));
    } else {
        managerConf.setClusterPrefixLength(Integer.toString(DEFAULT_CLUSTER_PREFIX_LENGTH));
    }
    if (cmd.hasOption("workloadRefreshPeriodInSeconds")) {
        managerConf.setWorkloadRefreshPeriodInSeconds(cmd.getOptionValue("workloadRefreshPeriodInSeconds"));
    } else {
        managerConf.setWorkloadRefreshPeriodInSeconds(
                Integer.toString(DEFAULT_WORKLOAD_REFRESH_PERIOD_IN_SECONDS));
    }
    if (cmd.hasOption("initMaxNumPartitionsPerRoute")) {
        managerConf.setInitMaxNumPartitionsPerRoute(cmd.getOptionValue("initMaxNumPartitionsPerRoute"));
    } else {
        managerConf
                .setInitMaxNumPartitionsPerRoute(Integer.toString(DEFAULT_INIT_MAX_NUM_PARTITIONS_PER_ROUTE));
    }
    if (cmd.hasOption("maxNumPartitionsPerRoute")) {
        managerConf.setMaxNumPartitionsPerRoute(cmd.getOptionValue("maxNumPartitionsPerRoute"));
    } else {
        managerConf.setMaxNumPartitionsPerRoute(Integer.toString(DEFAULT_MAX_NUM_PARTITIONS_PER_ROUTE));
    }
    if (cmd.hasOption("initMaxNumWorkersPerRoute")) {
        managerConf.setInitMaxNumWorkersPerRoute(cmd.getOptionValue("initMaxNumWorkersPerRoute"));
    } else {
        managerConf.setInitMaxNumWorkersPerRoute(Integer.toString(DEFAULT_INIT_MAX_NUM_WORKERS_PER_ROUTE));
    }
    if (cmd.hasOption("maxNumWorkersPerRoute")) {
        managerConf.setMaxNumWorkersPerRoute(cmd.getOptionValue("maxNumWorkersPerRoute"));
    } else {
        managerConf.setMaxNumWorkersPerRoute(Integer.toString(DEFAULT_MAX_NUM_WORKERS_PER_ROUTE));
    }
    if (cmd.hasOption("bytesPerSecondDefault")) {
        managerConf.setBytesPerSecondDefault(cmd.getOptionValue("bytesPerSecondDefault"));
    } else {
        managerConf.setBytesPerSecondDefault(Double.toString(DEFAULT_BYTES_PER_SECOND_DEFAULT));
    }
    if (cmd.hasOption("msgsPerSecondDefault")) {
        managerConf.setMsgsPerSecondDefault(cmd.getOptionValue("msgsPerSecondDefault"));
    } else {
        managerConf.setMsgsPerSecondDefault(Double.toString(DEFAULT_MSGS_PER_SECOND_DEFAULT));
    }
    if (cmd.hasOption("updateStatusCoolDownMs")) {
        managerConf.setUpdateStatusCoolDownMs(cmd.getOptionValue("updateStatusCoolDownMs"));
    } else {
        managerConf.setUpdateStatusCoolDownMs(Integer.toString(DEFAULT_UPDATE_STATUS_COOL_DOWN_MS));
    }

    if (cmd.hasOption("config")) {
        String fileName = cmd.getOptionValue("config");
        managerConf.setConfigFile(fileName);
        // load config from file
        PropertiesConfiguration configFromFile = new PropertiesConfiguration();
        configFromFile.setDelimiterParsingDisabled(true);
        try {
            configFromFile.load(fileName);
        } catch (ConfigurationException e) {
            throw new RuntimeException("Failed to load config from file " + fileName + ": " + e.getMessage());
        }
        // merge the config with command line. Option from command line has higher priority to override config from file
        @SuppressWarnings("unchecked")
        Iterator<String> keyIter = configFromFile.getKeys();
        while (keyIter.hasNext()) {
            String key = keyIter.next();
            if (!managerConf.containsKey(key)) {
                managerConf.addPropertyDirect(key, configFromFile.getProperty(key));
            }
        }
    } else {
        managerConf.setConfigFile("");
    }

    return managerConf;
}

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

public ConfigReader(String configurationPathname, int refresh) {

    if (configurationPathname != null) {
        if (refresh < 0)
            refresh = 0;/*from   www.ja  v  a 2s .  c o m*/
        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:com.shadwelldacunha.byteswipe.core.ConfigHandler.java

private void checkDefaults(String file) {
    try {/* w  ww  .ja  v a  2s . com*/
        PropertiesConfiguration defConfig = new PropertiesConfiguration(
                Utilities.getResource("byteswipe.properties"));
        Iterator<String> defKeys = defConfig.getKeys();

        //Add missing keys
        while (defKeys.hasNext()) {
            String key = defKeys.next();
            if (!config.containsKey(key)) {
                config.addProperty(key, defConfig.getProperty(key));
            }
        }

        config.save();
        //TODO: Handle exceptions
    } catch (ConfigurationException e) {
        e.printStackTrace();
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
}

From source file:firmadigital.Firma.java

private void cmdVerificarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdVerificarActionPerformed

    RespuestaSolicitud respuestaRecepcion;
    PropertiesConfiguration config;
    String claveAccesoComprobante = null;

    try {//from  w  ww  .j  av a  2  s. c o  m
        config = new PropertiesConfiguration("FirmaDigital.properties");
        if (config.getProperty("web.web_service") == null) {
            JOptionPane.showMessageDialog(null, "Primero debe ingrear a la pantalla de parmetros");
            return;
        }

        if (!lblRutaArchivo.getText().isEmpty() && !lblNombreArchivo.getText().isEmpty()) {
            File archivo = new File(lblRutaArchivo.getText(), lblNombreArchivo.getText());
            claveAccesoComprobante = ArchivoUtils.obtenerValorXML(archivo, "/*/infoTributaria/claveAcceso");
            String tipoComprobante = ArchivoUtils.obtenerValorXML(archivo, "/*/infoTributaria/codDoc")
                    .substring(1);
            String rucEmisor = ArchivoUtils.obtenerValorXML(archivo, "/*/infoTributaria/ruc");

            if ((tipoComprobante != null) && (claveAccesoComprobante != null)) {
                respuestaRecepcion = EnvioComprobantesWs.obtenerRespuestaEnvio(archivo, rucEmisor,
                        tipoComprobante, claveAccesoComprobante,
                        config.getProperty("web.web_service").toString());
                JOptionPane.showMessageDialog(null, respuestaRecepcion.getEstado());
            }
        } else {
            JOptionPane.showMessageDialog(null, "Tiene que especificar un archivo");
        }
    } catch (ConfigurationException ex) {
        Logger.getLogger(Firma.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:ke.co.tawi.babblesms.server.servlet.util.PropertiesConfig.java

/**
 * Populate the internal HashMap which will hold configuration keys and values
 *//*from  w  ww .  j ava2s . c om*/
private void initConfigHash() {
    PropertiesConfiguration config;
    String key;

    try {
        config = new PropertiesConfiguration();
        config.setListDelimiter('|'); // our array delimiter
        config.setFileName(configFile);
        config.load();

        Iterator<String> keys = config.getKeys();

        while (keys.hasNext()) {
            key = keys.next();
            configHash.put(key, (String) config.getProperty(key));
        }

    } catch (ConfigurationException e) {
        logger.error("ConfigurationException when trying to initialize configuration HashMap");
        logger.error(ExceptionUtils.getStackTrace(e));
    }
}

From source file:de.ingrid.portal.config.PortalConfig.java

private PortalConfig() throws Exception {
    super("ingrid-portal-apps.properties");
    //this.setReloadingStrategy(ReloadingStrategy)
    URL url = this.getClass().getResource("/ingrid-portal-apps.override.properties");
    if (url != null) {
        File f = new File(url.getPath());
        PropertiesConfiguration userConfig = new PropertiesConfiguration(f);
        Iterator<String> it = userConfig.getKeys();
        while (it.hasNext()) {
            String key = it.next();
            this.setProperty(key, userConfig.getProperty(key));
        }//from w ww . ja  va 2s . c o m
    }
}

From source file:com.linkedin.pinot.integration.tests.FileBasedServerBrokerStarters.java

@SuppressWarnings("unchecked")
private void log(PropertiesConfiguration props, String configsFor) {
    LOGGER.info("******************************* configs for : " + configsFor
            + " : ********************************************");

    final Iterator<String> keys = props.getKeys();

    while (keys.hasNext()) {
        final String key = keys.next();
        LOGGER.info(key + " : " + props.getProperty(key));
    }//  w  ww .  j  a  va2s .  c om

    LOGGER.info("******************************* configs end for : " + configsFor
            + " : ****************************************");
}

From source file:com.liferay.ide.project.core.tests.UpgradeLiferayProjectsOpTests.java

private void checkProperties(IFile file, String propertyName, String propertiesValue) {
    try {//from  w  w w .j av  a2s. c o  m
        File osfile = new File(file.getLocation().toOSString());
        PropertiesConfiguration pluginPackageProperties = new PropertiesConfiguration();
        pluginPackageProperties.load(osfile);
        String value = (String) pluginPackageProperties.getProperty(propertyName);
        assertTrue(value.contains(propertiesValue));
        file.refreshLocal(IResource.DEPTH_ZERO, new NullProgressMonitor());
    } catch (Exception e) {
        ProjectCore.logError(e);
    }
}

From source file:it.geosolutions.opensdi2.configurations.dao.PropertiesDAO.java

@Override
public boolean merge(OSDIConfiguration updatedConfig)
        throws OSDIConfigurationNotFoundException, OSDIConfigurationInternalErrorException {
    boolean outcome = false;
    File configFile = searchConfigurationFile(updatedConfig.getScopeID(), updatedConfig.getInstanceID());
    PropertiesConfiguration oldConfig = loadConfigurationInstance(configFile);
    OSDIConfigurationKVP updatedConfigKVP = (OSDIConfigurationKVP) updatedConfig;
    Iterator<String> iter = updatedConfigKVP.getAllKeys().iterator();
    String tmpKey = "";
    while (iter.hasNext()) {
        tmpKey = iter.next();/*w w  w . java2s  .  com*/
        Object newValue = updatedConfigKVP.getValue(tmpKey);
        Object oldValue = oldConfig.getProperty(tmpKey);
        if (newValue != null && !newValue.equals(oldValue)) {
            oldConfig.setProperty(tmpKey, newValue);
            outcome = true;
        }
    }
    try {
        oldConfig.save();
    } catch (ConfigurationException e) {
        throw new OSDIConfigurationInternalErrorException(
                "Error occurred while saving the updated configuration, exception msg is: '" + e.getMessage()
                        + "'");
    }
    return outcome;
}

From source file:com.konakartadmin.apiexamples.GetCustomerExamples.java

private String[] getPropertiesFromFile(String fileName, String keysStartingWith)
        throws KKAdminException, KKException, ConfigurationException {
    /*/*  w  ww  . j  a  va 2 s. c  o m*/
     * Find the specified properties file which is guaranteed to return the URL of
     * the properties file or throw an exception.
     */
    URL configFileURL = PropertyFileFinder.findPropertiesURL(fileName);

    PropertiesConfiguration conf = new PropertiesConfiguration(configFileURL);

    if (conf.isEmpty()) {
        throw new KKAdminException(
                "The configuration file: " + configFileURL + " does not appear to contain any keys");
    }

    // Now create the array of properties

    Iterator<?> keys = (conf.getKeys());
    int keyCount = 0;
    while (keys.hasNext()) {
        String key = (String) keys.next();
        String value = (String) conf.getProperty(key);
        if (keysStartingWith == null || key.startsWith(keysStartingWith)) {
            System.out.println(keyCount + ") " + key + " => " + value);
            keyCount++;
        }
    }

    String[] properties = new String[keyCount * 2];
    keys = (conf.getKeys());
    int propIdx = 0;
    while (keys.hasNext()) {
        String key = (String) keys.next();
        String value = (String) conf.getProperty(key);
        if (keysStartingWith == null || key.startsWith(keysStartingWith)) {
            properties[propIdx++] = key;
            properties[propIdx++] = value;
        }
    }

    return properties;
}