Example usage for org.apache.commons.configuration.tree ConfigurationNode getChildren

List of usage examples for org.apache.commons.configuration.tree ConfigurationNode getChildren

Introduction

In this page you can find the example usage for org.apache.commons.configuration.tree ConfigurationNode getChildren.

Prototype

List getChildren(String name);

Source Link

Document

Returns a list with all children of this node with the given name.

Usage

From source file:de.ingrid.portal.config.FacetsConfig.java

/**
 * Extract facet configuration/*ww w.  ja  v  a2s .c  om*/
 * 
 * @param facets
 * @return
 */
private static ArrayList<IngridFacet> extractFacets(List<ConfigurationNode> facet, IngridFacet parentFacet) {
    ArrayList<IngridFacet> ingridFacets = new ArrayList<IngridFacet>();

    if (facet != null) {
        for (ConfigurationNode facetNode : facet) {
            IngridFacet ingridFacet = new IngridFacet();
            if (facetNode.getChildren("id").size() > 0) {
                Node node = (Node) facetNode.getChildren("id").get(0);
                if (node != null) {
                    ingridFacet.setId(node.getValue().toString());
                }
            }

            if (parentFacet != null) {
                ingridFacet.setParent(parentFacet);
            }

            if (facetNode.getChildren("name").size() > 0) {
                Node node = (Node) facetNode.getChildren("name").get(0);
                if (node != null) {
                    ingridFacet.setName((String) node.getValue());
                }
            }

            if (facetNode.getChildren("[@sort]").size() > 0) {
                Node subNode = (Node) facetNode.getChildren("[@sort]").get(0);
                ingridFacet.setSort(subNode.getValue().toString());
            }

            if (facetNode.getChildren("query").size() > 0) {
                Node node = (Node) facetNode.getChildren("query").get(0);
                if (node != null) {
                    ingridFacet.setQuery((String) node.getValue());
                }
            }

            if (facetNode.getChildren("codelist-id").size() > 0) {
                Node node = (Node) facetNode.getChildren("codelist-id").get(0);
                if (node != null) {
                    ingridFacet.setCodelistId((String) node.getValue());
                }
            }

            if (facetNode.getChildren("codelist-entry-id").size() > 0) {
                Node node = (Node) facetNode.getChildren("codelist-entry-id").get(0);
                if (node != null) {
                    ingridFacet.setCodelistEntryId((String) node.getValue());
                }
            }

            if (facetNode.getChildren("from").size() > 0 && facetNode.getChildren("to").size() > 0) {
                String from = null;
                String to = null;
                SimpleDateFormat df = new SimpleDateFormat("yyyyMMdd");
                Calendar cal;

                //from
                Node node = (Node) facetNode.getChildren("from").get(0);
                cal = new GregorianCalendar();
                if (node != null) {
                    String value = node.getValue().toString();
                    if (value.equals("")) {
                        from = "";
                    } else {
                        TM_PeriodDuration pd = TM_PeriodDuration.parse(value);
                        if (pd.getValue(Interval.DAYS) != null && pd.getValue(Interval.DAYS).length() > 0) {
                            cal.add(Calendar.DAY_OF_MONTH, Integer.parseInt(pd.getValue(Interval.DAYS)) * (-1));
                        }

                        if (pd.getValue(Interval.MONTHS) != null && pd.getValue(Interval.MONTHS).length() > 0) {
                            cal.add(Calendar.MONTH, Integer.parseInt(pd.getValue(Interval.MONTHS)) * (-1));
                        }

                        if (pd.getValue(Interval.YEARS) != null && pd.getValue(Interval.YEARS).length() > 0) {
                            cal.add(Calendar.YEAR, Integer.parseInt(pd.getValue(Interval.YEARS)) * (-1));
                        }
                        from = df.format(cal.getTime());
                    }
                }

                //to
                node = (Node) facetNode.getChildren("to").get(0);
                cal = new GregorianCalendar();
                if (node != null) {
                    String value = node.getValue().toString();
                    if (value.equals("")) {
                        to = "";
                    } else {
                        TM_PeriodDuration pd = TM_PeriodDuration.parse(value);
                        if (pd.getValue(Interval.DAYS) != null && pd.getValue(Interval.DAYS).length() > 0) {
                            cal.add(Calendar.DAY_OF_MONTH, Integer.parseInt(pd.getValue(Interval.DAYS)) * (-1));
                        }

                        if (pd.getValue(Interval.MONTHS) != null && pd.getValue(Interval.MONTHS).length() > 0) {
                            cal.add(Calendar.MONTH, Integer.parseInt(pd.getValue(Interval.MONTHS)) * (-1));
                        }

                        if (pd.getValue(Interval.YEARS) != null && pd.getValue(Interval.YEARS).length() > 0) {
                            cal.add(Calendar.YEAR, Integer.parseInt(pd.getValue(Interval.YEARS)) * (-1));
                        }
                        to = df.format(cal.getTime());
                    }
                }
                if (from != null && to != null) {
                    ingridFacet.setQuery("t01_object.mod_time:[" + from + "0* TO " + to + "9*]");
                }
            }

            if (facetNode.getChildren("dependency").size() > 0) {
                Node node = (Node) facetNode.getChildren("dependency").get(0);
                if (node != null) {
                    ingridFacet.setDependency(node.getValue().toString());
                }
            }

            if (facetNode.getChildren("hidden").size() > 0) {
                Node node = (Node) facetNode.getChildren("hidden").get(0);
                if (node != null) {
                    ingridFacet.setHidden(node.getValue().toString());
                }
            }

            if (facetNode.getChildren("facets").size() > 0) {
                Node node = (Node) facetNode.getChildren("facets").get(0);
                if (node != null) {
                    if (node.getChildren("[@queryType]").size() > 0) {
                        Node subNode = (Node) node.getChildren("[@queryType]").get(0);
                        ingridFacet.setQueryType(subNode.getValue().toString());
                    }

                    Node facetsNode = (Node) facetNode.getChildren("facets").get(0);
                    if (facetNode != null) {
                        List<ConfigurationNode> subFacet = facetsNode.getChildren("facet");
                        if (subFacet != null) {
                            ingridFacet.setFacets(extractFacets(subFacet, ingridFacet));
                        }
                    }
                }
            }

            ingridFacets.add(ingridFacet);
        }
    }
    return ingridFacets;
}

