├── NQTVITCHspecification.pdf ├── .gitignore ├── src ├── org │ └── yaml │ │ └── snakeyaml │ │ ├── nodes │ │ ├── NodeId.java │ │ ├── AnchorNode.java │ │ ├── CollectionNode.java │ │ ├── NodeTuple.java │ │ ├── SequenceNode.java │ │ ├── ScalarNode.java │ │ ├── MappingNode.java │ │ ├── Node.java │ │ └── Tag.java │ │ ├── emitter │ │ ├── Emitable.java │ │ ├── EmitterState.java │ │ ├── EmitterException.java │ │ └── ScalarAnalysis.java │ │ ├── introspector │ │ ├── BeanAccess.java │ │ ├── MissingProperty.java │ │ ├── FieldProperty.java │ │ ├── Property.java │ │ ├── MethodProperty.java │ │ ├── GenericProperty.java │ │ └── PropertyUtils.java │ │ ├── serializer │ │ └── SerializerException.java │ │ ├── tokens │ │ ├── KeyToken.java │ │ ├── ValueToken.java │ │ ├── BlockEndToken.java │ │ ├── FlowEntryToken.java │ │ ├── StreamEndToken.java │ │ ├── BlockEntryToken.java │ │ ├── DocumentEndToken.java │ │ ├── StreamStartToken.java │ │ ├── DocumentStartToken.java │ │ ├── FlowMappingEndToken.java │ │ ├── FlowSequenceEndToken.java │ │ ├── BlockMappingStartToken.java │ │ ├── FlowMappingStartToken.java │ │ ├── FlowSequenceStartToken.java │ │ ├── BlockSequenceStartToken.java │ │ ├── TagTuple.java │ │ ├── AliasToken.java │ │ ├── AnchorToken.java │ │ ├── TagToken.java │ │ ├── ScalarToken.java │ │ ├── DirectiveToken.java │ │ └── Token.java │ │ ├── events │ │ ├── CollectionEndEvent.java │ │ ├── AliasEvent.java │ │ ├── MappingEndEvent.java │ │ ├── SequenceEndEvent.java │ │ ├── DocumentEndEvent.java │ │ ├── SequenceStartEvent.java │ │ ├── StreamEndEvent.java │ │ ├── StreamStartEvent.java │ │ ├── MappingStartEvent.java │ │ ├── NodeEvent.java │ │ ├── ImplicitTuple.java │ │ ├── Event.java │ │ ├── CollectionStartEvent.java │ │ ├── DocumentStartEvent.java │ │ └── ScalarEvent.java │ │ ├── parser │ │ ├── Production.java │ │ ├── VersionTagsTuple.java │ │ ├── ParserException.java │ │ └── Parser.java │ │ ├── error │ │ ├── YAMLException.java │ │ ├── MarkedYAMLException.java │ │ └── Mark.java │ │ ├── composer │ │ └── ComposerException.java │ │ ├── representer │ │ ├── Represent.java │ │ └── BaseRepresenter.java │ │ ├── util │ │ ├── ArrayStack.java │ │ └── UriEncoder.java │ │ ├── Loader.java │ │ ├── resolver │ │ ├── ResolverTuple.java │ │ ├── RagelMachine.rl │ │ └── Resolver.java │ │ ├── LoaderOptions.java │ │ ├── constructor │ │ ├── Dumper.java │ │ ├── extensions │ │ └── compactnotation │ │ │ ├── PackageCompactConstructor.java │ │ │ └── CompactData.java │ │ ├── reader │ │ ├── ReaderException.java │ │ ├── UnicodeReader.java │ │ └── StreamReader.java │ │ ├── scanner │ │ ├── SimpleKey.java │ │ ├── Scanner.java │ │ ├── ScannerException.java │ │ └── Constant.java │ │ ├── JavaBeanLoader.java │ │ ├── external │ │ └── com │ │ │ └── google │ │ │ └── gdata │ │ │ └── util │ │ │ └── common │ │ │ └── base │ │ │ └── Escaper.java │ │ ├── JavaBeanDumper.java │ │ └── TypeDescription.java ├── ParseDS.java ├── Parse.java └── Parsers.java └── README.md /NQTVITCHspecification.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Amay22/NASDAQ-ITCH-5.0-Parser/HEAD/NQTVITCHspecification.pdf -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | wiki/ 2 | *.wiki 3 | 4 | .DS_Store 5 | 6 | manifest.mf 7 | 8 | nbproject 9 | 10 | build.xml 11 | 12 | build/ 13 | 14 | 08022014.NASDAQ_ITCH50 15 | 16 | 09022014.NASDAQ_ITCH50 17 | 18 | *.class 19 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/nodes/NodeId.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 | * Enum for the three basic YAML types: scalar, sequence and mapping. 20 | */ 21 | public enum NodeId { 22 | scalar, sequence, mapping, anchor; 23 | } 24 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/emitter/Emitable.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.emitter; 17 | 18 | import java.io.IOException; 19 | 20 | import org.yaml.snakeyaml.events.Event; 21 | 22 | public interface Emitable { 23 | public void emit(Event event) throws IOException; 24 | } 25 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/emitter/EmitterState.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.emitter; 17 | 18 | import java.io.IOException; 19 | 20 | /** 21 | * Python's methods are first class object. Java needs a class. 22 | */ 23 | interface EmitterState { 24 | void expect() throws IOException; 25 | } -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/emitter/EmitterException.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.emitter; 17 | 18 | import org.yaml.snakeyaml.error.YAMLException; 19 | 20 | public class EmitterException extends YAMLException { 21 | private static final long serialVersionUID = -8280070025452995908L; 22 | 23 | public EmitterException(String msg) { 24 | super(msg); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/introspector/BeanAccess.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 | * Control instance variables. 20 | */ 21 | public enum BeanAccess { 22 | /** use JavaBean properties and public fields */ 23 | DEFAULT, 24 | 25 | /** use all declared fields (including inherited) */ 26 | FIELD, 27 | 28 | /** reserved */ 29 | PROPERTY; 30 | } -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/serializer/SerializerException.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.serializer; 17 | 18 | import org.yaml.snakeyaml.error.YAMLException; 19 | 20 | public class SerializerException extends YAMLException { 21 | private static final long serialVersionUID = 2632638197498912433L; 22 | 23 | public SerializerException(String message) { 24 | super(message); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/tokens/KeyToken.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 KeyToken extends Token { 21 | 22 | public KeyToken(Mark startMark, Mark endMark) { 23 | super(startMark, endMark); 24 | } 25 | 26 | @Override 27 | public Token.ID getTokenId() { 28 | return ID.Key; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/events/CollectionEndEvent.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 | * Base class for the end events of the collection nodes. 22 | */ 23 | public abstract class CollectionEndEvent extends Event { 24 | 25 | public CollectionEndEvent(Mark startMark, Mark endMark) { 26 | super(startMark, endMark); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/parser/Production.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.events.Event; 19 | 20 | /** 21 | * Helper for {@link ParserImpl}. A grammar rule to apply given the symbols on 22 | * top of its stack and the next input token 23 | * 24 | * @see http://en.wikipedia.org/wiki/LL_parser 25 | */ 26 | interface Production { 27 | public Event produce(); 28 | } 29 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/tokens/ValueToken.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 ValueToken extends Token { 21 | 22 | public ValueToken(Mark startMark, Mark endMark) { 23 | super(startMark, endMark); 24 | } 25 | 26 | @Override 27 | public Token.ID getTokenId() { 28 | return ID.Value; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/tokens/BlockEndToken.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 BlockEndToken extends Token { 21 | 22 | public BlockEndToken(Mark startMark, Mark endMark) { 23 | super(startMark, endMark); 24 | } 25 | 26 | @Override 27 | public Token.ID getTokenId() { 28 | return ID.BlockEnd; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/tokens/FlowEntryToken.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 FlowEntryToken extends Token { 21 | 22 | public FlowEntryToken(Mark startMark, Mark endMark) { 23 | super(startMark, endMark); 24 | } 25 | 26 | @Override 27 | public Token.ID getTokenId() { 28 | return ID.FlowEntry; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/tokens/StreamEndToken.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 StreamEndToken extends Token { 21 | 22 | public StreamEndToken(Mark startMark, Mark endMark) { 23 | super(startMark, endMark); 24 | } 25 | 26 | @Override 27 | public Token.ID getTokenId() { 28 | return ID.StreamEnd; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/tokens/BlockEntryToken.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 BlockEntryToken extends Token { 21 | 22 | public BlockEntryToken(Mark startMark, Mark endMark) { 23 | super(startMark, endMark); 24 | } 25 | 26 | @Override 27 | public Token.ID getTokenId() { 28 | return ID.BlockEntry; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/tokens/DocumentEndToken.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 DocumentEndToken extends Token { 21 | 22 | public DocumentEndToken(Mark startMark, Mark endMark) { 23 | super(startMark, endMark); 24 | } 25 | 26 | @Override 27 | public Token.ID getTokenId() { 28 | return ID.DocumentEnd; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/tokens/StreamStartToken.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 StreamStartToken extends Token { 21 | 22 | public StreamStartToken(Mark startMark, Mark endMark) { 23 | super(startMark, endMark); 24 | } 25 | 26 | @Override 27 | public Token.ID getTokenId() { 28 | return ID.StreamStart; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/tokens/DocumentStartToken.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 DocumentStartToken extends Token { 21 | 22 | public DocumentStartToken(Mark startMark, Mark endMark) { 23 | super(startMark, endMark); 24 | } 25 | 26 | @Override 27 | public Token.ID getTokenId() { 28 | return ID.DocumentStart; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/tokens/FlowMappingEndToken.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 FlowMappingEndToken extends Token { 21 | 22 | public FlowMappingEndToken(Mark startMark, Mark endMark) { 23 | super(startMark, endMark); 24 | } 25 | 26 | @Override 27 | public Token.ID getTokenId() { 28 | return ID.FlowMappingEnd; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/tokens/FlowSequenceEndToken.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 FlowSequenceEndToken extends Token { 21 | 22 | public FlowSequenceEndToken(Mark startMark, Mark endMark) { 23 | super(startMark, endMark); 24 | } 25 | 26 | @Override 27 | public Token.ID getTokenId() { 28 | return ID.FlowSequenceEnd; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/tokens/BlockMappingStartToken.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 BlockMappingStartToken extends Token { 21 | 22 | public BlockMappingStartToken(Mark startMark, Mark endMark) { 23 | super(startMark, endMark); 24 | } 25 | 26 | @Override 27 | public Token.ID getTokenId() { 28 | return ID.BlockMappingStart; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/tokens/FlowMappingStartToken.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 FlowMappingStartToken extends Token { 21 | 22 | public FlowMappingStartToken(Mark startMark, Mark endMark) { 23 | super(startMark, endMark); 24 | } 25 | 26 | @Override 27 | public Token.ID getTokenId() { 28 | return ID.FlowMappingStart; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/tokens/FlowSequenceStartToken.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 FlowSequenceStartToken extends Token { 21 | 22 | public FlowSequenceStartToken(Mark startMark, Mark endMark) { 23 | super(startMark, endMark); 24 | } 25 | 26 | @Override 27 | public Token.ID getTokenId() { 28 | return ID.FlowSequenceStart; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/tokens/BlockSequenceStartToken.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 BlockSequenceStartToken extends Token { 21 | 22 | public BlockSequenceStartToken(Mark startMark, Mark endMark) { 23 | super(startMark, endMark); 24 | } 25 | 26 | @Override 27 | public Token.ID getTokenId() { 28 | return ID.BlockSequenceStart; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/events/AliasEvent.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 inclusion of a previously anchored node. 22 | */ 23 | public final class AliasEvent extends NodeEvent { 24 | public AliasEvent(String anchor, Mark startMark, Mark endMark) { 25 | super(anchor, startMark, endMark); 26 | } 27 | 28 | @Override 29 | public boolean is(Event.ID id) { 30 | return ID.Alias == id; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/error/YAMLException.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.error; 17 | 18 | public class YAMLException extends RuntimeException { 19 | private static final long serialVersionUID = -4738336175050337570L; 20 | 21 | public YAMLException(String message) { 22 | super(message); 23 | } 24 | 25 | public YAMLException(Throwable cause) { 26 | super(cause); 27 | } 28 | 29 | public YAMLException(String message, Throwable cause) { 30 | super(message, cause); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/composer/ComposerException.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.composer; 17 | 18 | import org.yaml.snakeyaml.error.Mark; 19 | import org.yaml.snakeyaml.error.MarkedYAMLException; 20 | 21 | public class ComposerException extends MarkedYAMLException { 22 | private static final long serialVersionUID = 2146314636913113935L; 23 | 24 | protected ComposerException(String context, Mark contextMark, String problem, Mark problemMark) { 25 | super(context, contextMark, problem, problemMark); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/nodes/AnchorNode.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 | public class AnchorNode extends Node { 19 | 20 | private Node realNode; 21 | 22 | public AnchorNode(Node realNode) { 23 | super(realNode.getTag(), realNode.getStartMark(), realNode.getEndMark()); 24 | this.realNode = realNode; 25 | } 26 | 27 | @Override 28 | public NodeId getNodeId() { 29 | return NodeId.anchor; 30 | } 31 | 32 | public Node getRealNode() { 33 | return realNode; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/events/MappingEndEvent.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 mapping node. 22 | * 23 | * @see MappingStartEvent 24 | */ 25 | public final class MappingEndEvent extends CollectionEndEvent { 26 | 27 | public MappingEndEvent(Mark startMark, Mark endMark) { 28 | super(startMark, endMark); 29 | } 30 | 31 | @Override 32 | public boolean is(Event.ID id) { 33 | return ID.MappingEnd == id; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/events/SequenceEndEvent.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 sequence. 22 | * 23 | * @see SequenceStartEvent 24 | */ 25 | public final class SequenceEndEvent extends CollectionEndEvent { 26 | 27 | public SequenceEndEvent(Mark startMark, Mark endMark) { 28 | super(startMark, endMark); 29 | } 30 | 31 | @Override 32 | public boolean is(Event.ID id) { 33 | return ID.SequenceEnd == id; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/tokens/TagTuple.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 | public final class TagTuple { 19 | private final String handle; 20 | private final String suffix; 21 | 22 | public TagTuple(String handle, String suffix) { 23 | if (suffix == null) { 24 | throw new NullPointerException("Suffix must be provided."); 25 | } 26 | this.handle = handle; 27 | this.suffix = suffix; 28 | } 29 | 30 | public String getHandle() { 31 | return handle; 32 | } 33 | 34 | public String getSuffix() { 35 | return suffix; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/representer/Represent.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.representer; 17 | 18 | import org.yaml.snakeyaml.nodes.Node; 19 | 20 | /** 21 | * Create a Node Graph out of the provided Native Data Structure (Java 22 | * instance). 23 | * 24 | * @see Chapter 3. Processing YAML 25 | * Information 26 | */ 27 | public interface Represent { 28 | /** 29 | * Create a Node 30 | * 31 | * @param data 32 | * the instance to represent 33 | * @return Node to dump 34 | */ 35 | public Node representData(Object data); 36 | } 37 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/util/ArrayStack.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.util; 17 | 18 | import java.util.ArrayList; 19 | 20 | public class ArrayStack { 21 | private ArrayList stack; 22 | 23 | public ArrayStack(int initSize) { 24 | stack = new ArrayList(initSize); 25 | } 26 | 27 | public void push(T obj) { 28 | stack.add(obj); 29 | } 30 | 31 | public T pop() { 32 | return stack.remove(stack.size() - 1); 33 | } 34 | 35 | public boolean isEmpty() { 36 | return stack.isEmpty(); 37 | } 38 | 39 | public void clear() { 40 | stack.clear(); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/Loader.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.constructor.BaseConstructor; 19 | import org.yaml.snakeyaml.constructor.Constructor; 20 | import org.yaml.snakeyaml.resolver.Resolver; 21 | 22 | /** 23 | * @deprecated Loader's functionality was moved to Yaml 24 | */ 25 | public final class Loader { 26 | protected final BaseConstructor constructor; 27 | protected Resolver resolver; 28 | 29 | public Loader(BaseConstructor constructor) { 30 | super(); 31 | this.constructor = constructor; 32 | } 33 | 34 | public Loader() { 35 | this(new Constructor()); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/tokens/AliasToken.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 AliasToken extends Token { 21 | private final String value; 22 | 23 | public AliasToken(String value, Mark startMark, Mark endMark) { 24 | super(startMark, endMark); 25 | this.value = value; 26 | } 27 | 28 | public String getValue() { 29 | return this.value; 30 | } 31 | 32 | @Override 33 | protected String getArguments() { 34 | return "value=" + value; 35 | } 36 | 37 | @Override 38 | public Token.ID getTokenId() { 39 | return ID.Alias; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/tokens/AnchorToken.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 AnchorToken extends Token { 21 | private final String value; 22 | 23 | public AnchorToken(String value, Mark startMark, Mark endMark) { 24 | super(startMark, endMark); 25 | this.value = value; 26 | } 27 | 28 | public String getValue() { 29 | return this.value; 30 | } 31 | 32 | @Override 33 | protected String getArguments() { 34 | return "value=" + value; 35 | } 36 | 37 | @Override 38 | public Token.ID getTokenId() { 39 | return ID.Anchor; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/resolver/ResolverTuple.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.resolver; 17 | 18 | import java.util.regex.Pattern; 19 | 20 | import org.yaml.snakeyaml.nodes.Tag; 21 | 22 | final class ResolverTuple { 23 | private final Tag tag; 24 | private final Pattern regexp; 25 | 26 | public ResolverTuple(Tag tag, Pattern regexp) { 27 | this.tag = tag; 28 | this.regexp = regexp; 29 | } 30 | 31 | public Tag getTag() { 32 | return tag; 33 | } 34 | 35 | public Pattern getRegexp() { 36 | return regexp; 37 | } 38 | 39 | @Override 40 | public String toString() { 41 | return "Tuple tag=" + tag + " regexp=" + regexp; 42 | } 43 | } -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/LoaderOptions.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 | /** 19 | * @deprecated 20 | */ 21 | public class LoaderOptions { 22 | private TypeDescription rootTypeDescription; 23 | 24 | public LoaderOptions() { 25 | this(new TypeDescription(Object.class)); 26 | } 27 | 28 | public LoaderOptions(TypeDescription rootTypeDescription) { 29 | this.rootTypeDescription = rootTypeDescription; 30 | } 31 | 32 | public TypeDescription getRootTypeDescription() { 33 | return rootTypeDescription; 34 | } 35 | 36 | public void setRootTypeDescription(TypeDescription rootTypeDescription) { 37 | this.rootTypeDescription = rootTypeDescription; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/tokens/TagToken.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 TagToken extends Token { 21 | private final TagTuple value; 22 | 23 | public TagToken(TagTuple value, Mark startMark, Mark endMark) { 24 | super(startMark, endMark); 25 | this.value = value; 26 | } 27 | 28 | public TagTuple getValue() { 29 | return this.value; 30 | } 31 | 32 | @Override 33 | protected String getArguments() { 34 | return "value=[" + value.getHandle() + ", " + value.getSuffix() + "]"; 35 | } 36 | 37 | @Override 38 | public Token.ID getTokenId() { 39 | return ID.Tag; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/events/DocumentEndEvent.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 document. 22 | *

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 Map tags; 28 | 29 | public VersionTagsTuple(Version version, Map tags) { 30 | this.version = version; 31 | this.tags = tags; 32 | } 33 | 34 | public Version getVersion() { 35 | return version; 36 | } 37 | 38 | public Map getTags() { 39 | return tags; 40 | } 41 | 42 | @Override 43 | public String toString() { 44 | return String.format("VersionTagsTuple<%s, %s>", version, tags); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/extensions/compactnotation/PackageCompactConstructor.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.extensions.compactnotation; 17 | 18 | public class PackageCompactConstructor extends CompactConstructor { 19 | private String packageName; 20 | 21 | public PackageCompactConstructor(String packageName) { 22 | this.packageName = packageName; 23 | } 24 | 25 | @Override 26 | protected Class getClassForName(String name) throws ClassNotFoundException { 27 | if (name.indexOf('.') < 0) { 28 | try { 29 | Class clazz = Class.forName(packageName + "." + name); 30 | return clazz; 31 | } catch (ClassNotFoundException e) { 32 | // use super implementation 33 | } 34 | } 35 | return super.getClassForName(name); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # NASDAQ-ITCH-5.0-Parser 2 | Parses and prints the NASDAQ ITCH 5.0 data 3 | 4 | Thanks to Quannabe. I just modified the YAML file for the nerw ITCH 5.0 format. 5 | 6 | 7 | #How To 8 | 9 | The main function is location in ```src/parse.java```. Just enter the file name and path to the ITCH file that you wanna parse here [File Name](https://github.com/Amay22/NASDAQ-ITCH-5.0-Parser/blob/master/src/Parse.java#L56). 10 | 11 | ## Run Code 12 | 13 | Compile the code and run it. Navigate to the src directory and run the following commands in your terminal. 14 | 15 | ``` 16 | javac Parse.java 17 | java Parse [ITCH file path] 18 | ``` 19 | 20 | (Path can be left blank to read from stdin.) 21 | 22 | ## ITCH Format Variations 23 | 24 | Support is included for custom ITCH formats. See ```itch5.yaml``` for an example of how to construct an ITCH format configuration. To include a custom ITCH format configuration: 25 | 26 | ``` java Parse -y [YAML config] [ITCH file path] ``` 27 | 28 | ### Genium 29 | 30 | Genium is supported out of box. Use the ```genium2.yaml``` config included in the repo: 31 | 32 | ``` java Parse -y ../genium2.yaml [ITCH file path] ``` 33 | 34 | #Data 35 | 36 | Download raw ITCH 5.0 data from the following link: 37 | 38 | ftp://emi.nasdaq.com/ITCH/08022014.NASDAQ_ITCH50.gz 39 | 40 | #DATA FORMAT 41 | 42 | http://www.nasdaqtrader.com/content/technicalsupport/specifications/dataproducts/NQTVITCHspecification.pdf 43 | 44 | (For Nasdaq Genium) 45 | 46 | http://business.nasdaq.com/Docs/ITCHRefDataGuideNFXv2_00_tcm5044-18017.pdf 47 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/emitter/ScalarAnalysis.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.emitter; 17 | 18 | public final class ScalarAnalysis { 19 | public String scalar; 20 | public boolean empty; 21 | public boolean multiline; 22 | public boolean allowFlowPlain; 23 | public boolean allowBlockPlain; 24 | public boolean allowSingleQuoted; 25 | public boolean allowBlock; 26 | 27 | public ScalarAnalysis(String scalar, boolean empty, boolean multiline, boolean allowFlowPlain, 28 | boolean allowBlockPlain, boolean allowSingleQuoted, boolean allowBlock) { 29 | this.scalar = scalar; 30 | this.empty = empty; 31 | this.multiline = multiline; 32 | this.allowFlowPlain = allowFlowPlain; 33 | this.allowBlockPlain = allowBlockPlain; 34 | this.allowSingleQuoted = allowSingleQuoted; 35 | this.allowBlock = allowBlock; 36 | } 37 | } -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/extensions/compactnotation/CompactData.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.extensions.compactnotation; 17 | 18 | import java.util.ArrayList; 19 | import java.util.HashMap; 20 | import java.util.List; 21 | import java.util.Map; 22 | 23 | public class CompactData { 24 | private String prefix; 25 | private List arguments = new ArrayList(); 26 | private Map properties = new HashMap(); 27 | 28 | public CompactData(String prefix) { 29 | this.prefix = prefix; 30 | } 31 | 32 | public String getPrefix() { 33 | return prefix; 34 | } 35 | 36 | public Map getProperties() { 37 | return properties; 38 | } 39 | 40 | public List getArguments() { 41 | return arguments; 42 | } 43 | 44 | @Override 45 | public String toString() { 46 | return "CompactData: " + prefix + " " + properties; 47 | } 48 | } -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/constructor/CustomClassLoaderConstructor.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 | /** 19 | * Construct instances with a custom Class Loader. 20 | */ 21 | public class CustomClassLoaderConstructor extends Constructor { 22 | private ClassLoader loader = CustomClassLoaderConstructor.class.getClassLoader(); 23 | 24 | public CustomClassLoaderConstructor(ClassLoader cLoader) { 25 | this(Object.class, cLoader); 26 | } 27 | 28 | public CustomClassLoaderConstructor(Class theRoot, ClassLoader theLoader) { 29 | super(theRoot); 30 | if (theLoader == null) { 31 | throw new NullPointerException("Loader must be provided."); 32 | } 33 | this.loader = theLoader; 34 | } 35 | 36 | @Override 37 | protected Class getClassForName(String name) throws ClassNotFoundException { 38 | return Class.forName(name, true, loader); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/constructor/AbstractConstruct.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.YAMLException; 19 | import org.yaml.snakeyaml.nodes.Node; 20 | 21 | /** 22 | * Because recursive structures are not very common we provide a way to save 23 | * some typing when extending a constructor 24 | */ 25 | public abstract class AbstractConstruct implements Construct { 26 | 27 | /** 28 | * Fail with a reminder to provide the seconds step for a recursive 29 | * structure 30 | * 31 | * @see org.yaml.snakeyaml.constructor.Construct#construct2ndStep(org.yaml.snakeyaml.nodes.Node, 32 | * java.lang.Object) 33 | */ 34 | public void construct2ndStep(Node node, Object data) { 35 | if (node.isTwoStepsConstruction()) { 36 | throw new IllegalStateException("Not Implemented in " + getClass().getName()); 37 | } else { 38 | throw new YAMLException("Unexpected recursive structure for Node: " + node); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/nodes/CollectionNode.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 | * Base class for the two collection types {@link MappingNode mapping} and 22 | * {@link SequenceNode collection}. 23 | */ 24 | public abstract class CollectionNode extends Node { 25 | private Boolean flowStyle; 26 | 27 | public CollectionNode(Tag tag, Mark startMark, Mark endMark, Boolean flowStyle) { 28 | super(tag, startMark, endMark); 29 | this.flowStyle = flowStyle; 30 | } 31 | 32 | /** 33 | * Serialization style of this collection. 34 | * 35 | * @return true 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 | *

28 | *

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 ""; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/events/NodeEvent.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 | * Base class for all events that mark the beginning of a node. 22 | */ 23 | public abstract class NodeEvent extends Event { 24 | 25 | private final String anchor; 26 | 27 | public NodeEvent(String anchor, Mark startMark, Mark endMark) { 28 | super(startMark, endMark); 29 | this.anchor = anchor; 30 | } 31 | 32 | /** 33 | * Node anchor by which this node might later be referenced by a 34 | * {@link AliasEvent}. 35 | *

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 | *

28 | */ 29 | public class FieldProperty extends GenericProperty { 30 | private final Field field; 31 | 32 | public FieldProperty(Field field) { 33 | super(field.getName(), field.getType(), field.getGenericType()); 34 | this.field = field; 35 | field.setAccessible(true); 36 | } 37 | 38 | @Override 39 | public void set(Object object, Object value) throws Exception { 40 | field.set(object, value); 41 | } 42 | 43 | @Override 44 | public Object get(Object object) { 45 | try { 46 | return field.get(object); 47 | } catch (Exception e) { 48 | throw new YAMLException("Unable to access field " + field.getName() + " on object " 49 | + object + " : " + e); 50 | } 51 | } 52 | } -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/constructor/Construct.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.nodes.Node; 19 | 20 | /** 21 | * Provide a way to construct a Java instance out of the composed Node. Support 22 | * recursive objects if it is required. (create Native Data Structure out of 23 | * Node Graph) 24 | * 25 | * @see Chapter 3. Processing YAML 26 | * Information 27 | */ 28 | public interface Construct { 29 | /** 30 | * Construct a Java instance with all the properties injected when it is 31 | * possible. 32 | * 33 | * @param node 34 | * composed Node 35 | * @return a complete Java instance 36 | */ 37 | public Object construct(Node node); 38 | 39 | /** 40 | * Apply the second step when constructing recursive structures. Because the 41 | * instance is already created it can assign a reference to itself. 42 | * 43 | * @param node 44 | * composed Node 45 | * @param object 46 | * the instance constructed earlier by 47 | * 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 DirectiveToken extends Token { 24 | private final String name; 25 | private final List value; 26 | 27 | public DirectiveToken(String name, List value, Mark startMark, Mark endMark) { 28 | super(startMark, endMark); 29 | this.name = name; 30 | if (value != null && value.size() != 2) { 31 | throw new YAMLException("Two strings must be provided instead of " 32 | + String.valueOf(value.size())); 33 | } 34 | this.value = value; 35 | } 36 | 37 | public String getName() { 38 | return this.name; 39 | } 40 | 41 | public List getValue() { 42 | return this.value; 43 | } 44 | 45 | @Override 46 | protected String getArguments() { 47 | if (value != null) { 48 | return "name=" + name + ", value=[" + value.get(0) + ", " + value.get(1) + "]"; 49 | } else { 50 | return "name=" + name; 51 | } 52 | } 53 | 54 | @Override 55 | public Token.ID getTokenId() { 56 | return ID.Directive; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/events/ImplicitTuple.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 | /** 19 | * The implicit flag of a scalar event is a pair of boolean values that indicate 20 | * if the tag may be omitted when the scalar is emitted in a plain and non-plain 21 | * style correspondingly. 22 | * 23 | * @see Events 24 | */ 25 | public class ImplicitTuple { 26 | private final boolean plain; 27 | private final boolean nonPlain; 28 | 29 | public ImplicitTuple(boolean plain, boolean nonplain) { 30 | this.plain = plain; 31 | this.nonPlain = nonplain; 32 | } 33 | 34 | /** 35 | * @return true when tag may be omitted when the scalar is emitted in a 36 | * plain style. 37 | */ 38 | public boolean canOmitTagInPlainScalar() { 39 | return plain; 40 | } 41 | 42 | /** 43 | * @return true when tag may be omitted when the scalar is emitted in a 44 | * non-plain style. 45 | */ 46 | public boolean canOmitTagInNonPlainScalar() { 47 | return nonPlain; 48 | } 49 | 50 | public boolean bothFalse() { 51 | return !plain && !nonPlain; 52 | } 53 | 54 | @Override 55 | public String toString() { 56 | return "implicit=[" + plain + ", " + nonPlain + "]"; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/scanner/SimpleKey.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.error.Mark; 19 | 20 | /** 21 | * Simple keys treatment. 22 | *

23 | * 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 List value; 30 | 31 | public SequenceNode(Tag tag, boolean resolved, List value, Mark startMark, Mark endMark, 32 | Boolean flowStyle) { 33 | super(tag, startMark, endMark, flowStyle); 34 | if (value == null) { 35 | throw new NullPointerException("value in a Node is required."); 36 | } 37 | this.value = value; 38 | this.resolved = resolved; 39 | } 40 | 41 | public SequenceNode(Tag tag, List value, Boolean flowStyle) { 42 | this(tag, true, value, null, null, flowStyle); 43 | } 44 | 45 | @Override 46 | public NodeId getNodeId() { 47 | return NodeId.sequence; 48 | } 49 | 50 | /** 51 | * Returns the elements in this sequence. 52 | * 53 | * @return Nodes in the specified order. 54 | */ 55 | public List getValue() { 56 | return value; 57 | } 58 | 59 | public void setListType(Class listType) { 60 | for (Node node : value) { 61 | node.setType(listType); 62 | } 63 | } 64 | 65 | public String toString() { 66 | return "<" + this.getClass().getName() + " (tag=" + getTag() + ", value=" + getValue() 67 | + ")>"; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/parser/Parser.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.events.Event; 19 | 20 | /** 21 | * This interface represents an input stream of {@link Event Events}. 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.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 | * @return true 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 | * @return true 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 yMap; 14 | private Map fMap; 15 | private Map mMap; 16 | private final Yaml yaml; 17 | // constructor will take in the yaml parser 18 | ParseDS(String filename) throws FileNotFoundException { 19 | yaml = new Yaml(); 20 | InputStream yInput; 21 | yInput = new FileInputStream(new File(filename)); 22 | // load the yaml data structure 23 | Object y = yaml.load(yInput); 24 | // convert the data structure to a map 25 | yMap = (Map) y; 26 | buildFormats(); 27 | buildMessages(); 28 | } 29 | // Build the formats data structure 30 | public void buildFormats() { 31 | fMap = new HashMap<>(); 32 | ArrayList fArray = (ArrayList) yMap.get("formats"); 33 | 34 | for (int i = 0; i < fArray.size(); ++i) { 35 | Map tempMap = (Map) (fArray.get(i)); 36 | fMap.put(tempMap.keySet().toArray()[0], 37 | tempMap.values().toArray()[0]); 38 | } 39 | } 40 | // Build the messages data structure 41 | public void buildMessages() { 42 | mMap = (Map) yMap.get("messages"); 43 | } 44 | // Given Message type, return an array of the fields 45 | public ArrayList getFields(String mType) { 46 | Map tempMap = (Map) mMap.get(mType); 47 | assert tempMap != null : "File type missing: " + mType; 48 | return (ArrayList) tempMap.get("fields"); 49 | } 50 | // Given the field, get the correct parser format for that field 51 | public ArrayList getFormat(String field) { 52 | Object fieldVal = fMap.get(field); 53 | assert fieldVal != null : "Format field missing: " + field; 54 | return (ArrayList) fieldVal; 55 | } 56 | // Given message type, return String Message Name 57 | public String getFieldName(String mType) { 58 | Map tempMap = (Map) mMap.get(mType); 59 | return tempMap.get("name").toString(); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/util/UriEncoder.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.util; 17 | 18 | import java.io.UnsupportedEncodingException; 19 | import java.net.URLDecoder; 20 | import java.nio.ByteBuffer; 21 | import java.nio.CharBuffer; 22 | import java.nio.charset.CharacterCodingException; 23 | import java.nio.charset.Charset; 24 | import java.nio.charset.CharsetDecoder; 25 | import java.nio.charset.CodingErrorAction; 26 | 27 | import org.yaml.snakeyaml.error.YAMLException; 28 | import org.yaml.snakeyaml.external.com.google.gdata.util.common.base.Escaper; 29 | import org.yaml.snakeyaml.external.com.google.gdata.util.common.base.PercentEscaper; 30 | 31 | public abstract class UriEncoder { 32 | private static final CharsetDecoder UTF8Decoder = Charset.forName("UTF-8").newDecoder() 33 | .onMalformedInput(CodingErrorAction.REPORT); 34 | // Include the [] chars to the SAFEPATHCHARS_URLENCODER to avoid 35 | // its escape as required by spec. See 36 | // http://yaml.org/spec/1.1/#escaping%20in%20URI/ 37 | private static final String SAFE_CHARS = PercentEscaper.SAFEPATHCHARS_URLENCODER + "[]/"; 38 | private static final Escaper escaper = new PercentEscaper(SAFE_CHARS, false); 39 | 40 | /** 41 | * Escape special characters with '%' 42 | */ 43 | public static String encode(String uri) { 44 | return escaper.escape(uri); 45 | } 46 | 47 | /** 48 | * Decode '%'-escaped characters. Decoding fails in case of invalid UTF-8 49 | */ 50 | public static String decode(ByteBuffer buff) throws CharacterCodingException { 51 | CharBuffer chars = UTF8Decoder.decode(buff); 52 | return chars.toString(); 53 | } 54 | 55 | public static String decode(String buff) { 56 | try { 57 | return URLDecoder.decode(buff, "UTF-8"); 58 | } catch (UnsupportedEncodingException e) { 59 | throw new YAMLException(e); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/tokens/Token.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 | import org.yaml.snakeyaml.error.YAMLException; 20 | 21 | public abstract class Token { 22 | public enum ID { 23 | Alias, Anchor, BlockEnd, BlockEntry, BlockMappingStart, BlockSequenceStart, Directive, DocumentEnd, DocumentStart, FlowEntry, FlowMappingEnd, FlowMappingStart, FlowSequenceEnd, FlowSequenceStart, Key, Scalar, StreamEnd, StreamStart, Tag, Value 24 | } 25 | 26 | private final Mark startMark; 27 | private final Mark endMark; 28 | 29 | public Token(Mark startMark, Mark endMark) { 30 | if (startMark == null || endMark == null) { 31 | throw new YAMLException("Token requires marks."); 32 | } 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 Token in PyYAML" 51 | */ 52 | protected String getArguments() { 53 | return ""; 54 | } 55 | 56 | /** 57 | * For error reporting. 58 | * 59 | * @see "class variable 'id' in PyYAML" 60 | */ 61 | public abstract Token.ID getTokenId(); 62 | 63 | /* 64 | * for tests only 65 | */ 66 | @Override 67 | public boolean equals(Object obj) { 68 | if (obj instanceof Token) { 69 | return toString().equals(obj.toString()); 70 | } else { 71 | return false; 72 | } 73 | } 74 | 75 | /* 76 | * for tests only 77 | */ 78 | @Override 79 | public int hashCode() { 80 | return toString().hashCode(); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/events/CollectionStartEvent.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 | * Base class for the start events of the collection nodes. 22 | */ 23 | public abstract class CollectionStartEvent extends NodeEvent { 24 | private final String tag; 25 | // The implicit flag of a collection start event indicates if the tag may be 26 | // omitted when the collection is emitted 27 | private final boolean implicit; 28 | // flag indicates if a collection is block or flow 29 | private final Boolean flowStyle; 30 | 31 | public CollectionStartEvent(String anchor, String tag, boolean implicit, Mark startMark, 32 | Mark endMark, Boolean flowStyle) { 33 | super(anchor, startMark, endMark); 34 | this.tag = tag; 35 | this.implicit = implicit; 36 | this.flowStyle = flowStyle; 37 | } 38 | 39 | /** 40 | * Tag of this collection. 41 | * 42 | * @return The tag of this collection, or null if no explicit 43 | * tag is available. 44 | */ 45 | public String getTag() { 46 | return this.tag; 47 | } 48 | 49 | /** 50 | * true if the tag can be omitted while this collection is 51 | * emitted. 52 | * 53 | * @return True if the tag can be omitted while this collection is emitted. 54 | */ 55 | public boolean getImplicit() { 56 | return this.implicit; 57 | } 58 | 59 | /** 60 | * true if this collection is in flow style, false 61 | * for block style. 62 | * 63 | * @return If this collection is in flow style. 64 | */ 65 | public Boolean getFlowStyle() { 66 | return this.flowStyle; 67 | } 68 | 69 | @Override 70 | protected String getArguments() { 71 | return super.getArguments() + ", tag=" + tag + ", implicit=" + implicit; 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/introspector/Property.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 | *

20 | * A Property represents a single member variable of a class, 21 | * possibly including its accessor methods (getX, setX). The name stored in this 22 | * class is the actual name of the property as given for the class, not an 23 | * alias. 24 | *

25 | * 26 | *

27 | * Objects of this class have a total ordering which defaults to ordering based 28 | * on the name of the property. 29 | *

30 | */ 31 | public abstract class Property implements Comparable { 32 | 33 | private final String name; 34 | private final Class type; 35 | 36 | public Property(String name, Class type) { 37 | this.name = name; 38 | this.type = type; 39 | } 40 | 41 | public Class getType() { 42 | return type; 43 | } 44 | 45 | abstract public Class[] getActualTypeArguments(); 46 | 47 | public String getName() { 48 | return name; 49 | } 50 | 51 | @Override 52 | public String toString() { 53 | return getName() + " of " + getType(); 54 | } 55 | 56 | public int compareTo(Property o) { 57 | return name.compareTo(o.name); 58 | } 59 | 60 | public boolean isWritable() { 61 | return true; 62 | } 63 | 64 | public boolean isReadable() { 65 | return true; 66 | } 67 | 68 | abstract public void set(Object object, Object value) throws Exception; 69 | 70 | abstract public Object get(Object object); 71 | 72 | @Override 73 | public int hashCode() { 74 | return name.hashCode() + type.hashCode(); 75 | } 76 | 77 | @Override 78 | public boolean equals(Object other) { 79 | if (other instanceof Property) { 80 | Property p = (Property) other; 81 | return name.equals(p.getName()) && type.equals(p.getType()); 82 | } 83 | return false; 84 | } 85 | } -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/events/DocumentStartEvent.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 java.util.Map; 19 | 20 | import org.yaml.snakeyaml.DumperOptions.Version; 21 | import org.yaml.snakeyaml.error.Mark; 22 | 23 | /** 24 | * Marks the beginning of a document. 25 | *

26 | * This event followed by the document's content and a {@link DocumentEndEvent}. 27 | *

28 | */ 29 | public final class DocumentStartEvent extends Event { 30 | private final boolean explicit; 31 | private final Version version; 32 | private final Map tags; 33 | 34 | public DocumentStartEvent(Mark startMark, Mark endMark, boolean explicit, Version version, 35 | Map tags) { 36 | super(startMark, endMark); 37 | this.explicit = explicit; 38 | this.version = version; 39 | // TODO enforce not null 40 | // if (tags == null) { 41 | // throw new NullPointerException("Tags must be provided."); 42 | // } 43 | this.tags = tags; 44 | } 45 | 46 | public boolean getExplicit() { 47 | return explicit; 48 | } 49 | 50 | /** 51 | * YAML version the document conforms to. 52 | * 53 | * @return nullif the document has no explicit 54 | * %YAML directive. Otherwise an array with two 55 | * components, the major and minor part of the version (in this 56 | * order). 57 | */ 58 | public Version getVersion() { 59 | return version; 60 | } 61 | 62 | /** 63 | * Tag shorthands as defined by the %TAG directive. 64 | * 65 | * @return Mapping of 'handles' to 'prefixes' (the handles include the '!' 66 | * characters). 67 | */ 68 | public Map getTags() { 69 | return tags; 70 | } 71 | 72 | @Override 73 | public boolean is(Event.ID id) { 74 | return ID.DocumentStart == id; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/introspector/MethodProperty.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.beans.PropertyDescriptor; 19 | 20 | import org.yaml.snakeyaml.error.YAMLException; 21 | 22 | /** 23 | *

24 | * A MethodProperty is a Property which is accessed 25 | * through accessor methods (setX, getX). It is possible to have a 26 | * MethodProperty which has only setter, only getter, or both. It 27 | * is not possible to have a MethodProperty which has neither 28 | * setter nor getter. 29 | *

30 | */ 31 | public class MethodProperty extends GenericProperty { 32 | 33 | private final PropertyDescriptor property; 34 | private final boolean readable; 35 | private final boolean writable; 36 | 37 | public MethodProperty(PropertyDescriptor property) { 38 | super(property.getName(), property.getPropertyType(), 39 | property.getReadMethod() == null ? null : property.getReadMethod() 40 | .getGenericReturnType()); 41 | this.property = property; 42 | this.readable = property.getReadMethod() != null; 43 | this.writable = property.getWriteMethod() != null; 44 | } 45 | 46 | @Override 47 | public void set(Object object, Object value) throws Exception { 48 | property.getWriteMethod().invoke(object, value); 49 | } 50 | 51 | @Override 52 | public Object get(Object object) { 53 | try { 54 | property.getReadMethod().setAccessible(true);// issue 50 55 | return property.getReadMethod().invoke(object); 56 | } catch (Exception e) { 57 | throw new YAMLException("Unable to find getter for property '" + property.getName() 58 | + "' on object " + object + ":" + e); 59 | } 60 | } 61 | 62 | @Override 63 | public boolean isWritable() { 64 | return writable; 65 | } 66 | 67 | @Override 68 | public boolean isReadable() { 69 | return readable; 70 | } 71 | } -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/scanner/ScannerException.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.error.Mark; 19 | import org.yaml.snakeyaml.error.MarkedYAMLException; 20 | 21 | /** 22 | * Exception thrown by the {@link Scanner} implementations in case of malformed 23 | * input. 24 | */ 25 | public class ScannerException extends MarkedYAMLException { 26 | 27 | private static final long serialVersionUID = 4782293188600445954L; 28 | 29 | /** 30 | * Constructs an instance. 31 | * 32 | * @param context 33 | * Part of the input document in which vicinity the problem 34 | * occurred. 35 | * @param contextMark 36 | * Position of the context within the document. 37 | * @param problem 38 | * Part of the input document that caused the problem. 39 | * @param problemMark 40 | * Position of the problem within the document. 41 | * @param note 42 | * Message for the user with further information about the 43 | * problem. 44 | */ 45 | public ScannerException(String context, Mark contextMark, String problem, Mark problemMark, 46 | String note) { 47 | super(context, contextMark, problem, problemMark, note); 48 | } 49 | 50 | /** 51 | * Constructs an instance. 52 | * 53 | * @param context 54 | * Part of the input document in which vicinity the problem 55 | * occurred. 56 | * @param contextMark 57 | * Position of the context within the document. 58 | * @param problem 59 | * Part of the input document that caused the problem. 60 | * @param problemMark 61 | * Position of the problem within the document. 62 | */ 63 | public ScannerException(String context, Mark contextMark, String problem, Mark problemMark) { 64 | this(context, contextMark, problem, problemMark, null); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/resolver/RagelMachine.rl: -------------------------------------------------------------------------------- 1 | package org.yaml.snakeyaml.resolver; 2 | //Source for Ragel 6.3 3 | 4 | /** 5 | * Generated by Ragel 6.3 (http://www.complang.org/ragel/) 6 | * @see http://www.complang.org/ragel/ 7 | */ 8 | public class RagelMachine { 9 | %%{ 10 | machine snakeyaml; 11 | action bool_tag { tag = "tag:yaml.org,2002:bool"; } 12 | action merge_tag { tag = "tag:yaml.org,2002:merge"; } 13 | action null_tag { tag = "tag:yaml.org,2002:null"; } 14 | action value_tag { tag = "tag:yaml.org,2002:value"; } 15 | action int_tag { tag = "tag:yaml.org,2002:int"; } 16 | action float_tag { tag = "tag:yaml.org,2002:float"; } 17 | action timestamp_tag { tag = "tag:yaml.org,2002:timestamp"; } 18 | 19 | Bool = ("yes" | "Yes" | "YES" | "no" | "No" | "NO" | 20 | "true" | "True" | "TRUE" | "false" | "False" | "FALSE" | 21 | "on" | "On" | "ON" | "off" | "Off" | "OFF") %/bool_tag; 22 | Merge = "<<" %/merge_tag; 23 | Value = "=" %/value_tag; 24 | Null = ("~" | "null" | "Null" | "NULL" | " ") %/null_tag; 25 | 26 | sign = "-" | "+"; 27 | digit2 = digit | "_"; 28 | binaryInt = "0b" [0-1_]+; 29 | octalInt = "0" [0-7_]+; 30 | decimalInt = "0" | [1-9]digit2* (":" [0-5]? digit)*; 31 | hexaInt = "0x" [0-9a-fA-F_]+; 32 | Int = sign? (binaryInt | octalInt | decimalInt | hexaInt) %/int_tag; 33 | 34 | exp = [eE] sign digit+; 35 | Float = ((sign? ((digit+ digit2* "." digit2* exp?) 36 | | ((digit+ digit2*)? "." digit+ digit2* exp?) 37 | | (digit+ (":" [0-5]? digit)+ "." digit*) 38 | | "." ("inf" | "Inf" | "INF"))) 39 | | ("." ("nan" | "NaN" | "NAN"))) %/float_tag; 40 | 41 | TimestampShort = digit{4} ("-" digit{2}){2} %/timestamp_tag; 42 | fract = "." digit*; 43 | zone = [ \t]* ("Z" | (sign digit{1,2} ( ":" digit{2} )?)); 44 | Timestamp = digit{4} ("-" digit{1,2}){2} ([Tt] | [ \t]+) 45 | digit{1,2} ":" digit{2} ":" digit{2} fract? zone? %/timestamp_tag; 46 | 47 | Scalar = Bool | Null | Int | Float | TimestampShort | Merge | Value | Timestamp; 48 | main := Scalar; 49 | write data nofinal; 50 | }%% 51 | 52 | public String scan(String scalar) { 53 | if (scalar == null) { 54 | throw new NullPointerException("Scalar must be provided."); 55 | } 56 | String tag = null; 57 | int cs = 0; 58 | int p = 0; 59 | int pe = scalar.length(); 60 | int eof = pe; 61 | char[] data; 62 | if (pe == 0) { 63 | // NULL value 64 | data = new char[] { '~' }; 65 | pe = 1; 66 | eof = 1; 67 | } else { 68 | data = scalar.toCharArray(); 69 | } 70 | %%{ 71 | # Initialize and execute. 72 | write init; 73 | write exec; 74 | }%% 75 | 76 | return tag; 77 | } 78 | } -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/scanner/Constant.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 java.util.Arrays; 19 | 20 | public final class Constant { 21 | private final static String ALPHA_S = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-_"; 22 | 23 | private final static String LINEBR_S = "\n\u0085\u2028\u2029"; 24 | private final static String FULL_LINEBR_S = "\r" + LINEBR_S; 25 | private final static String NULL_OR_LINEBR_S = "\0" + FULL_LINEBR_S; 26 | private final static String NULL_BL_LINEBR_S = " " + NULL_OR_LINEBR_S; 27 | private final static String NULL_BL_T_LINEBR_S = "\t" + NULL_BL_LINEBR_S; 28 | private final static String NULL_BL_T_S = "\0 \t"; 29 | private final static String URI_CHARS_S = ALPHA_S + "-;/?:@&=+$,_.!~*\'()[]%"; 30 | 31 | public final static Constant LINEBR = new Constant(LINEBR_S); 32 | public final static Constant FULL_LINEBR = new Constant(FULL_LINEBR_S); 33 | public final static Constant NULL_OR_LINEBR = new Constant(NULL_OR_LINEBR_S); 34 | public final static Constant NULL_BL_LINEBR = new Constant(NULL_BL_LINEBR_S); 35 | public final static Constant NULL_BL_T_LINEBR = new Constant(NULL_BL_T_LINEBR_S); 36 | public final static Constant NULL_BL_T = new Constant(NULL_BL_T_S); 37 | public final static Constant URI_CHARS = new Constant(URI_CHARS_S); 38 | 39 | public final static Constant ALPHA = new Constant(ALPHA_S); 40 | 41 | private String content; 42 | boolean[] contains = new boolean[128]; 43 | boolean noASCII = false; 44 | 45 | private Constant(String content) { 46 | Arrays.fill(contains, false); 47 | StringBuilder sb = new StringBuilder(); 48 | for (int i = 0; i < content.length(); i++) { 49 | char ch = content.charAt(i); 50 | if (ch < 128) 51 | contains[ch] = true; 52 | else 53 | sb.append(ch); 54 | } 55 | if (sb.length() > 0) { 56 | noASCII = true; 57 | this.content = sb.toString(); 58 | } 59 | } 60 | 61 | public boolean has(char ch) { 62 | return (ch < 128) ? contains[ch] : noASCII && content.indexOf(ch, 0) != -1; 63 | } 64 | 65 | public boolean hasNo(char ch) { 66 | return !has(ch); 67 | } 68 | 69 | public boolean has(char ch, String additional) { 70 | return has(ch) || additional.indexOf(ch, 0) != -1; 71 | } 72 | 73 | public boolean hasNo(char ch, String additional) { 74 | return !has(ch, additional); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/Parse.java: -------------------------------------------------------------------------------- 1 | import java.io.File; 2 | import java.io.FileInputStream; 3 | import java.io.FileNotFoundException; 4 | import java.io.IOException; 5 | import java.io.InputStream; 6 | import java.util.ArrayList; 7 | 8 | public class Parse { 9 | private String filename; 10 | private boolean parseNPrint; 11 | private byte[] lenBytes = new byte[2]; 12 | private InputStream input; 13 | Parsers parsers; 14 | ParseDS parseDS; 15 | 16 | public Parse(String filename, String yamlFile, boolean parseNPrint) { 17 | // Check arg for printing parsing the message 18 | this.parseNPrint = parseNPrint; 19 | // Via YAML, create the Data Structures 20 | try { 21 | parseDS = new ParseDS(yamlFile); 22 | } catch (FileNotFoundException e) { 23 | System.out.println("File not found...Check Filename"); 24 | } 25 | // Create the parsers with the YAML data structures 26 | parsers = new Parsers(parseDS); 27 | this.filename = filename; 28 | // Open the input stream... 29 | try { 30 | if (filename.length() > 0) { 31 | // From the file's path if specified... 32 | input = new FileInputStream(new File(filename)); 33 | } else { 34 | /// ...or stdin otherwise 35 | input = System.in; 36 | } 37 | } catch (FileNotFoundException e) { 38 | System.out.println("File (" + filename + 39 | ") not found...Check Filename"); 40 | } 41 | } 42 | 43 | // Read the message from binary file 44 | public byte[] parse() throws IOException, InterruptedException { 45 | if (input.read() == -1) { // EOF 46 | return null; 47 | } 48 | int payLength = input.read(); 49 | byte[] payBytes = new byte[payLength]; // Get the payload 50 | 51 | int offset = 0; // Loop until we've read the full payload size 52 | while (offset < payLength) { 53 | offset += input.read(payBytes, offset, payLength - offset); 54 | } 55 | 56 | // Check if we are parsing and printing 57 | if (parseNPrint) { 58 | ArrayList messageArr = null; 59 | // Send payBytes byte[] to Parsers for processing 60 | // An arraylist will be returned with the message 61 | messageArr = (parsers.messageIn(payBytes)); 62 | System.out.println(messageArr); 63 | } 64 | return payBytes; 65 | } 66 | 67 | public static boolean hasCmdArgsYamlFlag (String args[]) { 68 | return args.length >= 1 && args[0].equals("-y"); 69 | } 70 | 71 | public static String readYamlPathArgs (String args[]) { 72 | if (hasCmdArgsYamlFlag(args)) { 73 | return args[1]; 74 | } else { 75 | return "..//itch5.yaml"; 76 | } 77 | } 78 | 79 | public static String readItchPathArgs (String args[]) { 80 | int argsPos = hasCmdArgsYamlFlag(args) ? 2 : 0; 81 | if (args.length > argsPos) { 82 | return args[argsPos]; 83 | } else { 84 | return ""; 85 | } 86 | } 87 | 88 | public static void main(String args[]) throws IOException, InterruptedException { 89 | String yamlPath = readYamlPathArgs(args); 90 | String filename = readItchPathArgs(args); 91 | Parse parse = new Parse(filename, yamlPath, 92 | true); // true to print otherwise enter false 93 | while (parse.parse() != null) {} 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/events/ScalarEvent.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 a scalar value. 22 | */ 23 | public final class ScalarEvent extends NodeEvent { 24 | private final String tag; 25 | // style flag of a scalar event indicates the style of the scalar. Possible 26 | // values are None, '', '\'', '"', '|', '>' 27 | private final Character style; 28 | private final String value; 29 | // The implicit flag of a scalar event is a pair of boolean values that 30 | // indicate if the tag may be omitted when the scalar is emitted in a plain 31 | // and non-plain style correspondingly. 32 | private final ImplicitTuple implicit; 33 | 34 | public ScalarEvent(String anchor, String tag, ImplicitTuple implicit, String value, 35 | Mark startMark, Mark endMark, Character style) { 36 | super(anchor, startMark, endMark); 37 | this.tag = tag; 38 | this.implicit = implicit; 39 | this.value = value; 40 | this.style = style; 41 | } 42 | 43 | /** 44 | * Tag of this scalar. 45 | * 46 | * @return The tag of this scalar, or null if no explicit tag 47 | * is available. 48 | */ 49 | public String getTag() { 50 | return this.tag; 51 | } 52 | 53 | /** 54 | * Style of the scalar. 55 | *
56 | *
null
57 | *
Flow Style - Plain
58 | *
'\''
59 | *
Flow Style - Single-Quoted
60 | *
'"'
61 | *
Flow Style - Double-Quoted
62 | *
'|'
63 | *
Block Style - Literal
64 | *
'>'
65 | *
Block Style - Folded
66 | *
67 | * 68 | * @see Kind/Style 69 | * Combinations 70 | * @return Style of the scalar. 71 | */ 72 | public Character getStyle() { 73 | return this.style; 74 | } 75 | 76 | /** 77 | * String representation of the value. 78 | *

79 | * Without quotes and escaping. 80 | *

81 | * 82 | * @return Value as Unicode string. 83 | */ 84 | public String getValue() { 85 | return this.value; 86 | } 87 | 88 | public ImplicitTuple getImplicit() { 89 | return this.implicit; 90 | } 91 | 92 | @Override 93 | protected String getArguments() { 94 | return super.getArguments() + ", tag=" + tag + ", " + implicit + ", value=" + value; 95 | } 96 | 97 | @Override 98 | public boolean is(Event.ID id) { 99 | return ID.Scalar == id; 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /src/Parsers.java: -------------------------------------------------------------------------------- 1 | 2 | import java.io.UnsupportedEncodingException; 3 | import java.nio.ByteBuffer; 4 | import java.util.ArrayList; 5 | import java.util.Arrays; 6 | 7 | public class Parsers { 8 | 9 | private final ParseDS parDS; 10 | // Constructor, takes a ParseDS object 11 | Parsers(ParseDS parDS) { 12 | this.parDS = parDS; 13 | } 14 | // Given a byte array and length, will return the length 15 | public String getString(byte[] payload) throws UnsupportedEncodingException { 16 | return new String(payload); 17 | } 18 | // given a byte array will return the Length of payload 19 | public Object getLen(byte[] payload) { 20 | // Convert to big end 21 | ByteBuffer length = ByteBuffer.wrap(payload); 22 | return (int) length.getShort(0); 23 | } 24 | // given byte array of any size, will return an INT 25 | public String getInt(byte[] payload) { 26 | long value = 0; 27 | for (int i = 0; i < payload.length; i++) { 28 | value = (value << 8) + (payload[i] & 0xff); 29 | } 30 | return ""+ value; 31 | } 32 | // given byte array of any size, will return an Double 33 | public String getDouble(byte[] payload) { 34 | return (""+(Double.parseDouble(getInt(payload))/10000)); 35 | } 36 | // Payload in, get the messageType, the fields, then the get the message 37 | public ArrayList messageIn(byte[] payload) throws UnsupportedEncodingException { 38 | // Keep track of where we are at in the message 39 | int messagePointer = 0; 40 | ArrayList messageArray = new ArrayList<>(); 41 | // Get the messageType (getChar only returns A char in the first byte) 42 | String messageType = ""+new String(payload).charAt(0); 43 | messageArray.add(messageType); 44 | // increment after look at first char 45 | messagePointer = messagePointer + 1; 46 | // Get the fields for this message 47 | ArrayList fieldsArray = this.parDS.getFields(messageType); 48 | // loop over fields array, parsing messages --start at 1, we already have messageType 49 | for (int i = 1; i < fieldsArray.size(); i++) { 50 | // Get the field for this part of the message 51 | ArrayList fieldArray = this.parDS.getFormat((String) fieldsArray.get(i)); 52 | // Call appropriate parser on the split payload 53 | messageArray.add(parse(Arrays.copyOfRange(payload, messagePointer, 54 | messagePointer + ((Integer) fieldArray.get(1))), 55 | fieldArray)); 56 | // Move the array cursor after looking at this field 57 | messagePointer = messagePointer + ((Integer) fieldArray.get(1)); 58 | } 59 | return messageArray; 60 | } 61 | // With input byteArray, len & parse type, call approp parser 62 | public String parse(byte[] arr, ArrayList fieldArray) throws UnsupportedEncodingException { 63 | String value = ""; 64 | switch ((Integer) fieldArray.get(0)) { 65 | case 1: 66 | value = getString(arr); 67 | break; 68 | case 2: 69 | value = ""+ Long.parseLong(getInt(arr)); 70 | break; 71 | case 3: 72 | value = ""+ Double.parseDouble(getDouble(arr)); 73 | break; 74 | case 4: 75 | value = ""+ (Double.parseDouble(getDouble(arr))/1000); 76 | break; 77 | } 78 | return value.trim(); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/error/MarkedYAMLException.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.error; 17 | 18 | public class MarkedYAMLException extends YAMLException { 19 | 20 | private static final long serialVersionUID = -9119388488683035101L; 21 | private String context; 22 | private Mark contextMark; 23 | private String problem; 24 | private Mark problemMark; 25 | private String note; 26 | 27 | protected MarkedYAMLException(String context, Mark contextMark, String problem, 28 | Mark problemMark, String note) { 29 | this(context, contextMark, problem, problemMark, note, null); 30 | } 31 | 32 | protected MarkedYAMLException(String context, Mark contextMark, String problem, 33 | Mark problemMark, String note, Throwable cause) { 34 | super(context + "; " + problem + "; " + problemMark, cause); 35 | this.context = context; 36 | this.contextMark = contextMark; 37 | this.problem = problem; 38 | this.problemMark = problemMark; 39 | this.note = note; 40 | } 41 | 42 | protected MarkedYAMLException(String context, Mark contextMark, String problem, Mark problemMark) { 43 | this(context, contextMark, problem, problemMark, null, null); 44 | } 45 | 46 | protected MarkedYAMLException(String context, Mark contextMark, String problem, 47 | Mark problemMark, Throwable cause) { 48 | this(context, contextMark, problem, problemMark, null, cause); 49 | } 50 | 51 | @Override 52 | public String toString() { 53 | StringBuilder lines = new StringBuilder(); 54 | if (context != null) { 55 | lines.append(context); 56 | lines.append("\n"); 57 | } 58 | if (contextMark != null 59 | && (problem == null || problemMark == null 60 | || (contextMark.getName().equals(problemMark.getName())) 61 | || (contextMark.getLine() != problemMark.getLine()) || (contextMark 62 | .getColumn() != problemMark.getColumn()))) { 63 | lines.append(contextMark.toString()); 64 | lines.append("\n"); 65 | } 66 | if (problem != null) { 67 | lines.append(problem); 68 | lines.append("\n"); 69 | } 70 | if (problemMark != null) { 71 | lines.append(problemMark.toString()); 72 | lines.append("\n"); 73 | } 74 | if (note != null) { 75 | lines.append(note); 76 | lines.append("\n"); 77 | } 78 | return lines.toString(); 79 | } 80 | 81 | public String getContext() { 82 | return context; 83 | } 84 | 85 | public Mark getContextMark() { 86 | return contextMark; 87 | } 88 | 89 | public String getProblem() { 90 | return problem; 91 | } 92 | 93 | public Mark getProblemMark() { 94 | return problemMark; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/nodes/MappingNode.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 map. 24 | *

25 | * A map is a collection of unsorted key-value pairs. 26 | *

27 | */ 28 | public class MappingNode extends CollectionNode { 29 | private List value; 30 | private boolean merged = false; 31 | 32 | public MappingNode(Tag tag, boolean resolved, List value, Mark startMark, 33 | Mark endMark, Boolean flowStyle) { 34 | super(tag, startMark, endMark, flowStyle); 35 | if (value == null) { 36 | throw new NullPointerException("value in a Node is required."); 37 | } 38 | this.value = value; 39 | this.resolved = resolved; 40 | } 41 | 42 | public MappingNode(Tag tag, List value, Boolean flowStyle) { 43 | this(tag, true, value, null, null, flowStyle); 44 | } 45 | 46 | @Override 47 | public NodeId getNodeId() { 48 | return NodeId.mapping; 49 | } 50 | 51 | /** 52 | * Returns the entries of this map. 53 | * 54 | * @return List of entries. 55 | */ 56 | public List getValue() { 57 | return value; 58 | } 59 | 60 | public void setValue(List merge) { 61 | value = merge; 62 | } 63 | 64 | public void setOnlyKeyType(Class keyType) { 65 | for (NodeTuple nodes : value) { 66 | nodes.getKeyNode().setType(keyType); 67 | } 68 | } 69 | 70 | public void setTypes(Class keyType, Class valueType) { 71 | for (NodeTuple nodes : value) { 72 | nodes.getValueNode().setType(valueType); 73 | nodes.getKeyNode().setType(keyType); 74 | } 75 | } 76 | 77 | @Override 78 | public String toString() { 79 | String values; 80 | StringBuilder buf = new StringBuilder(); 81 | for (NodeTuple node : getValue()) { 82 | buf.append("{ key="); 83 | buf.append(node.getKeyNode()); 84 | buf.append("; value="); 85 | if (node.getValueNode() instanceof CollectionNode) { 86 | // to avoid overflow in case of recursive structures 87 | buf.append(System.identityHashCode(node.getValueNode())); 88 | } else { 89 | buf.append(node.toString()); 90 | } 91 | buf.append(" }"); 92 | } 93 | values = buf.toString(); 94 | return "<" + this.getClass().getName() + " (tag=" + getTag() + ", values=" + values + ")>"; 95 | } 96 | 97 | /** 98 | * @param merged 99 | * - true if map contains merge node 100 | */ 101 | public void setMerged(boolean merged) { 102 | this.merged = merged; 103 | } 104 | 105 | /** 106 | * @return true if map contains merge node 107 | */ 108 | public boolean isMerged() { 109 | return merged; 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/introspector/GenericProperty.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.Array; 19 | import java.lang.reflect.GenericArrayType; 20 | import java.lang.reflect.ParameterizedType; 21 | import java.lang.reflect.Type; 22 | 23 | abstract public class GenericProperty extends Property { 24 | 25 | private Type genType; 26 | 27 | public GenericProperty(String name, Class aClass, Type aType) { 28 | super(name, aClass); 29 | genType = aType; 30 | actualClassesChecked = aType == null; 31 | } 32 | 33 | private boolean actualClassesChecked; 34 | private Class[] actualClasses; 35 | 36 | public Class[] getActualTypeArguments() { // should we synchronize here ? 37 | if (!actualClassesChecked) { 38 | if (genType instanceof ParameterizedType) { 39 | ParameterizedType parameterizedType = (ParameterizedType) genType; 40 | Type[] actualTypeArguments = parameterizedType.getActualTypeArguments(); 41 | if (actualTypeArguments.length > 0) { 42 | actualClasses = new Class[actualTypeArguments.length]; 43 | for (int i = 0; i < actualTypeArguments.length; i++) { 44 | if (actualTypeArguments[i] instanceof Class) { 45 | actualClasses[i] = (Class) actualTypeArguments[i]; 46 | } else if (actualTypeArguments[i] instanceof ParameterizedType) { 47 | actualClasses[i] = (Class) ((ParameterizedType) actualTypeArguments[i]) 48 | .getRawType(); 49 | } else if (actualTypeArguments[i] instanceof GenericArrayType) { 50 | Type componentType = ((GenericArrayType) actualTypeArguments[i]) 51 | .getGenericComponentType(); 52 | if (componentType instanceof Class) { 53 | actualClasses[i] = Array.newInstance((Class) componentType, 0) 54 | .getClass(); 55 | } else { 56 | actualClasses = null; 57 | break; 58 | } 59 | } else { 60 | actualClasses = null; 61 | break; 62 | } 63 | } 64 | } 65 | } else if (genType instanceof GenericArrayType) { 66 | Type componentType = ((GenericArrayType) genType).getGenericComponentType(); 67 | if (componentType instanceof Class) { 68 | actualClasses = new Class[] { (Class) componentType }; 69 | } 70 | } else if (genType instanceof Class) {// XXX this check is only 71 | // required for IcedTea6 72 | Class classType = (Class) genType; 73 | if (classType.isArray()) { 74 | actualClasses = new Class[1]; 75 | actualClasses[0] = getType().getComponentType(); 76 | } 77 | } 78 | actualClassesChecked = true; 79 | } 80 | return actualClasses; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/JavaBeanLoader.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 java.io.InputStream; 19 | import java.io.Reader; 20 | import java.io.StringReader; 21 | 22 | import org.yaml.snakeyaml.constructor.Constructor; 23 | import org.yaml.snakeyaml.introspector.BeanAccess; 24 | import org.yaml.snakeyaml.reader.UnicodeReader; 25 | import org.yaml.snakeyaml.representer.Representer; 26 | import org.yaml.snakeyaml.resolver.Resolver; 27 | 28 | /** 29 | * Convenience utility to parse JavaBeans. When the YAML document contains a 30 | * global tag with the class definition like '!!com.package.MyBean' it is 31 | * ignored in favour of the runtime class T. 32 | * 33 | * @deprecated use Yaml.loadAs() methods instead 34 | * @see Reflecting 36 | * generics 37 | */ 38 | public class JavaBeanLoader { 39 | private Yaml loader; 40 | 41 | public JavaBeanLoader(TypeDescription typeDescription) { 42 | this(typeDescription, BeanAccess.DEFAULT); 43 | } 44 | 45 | public JavaBeanLoader(TypeDescription typeDescription, BeanAccess beanAccess) { 46 | this(new LoaderOptions(typeDescription), beanAccess); 47 | } 48 | 49 | public JavaBeanLoader(LoaderOptions options, BeanAccess beanAccess) { 50 | if (options == null) { 51 | throw new NullPointerException("LoaderOptions must be provided."); 52 | } 53 | if (options.getRootTypeDescription() == null) { 54 | throw new NullPointerException("TypeDescription must be provided."); 55 | } 56 | Constructor constructor = new Constructor(options.getRootTypeDescription()); 57 | loader = new Yaml(constructor, options, new Representer(), new DumperOptions(), 58 | new Resolver()); 59 | loader.setBeanAccess(beanAccess); 60 | } 61 | 62 | public JavaBeanLoader(Class clazz, BeanAccess beanAccess) { 63 | this(new TypeDescription(clazz), beanAccess); 64 | } 65 | 66 | public JavaBeanLoader(Class clazz) { 67 | this(clazz, BeanAccess.DEFAULT); 68 | } 69 | 70 | /** 71 | * Parse the first YAML document in a stream and produce the corresponding 72 | * JavaBean. 73 | * 74 | * @param yaml 75 | * YAML document 76 | * @return parsed JavaBean 77 | */ 78 | @SuppressWarnings("unchecked") 79 | public T load(String yaml) { 80 | return (T) loader.load(new StringReader(yaml)); 81 | } 82 | 83 | /** 84 | * Parse the first YAML document in a stream and produce the corresponding 85 | * JavaBean. 86 | * 87 | * @param io 88 | * data to load from (BOM is respected and removed) 89 | * @return parsed JavaBean 90 | */ 91 | @SuppressWarnings("unchecked") 92 | public T load(InputStream io) { 93 | return (T) loader.load(new UnicodeReader(io)); 94 | } 95 | 96 | /** 97 | * Parse the first YAML document in a stream and produce the corresponding 98 | * Java object. 99 | * 100 | * @param io 101 | * data to load from (BOM must not be present) 102 | * @return parsed JavaBean 103 | */ 104 | @SuppressWarnings("unchecked") 105 | public T load(Reader io) { 106 | return (T) loader.load(io); 107 | } 108 | 109 | } 110 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/error/Mark.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.error; 17 | 18 | import org.yaml.snakeyaml.scanner.Constant; 19 | 20 | /** 21 | * It's just a record and its only use is producing nice error messages. Parser 22 | * does not use it for any other purposes. 23 | */ 24 | public final class Mark { 25 | private String name; 26 | private int index; 27 | private int line; 28 | private int column; 29 | private String buffer; 30 | private int pointer; 31 | 32 | public Mark(String name, int index, int line, int column, String buffer, int pointer) { 33 | super(); 34 | this.name = name; 35 | this.index = index; 36 | this.line = line; 37 | this.column = column; 38 | this.buffer = buffer; 39 | this.pointer = pointer; 40 | } 41 | 42 | private boolean isLineBreak(char ch) { 43 | return Constant.NULL_OR_LINEBR.has(ch); 44 | } 45 | 46 | public String get_snippet(int indent, int max_length) { 47 | if (buffer == null) { 48 | return null; 49 | } 50 | float half = max_length / 2 - 1; 51 | int start = pointer; 52 | String head = ""; 53 | while ((start > 0) && (!isLineBreak(buffer.charAt(start - 1)))) { 54 | start -= 1; 55 | if (pointer - start > half) { 56 | head = " ... "; 57 | start += 5; 58 | break; 59 | } 60 | } 61 | String tail = ""; 62 | int end = pointer; 63 | while ((end < buffer.length()) && (!isLineBreak(buffer.charAt(end)))) { 64 | end += 1; 65 | if (end - pointer > half) { 66 | tail = " ... "; 67 | end -= 5; 68 | break; 69 | } 70 | } 71 | String snippet = buffer.substring(start, end); 72 | StringBuilder result = new StringBuilder(); 73 | for (int i = 0; i < indent; i++) { 74 | result.append(" "); 75 | } 76 | result.append(head); 77 | result.append(snippet); 78 | result.append(tail); 79 | result.append("\n"); 80 | for (int i = 0; i < indent + pointer - start + head.length(); i++) { 81 | result.append(" "); 82 | } 83 | result.append("^"); 84 | return result.toString(); 85 | } 86 | 87 | public String get_snippet() { 88 | return get_snippet(4, 75); 89 | } 90 | 91 | @Override 92 | public String toString() { 93 | String snippet = get_snippet(); 94 | StringBuilder where = new StringBuilder(" in "); 95 | where.append(name); 96 | where.append(", line "); 97 | where.append(line + 1); 98 | where.append(", column "); 99 | where.append(column + 1); 100 | if (snippet != null) { 101 | where.append(":\n"); 102 | where.append(snippet); 103 | } 104 | return where.toString(); 105 | } 106 | 107 | public String getName() { 108 | return name; 109 | } 110 | 111 | /** 112 | * starts with 0 113 | */ 114 | public int getLine() { 115 | return line; 116 | } 117 | 118 | /** 119 | * starts with 0 120 | */ 121 | public int getColumn() { 122 | return column; 123 | } 124 | 125 | /** 126 | * starts with 0 127 | */ 128 | public int getIndex() { 129 | return index; 130 | } 131 | 132 | } 133 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/external/com/google/gdata/util/common/base/Escaper.java: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2008 Google Inc. 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | package org.yaml.snakeyaml.external.com.google.gdata.util.common.base; 17 | 18 | /** 19 | * An object that converts literal text into a format safe for inclusion in a 20 | * particular context (such as an XML document). Typically (but not always), the 21 | * inverse process of "unescaping" the text is performed automatically by the 22 | * relevant parser. 23 | * 24 | *

25 | * For example, an XML escaper would convert the literal string 26 | * {@code "Foo"} into {@code "Foo<Bar>"} to prevent {@code ""} 27 | * from being confused with an XML tag. When the resulting XML document is 28 | * parsed, the parser API will return this text as the original literal string 29 | * {@code "Foo"}. 30 | * 31 | *

32 | * An {@code Escaper} instance is required to be stateless, and safe when used 33 | * concurrently by multiple threads. 34 | * 35 | *

36 | * Several popular escapers are defined as constants in the class 37 | * {@link CharEscapers}. To create your own escapers, use 38 | * {@link CharEscaperBuilder}, or extend {@link CharEscaper} or 39 | * {@code UnicodeEscaper}. 40 | * 41 | * 42 | */ 43 | public interface Escaper { 44 | /** 45 | * Returns the escaped form of a given literal string. 46 | * 47 | *

48 | * Note that this method may treat input characters differently depending on 49 | * the specific escaper implementation. 50 | *

    51 | *
  • {@link UnicodeEscaper} handles UTF-16 correctly, 53 | * including surrogate character pairs. If the input is badly formed the 54 | * escaper should throw {@link IllegalArgumentException}. 55 | *
  • {@link CharEscaper} handles Java characters independently and does 56 | * not verify the input for well formed characters. A CharEscaper should not 57 | * be used in situations where input is not guaranteed to be restricted to 58 | * the Basic Multilingual Plane (BMP). 59 | *
60 | * 61 | * @param string 62 | * the literal string to be escaped 63 | * @return the escaped form of {@code string} 64 | * @throws NullPointerException 65 | * if {@code string} is null 66 | * @throws IllegalArgumentException 67 | * if {@code string} contains badly formed UTF-16 or cannot be 68 | * escaped for any other reason 69 | */ 70 | public String escape(String string); 71 | 72 | /** 73 | * Returns an {@code Appendable} instance which automatically escapes all 74 | * text appended to it before passing the resulting text to an underlying 75 | * {@code Appendable}. 76 | * 77 | *

78 | * Note that this method may treat input characters differently depending on 79 | * the specific escaper implementation. 80 | *

    81 | *
  • {@link UnicodeEscaper} handles UTF-16 correctly, 83 | * including surrogate character pairs. If the input is badly formed the 84 | * escaper should throw {@link IllegalArgumentException}. 85 | *
  • {@link CharEscaper} handles Java characters independently and does 86 | * not verify the input for well formed characters. A CharEscaper should not 87 | * be used in situations where input is not guaranteed to be restricted to 88 | * the Basic Multilingual Plane (BMP). 89 | *
90 | * 91 | * @param out 92 | * the underlying {@code Appendable} to append escaped output to 93 | * @return an {@code Appendable} which passes text to {@code out} after 94 | * escaping it. 95 | */ 96 | public Appendable escape(Appendable out); 97 | } 98 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/reader/UnicodeReader.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 | /** 19 | version: 1.1 / 2007-01-25 20 | - changed BOM recognition ordering (longer boms first) 21 | 22 | Original pseudocode : Thomas Weidenfeller 23 | Implementation tweaked: Aki Nieminen 24 | Implementation changed: Andrey Somov 25 | * UTF-32 removed because it is not supported by YAML 26 | * no default encoding 27 | 28 | http://www.unicode.org/unicode/faq/utf_bom.html 29 | BOMs: 30 | 00 00 FE FF = UTF-32, big-endian 31 | FF FE 00 00 = UTF-32, little-endian 32 | EF BB BF = UTF-8, 33 | FE FF = UTF-16, big-endian 34 | FF FE = UTF-16, little-endian 35 | 36 | Win2k Notepad: 37 | Unicode format = UTF-16LE 38 | ***/ 39 | 40 | import java.io.IOException; 41 | import java.io.InputStream; 42 | import java.io.InputStreamReader; 43 | import java.io.PushbackInputStream; 44 | import java.io.Reader; 45 | import java.nio.charset.Charset; 46 | import java.nio.charset.CharsetDecoder; 47 | import java.nio.charset.CodingErrorAction; 48 | 49 | /** 50 | * Generic unicode textreader, which will use BOM mark to identify the encoding 51 | * to be used. If BOM is not found then use a given default or system encoding. 52 | */ 53 | public class UnicodeReader extends Reader { 54 | private static final Charset UTF8 = Charset.forName("UTF-8"); 55 | private static final Charset UTF16BE = Charset.forName("UTF-16BE"); 56 | private static final Charset UTF16LE = Charset.forName("UTF-16LE"); 57 | 58 | PushbackInputStream internalIn; 59 | InputStreamReader internalIn2 = null; 60 | 61 | private static final int BOM_SIZE = 3; 62 | 63 | /** 64 | * @param in 65 | * InputStream to be read 66 | */ 67 | public UnicodeReader(InputStream in) { 68 | internalIn = new PushbackInputStream(in, BOM_SIZE); 69 | } 70 | 71 | /** 72 | * Get stream encoding or NULL if stream is uninitialized. Call init() or 73 | * read() method to initialize it. 74 | */ 75 | public String getEncoding() { 76 | return internalIn2.getEncoding(); 77 | } 78 | 79 | /** 80 | * Read-ahead four bytes and check for BOM marks. Extra bytes are unread 81 | * back to the stream, only BOM bytes are skipped. 82 | */ 83 | protected void init() throws IOException { 84 | if (internalIn2 != null) 85 | return; 86 | 87 | Charset encoding; 88 | byte bom[] = new byte[BOM_SIZE]; 89 | int n, unread; 90 | n = internalIn.read(bom, 0, bom.length); 91 | 92 | if ((bom[0] == (byte) 0xEF) && (bom[1] == (byte) 0xBB) && (bom[2] == (byte) 0xBF)) { 93 | encoding = UTF8; 94 | unread = n - 3; 95 | } else if ((bom[0] == (byte) 0xFE) && (bom[1] == (byte) 0xFF)) { 96 | encoding = UTF16BE; 97 | unread = n - 2; 98 | } else if ((bom[0] == (byte) 0xFF) && (bom[1] == (byte) 0xFE)) { 99 | encoding = UTF16LE; 100 | unread = n - 2; 101 | } else { 102 | // Unicode BOM mark not found, unread all bytes 103 | encoding = UTF8; 104 | unread = n; 105 | } 106 | 107 | if (unread > 0) 108 | internalIn.unread(bom, (n - unread), unread); 109 | 110 | // Use given encoding 111 | CharsetDecoder decoder = encoding.newDecoder().onUnmappableCharacter( 112 | CodingErrorAction.REPORT); 113 | internalIn2 = new InputStreamReader(internalIn, decoder); 114 | } 115 | 116 | public void close() throws IOException { 117 | init(); 118 | internalIn2.close(); 119 | } 120 | 121 | public int read(char[] cbuf, int off, int len) throws IOException { 122 | init(); 123 | return internalIn2.read(cbuf, off, len); 124 | } 125 | } -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/JavaBeanDumper.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 java.io.StringWriter; 19 | import java.io.Writer; 20 | 21 | import org.yaml.snakeyaml.DumperOptions.FlowStyle; 22 | import org.yaml.snakeyaml.introspector.BeanAccess; 23 | import org.yaml.snakeyaml.nodes.Tag; 24 | import org.yaml.snakeyaml.representer.Representer; 25 | 26 | /** 27 | * Convenience utility to serialize JavaBeans. 28 | * 29 | * @deprecated use Yaml.dumpAs(data, Tag.MAP) instead 30 | */ 31 | public class JavaBeanDumper { 32 | private boolean useGlobalTag; 33 | private FlowStyle flowStyle; 34 | private DumperOptions options; 35 | private Representer representer; 36 | private final BeanAccess beanAccess; 37 | 38 | /** 39 | * Create Dumper for JavaBeans 40 | * 41 | * @param useGlobalTag 42 | * true to emit the global tag with the class name 43 | */ 44 | public JavaBeanDumper(boolean useGlobalTag, BeanAccess beanAccess) { 45 | this.useGlobalTag = useGlobalTag; 46 | this.beanAccess = beanAccess; 47 | this.flowStyle = FlowStyle.BLOCK; 48 | } 49 | 50 | public JavaBeanDumper(boolean useGlobalTag) { 51 | this(useGlobalTag, BeanAccess.DEFAULT); 52 | } 53 | 54 | public JavaBeanDumper(BeanAccess beanAccess) { 55 | this(false, beanAccess); 56 | } 57 | 58 | /** 59 | * Create Dumper for JavaBeans. Use "tag:yaml.org,2002:map" as the root tag. 60 | */ 61 | public JavaBeanDumper() { 62 | this(BeanAccess.DEFAULT); 63 | } 64 | 65 | public JavaBeanDumper(Representer representer, DumperOptions options) { 66 | if (representer == null) { 67 | throw new NullPointerException("Representer must be provided."); 68 | } 69 | if (options == null) { 70 | throw new NullPointerException("DumperOptions must be provided."); 71 | } 72 | this.options = options; 73 | this.representer = representer; 74 | this.beanAccess = null; // bean access in not used if representer 75 | // supplied 76 | } 77 | 78 | /** 79 | * Serialize JavaBean 80 | * 81 | * @param data 82 | * JavaBean instance to serialize 83 | * @param output 84 | * destination 85 | */ 86 | public void dump(Object data, Writer output) { 87 | DumperOptions doptions; 88 | if (this.options == null) { 89 | doptions = new DumperOptions(); 90 | if (!useGlobalTag) { 91 | doptions.setExplicitRoot(Tag.MAP); 92 | } 93 | doptions.setDefaultFlowStyle(flowStyle); 94 | } else { 95 | doptions = this.options; 96 | } 97 | Representer repr; 98 | if (this.representer == null) { 99 | repr = new Representer(); 100 | repr.getPropertyUtils().setBeanAccess(beanAccess); 101 | } else { 102 | repr = this.representer; 103 | } 104 | Yaml dumper = new Yaml(repr, doptions); 105 | dumper.dump(data, output); 106 | } 107 | 108 | /** 109 | * Serialize JavaBean 110 | * 111 | * @param data 112 | * JavaBean instance to serialize 113 | * @return serialized YAML document 114 | */ 115 | public String dump(Object data) { 116 | StringWriter buffer = new StringWriter(); 117 | dump(data, buffer); 118 | return buffer.toString(); 119 | } 120 | 121 | public boolean isUseGlobalTag() { 122 | return useGlobalTag; 123 | } 124 | 125 | public void setUseGlobalTag(boolean useGlobalTag) { 126 | this.useGlobalTag = useGlobalTag; 127 | } 128 | 129 | public FlowStyle getFlowStyle() { 130 | return flowStyle; 131 | } 132 | 133 | public void setFlowStyle(FlowStyle flowStyle) { 134 | this.flowStyle = flowStyle; 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/TypeDescription.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 java.util.HashMap; 19 | import java.util.Map; 20 | 21 | import org.yaml.snakeyaml.nodes.Tag; 22 | 23 | /** 24 | * Provides additional runtime information necessary to create a custom Java 25 | * instance. 26 | */ 27 | public final class TypeDescription { 28 | private final Class type; 29 | private Tag tag; 30 | private Map> listProperties; 31 | private Map> keyProperties; 32 | private Map> valueProperties; 33 | 34 | public TypeDescription(Class clazz, Tag tag) { 35 | this.type = clazz; 36 | this.tag = tag; 37 | listProperties = new HashMap>(); 38 | keyProperties = new HashMap>(); 39 | valueProperties = new HashMap>(); 40 | } 41 | 42 | public TypeDescription(Class clazz, String tag) { 43 | this(clazz, new Tag(tag)); 44 | } 45 | 46 | public TypeDescription(Class clazz) { 47 | this(clazz, (Tag) null); 48 | } 49 | 50 | /** 51 | * Get tag which shall be used to load or dump the type (class). 52 | * 53 | * @return tag to be used. It may be a tag for Language-Independent Types 54 | * (http://www.yaml.org/type/) 55 | */ 56 | public Tag getTag() { 57 | return tag; 58 | } 59 | 60 | /** 61 | * Set tag to be used to load or dump the type (class). 62 | * 63 | * @param tag 64 | * local or global tag 65 | */ 66 | public void setTag(Tag tag) { 67 | this.tag = tag; 68 | } 69 | 70 | public void setTag(String tag) { 71 | setTag(new Tag(tag)); 72 | } 73 | 74 | /** 75 | * Get represented type (class) 76 | * 77 | * @return type (class) to be described. 78 | */ 79 | public Class getType() { 80 | return type; 81 | } 82 | 83 | /** 84 | * Specify that the property is a type-safe List. 85 | * 86 | * @param property 87 | * name of the JavaBean property 88 | * @param type 89 | * class of List values 90 | */ 91 | public void putListPropertyType(String property, Class type) { 92 | listProperties.put(property, type); 93 | } 94 | 95 | /** 96 | * Get class of List values for provided JavaBean property. 97 | * 98 | * @param property 99 | * property name 100 | * @return class of List values 101 | */ 102 | public Class getListPropertyType(String property) { 103 | return listProperties.get(property); 104 | } 105 | 106 | /** 107 | * Specify that the property is a type-safe Map. 108 | * 109 | * @param property 110 | * property name of this JavaBean 111 | * @param key 112 | * class of keys in Map 113 | * @param value 114 | * class of values in Map 115 | */ 116 | public void putMapPropertyType(String property, Class key, 117 | Class value) { 118 | keyProperties.put(property, key); 119 | valueProperties.put(property, value); 120 | } 121 | 122 | /** 123 | * Get keys type info for this JavaBean 124 | * 125 | * @param property 126 | * property name of this JavaBean 127 | * @return class of keys in the Map 128 | */ 129 | public Class getMapKeyType(String property) { 130 | return keyProperties.get(property); 131 | } 132 | 133 | /** 134 | * Get values type info for this JavaBean 135 | * 136 | * @param property 137 | * property name of this JavaBean 138 | * @return class of values in the Map 139 | */ 140 | public Class getMapValueType(String property) { 141 | return valueProperties.get(property); 142 | } 143 | 144 | @Override 145 | public String toString() { 146 | return "TypeDescription for " + getType() + " (tag='" + getTag() + "')"; 147 | } 148 | } 149 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/nodes/Node.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 | * Base class for all nodes. 22 | *

23 | * The nodes form the node-graph described in the YAML Specification. 25 | *

26 | *

27 | * While loading, the node graph is usually created by the 28 | * {@link org.yaml.snakeyaml.composer.Composer}, and later transformed into 29 | * application specific Java classes by the classes from the 30 | * {@link org.yaml.snakeyaml.constructor} package. 31 | *

32 | */ 33 | public abstract class Node { 34 | private Tag tag; 35 | private Mark startMark; 36 | protected Mark endMark; 37 | private Class type; 38 | private boolean twoStepsConstruction; 39 | /** 40 | * true when the tag is assigned by the resolver 41 | */ 42 | protected boolean resolved; 43 | protected Boolean useClassConstructor; 44 | 45 | public Node(Tag tag, Mark startMark, Mark endMark) { 46 | setTag(tag); 47 | this.startMark = startMark; 48 | this.endMark = endMark; 49 | this.type = Object.class; 50 | this.twoStepsConstruction = false; 51 | this.resolved = true; 52 | this.useClassConstructor = null; 53 | } 54 | 55 | /** 56 | * Tag of this node. 57 | *

58 | * Every node has a tag assigned. The tag is either local or global. 59 | * 60 | * @return Tag of this node. 61 | */ 62 | public Tag getTag() { 63 | return this.tag; 64 | } 65 | 66 | public Mark getEndMark() { 67 | return endMark; 68 | } 69 | 70 | /** 71 | * For error reporting. 72 | * 73 | * @see "class variable 'id' in PyYAML" 74 | * @return scalar, sequence, mapping 75 | */ 76 | public abstract NodeId getNodeId(); 77 | 78 | public Mark getStartMark() { 79 | return startMark; 80 | } 81 | 82 | public void setTag(Tag tag) { 83 | if (tag == null) { 84 | throw new NullPointerException("tag in a Node is required."); 85 | } 86 | this.tag = tag; 87 | } 88 | 89 | /** 90 | * Two Nodes are never equal. 91 | */ 92 | @Override 93 | public final boolean equals(Object obj) { 94 | return super.equals(obj); 95 | } 96 | 97 | public Class getType() { 98 | return type; 99 | } 100 | 101 | public void setType(Class type) { 102 | if (!type.isAssignableFrom(this.type)) { 103 | this.type = type; 104 | } 105 | } 106 | 107 | public void setTwoStepsConstruction(boolean twoStepsConstruction) { 108 | this.twoStepsConstruction = twoStepsConstruction; 109 | } 110 | 111 | /** 112 | * Indicates if this node must be constructed in two steps. 113 | *

114 | * Two-step construction is required whenever a node is a child (direct or 115 | * indirect) of it self. That is, if a recursive structure is build using 116 | * anchors and aliases. 117 | *

118 | *

119 | * Set by {@link org.yaml.snakeyaml.composer.Composer}, used during the 120 | * construction process. 121 | *

122 | *

123 | * Only relevant during loading. 124 | *

125 | * 126 | * @return true if the node is self referenced. 127 | */ 128 | public boolean isTwoStepsConstruction() { 129 | return twoStepsConstruction; 130 | } 131 | 132 | @Override 133 | public final int hashCode() { 134 | return super.hashCode(); 135 | } 136 | 137 | public boolean useClassConstructor() { 138 | if (useClassConstructor == null) { 139 | if (isResolved() && !Object.class.equals(type) && !tag.equals(Tag.NULL)) { 140 | return true; 141 | } else if (tag.isCompatible(getType())) { 142 | // the tag is compatible with the runtime class 143 | // the tag will be ignored 144 | return true; 145 | } else { 146 | return false; 147 | } 148 | } 149 | return useClassConstructor.booleanValue(); 150 | } 151 | 152 | public void setUseClassConstructor(Boolean useClassConstructor) { 153 | this.useClassConstructor = useClassConstructor; 154 | } 155 | 156 | /** 157 | * Indicates if the tag was added by 158 | * {@link org.yaml.snakeyaml.resolver.Resolver}. 159 | * 160 | * @return true if the tag of this node was resolved 161 | */ 162 | public boolean isResolved() { 163 | return resolved; 164 | } 165 | } 166 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/nodes/Tag.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.math.BigDecimal; 19 | import java.math.BigInteger; 20 | import java.net.URI; 21 | import java.sql.Timestamp; 22 | import java.util.Date; 23 | import java.util.HashMap; 24 | import java.util.HashSet; 25 | import java.util.Map; 26 | import java.util.Set; 27 | 28 | import org.yaml.snakeyaml.error.YAMLException; 29 | import org.yaml.snakeyaml.util.UriEncoder; 30 | 31 | public final class Tag implements Comparable { 32 | public static final String PREFIX = "tag:yaml.org,2002:"; 33 | public static final Tag YAML = new Tag(PREFIX + "yaml"); 34 | public static final Tag VALUE = new Tag(PREFIX + "value"); 35 | public static final Tag MERGE = new Tag(PREFIX + "merge"); 36 | public static final Tag SET = new Tag(PREFIX + "set"); 37 | public static final Tag PAIRS = new Tag(PREFIX + "pairs"); 38 | public static final Tag OMAP = new Tag(PREFIX + "omap"); 39 | public static final Tag BINARY = new Tag(PREFIX + "binary"); 40 | public static final Tag INT = new Tag(PREFIX + "int"); 41 | public static final Tag FLOAT = new Tag(PREFIX + "float"); 42 | public static final Tag TIMESTAMP = new Tag(PREFIX + "timestamp"); 43 | public static final Tag BOOL = new Tag(PREFIX + "bool"); 44 | public static final Tag NULL = new Tag(PREFIX + "null"); 45 | public static final Tag STR = new Tag(PREFIX + "str"); 46 | public static final Tag SEQ = new Tag(PREFIX + "seq"); 47 | public static final Tag MAP = new Tag(PREFIX + "map"); 48 | public static final Map>> COMPATIBILITY_MAP; 49 | static { 50 | COMPATIBILITY_MAP = new HashMap>>(); 51 | Set> floatSet = new HashSet>(); 52 | floatSet.add(Double.class); 53 | floatSet.add(Float.class); 54 | floatSet.add(BigDecimal.class); 55 | COMPATIBILITY_MAP.put(FLOAT, floatSet); 56 | // 57 | Set> intSet = new HashSet>(); 58 | intSet.add(Integer.class); 59 | intSet.add(Long.class); 60 | intSet.add(BigInteger.class); 61 | COMPATIBILITY_MAP.put(INT, intSet); 62 | // 63 | Set> timestampSet = new HashSet>(); 64 | timestampSet.add(Date.class); 65 | timestampSet.add(java.sql.Date.class); 66 | timestampSet.add(Timestamp.class); 67 | COMPATIBILITY_MAP.put(TIMESTAMP, timestampSet); 68 | } 69 | 70 | private final String value; 71 | 72 | public Tag(String tag) { 73 | if (tag == null) { 74 | throw new NullPointerException("Tag must be provided."); 75 | } else if (tag.length() == 0) { 76 | throw new IllegalArgumentException("Tag must not be empty."); 77 | } else if (tag.trim().length() != tag.length()) { 78 | throw new IllegalArgumentException("Tag must not contain leading or trailing spaces."); 79 | } 80 | this.value = UriEncoder.encode(tag); 81 | } 82 | 83 | public Tag(Class clazz) { 84 | if (clazz == null) { 85 | throw new NullPointerException("Class for tag must be provided."); 86 | } 87 | this.value = Tag.PREFIX + UriEncoder.encode(clazz.getName()); 88 | } 89 | 90 | public Tag(URI uri) { 91 | if (uri == null) { 92 | throw new NullPointerException("URI for tag must be provided."); 93 | } 94 | this.value = uri.toASCIIString(); 95 | } 96 | 97 | public String getValue() { 98 | return value; 99 | } 100 | 101 | public boolean startsWith(String prefix) { 102 | return value.startsWith(prefix); 103 | } 104 | 105 | public String getClassName() { 106 | if (!value.startsWith(Tag.PREFIX)) { 107 | throw new YAMLException("Invalid tag: " + value); 108 | } 109 | return UriEncoder.decode(value.substring(Tag.PREFIX.length())); 110 | } 111 | 112 | public int getLength() { 113 | return value.length(); 114 | } 115 | 116 | @Override 117 | public String toString() { 118 | return value; 119 | } 120 | 121 | @Override 122 | public boolean equals(Object obj) { 123 | if (obj instanceof Tag) { 124 | return value.equals(((Tag) obj).getValue()); 125 | } else if (obj instanceof String) { 126 | if (value.equals(obj.toString())) { 127 | // TODO to be removed later (version 2.0?) 128 | System.err.println("Comparing Tag and String is deprecated."); 129 | return true; 130 | } 131 | } 132 | return false; 133 | } 134 | 135 | @Override 136 | public int hashCode() { 137 | return value.hashCode(); 138 | } 139 | 140 | /** 141 | * Java has more then 1 class compatible with a language-independent tag 142 | * (!!int, !!float, !!timestamp etc) 143 | * 144 | * @param clazz 145 | * - Class to check compatibility 146 | * @return true when the Class can be represented by this 147 | * language-independent tag 148 | */ 149 | public boolean isCompatible(Class clazz) { 150 | Set> set = COMPATIBILITY_MAP.get(this); 151 | if (set != null) { 152 | return set.contains(clazz); 153 | } else { 154 | return false; 155 | } 156 | } 157 | 158 | /** 159 | * Check whether this tag matches the global tag for the Class 160 | * 161 | * @param clazz 162 | * - Class to check 163 | * @return true when the this tag can be used as a global tag for the Class 164 | */ 165 | public boolean matches(Class clazz) { 166 | return value.equals(Tag.PREFIX + clazz.getName()); 167 | } 168 | 169 | public int compareTo(Tag o) { 170 | return value.compareTo(o.getValue()); 171 | } 172 | } 173 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/resolver/Resolver.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.resolver; 17 | 18 | import java.util.ArrayList; 19 | import java.util.HashMap; 20 | import java.util.List; 21 | import java.util.Map; 22 | import java.util.regex.Pattern; 23 | 24 | import org.yaml.snakeyaml.nodes.NodeId; 25 | import org.yaml.snakeyaml.nodes.Tag; 26 | 27 | /** 28 | * Resolver tries to detect a type by scalars's content (when the type is 29 | * implicit) 30 | */ 31 | public class Resolver { 32 | public static final Pattern BOOL = Pattern 33 | .compile("^(?:yes|Yes|YES|no|No|NO|true|True|TRUE|false|False|FALSE|on|On|ON|off|Off|OFF)$"); 34 | 35 | /** 36 | * The regular expression is taken from the 1.2 specification but '_'s are 37 | * added to keep backwards compatibility 38 | */ 39 | public static final Pattern FLOAT = Pattern 40 | .compile("^([-+]?(\\.[0-9]+|[0-9_]+(\\.[0-9_]*)?)([eE][-+]?[0-9]+)?|[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*|[-+]?\\.(?:inf|Inf|INF)|\\.(?:nan|NaN|NAN))$"); 41 | public static final Pattern INT = Pattern 42 | .compile("^(?:[-+]?0b[0-1_]+|[-+]?0[0-7_]+|[-+]?(?:0|[1-9][0-9_]*)|[-+]?0x[0-9a-fA-F_]+|[-+]?[1-9][0-9_]*(?::[0-5]?[0-9])+)$"); 43 | public static final Pattern MERGE = Pattern.compile("^(?:<<)$"); 44 | public static final Pattern NULL = Pattern.compile("^(?:~|null|Null|NULL| )$"); 45 | public static final Pattern EMPTY = Pattern.compile("^$"); 46 | public static final Pattern TIMESTAMP = Pattern 47 | .compile("^(?:[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]|[0-9][0-9][0-9][0-9]-[0-9][0-9]?-[0-9][0-9]?(?:[Tt]|[ \t]+)[0-9][0-9]?:[0-9][0-9]:[0-9][0-9](?:\\.[0-9]*)?(?:[ \t]*(?:Z|[-+][0-9][0-9]?(?::[0-9][0-9])?))?)$"); 48 | public static final Pattern VALUE = Pattern.compile("^(?:=)$"); 49 | public static final Pattern YAML = Pattern.compile("^(?:!|&|\\*)$"); 50 | 51 | protected Map> yamlImplicitResolvers = new HashMap>(); 52 | 53 | /** 54 | * Create Resolver 55 | * 56 | * @param respectDefaultImplicitScalars 57 | * false to parse/dump scalars as plain Strings 58 | * @deprecated override addImplicitResolvers instead 59 | */ 60 | public Resolver(boolean respectDefaultImplicitScalars) { 61 | if (respectDefaultImplicitScalars) { 62 | addImplicitResolvers(); 63 | } 64 | } 65 | 66 | protected void addImplicitResolvers() { 67 | addImplicitResolver(Tag.BOOL, BOOL, "yYnNtTfFoO"); 68 | /* 69 | * INT must be before FLOAT because the regular expression for FLOAT 70 | * matches INT (see issue 130) 71 | * http://code.google.com/p/snakeyaml/issues/detail?id=130 72 | */ 73 | addImplicitResolver(Tag.INT, INT, "-+0123456789"); 74 | addImplicitResolver(Tag.FLOAT, FLOAT, "-+0123456789."); 75 | addImplicitResolver(Tag.MERGE, MERGE, "<"); 76 | addImplicitResolver(Tag.NULL, NULL, "~nN\0"); 77 | addImplicitResolver(Tag.NULL, EMPTY, null); 78 | addImplicitResolver(Tag.TIMESTAMP, TIMESTAMP, "0123456789"); 79 | addImplicitResolver(Tag.VALUE, VALUE, "="); 80 | // The following implicit resolver is only for documentation 81 | // purposes. 82 | // It cannot work 83 | // because plain scalars cannot start with '!', '&', or '*'. 84 | addImplicitResolver(Tag.YAML, YAML, "!&*"); 85 | } 86 | 87 | public Resolver() { 88 | this(true); 89 | } 90 | 91 | public void addImplicitResolver(Tag tag, Pattern regexp, String first) { 92 | if (first == null) { 93 | List curr = yamlImplicitResolvers.get(null); 94 | if (curr == null) { 95 | curr = new ArrayList(); 96 | yamlImplicitResolvers.put(null, curr); 97 | } 98 | curr.add(new ResolverTuple(tag, regexp)); 99 | } else { 100 | char[] chrs = first.toCharArray(); 101 | for (int i = 0, j = chrs.length; i < j; i++) { 102 | Character theC = Character.valueOf(chrs[i]); 103 | if (theC == 0) { 104 | // special case: for null 105 | theC = null; 106 | } 107 | List curr = yamlImplicitResolvers.get(theC); 108 | if (curr == null) { 109 | curr = new ArrayList(); 110 | yamlImplicitResolvers.put(theC, curr); 111 | } 112 | curr.add(new ResolverTuple(tag, regexp)); 113 | } 114 | } 115 | } 116 | 117 | public Tag resolve(NodeId kind, String value, boolean implicit) { 118 | if (kind == NodeId.scalar && implicit) { 119 | List resolvers = null; 120 | if (value.length() == 0) { 121 | resolvers = yamlImplicitResolvers.get('\0'); 122 | } else { 123 | resolvers = yamlImplicitResolvers.get(value.charAt(0)); 124 | } 125 | if (resolvers != null) { 126 | for (ResolverTuple v : resolvers) { 127 | Tag tag = v.getTag(); 128 | Pattern regexp = v.getRegexp(); 129 | if (regexp.matcher(value).matches()) { 130 | return tag; 131 | } 132 | } 133 | } 134 | if (yamlImplicitResolvers.containsKey(null)) { 135 | for (ResolverTuple v : yamlImplicitResolvers.get(null)) { 136 | Tag tag = v.getTag(); 137 | Pattern regexp = v.getRegexp(); 138 | if (regexp.matcher(value).matches()) { 139 | return tag; 140 | } 141 | } 142 | } 143 | } 144 | switch (kind) { 145 | case scalar: 146 | return Tag.STR; 147 | case sequence: 148 | return Tag.SEQ; 149 | default: 150 | return Tag.MAP; 151 | } 152 | } 153 | } -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/introspector/PropertyUtils.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.beans.IntrospectionException; 19 | import java.beans.Introspector; 20 | import java.beans.PropertyDescriptor; 21 | import java.lang.reflect.Field; 22 | import java.lang.reflect.Method; 23 | import java.lang.reflect.Modifier; 24 | import java.util.Collection; 25 | import java.util.HashMap; 26 | import java.util.LinkedHashMap; 27 | import java.util.Map; 28 | import java.util.Set; 29 | import java.util.TreeSet; 30 | 31 | import org.yaml.snakeyaml.error.YAMLException; 32 | 33 | public class PropertyUtils { 34 | 35 | private final Map, Map> propertiesCache = new HashMap, Map>(); 36 | private final Map, Set> readableProperties = new HashMap, Set>(); 37 | private BeanAccess beanAccess = BeanAccess.DEFAULT; 38 | private boolean allowReadOnlyProperties = false; 39 | private boolean skipMissingProperties = false; 40 | 41 | protected Map getPropertiesMap(Class type, BeanAccess bAccess) 42 | throws IntrospectionException { 43 | if (propertiesCache.containsKey(type)) { 44 | return propertiesCache.get(type); 45 | } 46 | 47 | Map properties = new LinkedHashMap(); 48 | boolean inaccessableFieldsExist = false; 49 | switch (bAccess) { 50 | case FIELD: 51 | for (Class c = type; c != null; c = c.getSuperclass()) { 52 | for (Field field : c.getDeclaredFields()) { 53 | int modifiers = field.getModifiers(); 54 | if (!Modifier.isStatic(modifiers) && !Modifier.isTransient(modifiers) 55 | && !properties.containsKey(field.getName())) { 56 | properties.put(field.getName(), new FieldProperty(field)); 57 | } 58 | } 59 | } 60 | break; 61 | default: 62 | // add JavaBean properties 63 | for (PropertyDescriptor property : Introspector.getBeanInfo(type) 64 | .getPropertyDescriptors()) { 65 | Method readMethod = property.getReadMethod(); 66 | if (readMethod == null || !readMethod.getName().equals("getClass")) { 67 | properties.put(property.getName(), new MethodProperty(property)); 68 | } 69 | } 70 | 71 | // add public fields 72 | for (Class c = type; c != null; c = c.getSuperclass()) { 73 | for (Field field : c.getDeclaredFields()) { 74 | int modifiers = field.getModifiers(); 75 | if (!Modifier.isStatic(modifiers) && !Modifier.isTransient(modifiers)) { 76 | if (Modifier.isPublic(modifiers)) { 77 | properties.put(field.getName(), new FieldProperty(field)); 78 | } else { 79 | inaccessableFieldsExist = true; 80 | } 81 | } 82 | } 83 | } 84 | break; 85 | } 86 | if (properties.isEmpty() && inaccessableFieldsExist) { 87 | throw new YAMLException("No JavaBean properties found in " + type.getName()); 88 | } 89 | propertiesCache.put(type, properties); 90 | return properties; 91 | } 92 | 93 | public Set getProperties(Class type) throws IntrospectionException { 94 | return getProperties(type, beanAccess); 95 | } 96 | 97 | public Set getProperties(Class type, BeanAccess bAccess) 98 | throws IntrospectionException { 99 | if (readableProperties.containsKey(type)) { 100 | return readableProperties.get(type); 101 | } 102 | Set properties = createPropertySet(type, bAccess); 103 | readableProperties.put(type, properties); 104 | return properties; 105 | } 106 | 107 | protected Set createPropertySet(Class type, BeanAccess bAccess) 108 | throws IntrospectionException { 109 | Set properties = new TreeSet(); 110 | Collection props = getPropertiesMap(type, bAccess).values(); 111 | for (Property property : props) { 112 | if (property.isReadable() && (allowReadOnlyProperties || property.isWritable())) { 113 | properties.add(property); 114 | } 115 | } 116 | return properties; 117 | } 118 | 119 | public Property getProperty(Class type, String name) 120 | throws IntrospectionException { 121 | return getProperty(type, name, beanAccess); 122 | } 123 | 124 | public Property getProperty(Class type, String name, BeanAccess bAccess) 125 | throws IntrospectionException { 126 | Map properties = getPropertiesMap(type, bAccess); 127 | Property property = properties.get(name); 128 | if (property == null && skipMissingProperties) { 129 | property = new MissingProperty(name); 130 | } 131 | if (property == null || !property.isWritable()) { 132 | throw new YAMLException("Unable to find property '" + name + "' on class: " 133 | + type.getName()); 134 | } 135 | return property; 136 | } 137 | 138 | public void setBeanAccess(BeanAccess beanAccess) { 139 | if (this.beanAccess != beanAccess) { 140 | this.beanAccess = beanAccess; 141 | propertiesCache.clear(); 142 | readableProperties.clear(); 143 | } 144 | } 145 | 146 | public void setAllowReadOnlyProperties(boolean allowReadOnlyProperties) { 147 | if (this.allowReadOnlyProperties != allowReadOnlyProperties) { 148 | this.allowReadOnlyProperties = allowReadOnlyProperties; 149 | readableProperties.clear(); 150 | } 151 | } 152 | 153 | /** 154 | * Skip properties that are missing during deserialization of YAML to a Java 155 | * object. The default is false. 156 | * 157 | * @param skipMissingProperties 158 | * true if missing properties should be skipped, false otherwise. 159 | */ 160 | public void setSkipMissingProperties(boolean skipMissingProperties) { 161 | if (this.skipMissingProperties != skipMissingProperties) { 162 | this.skipMissingProperties = skipMissingProperties; 163 | readableProperties.clear(); 164 | } 165 | } 166 | } 167 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/reader/StreamReader.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 java.io.IOException; 19 | import java.io.Reader; 20 | import java.nio.charset.Charset; 21 | import java.util.regex.Matcher; 22 | import java.util.regex.Pattern; 23 | 24 | import org.yaml.snakeyaml.error.Mark; 25 | import org.yaml.snakeyaml.error.YAMLException; 26 | import org.yaml.snakeyaml.scanner.Constant; 27 | 28 | /** 29 | * Reader: checks if characters are in allowed range, adds '\0' to the end. 30 | */ 31 | public class StreamReader { 32 | public final static Pattern NON_PRINTABLE = Pattern 33 | .compile("[^\t\n\r\u0020-\u007E\u0085\u00A0-\uD7FF\uE000-\uFFFD]"); 34 | private String name; 35 | private final Reader stream; 36 | private int pointer = 0; 37 | private boolean eof = true; 38 | private String buffer; 39 | private int index = 0; 40 | private int line = 0; 41 | private int column = 0; 42 | private char[] data; 43 | 44 | public StreamReader(String stream) { 45 | this.name = "'string'"; 46 | this.buffer = ""; // to set length to 0 47 | checkPrintable(stream); 48 | this.buffer = stream + "\0"; 49 | this.stream = null; 50 | this.eof = true; 51 | this.data = null; 52 | } 53 | 54 | public StreamReader(Reader reader) { 55 | this.name = "'reader'"; 56 | this.buffer = ""; 57 | this.stream = reader; 58 | this.eof = false; 59 | this.data = new char[1024]; 60 | this.update(); 61 | } 62 | 63 | void checkPrintable(CharSequence data) { 64 | Matcher em = NON_PRINTABLE.matcher(data); 65 | if (em.find()) { 66 | int position = this.index + this.buffer.length() - this.pointer + em.start(); 67 | throw new ReaderException(name, position, em.group().charAt(0), 68 | "special characters are not allowed"); 69 | } 70 | } 71 | 72 | /** 73 | * Checks chars for the non-printable characters. 74 | * 75 | * @param chars 76 | * the array where to search. 77 | * @param begin 78 | * the beginning index, inclusive. 79 | * @param end 80 | * the ending index, exclusive. 81 | * @throws ReaderException 82 | * if chars contains non-printable character(s). 83 | */ 84 | void checkPrintable(final char[] chars, final int begin, final int end) { 85 | for (int i = begin; i < end; i++) { 86 | final char c = chars[i]; 87 | 88 | if (isPrintable(c)) { 89 | continue; 90 | } 91 | 92 | int position = this.index + this.buffer.length() - this.pointer + i; 93 | throw new ReaderException(name, position, c, "special characters are not allowed"); 94 | } 95 | } 96 | 97 | public static boolean isPrintable(final char c) { 98 | return (c >= '\u0020' && c <= '\u007E') || c == '\n' || c == '\r' || c == '\t' 99 | || c == '\u0085' || (c >= '\u00A0' && c <= '\uD7FF') 100 | || (c >= '\uE000' && c <= '\uFFFD'); 101 | } 102 | 103 | public Mark getMark() { 104 | return new Mark(name, this.index, this.line, this.column, this.buffer, this.pointer); 105 | } 106 | 107 | public void forward() { 108 | forward(1); 109 | } 110 | 111 | /** 112 | * read the next length characters and move the pointer. 113 | * 114 | * @param length 115 | */ 116 | public void forward(int length) { 117 | if (this.pointer + length + 1 >= this.buffer.length()) { 118 | update(); 119 | } 120 | char ch = 0; 121 | for (int i = 0; i < length; i++) { 122 | ch = this.buffer.charAt(this.pointer); 123 | this.pointer++; 124 | this.index++; 125 | if (Constant.LINEBR.has(ch) || (ch == '\r' && buffer.charAt(pointer) != '\n')) { 126 | this.line++; 127 | this.column = 0; 128 | } else if (ch != '\uFEFF') { 129 | this.column++; 130 | } 131 | } 132 | } 133 | 134 | public char peek() { 135 | return this.buffer.charAt(this.pointer); 136 | } 137 | 138 | /** 139 | * Peek the next index-th character 140 | * 141 | * @param index 142 | * @return the next index-th character 143 | */ 144 | public char peek(int index) { 145 | if (this.pointer + index + 1 > this.buffer.length()) { 146 | update(); 147 | } 148 | return this.buffer.charAt(this.pointer + index); 149 | } 150 | 151 | /** 152 | * peek the next length characters 153 | * 154 | * @param length 155 | * @return the next length characters 156 | */ 157 | public String prefix(int length) { 158 | if (this.pointer + length >= this.buffer.length()) { 159 | update(); 160 | } 161 | if (this.pointer + length > this.buffer.length()) { 162 | return this.buffer.substring(this.pointer); 163 | } 164 | return this.buffer.substring(this.pointer, this.pointer + length); 165 | } 166 | 167 | /** 168 | * prefix(length) immediately followed by forward(length) 169 | */ 170 | public String prefixForward(int length) { 171 | final String prefix = prefix(length); 172 | this.pointer += length; 173 | this.index += length; 174 | // prefix never contains new line characters 175 | this.column += length; 176 | return prefix; 177 | } 178 | 179 | private void update() { 180 | if (!this.eof) { 181 | this.buffer = buffer.substring(this.pointer); 182 | this.pointer = 0; 183 | try { 184 | int converted = this.stream.read(data); 185 | if (converted > 0) { 186 | /* 187 | * Let's create StringBuilder manually. Anyway str1 + str2 188 | * generates new StringBuilder(str1).append(str2).toSting() 189 | * Giving correct capacity to the constructor prevents 190 | * unnecessary operations in appends. 191 | */ 192 | checkPrintable(data, 0, converted); 193 | this.buffer = new StringBuilder(buffer.length() + converted).append(buffer) 194 | .append(data, 0, converted).toString(); 195 | } else { 196 | this.eof = true; 197 | this.buffer += "\0"; 198 | } 199 | } catch (IOException ioe) { 200 | throw new YAMLException(ioe); 201 | } 202 | } 203 | } 204 | 205 | public int getColumn() { 206 | return column; 207 | } 208 | 209 | public Charset getEncoding() { 210 | return Charset.forName(((UnicodeReader) this.stream).getEncoding()); 211 | } 212 | 213 | public int getIndex() { 214 | return index; 215 | } 216 | 217 | public int getLine() { 218 | return line; 219 | } 220 | } 221 | -------------------------------------------------------------------------------- /src/org/yaml/snakeyaml/representer/BaseRepresenter.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.representer; 17 | 18 | import java.util.ArrayList; 19 | import java.util.HashMap; 20 | import java.util.IdentityHashMap; 21 | import java.util.LinkedHashMap; 22 | import java.util.List; 23 | import java.util.Map; 24 | 25 | import org.yaml.snakeyaml.DumperOptions.FlowStyle; 26 | import org.yaml.snakeyaml.DumperOptions.ScalarStyle; 27 | import org.yaml.snakeyaml.error.YAMLException; 28 | import org.yaml.snakeyaml.introspector.PropertyUtils; 29 | import org.yaml.snakeyaml.nodes.AnchorNode; 30 | import org.yaml.snakeyaml.nodes.MappingNode; 31 | import org.yaml.snakeyaml.nodes.Node; 32 | import org.yaml.snakeyaml.nodes.NodeTuple; 33 | import org.yaml.snakeyaml.nodes.ScalarNode; 34 | import org.yaml.snakeyaml.nodes.SequenceNode; 35 | import org.yaml.snakeyaml.nodes.Tag; 36 | 37 | /** 38 | * Represent basic YAML structures: scalar, sequence, mapping 39 | */ 40 | public abstract class BaseRepresenter { 41 | protected final Map, Represent> representers = new HashMap, Represent>(); 42 | /** 43 | * in Java 'null' is not a type. So we have to keep the null representer 44 | * separately otherwise it will coincide with the default representer which 45 | * is stored with the key null. 46 | */ 47 | protected Represent nullRepresenter; 48 | // the order is important (map can be also a sequence of key-values) 49 | protected final Map, Represent> multiRepresenters = new LinkedHashMap, Represent>(); 50 | protected Character defaultScalarStyle; 51 | protected FlowStyle defaultFlowStyle = FlowStyle.AUTO; 52 | protected final Map representedObjects = new IdentityHashMap() { 53 | private static final long serialVersionUID = -5576159264232131854L; 54 | 55 | public Node put(Object key, Node value) { 56 | return super.put(key, new AnchorNode(value)); 57 | } 58 | }; 59 | 60 | protected Object objectToRepresent; 61 | private PropertyUtils propertyUtils; 62 | private boolean explicitPropertyUtils = false; 63 | 64 | public Node represent(Object data) { 65 | Node node = representData(data); 66 | representedObjects.clear(); 67 | objectToRepresent = null; 68 | return node; 69 | } 70 | 71 | protected final Node representData(Object data) { 72 | objectToRepresent = data; 73 | // check for identity 74 | if (representedObjects.containsKey(objectToRepresent)) { 75 | Node node = representedObjects.get(objectToRepresent); 76 | return node; 77 | } 78 | // } 79 | // check for null first 80 | if (data == null) { 81 | Node node = nullRepresenter.representData(null); 82 | return node; 83 | } 84 | // check the same class 85 | Node node; 86 | Class clazz = data.getClass(); 87 | if (representers.containsKey(clazz)) { 88 | Represent representer = representers.get(clazz); 89 | node = representer.representData(data); 90 | } else { 91 | // check the parents 92 | for (Class repr : multiRepresenters.keySet()) { 93 | if (repr.isInstance(data)) { 94 | Represent representer = multiRepresenters.get(repr); 95 | node = representer.representData(data); 96 | return node; 97 | } 98 | } 99 | // check array of primitives 100 | if (clazz.isArray()) { 101 | throw new YAMLException("Arrays of primitives are not fully supported."); 102 | } 103 | // check defaults 104 | if (multiRepresenters.containsKey(null)) { 105 | Represent representer = multiRepresenters.get(null); 106 | node = representer.representData(data); 107 | } else { 108 | Represent representer = representers.get(null); 109 | node = representer.representData(data); 110 | } 111 | } 112 | return node; 113 | } 114 | 115 | protected Node representScalar(Tag tag, String value, Character style) { 116 | if (style == null) { 117 | style = this.defaultScalarStyle; 118 | } 119 | Node node = new ScalarNode(tag, value, null, null, style); 120 | return node; 121 | } 122 | 123 | protected Node representScalar(Tag tag, String value) { 124 | return representScalar(tag, value, null); 125 | } 126 | 127 | protected Node representSequence(Tag tag, Iterable sequence, Boolean flowStyle) { 128 | int size = 10;// default for ArrayList 129 | if (sequence instanceof List) { 130 | size = ((List) sequence).size(); 131 | } 132 | List value = new ArrayList(size); 133 | SequenceNode node = new SequenceNode(tag, value, flowStyle); 134 | representedObjects.put(objectToRepresent, node); 135 | boolean bestStyle = true; 136 | for (Object item : sequence) { 137 | Node nodeItem = representData(item); 138 | if (!((nodeItem instanceof ScalarNode && ((ScalarNode) nodeItem).getStyle() == null))) { 139 | bestStyle = false; 140 | } 141 | value.add(nodeItem); 142 | } 143 | if (flowStyle == null) { 144 | if (defaultFlowStyle != FlowStyle.AUTO) { 145 | node.setFlowStyle(defaultFlowStyle.getStyleBoolean()); 146 | } else { 147 | node.setFlowStyle(bestStyle); 148 | } 149 | } 150 | return node; 151 | } 152 | 153 | protected Node representMapping(Tag tag, Map mapping, 154 | Boolean flowStyle) { 155 | List value = new ArrayList(mapping.size()); 156 | MappingNode node = new MappingNode(tag, value, flowStyle); 157 | representedObjects.put(objectToRepresent, node); 158 | boolean bestStyle = true; 159 | for (Map.Entry entry : mapping.entrySet()) { 160 | Node nodeKey = representData(entry.getKey()); 161 | Node nodeValue = representData(entry.getValue()); 162 | if (!((nodeKey instanceof ScalarNode && ((ScalarNode) nodeKey).getStyle() == null))) { 163 | bestStyle = false; 164 | } 165 | if (!((nodeValue instanceof ScalarNode && ((ScalarNode) nodeValue).getStyle() == null))) { 166 | bestStyle = false; 167 | } 168 | value.add(new NodeTuple(nodeKey, nodeValue)); 169 | } 170 | if (flowStyle == null) { 171 | if (defaultFlowStyle != FlowStyle.AUTO) { 172 | node.setFlowStyle(defaultFlowStyle.getStyleBoolean()); 173 | } else { 174 | node.setFlowStyle(bestStyle); 175 | } 176 | } 177 | return node; 178 | } 179 | 180 | public void setDefaultScalarStyle(ScalarStyle defaultStyle) { 181 | this.defaultScalarStyle = defaultStyle.getChar(); 182 | } 183 | 184 | public void setDefaultFlowStyle(FlowStyle defaultFlowStyle) { 185 | this.defaultFlowStyle = defaultFlowStyle; 186 | } 187 | 188 | public FlowStyle getDefaultFlowStyle() { 189 | return this.defaultFlowStyle; 190 | } 191 | 192 | public void setPropertyUtils(PropertyUtils propertyUtils) { 193 | this.propertyUtils = propertyUtils; 194 | this.explicitPropertyUtils = true; 195 | } 196 | 197 | public final PropertyUtils getPropertyUtils() { 198 | if (propertyUtils == null) { 199 | propertyUtils = new PropertyUtils(); 200 | } 201 | return propertyUtils; 202 | } 203 | 204 | public final boolean isExplicitPropertyUtils() { 205 | return explicitPropertyUtils; 206 | } 207 | } 208 | --------------------------------------------------------------------------------