Example usage for org.apache.commons.configuration Configuration getString

List of usage examples for org.apache.commons.configuration Configuration getString

Introduction

In this page you can find the example usage for org.apache.commons.configuration Configuration getString.

Prototype

String getString(String key);

Source Link

Document

Get a string associated with the given configuration key.

Usage

From source file:com.linkedin.pinot.broker.routing.builder.LargeClusterRoutingTableBuilder.java

@Override
public void init(Configuration configuration, TableConfig tableConfig,
        ZkHelixPropertyStore<ZNRecord> propertyStore) {
    // TODO jfim This is a broker-level configuration for now, until we refactor the configuration of the routing table to allow per-table routing settings
    if (configuration.containsKey("offlineTargetServerCountPerQuery")) {
        final String targetServerCountPerQuery = configuration.getString("offlineTargetServerCountPerQuery");
        try {//  w  w  w.  j  av  a  2s. c  om
            _targetNumServersPerQuery = Integer.parseInt(targetServerCountPerQuery);
            LOGGER.info("Using offline target server count of {}", _targetNumServersPerQuery);
        } catch (Exception e) {
            LOGGER.warn(
                    "Could not get the offline target server count per query from configuration value {}, keeping default value {}",
                    targetServerCountPerQuery, _targetNumServersPerQuery, e);
        }
    } else {
        LOGGER.info("Using default value for offline target server count of {}", _targetNumServersPerQuery);
    }
}

From source file:edu.lternet.pasta.token.TokenManager.java

public TokenManager() {

    Configuration options = ConfigurationListener.getOptions();

    this.dbDriver = options.getString("db.Driver");
    this.dbURL = options.getString("db.URL");
    this.dbUser = options.getString("db.User");
    this.dbPassword = options.getString("db.Password");

}

From source file:com.appeligo.alerts.KeywordAlertChecker.java

public KeywordAlertChecker(Configuration config) {
    liveLineup = config.getString("liveLineup");
    url = config.getString("url");
}

From source file:com.kixeye.chassis.bootstrap.ConfigurationBuilderTest.java

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test// w  ww . j a v  a  2s  .com
public void fetchFromArchaius() {
    TestUtils.writePropertiesToFile(TEST_APP_CONFIG_PROPERTIES, filesCreated,
            new SimpleEntry(MODULE_1_KEY_2, MODULE_1_VALUE_2 + "-override"),
            new SimpleEntry(MODULE_1_KEY_3, MODULE_1_VALUE_3 + "-override"));
    TestUtils.writePropertiesToFile(
            TEST_APP_CONFIG_PROPERTIES.replace(".properties", "." + ENVIRONMENT + ".properties"), filesCreated,
            new SimpleEntry(MODULE_1_KEY_2, MODULE_1_VALUE_2 + "-override"));

    configurationBuilder.withApplicationProperties(TEST_APP_CONFIG_PROPERTIES_SPRING_PATH);
    Configuration configuration = configurationBuilder.build();

    Assert.assertEquals(MODULE_1_VALUE_1, configuration.getString(MODULE_1_KEY_1));
    Assert.assertEquals(MODULE_1_VALUE_2 + "-override", configuration.getString(MODULE_1_KEY_2));
    Assert.assertEquals(MODULE_1_VALUE_3 + "-override", configuration.getString(MODULE_1_KEY_3));

    Assert.assertEquals(MODULE_1_VALUE_1,
            DynamicPropertyFactory.getInstance().getStringProperty(MODULE_1_KEY_1, null).getValue());
    Assert.assertEquals(MODULE_1_VALUE_2 + "-override",
            DynamicPropertyFactory.getInstance().getStringProperty(MODULE_1_KEY_2, null).getValue());
    Assert.assertEquals(MODULE_1_VALUE_3 + "-override",
            DynamicPropertyFactory.getInstance().getStringProperty(MODULE_1_KEY_3, null).getValue());

}

From source file:net.sf.jclal.activelearning.scenario.AbstractScenario.java

/**
 * Configuration of Oracle.// w ww  .  j  a v  a  2s .  c  o  m
 *
 * @param configuration The configuration object to use
 */