From source file:club.jmint.crossing.config.CrossingConfig.java

@Override
public Config loadConfig() {
    super.loadConfig();
    XMLConfiguration conf = loadXMLConfigFile(configFilePath);

    ConfigurationNode root = conf.getRootNode();

    List<ConfigurationNode> ptypesnode = root.getChildren("providertypes");
    List<ConfigurationNode> typenode = ptypesnode.get(0).getChildren();
    ConfigurationNode node;/*  w w w .j  av  a2 s.c  om*/
    List<ConfigurationNode> name, enabled, clazz;
    for (int i = 0; i < typenode.size(); i++) {
        node = typenode.get(i);
        name = node.getAttributes("name");
        enabled = node.getAttributes("enabled");
        clazz = node.getAttributes("class");
        //System.out.println(name.get(0).getValue());
        //System.out.println(enabled.get(0).getValue());

        ptypesMap.put(name.get(0).getValue().toString(),
                new ProviderPair(name.get(0).getValue().toString(),
                        Boolean.parseBoolean(enabled.get(0).getValue().toString()),
                        clazz.get(0).getValue().toString()));
    }

    List<ConfigurationNode> srvsnode = root.getChildren("servers");
    List<ConfigurationNode> srvnode = srvsnode.get(0).getChildren();
    //ConfigurationNode node;
    List<ConfigurationNode> type, iplist, port, mp;
    for (int i = 0; i < srvnode.size(); i++) {
        node = srvnode.get(i);
        name = node.getAttributes("name");
        type = node.getAttributes("type");
        mp = node.getAttributes("methodProxy");
        iplist = node.getAttributes("ip");
        port = node.getAttributes("port");

        serversMap.put(name.get(0).getValue().toString(),
                new ServerPair(name.get(0).getValue().toString(), type.get(0).getValue().toString(),
                        mp.get(0).getValue().toString(), iplist.get(0).getValue().toString(),
                        Integer.parseInt(port.get(0).getValue().toString())));
    }

    List<ConfigurationNode> infsnode = root.getChildren("interfaces");
    List<ConfigurationNode> infnode = infsnode.get(0).getChildren();
    ConfigurationNode servernode;
    List<ConfigurationNode> sname, intf, iname, encrypt;
    ArrayList<InfPair> al;
    for (int i = 0; i < infnode.size(); i++) {
        node = infnode.get(i);
        sname = node.getAttributes("name");

        al = new ArrayList<InfPair>();
        intf = node.getChildren();
        for (int j = 0; j < intf.size(); j++) {
            servernode = intf.get(j);
            iname = servernode.getAttributes("name");
            encrypt = servernode.getAttributes("isEncrypt");

            al.add(new InfPair(iname.get(0).getValue().toString(),
                    Boolean.parseBoolean(encrypt.get(0).getValue().toString())));
        }
        infsMap.put(sname.get(0).getValue().toString(), al);
    }
    return this;
}

