23 | * This event follows the document's content. 24 | *
25 | */ 26 | public final class DocumentEndEvent extends Event { 27 | private final boolean explicit; 28 | 29 | public DocumentEndEvent(Mark startMark, Mark endMark, boolean explicit) { 30 | super(startMark, endMark); 31 | this.explicit = explicit; 32 | } 33 | 34 | public boolean getExplicit() { 35 | return explicit; 36 | } 37 | 38 | @Override 39 | public boolean is(Event.ID id) { 40 | return ID.DocumentEnd == id; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/constructor/ConstructorException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2008-2012, http://www.snakeyaml.org 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.yaml.snakeyaml.constructor; 17 | 18 | import org.yaml.snakeyaml.error.Mark; 19 | import org.yaml.snakeyaml.error.MarkedYAMLException; 20 | 21 | public class ConstructorException extends MarkedYAMLException { 22 | private static final long serialVersionUID = -8816339931365239910L; 23 | 24 | protected ConstructorException(String context, Mark contextMark, String problem, 25 | Mark problemMark, Throwable cause) { 26 | super(context, contextMark, problem, problemMark, cause); 27 | } 28 | 29 | protected ConstructorException(String context, Mark contextMark, String problem, 30 | Mark problemMark) { 31 | this(context, contextMark, problem, problemMark, null); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/events/SequenceStartEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2008-2012, http://www.snakeyaml.org 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.yaml.snakeyaml.events; 17 | 18 | import org.yaml.snakeyaml.error.Mark; 19 | 20 | /** 21 | * Marks the beginning of a sequence node. 22 | *23 | * This event is followed by the elements contained in the sequence, and a 24 | * {@link SequenceEndEvent}. 25 | *
26 | * 27 | * @see SequenceEndEvent 28 | */ 29 | public final class SequenceStartEvent extends CollectionStartEvent { 30 | public SequenceStartEvent(String anchor, String tag, boolean implicit, Mark startMark, 31 | Mark endMark, Boolean flowStyle) { 32 | super(anchor, tag, implicit, startMark, endMark, flowStyle); 33 | } 34 | 35 | @Override 36 | public boolean is(Event.ID id) { 37 | return ID.SequenceStart == id; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/introspector/MissingProperty.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2008-2012, http://www.snakeyaml.org 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.yaml.snakeyaml.introspector; 17 | 18 | /** 19 | * A property that does not map to a real property; this is used when {@link 20 | * PropertyUtils.setSkipMissingProperties(boolean)} is set to true. 21 | */ 22 | public class MissingProperty extends Property { 23 | 24 | public MissingProperty(String name) { 25 | super(name, Object.class); 26 | } 27 | 28 | @Override 29 | public Class>[] getActualTypeArguments() { 30 | return new Class[0]; 31 | } 32 | 33 | /** 34 | * Setter does nothing. 35 | */ 36 | @Override 37 | public void set(Object object, Object value) throws Exception { 38 | } 39 | 40 | @Override 41 | public Object get(Object object) { 42 | return object; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/events/StreamEndEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2008-2012, http://www.snakeyaml.org 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.yaml.snakeyaml.events; 17 | 18 | import org.yaml.snakeyaml.error.Mark; 19 | 20 | /** 21 | * Marks the end of a stream that might have contained multiple documents. 22 | *23 | * This event is the last event that a parser emits. Together with 24 | * {@link StreamStartEvent} (which is the first event a parser emits) they mark 25 | * the beginning and the end of a stream of documents. 26 | *
27 | *28 | * See {@link Event} for an exemplary output. 29 | *
30 | */ 31 | public final class StreamEndEvent extends Event { 32 | public StreamEndEvent(Mark startMark, Mark endMark) { 33 | super(startMark, endMark); 34 | } 35 | 36 | @Override 37 | public boolean is(Event.ID id) { 38 | return ID.StreamEnd == id; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/Dumper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2008-2012, http://www.snakeyaml.org 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.yaml.snakeyaml; 17 | 18 | import org.yaml.snakeyaml.representer.Representer; 19 | 20 | /** 21 | * @deprecated Dumper's functionality was moved to Yaml 22 | */ 23 | public final class Dumper { 24 | protected final Representer representer; 25 | protected final DumperOptions options; 26 | 27 | public Dumper(Representer representer, DumperOptions options) { 28 | this.representer = representer; 29 | this.options = options; 30 | } 31 | 32 | public Dumper(DumperOptions options) { 33 | this(new Representer(), options); 34 | } 35 | 36 | public Dumper(Representer representer) { 37 | this(representer, new DumperOptions()); 38 | } 39 | 40 | public Dumper() { 41 | this(new Representer(), new DumperOptions()); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/events/StreamStartEvent.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2008-2012, http://www.snakeyaml.org 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.yaml.snakeyaml.events; 17 | 18 | import org.yaml.snakeyaml.error.Mark; 19 | 20 | /** 21 | * Marks the start of a stream that might contain multiple documents. 22 | *23 | * This event is the first event that a parser emits. Together with 24 | * {@link StreamEndEvent} (which is the last event a parser emits) they mark the 25 | * beginning and the end of a stream of documents. 26 | *
27 | *28 | * See {@link Event} for an exemplary output. 29 | *
30 | */ 31 | public final class StreamStartEvent extends Event { 32 | 33 | public StreamStartEvent(Mark startMark, Mark endMark) { 34 | super(startMark, endMark); 35 | } 36 | 37 | @Override 38 | public boolean is(Event.ID id) { 39 | return ID.StreamStart == id; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/parser/VersionTagsTuple.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2008-2012, http://www.snakeyaml.org 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.yaml.snakeyaml.parser; 17 | 18 | import java.util.Map; 19 | 20 | import org.yaml.snakeyaml.DumperOptions.Version; 21 | 22 | /** 23 | * Store the internal state for directives 24 | */ 25 | class VersionTagsTuple { 26 | private Version version; 27 | private Maptrue for flow style, false for block
36 | * style.
37 | */
38 | public Boolean getFlowStyle() {
39 | return flowStyle;
40 | }
41 |
42 | public void setFlowStyle(Boolean flowStyle) {
43 | this.flowStyle = flowStyle;
44 | }
45 |
46 | public void setEndMark(Mark endMark) {
47 | this.endMark = endMark;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/org/yaml/snakeyaml/events/MappingStartEvent.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2008-2012, http://www.snakeyaml.org
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.yaml.snakeyaml.events;
17 |
18 | import org.yaml.snakeyaml.error.Mark;
19 |
20 | /**
21 | * Marks the beginning of a mapping node.
22 | *
23 | * This event is followed by a number of key value pairs.
24 | * The pairs are not in any particular order. However, the value always directly
25 | * follows the corresponding key.
26 | * After the key value pairs follows a {@link MappingEndEvent}.
27 | *
29 | * There must be an even number of node events between the start and end event. 30 | *
31 | * 32 | * @see MappingEndEvent 33 | */ 34 | public final class MappingStartEvent extends CollectionStartEvent { 35 | public MappingStartEvent(String anchor, String tag, boolean implicit, Mark startMark, 36 | Mark endMark, Boolean flowStyle) { 37 | super(anchor, tag, implicit, startMark, endMark, flowStyle); 38 | } 39 | 40 | @Override 41 | public boolean is(Event.ID id) { 42 | return ID.MappingStart == id; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/nodes/NodeTuple.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2008-2012, http://www.snakeyaml.org 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.yaml.snakeyaml.nodes; 17 | 18 | /** 19 | * Stores one key value pair used in a map. 20 | */ 21 | public final class NodeTuple { 22 | 23 | private Node keyNode; 24 | private Node valueNode; 25 | 26 | public NodeTuple(Node keyNode, Node valueNode) { 27 | if (keyNode == null || valueNode == null) { 28 | throw new NullPointerException("Nodes must be provided."); 29 | } 30 | this.keyNode = keyNode; 31 | this.valueNode = valueNode; 32 | } 33 | 34 | /** 35 | * Key node. 36 | */ 37 | final public Node getKeyNode() { 38 | return keyNode; 39 | } 40 | 41 | /** 42 | * Value node. 43 | * 44 | * @return value 45 | */ 46 | final public Node getValueNode() { 47 | return valueNode; 48 | } 49 | 50 | @Override 51 | public String toString() { 52 | return "
36 | * Note that {@link AliasEvent}s are by it self NodeEvents and
37 | * use this property to indicate the referenced anchor.
38 | *
39 | * @return Anchor of this node or null if no anchor is defined.
40 | */
41 | public String getAnchor() {
42 | return this.anchor;
43 | }
44 |
45 | @Override
46 | protected String getArguments() {
47 | return "anchor=" + anchor;
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/org/yaml/snakeyaml/parser/ParserException.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2008-2012, http://www.snakeyaml.org
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.yaml.snakeyaml.parser;
17 |
18 | import org.yaml.snakeyaml.error.Mark;
19 | import org.yaml.snakeyaml.error.MarkedYAMLException;
20 |
21 | /**
22 | * Exception thrown by the {@link Parser} implementations in case of malformed
23 | * input.
24 | */
25 | public class ParserException extends MarkedYAMLException {
26 | private static final long serialVersionUID = -2349253802798398038L;
27 |
28 | /**
29 | * Constructs an instance.
30 | *
31 | * @param context
32 | * Part of the input document in which vicinity the problem
33 | * occurred.
34 | * @param contextMark
35 | * Position of the context within the document.
36 | * @param problem
37 | * Part of the input document that caused the problem.
38 | * @param problemMark
39 | * Position of the problem. within the document.
40 | */
41 | public ParserException(String context, Mark contextMark, String problem, Mark problemMark) {
42 | super(context, contextMark, problem, problemMark, null, null);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/org/yaml/snakeyaml/reader/ReaderException.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2008-2012, http://www.snakeyaml.org
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.yaml.snakeyaml.reader;
17 |
18 | import org.yaml.snakeyaml.error.YAMLException;
19 |
20 | public class ReaderException extends YAMLException {
21 | private static final long serialVersionUID = 8710781187529689083L;
22 | private final String name;
23 | private final char character;
24 | private final int position;
25 |
26 | public ReaderException(String name, int position, char character, String message) {
27 | super(message);
28 | this.name = name;
29 | this.character = character;
30 | this.position = position;
31 | }
32 |
33 | public String getName() {
34 | return name;
35 | }
36 |
37 | public char getCharacter() {
38 | return character;
39 | }
40 |
41 | public int getPosition() {
42 | return position;
43 | }
44 |
45 | @Override
46 | public String toString() {
47 | return "unacceptable character '" + character + "' (0x"
48 | + Integer.toHexString((int) character).toUpperCase() + ") " + getMessage()
49 | + "\nin \"" + name + "\", position " + position;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/src/org/yaml/snakeyaml/tokens/ScalarToken.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2008-2012, http://www.snakeyaml.org
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.yaml.snakeyaml.tokens;
17 |
18 | import org.yaml.snakeyaml.error.Mark;
19 |
20 | public final class ScalarToken extends Token {
21 | private final String value;
22 | private final boolean plain;
23 | private final char style;
24 |
25 | public ScalarToken(String value, Mark startMark, Mark endMark, boolean plain) {
26 | this(value, plain, startMark, endMark, (char) 0);
27 | }
28 |
29 | public ScalarToken(String value, boolean plain, Mark startMark, Mark endMark, char style) {
30 | super(startMark, endMark);
31 | this.value = value;
32 | this.plain = plain;
33 | this.style = style;
34 | }
35 |
36 | public boolean getPlain() {
37 | return this.plain;
38 | }
39 |
40 | public String getValue() {
41 | return this.value;
42 | }
43 |
44 | public char getStyle() {
45 | return this.style;
46 | }
47 |
48 | @Override
49 | protected String getArguments() {
50 | return "value=" + value + ", plain=" + plain + ", style=" + style;
51 | }
52 |
53 | @Override
54 | public Token.ID getTokenId() {
55 | return ID.Scalar;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/org/yaml/snakeyaml/introspector/FieldProperty.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2008-2012, http://www.snakeyaml.org
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.yaml.snakeyaml.introspector;
17 |
18 | import java.lang.reflect.Field;
19 |
20 | import org.yaml.snakeyaml.error.YAMLException;
21 |
22 | /**
23 | *
24 | * A FieldProperty is a Property which is accessed as
25 | * a field, without going through accessor methods (setX, getX). The field may
26 | * have any scope (public, package, protected, private).
27 | *
construct(Node node) for the provided Node
48 | */
49 | public void construct2ndStep(Node node, Object object);
50 | }
51 |
--------------------------------------------------------------------------------
/src/org/yaml/snakeyaml/tokens/DirectiveToken.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (c) 2008-2012, http://www.snakeyaml.org
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License.
15 | */
16 | package org.yaml.snakeyaml.tokens;
17 |
18 | import java.util.List;
19 |
20 | import org.yaml.snakeyaml.error.Mark;
21 | import org.yaml.snakeyaml.error.YAMLException;
22 |
23 | public final class DirectiveToken23 | * Helper class for {@link ScannerImpl}. 24 | *
25 | * 26 | * @see ScannerImpl 27 | */ 28 | final class SimpleKey { 29 | private int tokenNumber; 30 | private boolean required; 31 | private int index; 32 | private int line; 33 | private int column; 34 | private Mark mark; 35 | 36 | public SimpleKey(int tokenNumber, boolean required, int index, int line, int column, Mark mark) { 37 | this.tokenNumber = tokenNumber; 38 | this.required = required; 39 | this.index = index; 40 | this.line = line; 41 | this.column = column; 42 | this.mark = mark; 43 | } 44 | 45 | public int getTokenNumber() { 46 | return this.tokenNumber; 47 | } 48 | 49 | public int getColumn() { 50 | return this.column; 51 | } 52 | 53 | public Mark getMark() { 54 | return mark; 55 | } 56 | 57 | public int getIndex() { 58 | return index; 59 | } 60 | 61 | public int getLine() { 62 | return line; 63 | } 64 | 65 | public boolean isRequired() { 66 | return required; 67 | } 68 | 69 | @Override 70 | public String toString() { 71 | return "SimpleKey - tokenNumber=" + tokenNumber + " required=" + required + " index=" 72 | + index + " line=" + line + " column=" + column; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/nodes/SequenceNode.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2008-2012, http://www.snakeyaml.org 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.yaml.snakeyaml.nodes; 17 | 18 | import java.util.List; 19 | 20 | import org.yaml.snakeyaml.error.Mark; 21 | 22 | /** 23 | * Represents a sequence. 24 | *25 | * A sequence is a ordered collection of nodes. 26 | *
27 | */ 28 | public class SequenceNode extends CollectionNode { 29 | final private List23 | * The parser and the scanner form together the 'Parse' step in the loading 24 | * process (see chapter 3.1 of the YAML 25 | * Specification). 26 | *
27 | * 28 | * @see org.yaml.snakeyaml.events.Event 29 | */ 30 | public interface Parser { 31 | 32 | /** 33 | * Check if the next event is one of the given type. 34 | * 35 | * @param choice 36 | * Event ID. 37 | * @returntrue if the next event can be assigned to a variable
38 | * of the given type. Returns false if no more events
39 | * are available.
40 | * @throws ParserException
41 | * Thrown in case of malformed input.
42 | */
43 | public boolean checkEvent(Event.ID choice);
44 |
45 | /**
46 | * Return the next event, but do not delete it from the stream.
47 | *
48 | * @return The event that will be returned on the next call to
49 | * {@link #getEvent}
50 | * @throws ParserException
51 | * Thrown in case of malformed input.
52 | */
53 | public Event peekEvent();
54 |
55 | /**
56 | * Returns the next event.
57 | * 58 | * The event will be removed from the stream. 59 | *
60 | * 61 | * @throws ParserException 62 | * Thrown in case of malformed input. 63 | */ 64 | public Event getEvent(); 65 | } 66 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/events/Event.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2008-2012, http://www.snakeyaml.org 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.yaml.snakeyaml.events; 17 | 18 | import org.yaml.snakeyaml.error.Mark; 19 | 20 | /** 21 | * Basic unit of output from a {@link org.yaml.snakeyaml.parser.Parser} or input 22 | * of a {@link org.yaml.snakeyaml.emitter.Emitter}. 23 | */ 24 | public abstract class Event { 25 | public enum ID { 26 | Alias, DocumentEnd, DocumentStart, MappingEnd, MappingStart, Scalar, SequenceEnd, SequenceStart, StreamEnd, StreamStart 27 | } 28 | 29 | private final Mark startMark; 30 | private final Mark endMark; 31 | 32 | public Event(Mark startMark, Mark endMark) { 33 | this.startMark = startMark; 34 | this.endMark = endMark; 35 | } 36 | 37 | public String toString() { 38 | return "<" + this.getClass().getName() + "(" + getArguments() + ")>"; 39 | } 40 | 41 | public Mark getStartMark() { 42 | return startMark; 43 | } 44 | 45 | public Mark getEndMark() { 46 | return endMark; 47 | } 48 | 49 | /** 50 | * @see "__repr__ for Event in PyYAML" 51 | */ 52 | protected String getArguments() { 53 | return ""; 54 | } 55 | 56 | public abstract boolean is(Event.ID id); 57 | 58 | /* 59 | * for tests only 60 | */ 61 | @Override 62 | public boolean equals(Object obj) { 63 | if (obj instanceof Event) { 64 | return toString().equals(obj.toString()); 65 | } else { 66 | return false; 67 | } 68 | } 69 | 70 | /* 71 | * for tests only 72 | */ 73 | @Override 74 | public int hashCode() { 75 | return toString().hashCode(); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/scanner/Scanner.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2008-2012, http://www.snakeyaml.org 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.yaml.snakeyaml.scanner; 17 | 18 | import org.yaml.snakeyaml.tokens.Token; 19 | 20 | /** 21 | * This interface represents an input stream of {@link Token Tokens}. 22 | *23 | * The parser and the scanner form together the 'Parse' step in the loading 24 | * process (see chapter 3.1 of the YAML 25 | * Specification). 26 | *
27 | * 28 | * @see org.yaml.snakeyaml.tokens.Token 29 | */ 30 | public interface Scanner { 31 | 32 | /** 33 | * Check if the next token is one of the given types. 34 | * 35 | * @param choices 36 | * token IDs. 37 | * @returntrue if the next token can be assigned to a variable
38 | * of at least one of the given types. Returns false if
39 | * no more tokens are available.
40 | * @throws ScannerException
41 | * Thrown in case of malformed input.
42 | */
43 | boolean checkToken(Token.ID... choices);
44 |
45 | /**
46 | * Return the next token, but do not delete it from the stream.
47 | *
48 | * @return The token that will be returned on the next call to
49 | * {@link #getToken}
50 | * @throws ScannerException
51 | * Thrown in case of malformed input.
52 | */
53 | Token peekToken();
54 |
55 | /**
56 | * Returns the next token.
57 | * 58 | * The token will be removed from the stream. 59 | *
60 | * 61 | * @throws ScannerException 62 | * Thrown in case of malformed input. 63 | */ 64 | Token getToken(); 65 | } 66 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/nodes/ScalarNode.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) 2008-2012, http://www.snakeyaml.org 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package org.yaml.snakeyaml.nodes; 17 | 18 | import org.yaml.snakeyaml.error.Mark; 19 | 20 | /** 21 | * Represents a scalar node. 22 | *23 | * Scalar nodes form the leaves in the node graph. 24 | *
25 | */ 26 | public class ScalarNode extends Node { 27 | private Character style; 28 | private String value; 29 | 30 | public ScalarNode(Tag tag, String value, Mark startMark, Mark endMark, Character style) { 31 | this(tag, true, value, startMark, endMark, style); 32 | } 33 | 34 | public ScalarNode(Tag tag, boolean resolved, String value, Mark startMark, Mark endMark, 35 | Character style) { 36 | super(tag, startMark, endMark); 37 | if (value == null) { 38 | throw new NullPointerException("value in a Node is required."); 39 | } 40 | this.value = value; 41 | this.style = style; 42 | this.resolved = resolved; 43 | } 44 | 45 | /** 46 | * Get scalar style of this node. 47 | * 48 | * @see org.yaml.snakeyaml.events.ScalarEvent 49 | * @see Chapter 9. Scalar 50 | * Styles 51 | */ 52 | public Character getStyle() { 53 | return style; 54 | } 55 | 56 | @Override 57 | public NodeId getNodeId() { 58 | return NodeId.scalar; 59 | } 60 | 61 | /** 62 | * Value of this scalar. 63 | * 64 | * @return Scalar's value. 65 | */ 66 | public String getValue() { 67 | return value; 68 | } 69 | 70 | public String toString() { 71 | return "<" + this.getClass().getName() + " (tag=" + getTag() + ", value=" + getValue() 72 | + ")>"; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/ParseDS.java: -------------------------------------------------------------------------------- 1 | 2 | import java.io.File; 3 | import java.io.FileInputStream; 4 | import java.io.FileNotFoundException; 5 | import java.io.InputStream; 6 | import java.util.ArrayList; 7 | import java.util.HashMap; 8 | import java.util.Map; 9 | import org.yaml.snakeyaml.Yaml; 10 | 11 | public final class ParseDS { 12 | // yaml DS map 13 | private final Map