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

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

Introduction

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

Prototype

Object getValue();

Source Link

Document

Returns the value of this node.

Usage

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

protected static Object unpackNode(ConfigurationNode node) {
    List<ConfigurationNode> children = node.getChildren();
    if (!children.isEmpty()) {
        Map<String, List<ConfigurationNode>> namedChildren = newHashMap();
        for (ConfigurationNode child : children) {
            if (namedChildren.containsKey(child.getName())) {
                namedChildren.get(child.getName()).add(child);
            } else {
                namedChildren.put(child.getName(), Lists.newArrayList(child));
            }//from   ww w .j a  v a  2 s . c  o  m
        }
        Map ret = newHashMap();
        for (Map.Entry<String, List<ConfigurationNode>> e : namedChildren.entrySet()) {
            List<ConfigurationNode> l = e.getValue();
            checkState(!l.isEmpty());
            boolean hasListAtt = l.stream().flatMap(n -> n.getAttributes(IS_LIST_ATTR).stream())
                    .map(o -> toBool(o)).findFirst().isPresent();
            Object no;
            if (l.size() > 1 || hasListAtt) {
                no = l.stream().map(n -> unpackNode(n)).filter(o -> o != null)
                        .collect(ImmutableCollectors.toImmutableList());
            } else {
                no = unpackNode(l.get(0));
            }
            ret.put(e.getKey(), no);
        }
        if (ret.size() == 1 && ret.containsKey("")) {
            return ret.get("");
        } else {
            return ret;
        }
    }
    return node.getValue();
}

From source file:nz.co.senanque.madura.configuration.ListBeanFactory.java

public synchronized Object createBean(Class beanClass, BeanDeclaration decl, Object param) throws Exception {
    XMLBeanDeclaration xmlDecl = (XMLBeanDeclaration) decl;
    ConfigurationNode n = xmlDecl.getNode();
    String nodeName = n.getName();
    n = n.getParentNode();/*from w  w  w . j a  v a2s  .  co m*/
    while (n != null) {
        if (n.getName() != null)
            nodeName = n.getName() + "/" + nodeName;
        n = n.getParentNode();
    }
    Object bean = beans.get(nodeName);
    if (bean != null) {
        // Yes, there is already an instance
        return bean;
    }
    final List<String> list = new ArrayList<String>();
    n = xmlDecl.getNode();
    List<ConfigurationNode> children = n.getChildren();
    for (ConfigurationNode node : children) {
        list.add(node.getValue().toString());
    }
    // Store it in map
    bean = list;
    beans.put(nodeName, bean);
    return bean;
}

From source file:nz.co.senanque.madura.configuration.XMLBeanFactory.java

private Element makeElement(ConfigurationNode node) {
    Element element = new Element(node.getName());
    Object value = node.getValue();
    if (value != null)
        element.setText(value.toString());
    List<ConfigurationNode> attributes = node.getAttributes();
    for (ConfigurationNode attribute : attributes) {
        element.setAttribute(new Attribute(attribute.getName(), attribute.getValue().toString()));
    }/*from  w  w  w . j  ava 2 s . c o m*/
    List<ConfigurationNode> children = node.getChildren();
    for (ConfigurationNode child : children) {
        element.addContent(makeElement(child));
    }
    return element;
}

From source file:org.apache.tinkerpop.gremlin.util.config.YamlConfiguration.java

protected Object saveHierarchy(final ConfigurationNode parentNode) {
    if (parentNode.getChildrenCount() == 0)
        return parentNode.getValue();

    if (parentNode.getChildrenCount("item") == parentNode.getChildrenCount()) {
        return parentNode.getChildren().stream().map(this::saveHierarchy).collect(Collectors.toList());
    } else {// w  ww.  java2 s.co  m
        final Map<String, Object> map = new LinkedHashMap<>();
        for (ConfigurationNode childNode : parentNode.getChildren()) {
            String nodeName = childNode.getName();
            if (this.xmlCompatibility && childNode.getAttributes("name").size() > 0)
                nodeName = String.valueOf(childNode.getAttributes("name").get(0).getValue());

            map.put(nodeName, saveHierarchy(childNode));
        }

        return map;
    }
}

From source file:org.kepler.configuration.CommonsConfigurationReader.java

/**
 * add the structure of root to prop/*from   www  .  ja  va  2s . co m*/
 */