From source file:com.stratio.explorer.conf.ExplorerConfiguration.java

private String getStringValue(String name, String d) {
    List<ConfigurationNode> properties = getRootNode().getChildren();
    if (properties == null || properties.size() == 0)
        return d;
    for (ConfigurationNode p : properties) {
        if (p.getChildren("name") != null && p.getChildren("name").size() > 0
                && name.equals(p.getChildren("name").get(0).getValue())) {
            return (String) p.getChildren("value").get(0).getValue();
        }//from w  w  w.j  a  v a  2s  .c o  m
    }
    return d;
}

From source file:com.stratio.explorer.conf.ExplorerConfiguration.java

private int getIntValue(String name, int d) {
    List<ConfigurationNode> properties = getRootNode().getChildren();
    if (properties == null || properties.size() == 0)
        return d;
    for (ConfigurationNode p : properties) {
        if (p.getChildren("name") != null && p.getChildren("name").size() > 0
                && name.equals(p.getChildren("name").get(0).getValue())) {
            return Integer.parseInt((String) p.getChildren("value").get(0).getValue());
        }//from w  ww .  j  av  a2 s  .  c o m
    }
    return d;
}

From source file:com.stratio.explorer.conf.ExplorerConfiguration.java

private long getLongValue(String name, long d) {
    List<ConfigurationNode> properties = getRootNode().getChildren();
    if (properties == null || properties.size() == 0)
        return d;
    for (ConfigurationNode p : properties) {
        if (p.getChildren("name") != null && p.getChildren("name").size() > 0
                && name.equals(p.getChildren("name").get(0).getValue())) {
            return Long.parseLong((String) p.getChildren("value").get(0).getValue());
        }//ww w  .j  a va 2 s .c o  m
    }
    return d;
}

From source file:com.stratio.explorer.conf.ExplorerConfiguration.java

private float getFloatValue(String name, float d) {
    List<ConfigurationNode> properties = getRootNode().getChildren();
    if (properties == null || properties.size() == 0)
        return d;
    for (ConfigurationNode p : properties) {
        if (p.getChildren("name") != null && p.getChildren("name").size() > 0
                && name.equals(p.getChildren("name").get(0).getValue())) {
            return Float.parseFloat((String) p.getChildren("value").get(0).getValue());
        }//from  w  ww  .j  a  va2 s  .c  o m
    }
    return d;
}

From source file:com.stratio.explorer.conf.ExplorerConfiguration.java

private boolean getBooleanValue(String name, boolean d) {
    List<ConfigurationNode> properties = getRootNode().getChildren();
    if (properties == null || properties.size() == 0)
        return d;
    for (ConfigurationNode p : properties) {
        if (p.getChildren("name") != null && p.getChildren("name").size() > 0
                && name.equals(p.getChildren("name").get(0).getValue())) {
            return Boolean.parseBoolean((String) p.getChildren("value").get(0).getValue());
        }/*w w  w  .j  a  v a2 s .co m*/
    }
    return d;
}

From source file:club.jmint.crossing.config.AclConfig.java

