Package org.yaml.snakeyaml.nodes

Examples of org.yaml.snakeyaml.nodes.ScalarNode


            final MappingNode mappingNode = (MappingNode) yaml;
            debug("writing map with size: {}", mappingNode.getValue().size());
            for (NodeTuple tuple : mappingNode.getValue()) {
                Node node = new Node();
                if (tuple.getKeyNode() instanceof ScalarNode) {
                    ScalarNode scalarNode = (ScalarNode) tuple.getKeyNode();
                    String keyValue = scalarNode.getValue();
                    debug("keyValue: {}", keyValue);
                    node.setName(keyValue);
                }
                parent.addChild(node);

                build(tuple.getValueNode(), node);
            }
        } else if (yaml instanceof SequenceNode) {
            SequenceNode sequenceNode = (SequenceNode) yaml;
            debug("writing sequence with size: {}", sequenceNode.getValue().size());
            List<Object> list = Lists.newArrayList();
            for (org.yaml.snakeyaml.nodes.Node node : sequenceNode.getValue()) {
                if (node instanceof ScalarNode) {
                    list.add(getScalarValue((ScalarNode) node));
                } else {
                    YamlProperties conf = new YamlProperties();
                    Node root = new Node();
                    conf.setRootNode(root);
                    build(node, root);
                    list.add(conf);
                }
            }
            parent.setValue(list);
        } else if (yaml instanceof ScalarNode) {
            final ScalarNode scalarNode = (ScalarNode) yaml;
            parent.setValue(getScalarValue(scalarNode));
        }
    }
View Full Code Here


    protected Node representScalar(Tag tag, String value, Character style) {
        if (style == null) {
            style = this.defaultScalarStyle;
        }
        Node node = new ScalarNode(tag, value, null, null, style);
        return node;
    }
View Full Code Here

        }
        assertEquals(1024 * 3, longEscURI.length());
        String yaml = "!" + longEscURI + " www";

        Node node = loader.compose(new StringReader(yaml));
        ScalarNode scalar = (ScalarNode) node;
        String etalon = "!";
        for (int i = 0; i < 1024; i++) {
            etalon += "A";
        }
        assertEquals(1025, etalon.length());
        assertEquals(etalon, scalar.getTag().toString());
    }
View Full Code Here

            this.representers.put(String.class, new FlexibleRepresent());
        }

        private class FlexibleRepresent extends RepresentString {
            public Node representData(Object data) {
                ScalarNode node = (ScalarNode) super.representData(data);
                if (node.getStyle() == null) {
                    // if Plain scalar style
                    if (node.getValue().length() < 25) {
                        return node;
                    } else {
                        // Folded scalar style
                        return new ScalarNode(node.getTag(), node.getValue(), node.getStartMark(),
                                node.getEndMark(), '>');
                    }
                } else {
                    return node;
                }
            }
View Full Code Here

    }

    private void compareNodes(Node node1, Node node2) {
        assertEquals(node1.getClass(), node2.getClass());
        if (node1 instanceof ScalarNode) {
            ScalarNode scalar1 = (ScalarNode) node1;
            ScalarNode scalar2 = (ScalarNode) node2;
            assertEquals(scalar1.getTag(), scalar2.getTag());
            assertEquals(scalar1.getValue(), scalar2.getValue());
        } else {
            if (node1 instanceof SequenceNode) {
                SequenceNode seq1 = (SequenceNode) node1;
                SequenceNode seq2 = (SequenceNode) node2;
                assertEquals(seq1.getTag(), seq2.getTag());
View Full Code Here

                }
                if (property.getName().equals("description")) {
                    // if description contains ':' use folded scalar style and
                    // not single quoted scalar style
                    if (bean.getDescription().indexOf(':') > 0) {
                        ScalarNode n = (ScalarNode) standard.getValueNode();
                        return new NodeTuple(standard.getKeyNode(), new ScalarNode(n.getTag(),
                                n.getValue(), n.getStartMark(), n.getEndMark(), '>'));
                    }
                }
                return standard;
            } else {
                return super
View Full Code Here

        String yaml = "abc: 3";
        MappingNode node = (MappingNode) loader.compose(new StringReader(yaml));
        List<NodeTuple> nodes = node.getValue();
        assertEquals(1, nodes.size());
        NodeTuple pairs = nodes.get(0);
        ScalarNode key = (ScalarNode) pairs.getKeyNode();
        assertEquals(Tag.STR, key.getTag());
        assertEquals("abc", key.getValue());
        //
        ScalarNode value = (ScalarNode) pairs.getValueNode();
        assertEquals(Tag.INT, value.getTag());
        assertEquals("3", value.getValue());
        //
        assertEquals(
                "<org.yaml.snakeyaml.nodes.MappingNode (tag=tag:yaml.org,2002:map, values={ key=<org.yaml.snakeyaml.nodes.ScalarNode (tag=tag:yaml.org,2002:str, value=abc)>; value=<NodeTuple keyNode=<org.yaml.snakeyaml.nodes.ScalarNode (tag=tag:yaml.org,2002:str, value=abc)>; valueNode=<org.yaml.snakeyaml.nodes.ScalarNode (tag=tag:yaml.org,2002:int, value=3)>> })>",
                node.toString());
    }
View Full Code Here

    @SuppressWarnings("deprecation")
    public void testCompose2() {
        LoaderOptions options = new LoaderOptions();
        Yaml loader = new Yaml(options);
        String yaml = "3";
        ScalarNode node = (ScalarNode) loader.compose(new StringReader(yaml));
        assertEquals(Tag.INT, node.getTag());
        assertEquals("3", node.getValue());
        // not sure whether it should be null or 0
        assertEquals(Character.valueOf('\u0000'), node.getStyle());
        assertEquals(Object.class, node.getType());
        Mark mark = node.getStartMark();
        assertEquals(0, mark.getColumn());
        assertEquals(0, mark.getLine());
        assertEquals("'reader'", mark.getName());
        assertEquals("    3\n    ^", mark.get_snippet());
        assertEquals("<org.yaml.snakeyaml.nodes.ScalarNode (tag=tag:yaml.org,2002:int, value=3)>",
                node.toString());
    }
View Full Code Here

    }

    private class Bean1ScalarConstructor extends ConstructScalar {
        @Override
        public Object construct(Node node) {
            ScalarNode snode = (ScalarNode) node;
            if (snode.getValue().length() == 0) {
                return new Bean1();
            } else {
                return new Bean1(new Integer(snode.getValue()));
            }
        }
View Full Code Here

    private class BeanHolderScalarConstructor extends ConstructScalar {
        @Override
        public Object construct(Node node) {
            if (node.getNodeId() == NodeId.scalar) {
                ScalarNode n = (ScalarNode) node;
                String value = n.getValue();
                int i = 3;
                if (value.length() != 0) {
                    i = Integer.parseInt(value);
                }
                return new BeanHolder(new Bean1(i));
View Full Code Here

TOP

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

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.