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

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

Introduction

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

Prototype

public String getString(String key) 

Source Link

Usage

From source file:com.sk89q.craftapi.auth.ConfigurationAuthentication.java

/**
 * Verify username and password pairs.//from   w w w. ja va 2 s.  c  om
 *
 * @param username
 * @param password
 * @return
 */
public boolean verifyCredentials(String username, String password) {
    List credentials = config.configurationsAt("credential");
    for (Object c : credentials) {
        HierarchicalConfiguration credential = (HierarchicalConfiguration) c;
        String user = credential.getString("username");
        String pass = credential.getString("password");
        if (user != null && pass != null && user.equals(username) && pass.equals(password)
                && implementsService(credential)) {
            return true;
        }
    }

    return false;
}

From source file:jsprit.core.algorithm.io.VehicleRoutingAlgorithms.java

private static SolutionAcceptor getAcceptor(HierarchicalConfiguration strategyConfig, VehicleRoutingProblem vrp,
        Set<PrioritizedVRAListener> algorithmListeners, TypedMap typedMap, int solutionMemory) {
    String acceptorName = strategyConfig.getString("acceptor[@name]");
    if (acceptorName == null)
        throw new IllegalStateException("no solution acceptor is defined");
    String acceptorId = strategyConfig.getString("acceptor[@id]");
    if (acceptorId == null)
        acceptorId = "noId";
    AcceptorKey acceptorKey = new AcceptorKey(makeKey(acceptorName, acceptorId));
    SolutionAcceptor definedAcceptor = typedMap.get(acceptorKey);
    if (definedAcceptor != null)
        return definedAcceptor;
    if (acceptorName.equals("acceptNewRemoveWorst")) {
        GreedyAcceptance acceptor = new GreedyAcceptance(solutionMemory);
        typedMap.put(acceptorKey, acceptor);
        return acceptor;
    }//  www. ja  v  a 2  s. c om
    if (acceptorName.equals("acceptNewRemoveFirst")) {
        AcceptNewRemoveFirst acceptor = new AcceptNewRemoveFirst(solutionMemory);
        typedMap.put(acceptorKey, acceptor);
        return acceptor;
    }
    if (acceptorName.equals("greedyAcceptance")) {
        GreedyAcceptance acceptor = new GreedyAcceptance(solutionMemory);
        typedMap.put(acceptorKey, acceptor);
        return acceptor;
    }
    if (acceptorName.equals("greedyAcceptance_minVehFirst")) {
        GreedyAcceptance_minVehFirst acceptor = new GreedyAcceptance_minVehFirst(solutionMemory);
        typedMap.put(acceptorKey, acceptor);
        return acceptor;
    }
    if (acceptorName.equals("schrimpfAcceptance")) {
        String nuWarmupIterations = strategyConfig.getString("acceptor.warmup");
        double alpha = strategyConfig.getDouble("acceptor.alpha");
        SchrimpfAcceptance schrimpf = new SchrimpfAcceptance(solutionMemory, alpha);
        if (nuWarmupIterations != null) {
            SchrimpfInitialThresholdGenerator iniThresholdGenerator = new SchrimpfInitialThresholdGenerator(
                    schrimpf, Integer.parseInt(nuWarmupIterations));
            algorithmListeners.add(new PrioritizedVRAListener(Priority.LOW, iniThresholdGenerator));
        } else {
            double threshold = strategyConfig.getDouble("acceptor.initialThreshold");
            schrimpf.setInitialThreshold(threshold);
        }
        algorithmListeners.add(new PrioritizedVRAListener(Priority.LOW, schrimpf));
        typedMap.put(acceptorKey, schrimpf);
        return schrimpf;
    }
    if (acceptorName.equals("experimentalSchrimpfAcceptance")) {
        int iterOfSchrimpf = strategyConfig.getInt("acceptor.warmup");
        double alpha = strategyConfig.getDouble("acceptor.alpha");
        ExperimentalSchrimpfAcceptance schrimpf = new ExperimentalSchrimpfAcceptance(solutionMemory, alpha,
                iterOfSchrimpf);
        algorithmListeners.add(new PrioritizedVRAListener(Priority.LOW, schrimpf));
        typedMap.put(acceptorKey, schrimpf);
        return schrimpf;
    } else {
        throw new IllegalStateException("solution acceptor " + acceptorName + " is not known");
    }
}

