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:de.nec.nle.siafu.model.Overlay.java

/**
 * Get an instance of Overlay which fits the particular overlay defined in
 * the simulation data. The values come from the InputStream obtained from
 * simulation data, and the name, type and type details are obtained from
 * the simulation configuration.//w w w  . j a  va 2  s .c om
 * 
 * @param name the overlay name
 * @param is the InputStream that represents the values
 * @param simulationConfig the configuration details for the overlay
 * @return an instance of Overlay whose getValue() method returns what you
 *         would expect from the overlay subtype
 */
public static Overlay getOverlay(final String name, final InputStream is,
        final Configuration simulationConfig) {
    String type = simulationConfig.getString("overlays." + name + "[@type]");
    if (type == null) {
        throw new RuntimeException("Configuration missing for overlay " + name);
    }
    if (type.equals("binary")) {
        return new BinaryOverlay(name, is, simulationConfig);
    } else if (type.equals("discrete")) {
        return new DiscreteOverlay(name, is, simulationConfig);
    } else if (type.equals("real")) {
        return new RealOverlay(name, is);
    } else {
        throw new RuntimeException("Unknown overlay type for " + name);
    }
}

From source file:com.feedzai.fos.common.validation.ValidationUtils.java

/**
 * Gets a <code>String</code> from the given configuration.
 *
 * @param configuration the configuration where the parameter lies
 * @param parameterName the name of the parameter
 * @return the <code>String</code>
 * @throws IllegalArgumentException if the parameter is null or blank
 *//*w w  w .  jav a 2  s.c  o  m*/
@NotBlank
public static String getStringNotBlank(Configuration configuration, @NotBlank String parameterName) {
    return Validate.notBlank(configuration.getString(parameterName), NOT_BLANK, parameterName);
}

From source file:edu.cornell.med.icb.R.RConfigurationUtils.java

/**
 * Gets the configuration for the RServe processes.
 * @return A url that for the RConnectionPool configuration file.
 *//*from   www. j a  v  a  2 s.c  o  m*/
static URL getConfigurationURL() {
    URL poolConfigURL; // if the user defined a configuration, use it
    final ResourceFinder resourceFinder = new ResourceFinder(".", "config");
    final Configuration systemConfiguration = new SystemConfiguration();
    if (systemConfiguration.containsKey(DEFAULT_CONFIGURATION_KEY)) {
        final String poolConfig = systemConfiguration.getString(DEFAULT_CONFIGURATION_KEY);
        try {
            // First see if we have a URL from the system configuration
            poolConfigURL = new URL(poolConfig);
        } catch (MalformedURLException e) {
            // resource is not a URL, attempt to get the resource from the class path
            poolConfigURL = resourceFinder.findResource(poolConfig);
        }
    } else {
        poolConfigURL = resourceFinder.findResource(DEFAULT_XML_CONFIGURATION_FILE);
    }
    return poolConfigURL;
}

From source file:com.github.anba.test262.BaseTest262.java

protected static List<Object[]> collectTestCases(Configuration configuration) throws IOException {
    // base directory to search for test javascript files
    String testpath = configuration.getString("");

    // set of test-case id to exclude from testing
    List<?> values = configuration.getList("exclude", emptyList());

    // if 'true' only the excluded test cases are used, otherwise they're
    // omitted/*w w  w  . j  ava 2 s.c o  m*/
    boolean only_excluded = configuration.getBoolean("only_excluded", false);

    // optional exclusion pattern
    String excludeRE = configuration.getString("exclude_re", "");
    Pattern exclude = Pattern.compile(excludeRE);

    return Resources.collectTestCases(testpath, values, only_excluded, exclude);
}

From source file:com.github.anba.test262.BaseTest262.java

protected static LazyInit<Configuration> newConfiguration() {
    return new LazyInit<Configuration>() {
        @Override/*from   ww w.j av a2 s  .co  m*/
        protected Configuration initialize() {
            Configuration config = loadConfiguration("resource:test262.properties");
            // test load for required property "test262"
            config.getString("test262");
            return config;
        }
    };
}

From source file:com.cisco.oss.foundation.http.server.TraceWrapper.java

public static List<String> getContentTypes(String serviceName) {
    List<String> types = new ArrayList<String>(5);
    String baseKey = serviceName + ".http.traceFilter.textContentTypes";
    Configuration subset = ConfigurationFactory.getConfiguration().subset(baseKey);
    Iterator<String> keys = subset.getKeys();
    while (keys.hasNext()) {
        String key = keys.next();
        types.add(subset.getString(key));
    }//from   w  w  w .jav a 2s.  c om
    return types;
}

From source file:com.gs.obevo.db.impl.core.compare.data.DbDataComparisonConfigFactory.java