public void setOracleConfiguration(Configuration configuration) {

    String oracleError = "oracle type= ";
    try {
        // oracle classname
        String oracleClassname = configuration.getString("oracle[@type]");

        oracleError += oracleClassname;

        // oracle class
        Class<? extends IOracle> oracleClass = (Class<? extends IOracle>) Class.forName(oracleClassname);

        // oracle instance
        IOracle oracle = oracleClass.newInstance();

        // Configure query strategy (if necessary)
        if (oracle instanceof IConfigure) {
            ((IConfigure) oracle).configure(configuration.subset("oracle"));
        }

        // Add this oracle to the scenario
        setOracle(oracle);

    } catch (ClassNotFoundException e) {
        throw new ConfigurationRuntimeException("\nIllegal oracle classname: " + oracleError, e);
    } catch (InstantiationException e) {
        throw new ConfigurationRuntimeException("\nIllegal oracle classname: " + oracleError, e);
    } catch (IllegalAccessException e) {
        throw new ConfigurationRuntimeException("\nIllegal oracle classname: " + oracleError, e);
    }

}

From source file:edu.kit.dama.staging.adapters.DefaultStorageVirtualizationAdapter.java

@Override
public boolean configure(Configuration pConfig) throws ConfigurationException {
    pathPattern = pConfig.getString("pathPattern");
    String archiveUrlProperty = pConfig.getString("archiveUrl");
    if (archiveUrlProperty == null) {
        throw new ConfigurationException("Property 'archiveUrl' is missing");
    }/*from   ww w .ja va2 s  . co m*/

    //replace TMP_DIR_PATTERN in target URL
    LOGGER.debug("Looking for replacements in archive location");
    String tmp = System.getProperty("java.io.tmpdir");
    if (!tmp.startsWith("/")) {
        tmp = "/" + tmp;
    }
    archiveUrlProperty = archiveUrlProperty.replaceAll(Pattern.quote(TMP_DIR_PATTERN),
            Matcher.quoteReplacement(tmp));
    LOGGER.debug("Using archive Url {}", archiveUrlProperty);
    //set baseDestinationURL property

    try {
        archiveUrl = new URL(archiveUrlProperty);
    } catch (MalformedURLException mue) {
        throw new ConfigurationException("archiveUrl property (" + archiveUrlProperty + ") is not a valid URL",
                mue);
    }

    AbstractFile destination = new AbstractFile(archiveUrl);
    //if caching location is local, check accessibility
    if (destination.isLocal()) {
        LOGGER.debug("Archive URL is local. Checking accessibility.");
        URI uri = null;

        try {
            uri = destination.getUrl().toURI();
        } catch (IllegalArgumentException ex) {
            //provided archive URL is no URI (e.g. file://folder/ -> third slash is missing after file:)
            throw new StagingIntitializationException(
                    "Archive location " + destination.getUrl().toString() + " has an invalid URI syntax", ex);
        } catch (URISyntaxException ex) {
            LOGGER.warn("Failed to check local archive URL. URL " + destination.getUrl()
                    + " seems not to be a valid URI.", ex);
        }
        File localFile = null;
        try {
            localFile = new File(uri);
        } catch (IllegalArgumentException ex) {
            throw new ConfigurationException("Archive URI " + uri
                    + " seems not to be a supported file URI. This storage virtualization implementation only supports URLs in the format file:///<path>/",
                    ex);
        }

        if (!FileUtils.isAccessible(localFile)) {
            throw new StagingIntitializationException(
                    "Archive location seems to be offline: '" + destination.getUrl().toString() + "'");
        }
    }

    try {
        if (!destination.exists()) {
            LOGGER.debug("Archive location does not exists, trying to create it...");
            destination = AbstractFile.createDirectory(destination);
            LOGGER.debug("Archive location successfully created ");
        } else {
            LOGGER.debug("Archive location already exists");
        }
        //clear cached values, e.g. for isReadable() and isWriteable()
        destination.clearCachedValues();
        //check access
        if (destination.isReadable() && destination.isWriteable()) {
            LOGGER.debug("Archive location '{}' is valid", destination.getUrl());
        } else {
            throw new StagingIntitializationException(
                    "Archive location '" + destination.getUrl().toString() + "' is not accessible");
        }
    } catch (AdalapiException ae) {
        throw new StagingIntitializationException(
                "Failed to setup archive location '" + destination.getUrl().toString() + "'", ae);
    }
    return true;
}

From source file:com.salesmanager.core.util.ProductImageUtil.java

