Java Code Examples for org.apache.commons.configuration2.tree.ImmutableNode#getValue()

The following examples show how to use org.apache.commons.configuration2.tree.ImmutableNode#getValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DbEnvironmentXmlEnricherTest.java    From obevo with Apache License 2.0 5 votes vote down vote up
private Object getNodeValue(ImmutableNode node) {
    if (node.getChildren().isEmpty()) {
        if (node.getAttributes() != null && !node.getAttributes().isEmpty()) {
            return constructMap(node);
        } else {
            return node.getValue();
        }
    } else {
        return constructMap(node);
    }
}
 
Example 2
Source File: XMLConfiguration.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc} This implementation ensures that the correct XML
 * element is created and inserted between the given siblings.
 */
@Override
protected void insert(final ImmutableNode newNode, final ImmutableNode parent,
        final ImmutableNode sibling1, final ImmutableNode sibling2,
        final ReferenceNodeHandler refHandler)
{
    if (XMLListReference.isListNode(newNode, refHandler))
    {
        return;
    }

    final Element elem = document.createElement(newNode.getNodeName());
    newElements.put(newNode, elem);
    updateAttributes(newNode, elem);
    if (newNode.getValue() != null)
    {
        final String txt =
                String.valueOf(listDelimiterHandler.escape(
                        newNode.getValue(),
                        ListDelimiterHandler.NOOP_TRANSFORMER));
        elem.appendChild(document.createTextNode(txt));
    }
    if (sibling2 == null)
    {
        getElement(parent, refHandler).appendChild(elem);
    }
    else if (sibling1 != null)
    {
        getElement(parent, refHandler).insertBefore(elem,
                getElement(sibling1, refHandler).getNextSibling());
    }
    else
    {
        getElement(parent, refHandler).insertBefore(elem,
                getElement(parent, refHandler).getFirstChild());
    }
}
 
Example 3
Source File: XMLPropertyListConfiguration.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * Append a node to the writer, indented according to a specific level.
 */
private void printNode(final PrintWriter out, final int indentLevel, final ImmutableNode node)
{
    final String padding = StringUtils.repeat(" ", indentLevel * INDENT_SIZE);

    if (node.getNodeName() != null)
    {
        out.println(padding + "<key>" + StringEscapeUtils.escapeXml10(node.getNodeName()) + "</key>");
    }

    final List<ImmutableNode> children = node.getChildren();
    if (!children.isEmpty())
    {
        out.println(padding + "<dict>");

        final Iterator<ImmutableNode> it = children.iterator();
        while (it.hasNext())
        {
            final ImmutableNode child = it.next();
            printNode(out, indentLevel + 1, child);

            if (it.hasNext())
            {
                out.println();
            }
        }

        out.println(padding + "</dict>");
    }
    else if (node.getValue() == null)
    {
        out.println(padding + "<dict/>");
    }
    else
    {
        final Object value = node.getValue();
        printValue(out, indentLevel, value);
    }
}
 
Example 4
Source File: AbstractYAMLBasedConfiguration.java    From commons-configuration with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a YAML map, i.e. String -&gt; Object from a given configuration
 * node.
 *
 * @param node The configuration node to create a map from.
 * @return A Map that contains the configuration node information.
 */
protected Map<String, Object> constructMap(final ImmutableNode node)
{
    final Map<String, Object> map = new HashMap<>(node.getChildren().size());
    for (final ImmutableNode cNode : node.getChildren())
    {
        final Object value = cNode.getChildren().isEmpty() ? cNode.getValue()
                : constructMap(cNode);
        addEntry(map, cNode.getNodeName(), value);
    }
    return map;
}
 
Example 5
Source File: INIConfiguration.java    From commons-configuration with Apache License 2.0 2 votes vote down vote up
/**
 * Checks whether the specified configuration node represents a section.
 *
 * @param node the node in question
 * @return a flag whether this node represents a section
 */
private static boolean isSectionNode(final ImmutableNode node)
{
    return node.getValue() == null;
}