本文整理汇总了Java中org.yaml.snakeyaml.nodes.ScalarNode.getValue方法的典型用法代码示例。如果您正苦于以下问题:Java ScalarNode.getValue方法的具体用法?Java ScalarNode.getValue怎么用?Java ScalarNode.getValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.yaml.snakeyaml.nodes.ScalarNode
的用法示例。
在下文中一共展示了ScalarNode.getValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: construct
import org.yaml.snakeyaml.nodes.ScalarNode; //导入方法依赖的package包/类
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());
}
}
}
示例2: construct
import org.yaml.snakeyaml.nodes.ScalarNode; //导入方法依赖的package包/类
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 yamlConstructors.get(Tag.FLOAT).construct(node);
} else {
throw new IllegalArgumentException(
"Unable to parse as Number: " + scalar.getValue());
}
}
}
示例3: construct
import org.yaml.snakeyaml.nodes.ScalarNode; //导入方法依赖的package包/类
@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()));
}
}
示例4: representData
import org.yaml.snakeyaml.nodes.ScalarNode; //导入方法依赖的package包/类
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;
}
}
示例5: getPath
import org.yaml.snakeyaml.nodes.ScalarNode; //导入方法依赖的package包/类
/**
* 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;
}
示例6: construct
import org.yaml.snakeyaml.nodes.ScalarNode; //导入方法依赖的package包/类
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;
}
示例7: getValue
import org.yaml.snakeyaml.nodes.ScalarNode; //导入方法依赖的package包/类
public static String getValue(ScalarNode node) {
int style = (int)node.getStyle();
String value = node.getValue();
if (value.equals("null") && style == 0) {
return null;
} else {
return value;
}
}
示例8: printScalar
import org.yaml.snakeyaml.nodes.ScalarNode; //导入方法依赖的package包/类
public static String printScalar(ScalarNode node) {
int style = (int)node.getStyle();
String value = node.getValue();
if (style != 0) {
return node.getStyle() + value + node.getStyle();
} else {
return value;
}
}
示例9: serializeNode
import org.yaml.snakeyaml.nodes.ScalarNode; //导入方法依赖的package包/类
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));
}
}
}
示例10: constructScalar
import org.yaml.snakeyaml.nodes.ScalarNode; //导入方法依赖的package包/类
protected Object constructScalar(ScalarNode node) {
return node.getValue();
}
示例11: serializeNode
import org.yaml.snakeyaml.nodes.ScalarNode; //导入方法依赖的package包/类
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));
}
}
}
示例12: serializeNode
import org.yaml.snakeyaml.nodes.ScalarNode; //导入方法依赖的package包/类
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()));
@SuppressWarnings("unused")
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));
}
}
}
示例13: constructStandardJavaInstance
import org.yaml.snakeyaml.nodes.ScalarNode; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private Object constructStandardJavaInstance(@SuppressWarnings("rawtypes") Class type,
ScalarNode node) {
Object result;
if (type == String.class) {
Construct stringConstructor = yamlConstructors.get(Tag.STR);
result = stringConstructor.construct(node);
} else if (type == Boolean.class || type == Boolean.TYPE) {
Construct boolConstructor = yamlConstructors.get(Tag.BOOL);
result = boolConstructor.construct(node);
} else if (type == Character.class || type == Character.TYPE) {
Construct charConstructor = yamlConstructors.get(Tag.STR);
String ch = (String) charConstructor.construct(node);
if (ch.length() == 0) {
result = null;
} else if (ch.length() != 1) {
throw new YAMLException("Invalid node Character: '" + ch + "'; length: "
+ ch.length());
} else {
result = Character.valueOf(ch.charAt(0));
}
} else if (Date.class.isAssignableFrom(type)) {
Construct dateConstructor = yamlConstructors.get(Tag.TIMESTAMP);
Date date = (Date) dateConstructor.construct(node);
if (type == Date.class) {
result = date;
} else {
try {
java.lang.reflect.Constructor<?> constr = type.getConstructor(long.class);
result = constr.newInstance(date.getTime());
} catch (Exception e) {
throw new YAMLException("Cannot construct: '" + type + "'");
}
}
} else if (type == Float.class || type == Double.class || type == Float.TYPE
|| type == Double.TYPE || type == BigDecimal.class) {
if (type == BigDecimal.class) {
result = new BigDecimal(node.getValue());
} else {
Construct doubleConstructor = yamlConstructors.get(Tag.FLOAT);
result = doubleConstructor.construct(node);
if (type == Float.class || type == Float.TYPE) {
result = new Float((Double) result);
}
}
} else if (type == Byte.class || type == Short.class || type == Integer.class
|| type == Long.class || type == BigInteger.class || type == Byte.TYPE
|| type == Short.TYPE || type == Integer.TYPE || type == Long.TYPE) {
Construct intConstructor = yamlConstructors.get(Tag.INT);
result = intConstructor.construct(node);
if (type == Byte.class || type == Byte.TYPE) {
result = new Byte(result.toString());
} else if (type == Short.class || type == Short.TYPE) {
result = new Short(result.toString());
} else if (type == Integer.class || type == Integer.TYPE) {
result = Integer.parseInt(result.toString());
} else if (type == Long.class || type == Long.TYPE) {
result = new Long(result.toString());
} else {
// only BigInteger left
result = new BigInteger(result.toString());
}
} else if (Enum.class.isAssignableFrom(type)) {
String enumValueName = node.getValue();
try {
result = Enum.valueOf(type, enumValueName);
} catch (Exception ex) {
throw new YAMLException("Unable to find enum value '" + enumValueName
+ "' for enum class: " + type.getName());
}
} else if (Calendar.class.isAssignableFrom(type)) {
ConstructYamlTimestamp contr = new ConstructYamlTimestamp();
contr.construct(node);
result = contr.getCalendar();
} else {
throw new YAMLException("Unsupported class: " + type);
}
return result;
}
示例14: setPrefixTriggers
import org.yaml.snakeyaml.nodes.ScalarNode; //导入方法依赖的package包/类
/**
* 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()]));
}
}
}
}
}
}
示例15: serializeNode
import org.yaml.snakeyaml.nodes.ScalarNode; //导入方法依赖的package包/类
private void serializeNode(Node node, final 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));
}
}
}