public Map<String, String> getDefaultConfigMap() {
    Configuration conf = PropertiesUtil.getConfiguration();
    Map<String, String> defaultConfigMap = new HashMap<String, String>();
    defaultConfigMap.put("largeimageheight", conf.getString("core.product.config.large.image.height"));
    defaultConfigMap.put("largeimagewidth", conf.getString("core.product.config.large.image.width"));
    defaultConfigMap.put("smallimageheight", conf.getString("core.product.config.small.image.height"));
    defaultConfigMap.put("smallimagewidth", conf.getString("core.product.config.small.image.width"));
    defaultConfigMap.put("listingimageheight", conf.getString("core.product.config.large.image.height"));
    defaultConfigMap.put("listingimagewidth", conf.getString("core.product.config.large.image.width"));
    return defaultConfigMap;
}

From source file:com.kixeye.chassis.bootstrap.ConfigurationBuilderTest.java

@Test
public void buildConfigurationOutsideAws() {
    Configuration configuration = configurationBuilder.build();

    Assert.assertEquals(ConfigurationBuilder.LOCAL_INSTANCE_ID,
            configuration.getString(BootstrapConfigKeys.AWS_INSTANCE_ID.getPropertyName()));
    Assert.assertEquals(ConfigurationBuilder.UNKNOWN,
            configuration.getString(BootstrapConfigKeys.AWS_INSTANCE_AVAILABILITY_ZONE.getPropertyName()));
    Assert.assertEquals(ConfigurationBuilder.UNKNOWN,
            configuration.getString(BootstrapConfigKeys.AWS_INSTANCE_REGION.getPropertyName()));
}

From source file:com.vvote.verifier.component.votePacking.VotePackingConfig.java

/**
 * Constructor for a VotePackingConfig object from a String
 * //w  ww .  ja  v a2s  . c o  m
 * @param configLocation
 *            The filename or filepath of the config in string format
 * @throws ConfigException
 */
public VotePackingConfig(String configLocation) throws ConfigException {
    logger.debug("Reading in Vote Packing specific configuration data");

    if (configLocation == null) {
        logger.error("Cannot successfully create a VotePackingConfig");
        throw new ConfigException("Cannot successfully create a VotePackingConfig");
    }

    if (configLocation.length() == 0) {
        logger.error("Cannot successfully create a VotePackingConfig");
        throw new ConfigException("Cannot successfully create a VotePackingConfig");
    }

    try {
        Configuration config = new PropertiesConfiguration(configLocation);

        if (config.containsKey(ConfigFileConstants.VotePackingConfig.CURVE)) {
            this.curve = config.getString(ConfigFileConstants.VotePackingConfig.CURVE);
        } else {
            logger.error(
                    "Cannot successfully create a VotePackingConfig - must contain the name of the curve used");
            throw new ConfigException(
                    "Cannot successfully create a VotePackingConfig - must contain the name of the curve used");
        }

        if (config.containsKey(ConfigFileConstants.VotePackingConfig.PADDING_FILE)) {
            this.paddingFile = config.getString(ConfigFileConstants.VotePackingConfig.PADDING_FILE);
        } else {
            logger.error(
                    "Cannot successfully create a VotePackingConfig - must contain the name of the padding file");
            throw new ConfigException(
                    "Cannot successfully create a VotePackingConfig - must contain the name of the padding file");
        }

        if (config.containsKey(ConfigFileConstants.VotePackingConfig.TABLE_LA_LINE_LENGTH)) {
            this.laLineLength = config.getInt(ConfigFileConstants.VotePackingConfig.TABLE_LA_LINE_LENGTH);
        } else {
            this.laLineLength = -1;
        }

        if (config.containsKey(ConfigFileConstants.VotePackingConfig.TABLE_LA_PACKING)) {
            this.laPacking = config.getInt(ConfigFileConstants.VotePackingConfig.TABLE_LA_PACKING);
        } else {
            this.laPacking = -1;
        }

        if (config.containsKey(ConfigFileConstants.VotePackingConfig.TABLE_BTL_LINE_LENGTH)) {
            this.lcBTLLineLength = config.getInt(ConfigFileConstants.VotePackingConfig.TABLE_BTL_LINE_LENGTH);
        } else {
            this.lcBTLLineLength = -1;
        }

        if (config.containsKey(ConfigFileConstants.VotePackingConfig.TABLE_BTL_PACKING)) {
            this.lcBTLPacking = config.getInt(ConfigFileConstants.VotePackingConfig.TABLE_BTL_PACKING);
        } else {
            this.lcBTLPacking = -1;
        }

        if (config.containsKey(ConfigFileConstants.VotePackingConfig.CANDIDATE_TABLES)) {
            this.candidateTablesFolder = config
                    .getString(ConfigFileConstants.VotePackingConfig.CANDIDATE_TABLES);
        } else {
            logger.error(
                    "Cannot successfully create a VotePackingConfig - must contain the name of the candidates table");
            throw new ConfigException(
                    "Cannot successfully create a VotePackingConfig - must contain the candidates table");
        }

        this.useDirect = new HashMap<RaceType, Boolean>();
        this.useDirect.put(RaceType.LA, false);
        this.useDirect.put(RaceType.LC_ATL, false);
        this.useDirect.put(RaceType.LC_BTL, false);

        if (config.containsKey(ConfigFileConstants.VotePackingConfig.USE_DIRECT)) {
            String[] directlyUsed = config.getStringArray(ConfigFileConstants.VotePackingConfig.USE_DIRECT);

            for (String race : directlyUsed) {
                RaceType raceType = RaceType.fromString(race);

                if (raceType != null) {
                    this.useDirect.remove(raceType);
                    this.useDirect.put(raceType, true);
                } else {
                    logger.error(
                            "Cannot successfully create a VotePackingConfig - misformed use direct race type");
                    throw new ConfigException(
                            "Cannot successfully create a VotePackingConfig - misformed use direct race type");
                }
            }
        }

    } catch (ConfigurationException e) {
        logger.error("Cannot successfully create a VotePackingConfig", e);
        throw new ConfigException("Cannot successfully create a VotePackingConfig", e);
    }
}

