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

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

Introduction

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

Prototype

public String getString(String key) 

Source Link

Usage

From source file:de.uni_rostock.goodod.owl.normalization.BasicNormalizerFactory.java

protected void populateMap() {
    if (null == config) {
        return;//from   w  ww  . j a v a  2  s  . c  o  m
    }
    SubnodeConfiguration mapCfg = config.configurationAt("importMap");
    @SuppressWarnings("unchecked")
    Iterator<String> iter = mapCfg.getKeys();
    while (iter.hasNext()) {
        String key = iter.next();
        String oldImport = key.replace("..", ".");
        String newImport = mapCfg.getString(key);
        importMap.put(IRI.create(oldImport), IRI.create(newImport));
    }

}

From source file:eu.itesla_project.dymola.DymolaAdaptersMatParamsWriter.java

public DymolaAdaptersMatParamsWriter(HierarchicalINIConfiguration configuration) {
    if (configuration == null) {
        throw new RuntimeException("null config");
    }/*from w  w  w. j  av a 2 s  . co m*/
    this.configuration = configuration;
    //this below will simply log parameters ..
    for (String section : configuration.getSections()) {
        SubnodeConfiguration node = configuration.getSection(section);
        List<String> paramsSummary = StreamSupport
                .stream(Spliterators.spliteratorUnknownSize(node.getKeys(), Spliterator.ORDERED), false)
                .map(p -> p + "=" + node.getString(p)).collect(Collectors.<String>toList());
        LOGGER.info("index {}: {}", section, paramsSummary);
    }
}

From source file:ee.ria.xroad.common.SystemPropertiesLoader.java

private void loadSection(String sectionName, SubnodeConfiguration sec) {
    sec.getKeys().forEachRemaining(key -> setProperty(prefix + sectionName + "." + key, sec.getString(key)));
}

From source file:com.yfiton.notifiers.slack.SlackNotifier.java

@Override
protected void notify(Parameters parameters) throws NotificationException {
    SubnodeConfiguration config = retrieveTeamInformation();

    if (config == null) {
        throw new NotificationException("Invalid configuration");
    }/*w  w w.j  a  va2  s  . co  m*/

    SlackWebApiClient slackClient = SlackClientFactory.createWebApiClient(config.getString("accessToken"));

    ChatPostMessageMethod chatPostMessageMethod = new ChatPostMessageMethod(channel, message);
    chatPostMessageMethod.setAs_user(true);

    slackClient.postMessage(chatPostMessageMethod);

    log.info("https://" + config.getString("teamName") + ".slack.com/messages/" + channel + "/");
}

From source file:de.uni_rostock.goodod.owl.comparison.TripleBasedEntitySimComparator.java

public TripleBasedEntitySimComparator(OntologyPair p, boolean includeImports) throws Throwable {
    super(p, includeImports);
    SubnodeConfiguration conf = Configuration.getConfiguration()
            .configurationFromDomainForClassWithShorthandSuffix("measures", this.getClass(), "Comparator");

    String aggrScheme = "MaxCoupling";
    if (null != conf) {
        aggrScheme = conf.getString("aggregation");
    }//  w  w w.  ja  va  2 s . c  o m
    if (aggrScheme.equals("AverageLinkage")) {
        aggregation = AggregationScheme.AVERAGE_LINKAGE;
    } else if (aggrScheme.equals("Hausdorff")) {
        aggregation = AggregationScheme.HAUSDORFF;
    } else {
        //MaxCoupling is the default;
        aggregation = AggregationScheme.MAX_COUPLING;
        if (false == aggrScheme.equals("MaxCoupling")) {
            logger.warn("Unkown aggregation scheme '" + aggrScheme + "', using MaxCoupling.");
        }
    }
    // Get a serialization of the OWLAPI representation:
    ByteArrayOutputStream sourceA = outputStreamForOntology(pair.getOntologyA());
    ByteArrayOutputStream sourceB = outputStreamForOntology(pair.getOntologyB());

    // Also record their base URIs
    String uriA = pair.getOntologyA().getOntologyID().getOntologyIRI().toString();
    String uriB = pair.getOntologyB().getOntologyID().getOntologyIRI().toString();

    // Place them in a new input stream for JENA
    ByteArrayInputStream destinationA = new ByteArrayInputStream(sourceA.toByteArray());
    ByteArrayInputStream destinationB = new ByteArrayInputStream(sourceB.toByteArray());

    // Indicate to the JVM that it can collect the output streams, just in
    // case it needs to GC while generating the JENA model.
    sourceA = null;
    sourceB = null;

    // Create two OWL OntModels for the JENA representation of our ontologies:
    OntModel jenaA = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, null);
    OntModel jenaB = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, null);

    // Deserialize the ontologies from the buffer:
    jenaA.read(destinationA, uriA);
    jenaB.read(destinationB, uriB);

    // Throw away the input streams:
    destinationA = null;
    destinationB = null;

    // place the new models in our ivars. (Note: They're HeavyLoadedOntology<OntModel> now)
    ontologyA = jenaOntoWrapFactory.newOntology(jenaA);
    ontologyB = jenaOntoWrapFactory.newOntology(jenaB);
}

