Package org.yaml.snakeyaml.nodes

Examples of org.yaml.snakeyaml.nodes.Node


        @Override
        protected void constructMapping2ndStep(MappingNode node, Map<Object, Object> mapping) {
            List<NodeTuple> nodeValue = (List<NodeTuple>) node.getValue();
            for (NodeTuple tuple : nodeValue) {
                Node keyNode = tuple.getKeyNode();
                Node valueNode = tuple.getValueNode();
                Object key = constructObject(keyNode);
                if (key != null) {
                    key.hashCode();// check circular dependencies
                }
                Object value = constructObject(valueNode);
View Full Code Here


        }

        public class FileRepresenter implements Represent {
            public Node representData(Object data) {
                File file = (File) data;
                Node scalar = representScalar(new Tag("!!java.io.File"), file.getAbsolutePath());
                return scalar;
            }
View Full Code Here

        @Override
        protected NodeTuple representJavaBeanProperty(Object javaBean, Property property,
                Object propertyValue, Tag customTag) {
            NodeTuple tuple = super.representJavaBeanProperty(javaBean, property, propertyValue,
                    customTag);
            Node valueNode = tuple.getValueNode();
            if (Tag.NULL.equals(valueNode.getTag())) {
                return null;// skip 'null' values
            }
            if (valueNode instanceof CollectionNode) {
                if (Tag.SEQ.equals(valueNode.getTag())) {
                    SequenceNode seq = (SequenceNode) valueNode;
                    if (seq.getValue().isEmpty()) {
                        return null;// skip empty lists
                    }
                }
                if (Tag.MAP.equals(valueNode.getTag())) {
                    MappingNode seq = (MappingNode) valueNode;
                    if (seq.getValue().isEmpty()) {
                        return null;// skip empty maps
                    }
                }
View Full Code Here

        bean.setDate(etalon);
        DumperOptions options = new DumperOptions();
        options.setDefaultFlowStyle(FlowStyle.BLOCK);
        Yaml dumper = new Yaml(new JodaTimeRepresenter(), options);
        // compare Nodes with flow style AUTO and flow style BLOCK
        Node node1 = dumper.represent(bean);
        DumperOptions options2 = new DumperOptions();
        options2.setDefaultFlowStyle(FlowStyle.AUTO);
        Yaml dumper2 = new Yaml(new JodaTimeRepresenter(), options2);
        Node node2 = dumper2.represent(bean);
        assertEquals(node2.toString(), node1.toString());
        // compare Events with flow style AUTO and flow style BLOCK
        List<Event> events1 = dumper.serialize(node1);
        List<Event> events2 = dumper2.serialize(node2);
        assertEquals(events2.size(), events1.size());
        int i = 0;
View Full Code Here

public class ComposerImplTest extends TestCase {

    public void testGetNode() {
        String data = "american:\n  - Boston Red Sox";
        Yaml yaml = new Yaml();
        Node node = yaml.compose(new StringReader(data));
        assertNotNull(node);
        assertTrue(node instanceof MappingNode);
        String data2 = "---\namerican:\n- Boston Red Sox";
        Node node2 = yaml.compose(new StringReader(data2));
        assertNotNull(node2);
        assertFalse(node.equals(node2));
    }
View Full Code Here

    }

    public void testComposeBean() {
        String data = "!!org.yaml.snakeyaml.composer.ComposerImplTest$BeanToCompose {name: Bill, age: 18}";
        Yaml yaml = new Yaml();
        Node node = yaml.compose(new StringReader(data));
        assertNotNull(node);
        assertTrue(node instanceof MappingNode);
        assertEquals(
                "tag:yaml.org,2002:org.yaml.snakeyaml.composer.ComposerImplTest$BeanToCompose",
                node.getTag().getValue());
        assertEquals(NodeId.mapping, node.getNodeId());
        assertEquals(Object.class, node.getType());
    }
View Full Code Here

    // Code borrowed from snakeyaml (http://code.google.com/p/snakeyaml/source/browse/src/test/java/org/yaml/snakeyaml/issues/issue60/SkipBeanTest.java)
    @Override
    protected NodeTuple representJavaBeanProperty(Object javaBean, Property property, Object propertyValue, Tag customTag) {
        NodeTuple tuple = super.representJavaBeanProperty(javaBean, property, propertyValue, customTag);
        Node valueNode = tuple.getValueNode();
        if (valueNode instanceof CollectionNode) {
            // Removed null check
            if (Tag.SEQ.equals(valueNode.getTag())) {
                SequenceNode seq = (SequenceNode) valueNode;
                if (seq.getValue().isEmpty()) {
                    return null; // skip empty lists
                }
            }
            if (Tag.MAP.equals(valueNode.getTag())) {
                MappingNode seq = (MappingNode) valueNode;
                if (seq.getValue().isEmpty()) {
                    return null; // skip empty maps
                }
            }
View Full Code Here

    @SuppressWarnings("rawtypes")
    @Override
    public TupleRule<?, ?> getRuleForTuple(NodeTuple nodeTuple)
    {
        Node keyNode = nodeTuple.getKeyNode();
        String paramName;
        if (keyNode instanceof ScalarNode)
        {
            paramName = ((ScalarNode) keyNode).getValue();
            if (paramName.equals("version"))
            {
                errors.add(ValidationResult.createErrorResult("'" + paramName + "'" + " can not be declared, it is a reserved URI parameter.", keyNode));
            }
            else if (getUriRule().getParameters().contains(paramName))
            {
                return new ParamRule(paramName, getNodeRuleFactory());
            }
            else
            {
                errors.add(ValidationResult.createErrorResult("Parameter '" + paramName + "' not declared in baseUri", keyNode));
            }
        }
        else
        {
            errors.add(ValidationResult.createErrorResult("Invalid element", keyNode));
        }

        return new DefaultTupleRule(keyNode.toString(), new DefaultTupleHandler(), getNodeRuleFactory());
    }
View Full Code Here

        {
            //already resolved
            return node;
        }

        Node includeNode;
        if (node.getNodeId() != scalar)
        {
            nodeHandler.onCustomTagError(INCLUDE_TAG, node, "Include cannot be non-scalar");
            return mockInclude(node);
        }
        ScalarNode scalarNode = (ScalarNode) node;
        String resourceName = contextPath.resolveAbsolutePath(scalarNode.getValue());
        InputStream inputStream = resourceLoader.fetchResource(resourceName);

        if (inputStream == null)
        {
            nodeHandler.onCustomTagError(INCLUDE_TAG, node, "Include cannot be resolved " + resourceName);
            return mockInclude(node);
        }
        else if (resourceName.endsWith(".raml") || resourceName.endsWith(".yaml") || resourceName.endsWith(".yml"))
        {
            Yaml yamlParser = new Yaml();
            includeNode = yamlParser.compose(new InputStreamReader(inputStream));
        }
        else //scalar value
        {
            //String newValue = IOUtils.toString(inputStream);
            String newValue = StreamUtils.toString(inputStream);
            includeNode = new IncludeScalarNode(resourceName, newValue, scalarNode);
        }
        if (includeNode == null)
        {
            nodeHandler.onCustomTagError(INCLUDE_TAG, node, "Include file is empty " + resourceName);
            return mockInclude(node);
        }
        //retag node with included resource info
        String markInfo = node.getStartMark().getLine() + SEPARATOR + node.getStartMark().getColumn()
                          + SEPARATOR + node.getEndMark().getColumn();
        includeNode.setTag(new Tag(INCLUDE_APPLIED_TAG + resourceName + SEPARATOR + markInfo));
        return includeNode;
    }
View Full Code Here

        long startTime = currentTimeMillis();

        try
        {
            Yaml yamlParser = new Yaml();
            Node root = yamlParser.compose(content);
            if (root != null && root.getNodeId() == mapping)
            {
                validate((MappingNode) root, resourceLocation);
            }
            else
            {
View Full Code Here

TOP

Related Classes of org.yaml.snakeyaml.nodes.Node

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.