From source file:com.appeligo.channelfeed.CaptureApp.java

/**
 * @param args//ww w  . jav a 2 s .  c  o  m
 * @param defaultConfigFile 
 * @throws ConfigurationException 
 */
public CaptureApp(String[] args, String defaultConfigFile) {

    try {
        // Set up a simple configuration that logs on the console.
        PatternLayout pattern = new PatternLayout("%d{ISO8601} %-5p [%-c{1} - %t] - %m%n");
        BasicConfigurator.configure(new ConsoleAppender(pattern));

        configFile = defaultConfigFile;
        if (args.length > 0) {
            if (args.length == 2 && args[0].equals("-config")) {
                configFile = args[1];
            } else {
                log.error("Usage: java " + getClass().getName() + " [-config <xmlfile>]");
                throw new Error("Cannot continue");
            }
        }

        config = new XMLConfiguration(configFile);

        configureLogging(config, pattern);

        String documentRoot = config.getString("documentRoot[@path]");
        log.info("documentRoot = " + documentRoot);
        if (documentRoot == null) {
            log.error("Document root is not set (typically it is \"/var/flip.tv\")");
            throw new Error("Cannot continue");
        } else {
            documentRoot.trim();
            if (!documentRoot.endsWith("/")) {
                documentRoot += "/";
            }
        }
        captionDocumentRoot = documentRoot + "captiondb";
        previewDocumentRoot = documentRoot + "previews";

        String epgServer = config.getString("epgServer[@url]");
        log.info("epgServer = " + epgServer);
        connectToEPG(epgServer);

        writing = config.getBoolean("writing", true);
        log.info("writing = " + writing);

        int destinationsCount = config.getList("destinations.destination[@url]").size();
        destinationURLs = new String[destinationsCount];
        destinationRaws = new boolean[destinationsCount];
        for (int i = 0; i < destinationsCount; i++) {
            Configuration destination = config.subset("destinations.destination(" + i + ")");
            destinationURLs[i] = destination.getString("[@url]");
            destinationRaws[i] = destination.getBoolean("[@raw]", false);
            log.info("destination " + i + " = " + destinationURLs[i] + ", raw=" + destinationRaws[i]);
        }

        final String captionPort = config.getString("captionPort[@number]");
        log.info("captionPort = " + captionPort);

        if (captionPort != null) {
            catchCaptions(captionPort);
        }

        int providerCount = config.getList("providers.provider.headend").size();

        for (int i = 0; i < providerCount; i++) {
            Configuration provider = config.subset("providers.provider(" + i + ")");
            headend = provider.getString("headend");
            lineupDevice = provider.getString("lineupDevice");
            frequencyStandard = FrequencyStandard.valueOf(provider.getString("frequencyStandard"));
            log.info(identifyMe());

            if (headend == null || lineupDevice == null || frequencyStandard == null) {
                log.error("Invalid configuration in: " + identifyMe());
                throw new Error("Cannot continue");
            }

            openSources(provider);
        }
    } catch (ConfigurationException e) {
        log.error("Configuration error in file " + configFile, e);
        throw new Error("Cannot continue");
    } catch (Throwable e) {
        log.error("Unexpected Exception", e);
        throw new Error("Cannot continue");
    }
}