From source file:com.norconex.importer.handler.tagger.impl.CharacterCaseTagger.java

@Override
protected void loadHandlerFromXML(XMLConfiguration xml) {
    List<HierarchicalConfiguration> nodes = xml.configurationsAt("characterCase");
    fieldCases.clear();//  ww w.ja  v  a2  s.  co m
    for (HierarchicalConfiguration node : nodes) {
        addFieldCase(node.getString("[@fieldName]"), node.getString("[@type]"));
    }
}

From source file:com.sk89q.craftapi.auth.ConfigurationAuthentication.java

/**
 * Verify username and password pairs using a HMAC digest.
 *
 * @param username/*from w w w .ja va2  s .c o  m*/
 * @param password
 * @return
 */
public boolean verifyCredentials(Mac mac, String username, byte[] digest) {
    List credentials = config.configurationsAt("credential");
    for (Object c : credentials) {
        HierarchicalConfiguration credential = (HierarchicalConfiguration) c;
        String user = credential.getString("username");
        String pass = credential.getString("password");
        if (user != null && pass != null && user.equals(username) && implementsService(credential)) {
            byte[] testDigest = mac.doFinal(pass.getBytes());

            if (Arrays.equals(testDigest, digest)) {
                return true;
            }
        }
    }

    return false;
}

From source file:com.vangent.hieos.empi.config.MatchFieldConfig.java

/**
 * /*from  www.  j  av  a 2  s .c  om*/
 * @param hc
 * @param empiConfig
 * @throws EMPIException
 */
public void load(HierarchicalConfiguration hc, EMPIConfig empiConfig) throws EMPIException {
    this.name = hc.getString(NAME);
    //this.enabledDuringSubjectAdd = hc.getBoolean(ENABLED_DURING_SUBJECT_ADD, true);
    this.acceptThreshold = hc.getDouble(ACCEPT_THRESHOLD);
    this.rejectThreshold = hc.getDouble(REJECT_THRESHOLD);
    this.weight = hc.getDouble(WEIGHT);

    // Link to distance function configuration.
    HierarchicalConfiguration hcDistanceFunction = hc.configurationAt(DISTANCE_FUNCTION);
    String distanceFunctionName = hcDistanceFunction.getString(DISTANCE_FUNCTION_NAME);
    this.distanceFunctionConfig = this.getDistanceFunctionConfig(empiConfig, hcDistanceFunction,
            distanceFunctionName);

    // Link to field configuration.
    this.fieldConfig = empiConfig.getFieldConfig(this.name);
}

From source file:com.intuit.tank.vm.settings.MailMessageConfig.java

/**
 * {@inheritDoc}//from ww w . ja  va 2s.co  m
 */
@Override
protected void initConfig(XMLConfiguration configuration) {
    messages.clear();
    if (config != null) {
        String style = getStyle();
        @SuppressWarnings("unchecked")
        List<HierarchicalConfiguration> msgConfigs = config.configurationsAt(KEY_MESSAGE_NODE);
        for (HierarchicalConfiguration msgConfig : msgConfigs) {
            String event = msgConfig.getString(KEY_EVENT);
            String subject = msgConfig.getString(KEY_SUBJECT);
            String body = msgConfig.getString(KEY_BODY);
            if (!StringUtils.isEmpty(event) && !StringUtils.isEmpty(subject) && !StringUtils.isEmpty(body)) {
                messages.put(event, new MailMessage(body, subject, style));
            }
        }
    }
}

From source file:com.norconex.importer.handler.tagger.impl.ConstantTagger.java

@Override
protected void loadHandlerFromXML(XMLConfiguration xml) {
    List<HierarchicalConfiguration> nodes = xml.configurationsAt("constant");
    for (HierarchicalConfiguration node : nodes) {
        String name = node.getString("[@name]");
        String value = node.getString("");
        addConstant(name, value);//from   w  w w.  j  ava2  s. c  om
    }
}

From source file:com.norconex.importer.handler.transformer.impl.ReplaceTransformer.java

@Override
protected void loadHandlerFromXML(XMLConfiguration xml) throws IOException {
    setCaseSensitive(xml.getBoolean("[@caseSensitive]", false));

    List<HierarchicalConfiguration> nodes = xml.configurationsAt("replace");
    for (HierarchicalConfiguration node : nodes) {
        replacements.put(node.getString("fromValue"), node.getString("toValue"));
    }//www .  j a  v a  2  s.  co m
}