public static DbDataComparisonConfig createFromProperties(final Configuration config) {
    Properties propsView = ConfigurationConverter.getProperties(config); // config.getString() automatically parses
    // for commas...would like to avoid this
    DbDataComparisonConfig compConfig = new DbDataComparisonConfig();
    compConfig.setInputTables(Lists.mutable.with(propsView.getProperty("tables.include").split(",")));
    compConfig// w  w w.  java2s . c o  m
            .setExcludedTables(Lists.mutable.with(propsView.getProperty("tables.exclude").split(",")).toSet());
    String comparisonsStr = propsView.getProperty("comparisons");

    MutableList<Pair<String, String>> compCmdPairs = Lists.mutable.empty();
    MutableSet<String> dsNames = UnifiedSet.newSet();
    for (String compPairStr : comparisonsStr.split(";")) {
        String[] pairParts = compPairStr.split(",");
        compCmdPairs.add(Tuples.pair(pairParts[0], pairParts[1]));

        // note - if I knew where the Pair.TO_ONE TO_TWO selectors were, I'd use those
        dsNames.add(pairParts[0]);
        dsNames.add(pairParts[1]);
    }

    compConfig.setComparisonCommandNamePairs(compCmdPairs);

    MutableList<DbDataSource> dbDataSources = dsNames.toList().collect(new Function<String, DbDataSource>() {
        @Override
        public DbDataSource valueOf(String dsName) {
            Configuration dsConfig = config.subset(dsName);

            DbDataSource dbDataSource = new DbDataSource();
            dbDataSource.setName(dsName);
            dbDataSource.setUrl(dsConfig.getString("url"));
            dbDataSource.setSchema(dsConfig.getString("schema"));
            dbDataSource.setUsername(dsConfig.getString("username"));
            dbDataSource.setPassword(dsConfig.getString("password"));
            dbDataSource.setDriverClassName(dsConfig.getString("driverClass"));

            return dbDataSource;
        }
    });
    compConfig.setDbDataSources(dbDataSources);
    return compConfig;
}

From source file:com.orientechnologies.orient.server.distributed.OrientdbEdgeTest.java

private static void verifyDatabaseExists(Configuration conf) {
    final String url = conf.getString("storage.url");

    if (!url.startsWith("remote:"))
        return;// w  w  w .j  a v  a2  s .  c  o  m

    try {
        final OServerAdmin admin = new OServerAdmin(url);

        admin.connect(conf.getString("storage.user"), conf.getString("storage.password"));

        if (!admin.existsDatabase()) {
            System.err.println("creating database " + url);
            admin.createDatabase("graph", "plocal");
        }

        try {
            OrientGraph t = new OrientGraph(url, conf.getString("storage.user"),
                    conf.getString("storage.password"));
            t.command(new OCommandSQL("alter database custom useLightweightEdges=false")).execute();
            t.commit();
            t.shutdown();
        } catch (Throwable ignored) {
            // blank
        }

        try {
            OrientGraph t = new OrientGraph(url, conf.getString("storage.user"),
                    conf.getString("storage.password"));
            t.command(new OCommandSQL("ALTER CLASS V CLUSTERSELECTION balanced")).execute();
            t.commit();
            t.shutdown();
        } catch (Throwable ignored) {
            // blank
        }

        try {
            OrientGraph t = new OrientGraph(url, conf.getString("storage.user"),
                    conf.getString("storage.password"));
            t.command(new OCommandSQL("ALTER CLASS E CLUSTERSELECTION balanced")).execute();
            t.commit();
            t.shutdown();
        } catch (Throwable ignored) {
            // blank
        }

        admin.close();
    } catch (IOException ex1) {
        throw new RuntimeException(ex1);
    }
}

From source file:com.manydesigns.elements.blobs.BlobManager.java

public static BlobManager createDefaultBlobManager() {
    Configuration elementsConfiguration = ElementsProperties.getConfiguration();
    String blobsDirPath = elementsConfiguration.getString(ElementsProperties.BLOBS_DIR);
    File blobsDir;//from w  w  w .ja v a2 s. c om
    if (blobsDirPath == null) {
        blobsDir = null;
    } else {
        blobsDir = new File(blobsDirPath);
    }
    String metaFilenamePattern = elementsConfiguration
            .getString(ElementsProperties.BLOBS_META_FILENAME_PATTERN);
    String dataFilenamePattern = elementsConfiguration
            .getString(ElementsProperties.BLOBS_DATA_FILENAME_PATTERN);
    return new BlobManager(blobsDir, metaFilenamePattern, dataFilenamePattern);
}

From source file:com.w20e.socrates.servlet.ValidatorHelper.java

/**
 * Determine UI properties for given list of renderables.
 * // www.ja v a  2 s .c o m
 * @param items
 *            List of items to use.
 * @throws Exception
 *             in case of Velocity errors, or output stream errors.
 */
public static void getRenderableProperties(final Collection<Renderable> items,
        final Map<String, Map<String, String>> props, final RunnerContext pContext) throws Exception {

    Locale locale = pContext.getLocale();

    Configuration cfg = pContext.getConfiguration();

    String base = cfg.getString("formatter.locale.prefix");

    UTF8ResourceBundle bundle = UTF8ResourceBundleImpl.getBundle(base, locale);

    Stack<Group> parents = new Stack<Group>();

    // Let's loop over renderable items.
    //
    for (Renderable rItem : items) {

        addItem(rItem, parents, props, pContext.getInstance(), pContext.getModel(), pContext.getRenderConfig(),
                bundle, locale);

    }
}