@Override
public Config loadConfig() {
    super.loadConfig();
    XMLConfiguration conf = loadXMLConfigFile(configFilePath);

    ConfigurationNode root = conf.getRootNode();
    List<ConfigurationNode> aclenabled = root.getAttributes("enabled");
    isAclEnabled = Boolean.parseBoolean(aclenabled.get(0).getValue().toString());
    //System.out.println(aclenabled.get(0).getValue().toString());
    //System.out.println(isAclEnabled);

    List<ConfigurationNode> rulesnode = root.getChildren("rules");
    List<ConfigurationNode> rulenode = rulesnode.get(0).getChildren();
    ConfigurationNode node;/*  w w w  . j  a v a2s  . c om*/
    List<ConfigurationNode> name, enabled;
    String rname;
    for (int i = 0; i < rulenode.size(); i++) {
        node = rulenode.get(i);
        name = node.getAttributes("name");
        enabled = node.getAttributes("enabled");

        //System.out.println(name.get(0).getValue().toString());
        //System.out.println(enabled.get(0).getValue().toString());;
        rname = name.get(0).getValue().toString();
        ruleMap.put(rname, new AclRule(rname, Boolean.parseBoolean(enabled.get(0).getValue().toString())));

    }

    List<ConfigurationNode> gcsnode = root.getChildren("grantedclient");
    List<ConfigurationNode> gcnode = gcsnode.get(0).getChildren();
    //ConfigurationNode node;
    List<ConfigurationNode> ip, desc;
    String iname;
    for (int i = 0; i < gcnode.size(); i++) {
        node = gcnode.get(i);
        name = node.getAttributes("name");
        ip = node.getAttributes("ip");
        enabled = node.getAttributes("enabled");
        desc = node.getAttributes("desc");

        //System.out.println(name.get(0).getValue().toString());
        //System.out.println(ip.get(0).getValue().toString());
        //System.out.println(access.get(0).getValue().toString());
        iname = name.get(0).getValue().toString();
        gcipMap.put(iname, new GrantedIPair(iname, ip.get(0).getValue().toString(),
                Boolean.parseBoolean(enabled.get(0).getValue().toString()), desc.get(0).getValue().toString()));

    }

    List<ConfigurationNode> gisnode = root.getChildren("grantedif");
    List<ConfigurationNode> ginode = gisnode.get(0).getChildren();
    ConfigurationNode clientnode;
    List<ConfigurationNode> client, value;
    ArrayList<String> al;
    for (int i = 0; i < ginode.size(); i++) {
        node = ginode.get(i);
        name = node.getAttributes("name");
        //System.out.println(node.getName());
        //System.out.println(name.get(0).getValue().toString());

        al = new ArrayList<String>();
        client = node.getChildren();
        for (int j = 0; j < client.size(); j++) {
            clientnode = client.get(j);
            value = clientnode.getAttributes("value");
            //System.out.println(value.get(0).getValue().toString());
            al.add(value.get(0).getValue().toString());
        }
        gifMap.put(name.get(0).getValue().toString(), al);
        //System.out.println(gifMap.get(name.get(0).getValue().toString()).get(0));

    }

    return this;
}

From source file:org.apache.zeppelin.conf.ZeppelinConfiguration.java

private String getStringValue(String name, String d) {
    List<ConfigurationNode> properties = getRootNode().getChildren();
    if (properties == null || properties.size() == 0) {
        return d;
    }//w  ww .  ja va2s .com
    for (ConfigurationNode p : properties) {
        if (p.getChildren("name") != null && p.getChildren("name").size() > 0
                && name.equals(p.getChildren("name").get(0).getValue())) {
            return (String) p.getChildren("value").get(0).getValue();
        }
    }
    return d;
}

From source file:org.apache.zeppelin.conf.ZeppelinConfiguration.java

private int getIntValue(String name, int d) {
    List<ConfigurationNode> properties = getRootNode().getChildren();
    if (properties == null || properties.size() == 0) {
        return d;
    }//from   ww w .ja v  a 2s.c om
    for (ConfigurationNode p : properties) {
        if (p.getChildren("name") != null && p.getChildren("name").size() > 0
                && name.equals(p.getChildren("name").get(0).getValue())) {
            return Integer.parseInt((String) p.getChildren("value").get(0).getValue());
        }
    }
    return d;
}