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.github.anba.es6draft.util.Resources.java

/**
 * Returns the test suite's base path.//from   w  w  w . java  2s.  co  m
 */
public static Path getTestSuitePath(Configuration configuration) {
    try {
        String testSuite = configuration.getString("");
        return Paths.get(testSuite).toAbsolutePath();
    } catch (InvalidPathException | NoSuchElementException e) {
        System.err.println(e.getMessage());
        return null;
    }
}

From source file:edu.kit.dama.mdm.tools.TransitionTypeHandlerFactory.java

/**
 * Factory a transition type handler for the provided transition type. The
 * factory will check in the according configuration section for the
 * configured handler. If no handler section exists, a
 * NullTransitionTypeHandler is returned.
 *
 * If a section for the transition type exists, the handler class is
 * obtained, checked and the handler is instantiated, configured and
 * returned. If the handler class is not set, a NullTransitionTypeHandler is
 * returned.. Otherwise, if a handler class is provided and any of these
 * previous steps fails, a ConfigurationException is thrown.
 *
 * @param pType The transition type for which the handler should be
 * returned./*from  w ww . j  ava 2  s  .  co  m*/
 *
 * @return The transition type handler instance.
 *
 * @throws ConfigurationException if a handler section was found, but
 * instantiation or configuration of the handler has failed.
 */
public static AbstractTransitionTypeHandler factoryTransitionTypeHandler(TransitionType pType)
        throws ConfigurationException {
    LOGGER.debug("Trying to factory transition type handler for type '{}'", pType);
    Configuration subConfig = DataManagerSettings.getSingleton()
            .getSubConfiguration(DataManagerSettings.METADATA_MANAGEMENT_CONFIG_ROOT);
    if (subConfig == null) {
        //old datamanager.xml, no metadataManagement config node
        LOGGER.info(
                "No section '{}' found in datamanager.xml configuration file. Probably, transition type handlers have not been configured, yet. Returning NullTransitionTypeHandler.",
                DataManagerSettings.METADATA_MANAGEMENT_CONFIG_ROOT);
        return new NullTransitionTypeHandler();
    }

    Configuration subset = subConfig.subset("transitionTypes." + pType.toString());
    if (subset == null) {
        //no configuration found for te transition type...type not supported.
        LOGGER.info(
                "No sub-section for handler type '{}' found in datamanager.xml configuration file. Probably, the transition type handler has not been configured, yet. Returning NullTransitionTypeHandler.",
                pType);
        return new NullTransitionTypeHandler();
    }

    try {
        String handlerClass = subset.getString("handlerClass");
        if (handlerClass == null) {
            LOGGER.info(
                    "No handler class defined for type '" + pType + "'. Returning NullTransitionTypeHandler.");
            return new NullTransitionTypeHandler();
        }
        Class clazz = Class.forName(handlerClass);
        Object instance = clazz.getConstructor().newInstance();
        ((IConfigurableAdapter) instance).configure(subset);
        return (AbstractTransitionTypeHandler) instance;
    } catch (ClassNotFoundException cnfe) {
        throw new ConfigurationException("Failed to locate transition handler class for type '" + pType + "'",
                cnfe);
    } catch (InstantiationException | IllegalAccessException | InvocationTargetException ie) {
        throw new ConfigurationException(
                "Failed to instantiate and configure transition handler for type '" + pType + "'", ie);
    } catch (NoSuchMethodException nsme) {
        throw new ConfigurationException(
                "Missing default constructor for transition handler class for type '" + pType + "'", nsme);
    } catch (ClassCastException cce) {
        throw new ConfigurationException(
                "Transition handler instance for type '" + pType + "' does not implement IConfigurableAdapter.",
                cce);
    }
}

From source file:gaffer.gafferpop.GafferPopGraph.java

private static Graph createGraph(final Configuration configuration) {
    final Path storeProps = Paths.get(configuration.getString(STORE_PROPERTIES));
    final Schema schema = new Schema();
    for (String schemaPath : configuration.getStringArray(SCHEMAS)) {
        schema.merge(Schema.fromJson(Paths.get(schemaPath)));
    }// w w  w . j  a  v a  2  s .c  o  m

    return new Graph.Builder().storeProperties(storeProps).addSchema(schema).build();
}

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

protected static OrientGraphFactory getGraphFactory() throws Exception {
    Configuration conf = new BaseConfiguration();

    conf.setProperty("storage.url", "remote:localhost/test");
    conf.setProperty("storage.pool-min", "1");
    conf.setProperty("storage.pool-max", "10");
    conf.setProperty("storage.user", "admin");
    conf.setProperty("storage.password", "admin");

    OGlobalConfiguration.CLIENT_CONNECT_POOL_WAIT_TIMEOUT.setValue(15000);

    verifyDatabaseExists(conf);/*from   w w w .j a  v a2  s  .com*/

    return new OrientGraphFactory(conf.getString("storage.url"), conf.getString("storage.user"),
            conf.getString("storage.password")).setupPool(conf.getInt("storage.pool-min"),
                    conf.getInt("storage.pool-max"));
}