From source file:iddb.web.security.SecurityConfig.java

private SecurityConfig() {
    try {//w  w  w  . j av a2  s . co m
        HierarchicalINIConfiguration configFile = new HierarchicalINIConfiguration(
                this.getClass().getClassLoader().getResource("security.properties"));
        for (Object section : configFile.getSections()) {
            SubnodeConfiguration node = configFile.getSection((String) section);
            Map<String, String> map = new LinkedHashMap<String, String>();
            for (@SuppressWarnings("unchecked")
            Iterator<Object> it = node.getKeys(); it.hasNext();) {
                String key = it.next().toString();
                if (log.isTraceEnabled()) {
                    log.trace("Loading '{}' with value '{}' on section '{}'",
                            new String[] { key, node.getString(key), section.toString() });
                }
                map.put(key, node.getString(key));
            }
            config.put(section.toString(), map);
        }
    } catch (ConfigurationException e) {
        log.error(e.getMessage());
    }
}

From source file:com.bist.elasticsearch.jetty.security.AuthorizationConfigurationLoader.java

protected void loadIndiceAuthZ(QueryConstraints queryConstraints, String section,
        SubnodeConfiguration subnodeConfiguration) {
    Iterator<String> iterator = subnodeConfiguration.getKeys();
    while (iterator.hasNext()) {
        String key = iterator.next();
        String regex;//from w ww  .j a v a 2s. c  o m
        if (section.startsWith("_")) // special like _all _plugin etc
            regex = "^" + section + "$";
        else
            regex = "^" + section + "-\\d{4}\\.\\d{2}\\.\\d{2}$";
        if (key.equals("users")) {
            for (String userName : subnodeConfiguration.getString(key).split(",")) {
                queryConstraints.addUserIndiceQuery(userName, regex);

            }
        } else {
            String groupName = subnodeConfiguration.getString(key);
            queryConstraints.addGroupIndiceQuery(groupName, regex);
        }
    }
}

From source file:edu.stolaf.cs.wmrserver.TransformProcessor.java

private String wrap(SubnodeConfiguration languageConf, String transformTypeString, String transformSource)
        throws IOException {
    // Get any wrapping code appropriate for the specified language,
    // including the shebang

    StrBuilder prefix = new StrBuilder();
    StrBuilder suffix = new StrBuilder();

    // Include the shebang???
    String interp = languageConf.getString("interpreter");
    if (interp != null && !interp.isEmpty())
        prefix.append("#!" + languageConf.getString("interpreter") + "\n");

    // Get the file extension appropriate for the language
    String scriptExtension = languageConf.getString("extension", "");
    if (!scriptExtension.isEmpty())
        scriptExtension = "." + scriptExtension;

    // Include the wrapper libraries, which potentially handle I/O, etc.
    File libDir = getLibraryDirectory(languageConf);
    if (libDir != null) {
        if (!libDir.isDirectory() || !libDir.canRead())
            throw new IOException("Library directory for " + transformTypeString + " did not exist "
                    + "or was not readable: " + libDir.toString());

        Reader libReader = null;//from w  w  w .j av  a2  s  .  c  om
        try {
            File libFile = new File(libDir, transformTypeString + "-prefix" + scriptExtension);
            if (libFile.isFile() && libFile.canRead()) {
                libReader = new FileReader(libFile);
                IOUtils.copy(libReader, prefix.asWriter());
                IOUtils.closeQuietly(libReader);
            }

            libFile = new File(libDir, transformTypeString + "-suffix" + scriptExtension);
            if (libFile.isFile() && libFile.canRead()) {
                libReader = new FileReader(libFile);
                IOUtils.copy(libReader, suffix.asWriter());
            }
        } catch (IOException ex) {
            throw new IOException("Could not add the wrapper library to the " + transformTypeString
                    + " code due to an exception.", ex);
        } finally {
            IOUtils.closeQuietly(libReader);
        }
    }

    return prefix.toString() + "\n" + transformSource + "\n" + suffix.toString();
}

From source file:com.oltpbenchmark.multitenancy.schedule.Schedule.java