private ConfigurationProperty getConfiguration(ConfigurationNode root, Module m,
        ConfigurationNamespace namespace) throws Exception {
    String originMod;
    boolean originOk = true;
    ConfigurationProperty cp = new ConfigurationProperty(m, root.getName());
    cp.setNamespace(namespace);
    String value = (String) root.getValue();
    boolean mutable = true;
    if (value != null && !value.equals("")) {
        cp.setValue(value);
    }

    if (root.getChildrenCount() != 0) {
        Iterator it = root.getChildren().iterator();
        while (it.hasNext()) {
            ConfigurationNode child = (ConfigurationNode) it.next();
            ConfigurationProperty nextProp = getConfiguration(child, m, namespace);
            if (nextProp == null) {
                if (_isDebugging) {
                    _log.debug("not loading property " + child.getName()
                            + " because it was added from an inactive module.");
                }
                continue;
            }

            if (nextProp.getName().equals("mutable")) {
                if (nextProp.getValue() != null && nextProp.getValue().equals("false")) {
                    cp.setMutable(false);
                }
            } else if (nextProp.getName().equals("originModule")) {
                if (nextProp.getValue() != null && !nextProp.getValue().equals("")) {
                    originMod = nextProp.getValue();
                    if (!ModuleTree.instance().contains(originMod)) {
                        originOk = false;
                    } else {
                        cp.setOriginModule(ConfigurationManager.getModule(originMod));
                    }
                }
            }

            cp.addProperty(nextProp, true);
        }
    }

    if (originOk) {
        return cp;
    } else {
        return null;
    }
}

From source file:org.lable.oss.dynamicconfig.core.commonsconfiguration.Objectifier.java

/**
 * Process a node in the Config tree, and store it with its parent node in an object tree.
 * <p>//from  w  w  w.  j  ava  2  s. c o  m
 * This method recursively calls itself to walk a Config tree.
 *
 * @param parent Parent of the current node, as represented in the Config tree.
 * @return An object tree.
 */
public static Object traverseTreeAndEmit(ConfigurationNode parent) {
    if (parent.getChildrenCount() == 0) {
        return parent.getValue();
    } else {
        Map<String, Object> map = new LinkedHashMap<>();
        for (Object o : parent.getChildren()) {
            ConfigurationNode child = (ConfigurationNode) o;
            String nodeName = child.getName();
            addToMap(map, nodeName, traverseTreeAndEmit(child));
        }
        return map;
    }
}

From source file:org.wso2.carbon.device.mgt.iot.agent.kura.display.SequenceRunner.java

private List<ResourceType> getSequence() {
    List<ResourceType> sequence = new ArrayList<>();

    ConfigManager configManager = ConfigManager.getInstance();

    List<HierarchicalConfiguration> resources = configManager.getContentConfig()
            .configurationsAt("Content.DisplaySequence.Resource");

    for (HierarchicalConfiguration resource : resources) {

        String resourceTypeHandler = resource.getString("[@handler]");
        ResourceType resourceObj = null;

        try {//from  www  . ja v  a 2s  .  c o  m
            resourceObj = (ResourceType) Class.forName(resourceTypeHandler).newInstance();
        } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
            log.severe("Error occurred while resolving resource type: " + e.getMessage());
        }

        //read all init args
        Map<String, String> configArgs = new HashMap<>();
        ConfigurationNode node = resource.getRootNode();
        List<ConfigurationNode> attrs = node.getAttributes();

        for (ConfigurationNode attr : attrs) {
            configArgs.put(attr.getName(), attr.getValue().toString());
        }

        //initialize the resource with config args
        resourceObj.init(configArgs);

        //add it to the sequence
        sequence.add(resourceObj);
    }

    return sequence;
}

From source file:org.zaproxy.admin.VerifyCoreZapVersionsEntries.java

private static List<Element> elements(Path zapVersionsFile) throws Exception {
    List<Element> elements = new ArrayList<>();
    new ZapXmlConfiguration(zapVersionsFile.toFile()).configurationAt("core").getRootNode()
            .visit(new ConfigurationNodeVisitor() {

                @Override//from  w ww  .  j ava 2 s  . c  o  m
                public void visitBeforeChildren(ConfigurationNode node) {
                    elements.add(Element.of(getHierarchicalName(node), Objects.toString(node.getValue())));
                }

                @Override
                public void visitAfterChildren(ConfigurationNode node) {
                    // Nothing to do.
                }

                @Override
                public boolean terminate() {
                    return false;
                }
            });

    return elements;
}

From source file:org.zaproxy.zap.extension.quickstart.ExtensionQuickStart.java

private String getFirstChildNodeString(ConfigurationNode node, String childName) {
    ConfigurationNode child = this.getFirstChildNode(node, childName);
    if (child != null) {
        return child.getValue().toString();
    }/*from   ww  w . ja v a 2s.  c  o m*/
    return null;
}