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

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

Introduction

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

Prototype

public List getList(String key) 

Source Link

Usage

From source file:com.gs.obevo.db.api.factory.DbEnvironmentXmlEnricher.java

private static ImmutableList<String> iterString(HierarchicalConfiguration c, String path) {
    List<String> list = c.getList(path);
    return list != null ? ListAdapter.adapt(list).toImmutable() : Lists.immutable.<String>empty();
}

From source file:com.wrmsr.neurosis.util.Configs.java

public static List<String> getAllStrings(HierarchicalConfiguration hc, String key) {
    List<String> values = hc.getList(key).stream().filter(o -> o != null).map(Object::toString)
            .collect(Collectors.toList());
    try {//from w  ww  .  j a v  a  2  s .  c o  m
        HierarchicalConfiguration subhc = hc.configurationAt(key);
        for (String subkey : Lists.newArrayList(subhc.getKeys())) {
            if (!isNullOrEmpty(subkey)) {
                String subvalue = subhc.getString(subkey);
                if (subvalue != null) {
                    values.add(subvalue);
                }
            }
        }
    } catch (IllegalArgumentException e) {
        // pass
    }
    return values;
}

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

/**
 * Returns true if a credential has access to the desired service.
 *
 * @param credential//w w w  . j  a v  a 2s  .c om
 * @return
 */
private boolean implementsService(HierarchicalConfiguration credential) {
    if (service == null) {
        return true;
    }

    for (Object serv : credential.getList("service")) {
        if (serv instanceof String) {
            if (service.equals(serv)) {
                return true;
            }
        }
    }

    return false;
}

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

private ClusterNodes buildClusterNodes(HierarchicalConfiguration configuration) {
    short no = configuration.getShort("no", (short) -1);
    //int port = configuration.getInt("port", DEFAULT_TCP_PORT);
    List<String> serverList = configuration.getList("servers");
    List<String> partitionList = configuration.getList("partitions");
    StringBuilder sb = new StringBuilder();

    if (no == -1)
        sb.append("no is not defined, ");
    if (serverList == null || serverList.size() == 0)
        sb.append(" servers is not defined,");
    else {//from  w  w  w. j a  v a2s.  co m
        int error = 0;
        for (String each : serverList) {
            if (serverSets.contains(each)) {
                error++;
                sb.append(" " + each);
            } else
                serverSets.add(each);
        }
        if (error > 0)
            throw new RuntimeException(error + " duplicate server url" + sb.toString());
    }
    if (partitionList == null || partitionList.size() == 0)
        sb.append(" partitionList is not defined");
    if (sb.length() > 0)
        throw new RuntimeException("error on buildClusterNodes " + sb.toString());
    else {
        int error = 0;
        String[] servers = new String[serverList.size()];
        int[] partitions = new int[partitionList.size()];
        for (int i = 0; i < partitionList.size(); i++) {
            partitions[i] = Integer.valueOf(partitionList.get(i));
            if (sets.contains(partitions[i])) {
                error++;
                sb.append(" partitions # " + partitions[i]);
            } else
                sets.add(partitions[i]);
        }
        if (error > 0) {
            throw new RuntimeException(error + " duplicate" + sb.toString());
        }
        return new ClusterNodes(no, serverList.toArray(servers), partitions);
    }
}

From source file:au.com.dw.testdatacapturej.config.ConfigurationFileTest.java

/**
 * Test for getting setter method config from the Configuration.
 * /*ww w.j  a va  2 s .c  om*/
 */