private HashMap<Integer, ScheduleEvents> parseEvents() {
    HashMap<Integer, ScheduleEvents> newMap = new HashMap<Integer, ScheduleEvents>();
    try {/*from   w  w w  .j a va 2s. c  o m*/
        // read config file
        XMLConfiguration xmlConfig = new XMLConfiguration(scenarioFile);
        xmlConfig.setExpressionEngine(new XPathExpressionEngine());

        // iterate over all defined events and parse configuration
        int size = xmlConfig
                .configurationsAt(ScenarioConfigElements.EVENTS_KEY + "/" + ScenarioConfigElements.EVENT_KEY)
                .size();
        for (int i = 1; i < size + 1; i++) {
            SubnodeConfiguration event = xmlConfig.configurationAt(
                    ScenarioConfigElements.EVENTS_KEY + "/" + ScenarioConfigElements.EVENT_KEY + "[" + i + "]");
            // create settings for a benchmark run
            BenchmarkSettings benchSettings = new BenchmarkSettings(event);

            // get schedule times
            long eventStart = 0, eventStop = -1, eventRepeat = -1;
            if (event.containsKey(ScenarioConfigElements.EVENT_START_KEY))
                eventStart = parseTimeFormat(event.getString(ScenarioConfigElements.EVENT_START_KEY));
            else
                LOG.debug("There is no start time defined for an event, it will be started immediately!");
            if (event.containsKey(ScenarioConfigElements.EVENT_REPEAT_KEY))
                eventRepeat = parseTimeFormat(event.getString(ScenarioConfigElements.EVENT_REPEAT_KEY));
            if (event.containsKey(ScenarioConfigElements.EVENT_STOP_KEY))
                eventStop = parseTimeFormat(event.getString(ScenarioConfigElements.EVENT_STOP_KEY));

            // validate schedule times
            if (eventRepeat > -1 && eventStop == -1 && duration == -1) {
                LOG.fatal(
                        "Infinitely event execution was defined: Repeated event without repeating end and scenario end");
                System.exit(-1);
            }
            if (eventRepeat == 0) {
                LOG.fatal("An Event cannot be repeated simoultaneously (avoid infinite loop)!");
                System.exit(-1);
            }
            if (eventStart > eventStop && eventStop != -1) {
                LOG.fatal("Event cannot be stopped until starting it!");
                System.exit(-1);
            }

            // get tenant IDs
            int firstTenantID = 1, tenantsPerExecution = 1, tenantIdIncement = 1;
            if (event.containsKey(ScenarioConfigElements.FIRST_TENANT_ID_KEY))
                firstTenantID = (event.getInt(ScenarioConfigElements.FIRST_TENANT_ID_KEY));
            if (event.containsKey(ScenarioConfigElements.TENANTS_PER_EXECUTION_KEY))
                tenantsPerExecution = (event.getInt(ScenarioConfigElements.TENANTS_PER_EXECUTION_KEY));
            if (event.containsKey(ScenarioConfigElements.TENANT_ID_INCREMENT_KEY))
                tenantIdIncement = (event.getInt(ScenarioConfigElements.TENANT_ID_INCREMENT_KEY));

            // validate tenant IDs
            if (tenantsPerExecution < 0) {
                LOG.fatal("Value '" + tenantsPerExecution + "' for tenants per executions is not valid!");
                System.exit(-1);
            }

            // execution times and assign to tenants
            if (duration != -1 && duration < eventStop)
                eventStop = duration;
            int exec = 0;
            long execTime = eventStart;
            while ((execTime <= eventStop) || (eventStop == -1 && exec == 0)) {
                // iterate over all tenants in this execution
                for (int j = 0; j < tenantsPerExecution; j++) {
                    int currentTenantID = firstTenantID + (exec * tenantsPerExecution * tenantIdIncement)
                            + (j * tenantIdIncement);
                    if (!newMap.containsKey(currentTenantID)) {
                        ScheduleEvents tenEvents = new ScheduleEvents();
                        tenEvents.addEvent(execTime, benchSettings);
                        newMap.put(currentTenantID, tenEvents);
                        tenantList.add(currentTenantID);
                    } else
                        newMap.get(currentTenantID).addEvent(execTime, benchSettings);
                }
                if (eventRepeat == -1)
                    break;
                execTime += eventRepeat;
                exec++;
            }
        }
    } catch (ConfigurationException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return newMap;
}

From source file:edu.isi.wings.portal.classes.Config.java

@SuppressWarnings("rawtypes")
private ExeEngine getExeEngine(SubnodeConfiguration node) {
    String name = node.getString("name");
    String impl = node.getString("implementation");
    ExeEngine.Type type = ExeEngine.Type.valueOf(node.getString("type"));
    ExeEngine engine = new ExeEngine(name, impl, type);
    for (Iterator it = node.getKeys("properties"); it.hasNext();) {
        String key = (String) it.next();
        String value = node.getString(key);
        engine.addProperty(key.replace("properties.", ""), value);
    }/*from   ww w  . j  av a2s. com*/
    return engine;
}