From source file:com.tamnd.core.util.ZConfig.java

private static void ConfigToMap(ConcurrentMap<String, String> map, Configuration config, boolean overwrDup) {
    if (config == null) {
        return;//w ww .  jav a2  s . c  o  m
    }
    Iterator<String> keyIt = config.getKeys();
    while (keyIt.hasNext()) {
        String key = keyIt.next();
        if (key == null || key.isEmpty()) {
            continue;
        }
        try {
            String value = config.getString(key);
            if (value == null) {
                continue;
            }
            if (overwrDup) {
                String oldVal = map.put(key, value);
                if (oldVal != null) {
                    System.out.println("Configuration key \"" + key + "\" has old value \"" + oldVal
                            + "\" has been overwritten by new value \"" + value + "\"");
                }
            } else {
                String oldVal = map.putIfAbsent(key, value);
                if (oldVal != null) {
                    System.out.println("Configuration key \"" + key + "\" has value \"" + oldVal
                            + "\" NOT be overwrited by new value \"" + value + "\"");
                }
            }
        } catch (Exception ex) {
            System.err.println(ex);
        }
    }
}

From source file:co.turnus.analysis.profiler.orcc.dynamic.OrccDynamicProfilerOptions.java

private static void setOutputPath(Configuration conf, String customPath) {
    // store the root path for the output.
    File outPath = null;//from   w  ww  . j ava  2s  .c  o  m
    boolean traceProject = conf.getBoolean(CREATE_TRACE_PROJECT);
    if (customPath != null && !customPath.isEmpty()) {
        outPath = new File(customPath);
    } else {
        String project = conf.getString(ORCC_PROJECT);
        IProject pojo = EcoreHelper.getProject(project);
        outPath = pojo.getRawLocation().makeAbsolute().toFile();
        outPath = new File(outPath, "turnus");

        if (traceProject) {
            outPath = new File(outPath, "traces");
        } else {
            outPath = new File(outPath, "profiling");
        }
    }

    if (traceProject) {
        String trace = conf.getString(TRACE_PROJECT_NAME);

        // make path os friendly...
        trace = trace.replace(" ", "_");

        File tmpPath = new File(outPath, trace);
        if (tmpPath.exists()) {
            tmpPath = TurnusUtils.findNextAvailable(outPath, trace, "_v", 2);
        }
        outPath = tmpPath;
    }

    conf.setProperty(OUTPUT_PATH, outPath.getAbsolutePath());

}

From source file:com.cloudera.whirr.cm.CmServerClusterInstance.java

private static String getVersionSubstring(Configuration configuration, String property, String prefix)
        throws IOException {
    String version = configuration.getString(property);
    if (version == null || !version.startsWith(prefix)) {
        return null;
    } else {/*from  w ww.  ja v a2s . co m*/
        return version.substring(prefix.length());
    }
}

From source file:net.sf.webphotos.tools.Thumbnail.java

/**
 * Busca no arquivo de configurao, classe
 * {@link net.sf.webphotos.util.Config Config}, os tamnahos dos 4 thumbs e
 * seta esses valores nas variveis desta classe. Testa se o usurio setou
 * valores de marca d'gua e texto para o thumb4, caso afirmativo, busca os
 * valores necessrios no arquivo de configurao.
 *//*from w ww  .j a v  a2s.c  om*/
private static void inicializar() {

    // le as configuraes do usurio
    Configuration c = Util.getConfig();

    // tamanhos de thumbnails
    t1 = c.getInt("thumbnail1");
    t2 = c.getInt("thumbnail2");
    t3 = c.getInt("thumbnail3");
    t4 = c.getInt("thumbnail4");

    // usuario setou marca d'agua para thumbnail 4 ?
    // TODO: melhorar teste para captao destes parametros
    try {
        marcadagua = c.getString("marcadagua");
        mdPosicao = c.getInt("marcadagua.posicao");
        mdMargem = c.getInt("marcadagua.margem");
        mdTransparencia = c.getInt("marcadagua.transparencia");
    } catch (Exception ex) {
        ex.printStackTrace(Util.err);
    }

    // usurio setou texto para o thumbnail 4 ?
    try {
        texto = c.getString("texto");
        txPosicao = c.getInt("texto.posicao");
        txMargem = c.getInt("texto.margem");
        txTamanho = c.getInt("texto.tamanho");
        txEstilo = c.getInt("texto.estilo");
        txFamilia = c.getString("texto.familia");

        String[] aux = c.getStringArray("texto.corFrente");
        txCorFrente = new Color(Integer.parseInt(aux[0]), Integer.parseInt(aux[1]), Integer.parseInt(aux[2]));
        aux = c.getStringArray("texto.corFundo");
        txCorFundo = new Color(Integer.parseInt(aux[0]), Integer.parseInt(aux[1]), Integer.parseInt(aux[2]));
    } catch (Exception ex) {
        ex.printStackTrace(Util.err);
    }

}

