Java Code Examples for org.yaml.snakeyaml.nodes.ScalarNode#getValue()
The following examples show how to use
org.yaml.snakeyaml.nodes.ScalarNode#getValue() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SafeConstructor.java From snake-yaml with Apache License 2.0 | 6 votes |
public Object construct(Node node) { ScalarNode scalar = (ScalarNode) node; try { return nf.parse(scalar.getValue()); } catch (ParseException e) { String lowerCaseValue = scalar.getValue().toLowerCase(); if (lowerCaseValue.contains("inf") || lowerCaseValue.contains("nan")) { /* * Non-finites such as (+/-)infinity and NaN are not * parseable by NumberFormat when these `Double` values are * dumped by snakeyaml. Delegate to the `Tag.FLOAT` * constructor when for this expected failure cause. */ return (Number) yamlConstructors.get(Tag.FLOAT).construct(node); } else { throw new IllegalArgumentException("Unable to parse as Number: " + scalar.getValue()); } } }
Example 2
Source File: Yaml.java From java with Apache License 2.0 | 5 votes |
private IntOrString constructIntOrString(ScalarNode node) { try { return new IntOrString(Integer.parseInt(node.getValue())); } catch (NumberFormatException err) { return new IntOrString(node.getValue()); } }
Example 3
Source File: Yaml.java From java with Apache License 2.0 | 5 votes |
private Object constructDateTime(ScalarNode node) { if (node.getValue() == null || "null".equalsIgnoreCase(node.getValue())) { return null; } else { return new DateTime(node.getValue(), DateTimeZone.UTC); } }
Example 4
Source File: BundleCacher.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
/** * Grab the property value, assume it's a relative path and prepend the bundle's directory to make it an * absolute path. * * @param node * @return */ protected String getPath(Node node, String propertyName) { String relativePath = null; if (node instanceof MappingNode) { MappingNode map = (MappingNode) node; List<NodeTuple> nodes = map.getValue(); for (NodeTuple tuple : nodes) { Node keyNode = tuple.getKeyNode(); if (keyNode instanceof ScalarNode) { ScalarNode scalar = (ScalarNode) keyNode; String valueOfKey = scalar.getValue(); if (propertyName.equals(valueOfKey)) { Node valueNode = tuple.getValueNode(); if (valueNode instanceof ScalarNode) { ScalarNode scalarValue = (ScalarNode) valueNode; relativePath = scalarValue.getValue(); break; } } } } } if (relativePath != null) { IPath pathObj = Path.fromOSString(relativePath); if (!pathObj.isAbsolute()) { // Prepend the bundle directory. relativePath = new File(bundleDirectory, relativePath).getAbsolutePath(); } } return relativePath; }
Example 5
Source File: SafeConstructor.java From orion.server with Eclipse Public License 1.0 | 5 votes |
public Object construct(Node node) { ScalarNode scalar = (ScalarNode) node; try { return nf.parse(scalar.getValue()); } catch (ParseException e) { throw new IllegalArgumentException("Unable to parse as Number: " + scalar.getValue()); } }
Example 6
Source File: BundleCacher.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
public Object construct(Node node) { node.setType(SmartTypingPairsElement.class); String path = getPath(node); SmartTypingPairsElement be = new SmartTypingPairsElement(path); MappingNode mapNode = (MappingNode) node; List<NodeTuple> tuples = mapNode.getValue(); for (NodeTuple tuple : tuples) { ScalarNode keyNode = (ScalarNode) tuple.getKeyNode(); String key = keyNode.getValue(); // "pairs", "scope", "displayName" are required if ("pairs".equals(key)) //$NON-NLS-1$ { SequenceNode pairsValueNode = (SequenceNode) tuple.getValueNode(); List<Character> pairs = new ArrayList<Character>(); List<Node> pairsValues = pairsValueNode.getValue(); for (Node pairValue : pairsValues) { ScalarNode blah = (ScalarNode) pairValue; String pairCharacter = blah.getValue(); pairs.add(Character.valueOf(pairCharacter.charAt(0))); } be.setPairs(pairs); } else if ("scope".equals(key)) //$NON-NLS-1$ { ScalarNode scopeValueNode = (ScalarNode) tuple.getValueNode(); be.setScope(scopeValueNode.getValue()); } else if ("displayName".equals(key)) //$NON-NLS-1$ { ScalarNode displayNameNode = (ScalarNode) tuple.getValueNode(); be.setDisplayName(displayNameNode.getValue()); } } return be; }
Example 7
Source File: FlexibleScalarStyleTest.java From snake-yaml with Apache License 2.0 | 5 votes |
public Node representData(Object data) { ScalarNode node = (ScalarNode) super.representData(data); if (node.getStyle() == null) { // if Plain scalar style if (node.getValue().length() < 25) { return node; } else { // Folded scalar style return new ScalarNode(node.getTag(), node.getValue(), node.getStartMark(), node.getEndMark(), '>'); } } else { return node; } }
Example 8
Source File: BeanConstructor.java From snake-yaml with Apache License 2.0 | 5 votes |
@Override public Object construct(Node node) { if (node.getNodeId() == NodeId.scalar) { ScalarNode n = (ScalarNode) node; String value = n.getValue(); int i = 3; if (value.length() != 0) { i = Integer.parseInt(value); } return new BeanHolder(new Bean1(i)); } else { return new BeanHolder(); } }
Example 9
Source File: BeanConstructor.java From snake-yaml with Apache License 2.0 | 5 votes |
@Override public Object construct(Node node) { ScalarNode snode = (ScalarNode) node; if (snode.getValue().length() == 0) { return new Bean1(); } else { return new Bean1(new Integer(snode.getValue())); } }
Example 10
Source File: BundleCacher.java From APICloud-Studio with GNU General Public License v3.0 | 4 votes |
/** * Fix for https://aptana.lighthouseapp.com/projects/35272/tickets/1658 Sets the prefix triggers for * CommandElements and subclasses. Fixes an issue where "[def]" isn't treated as an array of strings with * "def" as an item in it (and would instead think it's a string of "[def]"). */ protected void setPrefixTriggers(Node node, CommandElement be) { MappingNode mapNode = (MappingNode) node; List<NodeTuple> tuples = mapNode.getValue(); for (NodeTuple tuple : tuples) { ScalarNode keyNode = (ScalarNode) tuple.getKeyNode(); String key = keyNode.getValue(); if ("customProperties".equals(key)) //$NON-NLS-1$ { Node customPropertiesValueNode = tuple.getValueNode(); if (customPropertiesValueNode instanceof MappingNode) { MappingNode custompropertiesNode = (MappingNode) customPropertiesValueNode; for (NodeTuple propTuple : custompropertiesNode.getValue()) { ScalarNode propKeyNode = (ScalarNode) propTuple.getKeyNode(); if ("prefix_values".equals(propKeyNode.getValue())) //$NON-NLS-1$ { SequenceNode prefixValuesNode = (SequenceNode) propTuple.getValueNode(); List<String> values = new ArrayList<String>(); for (Node prefixValue : prefixValuesNode.getValue()) { if (prefixValue instanceof ScalarNode) { ScalarNode blah = (ScalarNode) prefixValue; values.add(blah.getValue()); } else { IdeLog.logWarning(ScriptingActivator.getDefault(), "Expected a flattened array for trigger, but got nested arrays."); //$NON-NLS-1$ } } be.setTrigger(TriggerType.PREFIX.getName(), values.toArray(new String[values.size()])); } } } } } }
Example 11
Source File: BaseConstructor.java From onedev with MIT License | 4 votes |
protected String constructScalar(ScalarNode node) { return node.getValue(); }
Example 12
Source File: Serializer.java From Diorite with MIT License | 4 votes |
private void serializeNode(Node node, @Nullable Node parent, LinkedList<String> commentPath, boolean mappingScalar) throws IOException { if (node.getNodeId() == NodeId.anchor) { node = ((AnchorNode) node).getRealNode(); } String tAlias = this.anchors.get(node); if (this.serializedNodes.contains(node)) { this.emitter.emit(new AliasEvent(tAlias, null, null)); } else { this.serializedNodes.add(node); switch (node.getNodeId()) { case scalar: ScalarNode scalarNode = (ScalarNode) node; Tag detectedTag = this.resolver.resolve(NodeId.scalar, scalarNode.getValue(), true); Tag defaultTag = this.resolver.resolve(NodeId.scalar, scalarNode.getValue(), false); String[] pathNodes = commentPath.toArray(new String[commentPath.size()]); String comment; if (this.checkCommentsSet(pathNodes)) { comment = this.comments.getComment(pathNodes); } else { comment = null; } ImplicitTuple tuple = new ImplicitTupleExtension(node.getTag().equals(detectedTag), node.getTag().equals(defaultTag), comment); ScalarEvent event = new ScalarEvent(tAlias, node.getTag().getValue(), tuple, scalarNode.getValue(), null, null, scalarNode.getStyle()); this.emitter.emit(event); break; case sequence: SequenceNode seqNode = (SequenceNode) node; boolean implicitS = node.getTag().equals(this.resolver.resolve(NodeId.sequence, null, true)); this.emitter.emit(new SequenceStartEvent(tAlias, node.getTag().getValue(), implicitS, null, null, seqNode.getFlowStyle())); List<Node> list = seqNode.getValue(); for (Node item : list) { this.serializeNode(item, node, commentPath, false); } this.emitter.emit(new SequenceEndEvent(null, null)); break; default:// instance of MappingNode Tag implicitTag = this.resolver.resolve(NodeId.mapping, null, true); boolean implicitM = node.getTag().equals(implicitTag); this.emitter.emit(new MappingStartEvent(tAlias, node.getTag().getValue(), implicitM, null, null, ((CollectionNode) node).getFlowStyle())); MappingNode mnode = (MappingNode) node; List<NodeTuple> map = mnode.getValue(); for (NodeTuple row : map) { Node key = row.getKeyNode(); Node value = row.getValueNode(); if (key instanceof ScalarNode) { commentPath.add(((ScalarNode) key).getValue()); } this.serializeNode(key, mnode, commentPath, true); this.serializeNode(value, mnode, commentPath, false); if (key instanceof ScalarNode) { commentPath.removeLast(); } } this.emitter.emit(new MappingEndEvent(null, null)); } } }
Example 13
Source File: BaseConstructor.java From snake-yaml with Apache License 2.0 | 4 votes |
protected Object constructScalar(ScalarNode node) { return node.getValue(); }
Example 14
Source File: Serializer.java From snake-yaml with Apache License 2.0 | 4 votes |
private void serializeNode(Node node, Node parent) throws IOException { if (node.getNodeId() == NodeId.anchor) { node = ((AnchorNode) node).getRealNode(); } String tAlias = this.anchors.get(node); if (this.serializedNodes.contains(node)) { this.emitter.emit(new AliasEvent(tAlias, null, null)); } else { this.serializedNodes.add(node); switch (node.getNodeId()) { case scalar: ScalarNode scalarNode = (ScalarNode) node; Tag detectedTag = this.resolver.resolve(NodeId.scalar, scalarNode.getValue(), true); Tag defaultTag = this.resolver.resolve(NodeId.scalar, scalarNode.getValue(), false); ImplicitTuple tuple = new ImplicitTuple(node.getTag().equals(detectedTag), node .getTag().equals(defaultTag)); ScalarEvent event = new ScalarEvent(tAlias, node.getTag().getValue(), tuple, scalarNode.getValue(), null, null, scalarNode.getStyle()); this.emitter.emit(event); break; case sequence: SequenceNode seqNode = (SequenceNode) node; boolean implicitS = node.getTag().equals(this.resolver.resolve(NodeId.sequence, null, true)); this.emitter.emit(new SequenceStartEvent(tAlias, node.getTag().getValue(), implicitS, null, null, seqNode.getFlowStyle())); List<Node> list = seqNode.getValue(); for (Node item : list) { serializeNode(item, node); } this.emitter.emit(new SequenceEndEvent(null, null)); break; default:// instance of MappingNode Tag implicitTag = this.resolver.resolve(NodeId.mapping, null, true); boolean implicitM = node.getTag().equals(implicitTag); this.emitter.emit(new MappingStartEvent(tAlias, node.getTag().getValue(), implicitM, null, null, ((CollectionNode) node).getFlowStyle())); MappingNode mnode = (MappingNode) node; List<NodeTuple> map = mnode.getValue(); for (NodeTuple row : map) { Node key = row.getKeyNode(); Node value = row.getValueNode(); serializeNode(key, mnode); serializeNode(value, mnode); } this.emitter.emit(new MappingEndEvent(null, null)); } } }
Example 15
Source File: SecureConstruct.java From multiapps with Apache License 2.0 | 4 votes |
@Override public Object construct(Node node) { ScalarNode scalarNode = (ScalarNode) node; return new SecureObject(scalarNode.getValue()); }
Example 16
Source File: SkriptYamlConstructor.java From skript-yaml with MIT License | 4 votes |
@Override public Object construct(Node node) { ScalarNode scalar = (ScalarNode) node; String nodeValue = scalar.getValue(); return WeatherType.parse(nodeValue); }
Example 17
Source File: SkriptYamlConstructor.java From skript-yaml with MIT License | 4 votes |
@Override public Object construct(Node node) { ScalarNode scalar = (ScalarNode) node; String nodeValue = scalar.getValue(); return Color.byName(nodeValue); }
Example 18
Source File: SkriptYamlConstructor.java From skript-yaml with MIT License | 4 votes |
@Override public Object construct(Node node) { ScalarNode scalar = (ScalarNode) node; String nodeValue = scalar.getValue(); return Time.parse(nodeValue); }
Example 19
Source File: BaseConstructor.java From orion.server with Eclipse Public License 1.0 | 4 votes |
protected Object constructScalar(ScalarNode node) { return node.getValue(); }
Example 20
Source File: Serializer.java From orion.server with Eclipse Public License 1.0 | 4 votes |
private void serializeNode(Node node, Node parent) throws IOException { if (node.getNodeId() == NodeId.anchor) { node = ((AnchorNode) node).getRealNode(); } String tAlias = this.anchors.get(node); if (this.serializedNodes.contains(node)) { this.emitter.emit(new AliasEvent(tAlias, null, null)); } else { this.serializedNodes.add(node); switch (node.getNodeId()) { case scalar: ScalarNode scalarNode = (ScalarNode) node; Tag detectedTag = this.resolver.resolve(NodeId.scalar, scalarNode.getValue(), true); Tag defaultTag = this.resolver.resolve(NodeId.scalar, scalarNode.getValue(), false); ImplicitTuple tuple = new ImplicitTuple(node.getTag().equals(detectedTag), node .getTag().equals(defaultTag)); ScalarEvent event = new ScalarEvent(tAlias, node.getTag().getValue(), tuple, scalarNode.getValue(), null, null, scalarNode.getStyle()); this.emitter.emit(event); break; case sequence: SequenceNode seqNode = (SequenceNode) node; boolean implicitS = (node.getTag().equals(this.resolver.resolve(NodeId.sequence, null, true))); this.emitter.emit(new SequenceStartEvent(tAlias, node.getTag().getValue(), implicitS, null, null, seqNode.getFlowStyle())); int indexCounter = 0; List<Node> list = seqNode.getValue(); for (Node item : list) { serializeNode(item, node); indexCounter++; } this.emitter.emit(new SequenceEndEvent(null, null)); break; default:// instance of MappingNode Tag implicitTag = this.resolver.resolve(NodeId.mapping, null, true); boolean implicitM = (node.getTag().equals(implicitTag)); this.emitter.emit(new MappingStartEvent(tAlias, node.getTag().getValue(), implicitM, null, null, ((CollectionNode) node).getFlowStyle())); MappingNode mnode = (MappingNode) node; List<NodeTuple> map = mnode.getValue(); for (NodeTuple row : map) { Node key = row.getKeyNode(); Node value = row.getValueNode(); serializeNode(key, mnode); serializeNode(value, mnode); } this.emitter.emit(new MappingEndEvent(null, null)); } } }