@Test
public void setterFileReadTest() {
    try {

        List<?> setters = xmlSetterConfig.configurationsAt("setter");
        for (Iterator<?> it = setters.iterator(); it.hasNext();) {
            HierarchicalConfiguration sub = (HierarchicalConfiguration) it.next();
            // sub contains now all data about a single field

            String className = sub.getString("[@class]");
            System.out.println(className);

            List<String> fieldNames = configUtil.toStringList(sub.getList("field.field-name"));
            assertNotNull(fieldNames);
            assertFalse(fieldNames.isEmpty());

            for (String fieldName : fieldNames) {
                System.out.println(fieldName);
                assertNotNull(fieldName);
            }
        }

    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}

From source file:au.com.dw.testdatacapturej.config.ConfigurationFileTest.java

/**
 * Test for getting collection adder config from the Configuration.
 * //from   w  w w.  j  a v  a  2s  .com
 */
@Test
public void collectionFileReadTest() {
    try {

        List<?> collections = xmlCollectionConfig.configurationsAt("container");
        for (Iterator<?> it = collections.iterator(); it.hasNext();) {
            HierarchicalConfiguration sub = (HierarchicalConfiguration) it.next();
            // sub contains now all data about a single field

            String className = sub.getString("[@class]");
            System.out.println(className);

            List<String> fieldNames = configUtil.toStringList(sub.getList("argument.field-name"));
            assertNotNull(fieldNames);
            assertFalse(fieldNames.isEmpty());

            for (String fieldName : fieldNames) {
                System.out.println(fieldName);
                assertNotNull(fieldName);
            }

            List<String> adderMethodNames = configUtil.toStringList(sub.getList("argument.adder-method"));
            assertNotNull(adderMethodNames);
            assertFalse(adderMethodNames.isEmpty());

            for (String adderMethodName : adderMethodNames) {
                System.out.println(adderMethodName);
                assertNotNull(adderMethodName);
            }

        }

    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}

From source file:au.com.dw.testdatacapturej.config.ConfigurationFileTest.java

/**
 * Test for getting constructor parameters from the Configuration.
 * /*from   ww  w  . j  a  v a 2s.c  o m*/
 */
@Test
public void constructorFileReadTest() {
    try {
        /*
        // get the first constructor block
        HierarchicalConfiguration sub = xmlConfig.configurationAt("constructor(0)");
        String className = xmlConfig.getString("constructor(0)[@class]");
        System.out.println(className);
        List<String> paramFieldNames = (List<String>)sub.getList("argument.field-name");
        assertEquals(1, paramFieldNames.size());
                
        String fieldName = paramFieldNames.get(0);
        assertEquals(noSetterFieldName, fieldName);
                
        // next constructor block
        sub = xmlConfig.configurationAt("constructor(1)");
        className = xmlConfig.getString("constructor(1)[@class]");
        System.out.println(className);
        paramFieldNames = (List<String>)sub.getList("argument.field-name");
        assertEquals(2, paramFieldNames.size());
                
        fieldName = paramFieldNames.get(0);
        assertEquals(noSetterFieldName, fieldName);
        fieldName = paramFieldNames.get(1);
        assertEquals(noSetterFieldName2, fieldName);
        */
        List<?> constructors = xmlConstructorConfig.configurationsAt("constructor");
        for (Iterator<?> it = constructors.iterator(); it.hasNext();) {
            HierarchicalConfiguration sub = (HierarchicalConfiguration) it.next();
            // sub contains now all data about a single field

            String className = sub.getString("[@class]");
            System.out.println(className);

            List<String> paramFieldNames = configUtil.toStringList(sub.getList("argument.field-name"));
            assertNotNull(paramFieldNames);
            assertFalse(paramFieldNames.isEmpty());

            for (String fieldName : paramFieldNames) {
                System.out.println(fieldName);
                assertNotNull(fieldName);
            }
        }

    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}

From source file:net.datenwerke.sandbox.util.SandboxParser.java

protected void configurePackages(SandboxContext set, HierarchicalConfiguration rs) {
    for (Object e : rs.getList("packages.whitelist.entry"))
        set.addPackagePermission(AccessType.PERMIT, (String) e);

    for (Object e : rs.getList("packages.blacklist.entry"))
        set.addPackagePermission(AccessType.DENY, (String) e);

    for (HierarchicalConfiguration compl : rs.configurationsAt("packages.whitelist.complex")) {
        String cName = compl.getString("[@name]");

        Collection<StackEntry> entries = new HashSet<StackEntry>();

        for (HierarchicalConfiguration stack : compl.configurationsAt("check"))
            entries.add(getStackEntry(stack));

        PackagePermission wpkg = new PackagePermission(cName, entries);

        set.addPackagePermission(wpkg);// w  w w  .  ja  v  a  2  s . co  m
    }
}

From source file:net.datenwerke.sandbox.util.SandboxParser.java

protected void configureClasses(SandboxContext set, HierarchicalConfiguration rs) throws MalformedURLException {
    for (Object e : rs.getList("classes.whitelist.entry"))
        set.addClassPermission(AccessType.PERMIT, (String) e);

    for (Object e : rs.getList("classes.whitelist.jar")) {
        set.addJarToWhitelist(new URL((String) e));
    }/*from   w ww  .  jav a  2  s  .  c om*/

    for (Object e : rs.getList("classes.blacklist.entry"))
        set.addClassPermission(AccessType.DENY, (String) e);

    for (HierarchicalConfiguration compl : rs.configurationsAt("classes.whitelist.complex")) {
        String cName = compl.getString("[@name]");

        Collection<StackEntry> entries = new HashSet<StackEntry>();

        for (HierarchicalConfiguration stack : compl.configurationsAt("check"))
            entries.add(getStackEntry(stack));

        ClassPermission wclazz = new ClassPermission(cName, entries);

        set.addClassPermission(wclazz);
    }
}

From source file:net.datenwerke.sandbox.util.SandboxParser.java

protected void configureClassesForApplicationLoader(SandboxContext set, HierarchicalConfiguration rs)
        throws MalformedURLException {
    for (Object e : rs.getList("applicationLoader.class"))
        set.addClassForApplicationLoader((String) e);
    for (Object e : rs.getList("applicationLoader.classPrefix"))
        set.addClassForApplicationLoader((String) e, Mode.PREFIX);
    for (Object e : rs.getList("applicationLoader.jar"))
        set.addJarForApplicationLoader(new URL((String) e));

    for (Object e : rs.getList("sandboxLoader.class"))
        set.addClassForSandboxLoader((String) e);
    for (Object e : rs.getList("sandboxLoader.classPrefix"))
        set.addClassForSandboxLoader((String) e, Mode.PREFIX);
}