From source file:com.qmetry.qaf.automation.testng.report.ReporterUtil.java

public static synchronized void updateOverview(ITestContext context, ITestResult result) {
    try {//from ww w . j a  va 2 s .  c  om
        String file = ApplicationProperties.JSON_REPORT_DIR.getStringVal() + "/" + getTestName(context)
                + "/overview.json";
        TestOverview overview = getJsonObjectFromFile(file, TestOverview.class);
        if (null == result) {
            Map<String, Object> runPrams = new HashMap<String, Object>(
                    context.getCurrentXmlTest().getAllParameters());
            Configuration env = getBundle().subset("env");
            Iterator<?> iter = env.getKeys();
            while (iter.hasNext()) {
                String key = (String) iter.next();
                runPrams.put(key, env.getString(key));
            }
            Map<String, Object> envInfo = new HashMap<String, Object>();
            envInfo.put("isfw-build-info", getBundle().getObject("isfw.build.info"));
            envInfo.put("run-parameters", runPrams);
            envInfo.put("browser-desired-capabilities", getBundle().getObject("driver.desiredCapabilities"));
            envInfo.put("browser-actual-capabilities", getActualCapabilities());

            overview.setEnvInfo(envInfo);
            Map<String, Object> executionEnvInfo = new HashMap<String, Object>();
            executionEnvInfo.put("os.name", System.getProperty("os.name"));
            executionEnvInfo.put("os.version", System.getProperty("os.version"));

            executionEnvInfo.put("os.arch", System.getProperty("os.arch"));
            executionEnvInfo.put("java.version", System.getProperty("java.version"));
            executionEnvInfo.put("java.vendor", System.getProperty("java.vendor"));
            executionEnvInfo.put("java.arch", System.getProperty("sun.arch.data.model"));

            executionEnvInfo.put("user.name", System.getProperty("user.name"));
            try {
                executionEnvInfo.put("host", InetAddress.getLocalHost().getHostName());
            } catch (Exception e) {
                // This code added for MAC to fetch hostname
                String hostname = execHostName("hostname");
                executionEnvInfo.put("host", hostname);
            }

            envInfo.put("execution-env-info", executionEnvInfo);

        }

        int pass = getPassCnt(context);
        int fail = getFailCnt(context) + getFailWithPassPerCnt(context);
        int skip = getSkipCnt(context);
        int total = getTotal(context);

        overview.setTotal(total > (pass + fail + skip) ? total : pass + fail + skip);
        overview.setPass(pass);
        overview.setSkip(skip);
        overview.setFail(fail);
        if (null != result) {
            overview.getClasses().add(result.getTestClass().getName());
        }
        if ((overview.getStartTime() > 0)) {
            overview.setEndTime(System.currentTimeMillis());
        } else {
            overview.setStartTime(System.currentTimeMillis());
        }
        writeJsonObjectToFile(file, overview);
        updateMetaInfo(context.getSuite());
    } catch (Exception e) {
        logger.debug(e);
    }
}

From source file:dk.itst.oiosaml.sp.service.util.Utils.java

public static Map<String, SAMLHandler> getHandlers(Configuration config, ServletContext servletContext) {
    Map<String, SAMLHandler> handlers = new HashMap<String, SAMLHandler>();

    for (Iterator<?> i = config.getKeys(); i.hasNext();) {
        String key = (String) i.next();
        if (!key.startsWith("oiosaml-sp.protocol.endpoints."))
            continue;
        log.debug("Checking " + key);

        try {//from   w w w  .  j av a2 s.  co  m
            Class<?> c = Class.forName(config.getString(key));
            SAMLHandler instance;
            try {
                Constructor<?> constructor = c.getConstructor(Configuration.class);
                instance = (SAMLHandler) constructor.newInstance(config);
            } catch (NoSuchMethodException e) {
                try {
                    Constructor<?> constructor = c.getConstructor(ServletContext.class);
                    instance = (SAMLHandler) constructor.newInstance(servletContext);
                } catch (NoSuchMethodException ex) {
                    instance = (SAMLHandler) c.newInstance();
                }
            }

            //            log.info("instance:" + instance.toString()); // pdurbin
            handlers.put(key.substring(key.lastIndexOf('.') + 1), instance);

        } catch (Exception e) {
            log.error("Unable to instantiate " + key + ": " + config.getString(key), e);
            throw new RuntimeException(e);
        }

    }

    return handlers;
}