From source file:com.sm.store.cluster.BuildStoreConfig.java

private StoreConfig buildStoreConfig(HierarchicalConfiguration configuration) {
    StringBuilder sb = new StringBuilder();
    String name = configuration.getString("name");
    if (name == null)
        sb.append("store name is not defined ");
    String path = configuration.getString("path", "data");
    String filename = configuration.getString("filename", name);
    boolean delay = configuration.getBoolean("delayWrite", true);
    int mode = configuration.getInt("mode", 0);
    int delayThread = configuration.getInt("delayThread", 2);
    String serializeClass = configuration.getString("serializer", "com.sm.localstore.impl.HessianSerializer");
    String blockSizeClass = configuration.getString("blockSize");
    BlockSize blockSize = null;/* w  w w.j ava2  s .c o m*/
    if (blockSizeClass != null) {
        try {
            blockSize = (BlockSize) Class.forName(blockSizeClass).newInstance();
        } catch (Exception ex) {
            sb.append(("unable to load " + blockSizeClass + " " + ex.getMessage()));
        }
    }
    boolean useCache = configuration.getBoolean("useCache", false);
    long maxCache = configuration.getLong("maxCache", 1000 * 1000 * 1000L);
    String logPath = configuration.getString("logPath", "log");
    String replicaUrl = configuration.getString("replicaUrl");
    String purgeClass = configuration.getString("purgeClass");
    if (sb.length() > 0) {
        throw new RuntimeException("error on buildStoreConfig " + sb.toString());
    } else {
        StoreConfig storeConfig = new StoreConfig(name, path, 10, null);
        storeConfig.setDelay(delay);
        storeConfig.setDelayThread(delayThread);
        storeConfig.setLogPath(logPath);
        storeConfig.setBlockSize(blockSize);
        storeConfig.setPurgeClass(purgeClass);
        //            return new StoreConfig(name, path, filename, delay, mode, writeThread, useCache, maxCache, maxCache,
        //                    logPath, serializeClass, blockSize, replicaUrl);
        return storeConfig;
    }
}

From source file:com.sm.store.BuildRemoteConfig.java

private StoreConfig buildStoreConfig(HierarchicalConfiguration configuration) {
    StringBuilder sb = new StringBuilder();
    String name = configuration.getString("name");
    if (name == null)
        sb.append("store name is not defined ");
    String path = configuration.getString("path", "data");
    String filename = configuration.getString("filename", name);
    boolean delay = configuration.getBoolean("delay", true);
    int mode = configuration.getInt("mode", 0);
    int freq = configuration.getInt("freq", this.freq == 0 ? 1 : this.freq);
    int batchSize = configuration.getInt("batchSize", 10);
    String logPath = configuration.getString("logPath", "log");
    List<String> replicaUrl = configuration.getList("replicaUrl");
    long replciaTimeout = configuration.getLong("replicaTimeout", 60000);
    if (replicaUrl == null)
        sb.append("no replicaUrl is defined");
    boolean sorted = configuration.getBoolean("sorted", false);
    if (sb.length() > 0) {
        throw new RuntimeException("error on buildStoreConfig " + sb.toString());
    } else {//from w w w .j  a va  2  s .  c  o  m
        StoreConfig storeConfig = new StoreConfig(name, path, freq, replicaUrl, batchSize, delay, mode, sorted);
        storeConfig.setGetTriggerName(configuration.getString("getTrigger"));
        storeConfig.setPutTriggerName(configuration.getString("putTrigger"));
        storeConfig.setDeleteTriggerName(configuration.getString("deleteTrigger"));
        storeConfig.setUseMaxCache(configuration.getBoolean("useMaxCache", false));
        storeConfig.setMaxCacheMemory(configuration.getInt("maxCacheMemory", 20000));
        storeConfig.setUseLRU(configuration.getBoolean("useLRU", false));
        storeConfig.setLogPath(logPath);
        storeConfig.setReplicaTimeout(replciaTimeout);
        //add pstReplicaURl
        storeConfig.setPstReplicaUrl(configuration.getList("pstReplicaUrl"));
        storeConfig.setSerializeClass(configuration.getString("serializeClass"));
        return storeConfig;
    }

}