Package org.apache.commons.configuration.tree

Examples of org.apache.commons.configuration.tree.ConfigurationNode


         *
         * @param node the node
         */
        public void visitBeforeChildren(ConfigurationNode node)
        {
            ConfigurationNode copy = (ConfigurationNode) node.clone();
            copy.setParentNode(null);

            if (!copyStack.isEmpty())
            {
                if (node.isAttribute())
                {
View Full Code Here


        else
        {
            List<Object> list = new ArrayList<Object>();
            for (Iterator<?> it = nodes.iterator(); it.hasNext();)
            {
                ConfigurationNode node = (ConfigurationNode) it.next();
                if (node.getValue() != null)
                {                                             
                    list.add(node.getValue());
                }
            }

            if (list.size() < 1)
            {
View Full Code Here

            // String name = sub.getString("@" + NAME_ATTRIBUTE);
            // String value = sub.getString("@" + VALUE_ATTRIBUTE);
            List nameAtts = sub.getRootNode().getAttributes(NAME_ATTRIBUTE);
            List valueAtts = sub.getRootNode().getAttributes(VALUE_ATTRIBUTE);
            if (nameAtts != null && nameAtts.size() > 0) {
                ConfigurationNode nameAttNode = (ConfigurationNode)nameAtts.get(0);
                name = (String)nameAttNode.getValue();
            }
            if (valueAtts != null && valueAtts.size() > 0) {
                ConfigurationNode valueAttNode = (ConfigurationNode)valueAtts.get(0);
                value = (String)valueAttNode.getValue();
            }

            if (name == null && value != null) {
                throw new ConfigurationException("Parameter name not set");
            } else if (name != null && value == null) {
View Full Code Here

     */
    protected String getAttribute(HierarchicalConfiguration config, String name)
            throws ConfigurationException {
        // String attribute = config.getString("@" + name);
        SubnodeConfiguration xmlconfig = (SubnodeConfiguration)config;
        ConfigurationNode rootNode = xmlconfig.getRootNode();
        String rootNodeName = rootNode.getName();
        List atts = rootNode.getAttributes(name);
        String attribute = null;
        // Object obj = config.getProperty(name);
        if (atts != null && atts.size() > 0) {
            attribute = (String)((ConfigurationNode)atts.get(0)).getValue();
        }
View Full Code Here

    public void testInitCopy() throws ConfigurationException
    {
        XMLConfiguration copy = new XMLConfiguration(conf);
        assertEquals("value", copy.getProperty("element"));
        assertNull("Document was copied, too", copy.getDocument());
        ConfigurationNode root = copy.getRootNode();
        for (ConfigurationNode node : root.getChildren())
        {
            assertNull("Reference was not cleared", node.getReference());
        }

        removeTestFile();
View Full Code Here

     * CONFIGURATION-294.
     */
    @Test
    public void testAddNodesAndSave() throws ConfigurationException
    {
        ConfigurationNode node = new HierarchicalConfiguration.Node("test");
        ConfigurationNode child = new HierarchicalConfiguration.Node("child");
        node.addChild(child);
        ConfigurationNode attr = new HierarchicalConfiguration.Node("attr");
        node.addAttribute(attr);
        ConfigurationNode node2 = conf.createNode("test2");
        Collection<ConfigurationNode> nodes = new ArrayList<ConfigurationNode>(2);
        nodes.add(node);
        nodes.add(node2);
        conf.addNodes("add.nodes", nodes);
        conf.setFile(testSaveConf);
View Full Code Here

        conf.addProperty("testAddNodes.property(1).value", "value2");
        Collection<ConfigurationNode> nodes = new ArrayList<ConfigurationNode>();
        nodes.add(new HierarchicalConfiguration.Node("property"));
        conf.addNodes("testAddNodes", nodes);
        nodes.clear();
        ConfigurationNode nd = new HierarchicalConfiguration.Node("name",
                "prop3");
        nd.setAttribute(true);
        nodes.add(nd);
        conf.addNodes("testAddNodes.property(2)", nodes);
        assertEquals("Attribute not added", "prop3", conf
                .getString("testAddNodes.property(2)[@name]"));
    }
View Full Code Here

    @Test
    public void testAddNodesToSubnodeConfiguration() throws Exception
    {
        SubnodeConfiguration sub = conf.configurationAt("element2");
        sub.addProperty("newKey", "newvalue");
        ConfigurationNode root = conf.getRootNode();
        ConfigurationNode elem = root.getChildren("element2").get(0);
        ConfigurationNode newNode = elem.getChildren("newKey").get(0);
        assertTrue("Wrong node type: " + newNode,
                newNode instanceof XMLConfiguration.XMLNode);
    }
View Full Code Here

    public void load(Reader reader) throws ConfigurationException
    {
        try
        {
            BufferedReader bufferedReader = new BufferedReader(reader);
            ConfigurationNode sectionNode = getRootNode();

            String line = bufferedReader.readLine();
            while (line != null)
            {
                line = line.trim();
                if (!isCommentLine(line))
                {
                    if (isSectionLine(line))
                    {
                        String section = line.substring(1, line.length() - 1);
                        sectionNode = getSectionNode(section);
                    }

                    else
                    {
                        String key = "";
                        String value = "";
                        int index = findSeparator(line);
                        if (index >= 0)
                        {
                            key = line.substring(0, index);
                            value = parseValue(line.substring(index + 1), bufferedReader);
                        }
                        else
                        {
                            key = line;
                        }
                        key = key.trim();
                        if (key.length() < 1)
                        {
                            // use space for properties with no key
                            key = " ";
                        }
                        ConfigurationNode node = createNode(key);
                        node.setValue(value);
                        sectionNode.addChild(node);
                    }
                }

                line = bufferedReader.readLine();
View Full Code Here

        boolean globalSection = false;
        boolean inSection = false;

        for (Iterator it = getRootNode().getChildren().iterator(); it.hasNext();)
        {
            ConfigurationNode node = (ConfigurationNode) it.next();
            if (isSectionNode(node))
            {
                inSection = true;
                sections.add(node.getName());
            }
            else
            {
                if (!inSection && !globalSection)
                {
View Full Code Here

TOP

Related Classes of org.apache.commons.configuration.tree.ConfigurationNode

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.