public String toString() { return "<" + this.getClass().getName() + " (tag=" + getTag() + ", value=" + getValue() + ")>"; }
|| type == Character.class || type == BigInteger.class || type == BigDecimal.class || Enum.class.isAssignableFrom(type) || Tag.BINARY.equals(node.getTag()) || Calendar.class.isAssignableFrom(type) || type == UUID.class) { } catch (Exception e) { throw new YAMLException("Can't construct a java object for scalar " + node.getTag() + "; No String constructor found. Exception=" + e.getMessage(), e); } catch (Exception e) { throw new ConstructorException(null, null, "Can't construct a java object for scalar " + node.getTag() + "; exception=" + e.getMessage(), node.getStartMark(), e);
KeyScalarNode(ScalarNode node) { super(node.getTag(), node.getValue(), node.getStartMark(), node.getEndMark(), node.getScalarStyle()); }
public String toString() { return "<" + this.getClass().getName() + " (tag=" + getTag() + ", value=" + getValue() + ")>"; } }
public String toString() { return "<" + this.getClass().getName() + " (tag=" + getTag() + ", value=" + getValue() + ")>"; }
public String toString() { return "<" + this.getClass().getName() + " (tag=" + getTag() + ", value=" + getValue() + ")>"; } }
private void validateKeys(MappingNode node) { Map<String, Long> keyCounts = node.getValue().stream() .map(NodeTuple::getKeyNode) .filter(n -> n instanceof ScalarNode) .map(ScalarNode.class::cast) .filter(n -> !"!include".equals(n.getTag().getValue())) // exclude !include tag .collect(Collectors.groupingBy(ScalarNode::getValue, Collectors.counting())); List<String> duplicatedKeys = keyCounts.entrySet().stream() .filter(it -> it.getValue() > 1) .map(Map.Entry<String, Long>::getKey) .collect(Collectors.toList()); if (!duplicatedKeys.isEmpty()) { throw new DuplicateKeyYAMLException(duplicatedKeys); } } }
private ScalarNode cloneScalarNode(ScalarNode node, Map<String, String> parameters) { String value = node.getValue(); Matcher matcher = TEMPLATE_PARAMETER_PATTERN.matcher(value); StringBuffer sb = new StringBuffer(); while (matcher.find()) { matcher.appendReplacement(sb, ""); sb.append(resolveParameter(matcher.group(), parameters, node)); } matcher.appendTail(sb); return new ScalarNode(node.getTag(), sb.toString(), node.getStartMark(), node.getEndMark(), node.getStyle()); }
private ScalarNode cloneScalarNode(ScalarNode node, Map<String, String> parameters) { String value = node.getValue(); Matcher matcher = TEMPLATE_PARAMETER_PATTERN.matcher(value); StringBuffer sb = new StringBuffer(); while (matcher.find()) { matcher.appendReplacement(sb, ""); sb.append(resolveParameter(matcher.group(), parameters, node)); } matcher.appendTail(sb); return new ScalarNode(node.getTag(), sb.toString(), node.getStartMark(), node.getEndMark(), node.getStyle()); }
private int getLineOffset(ScalarNode schemaNode) { boolean isInclude = schemaNode.getTag().startsWith(INCLUDE_APPLIED_TAG); return isInclude ? -1 : schemaNode.getStartMark().getLine(); }
private int getLineOffset(ScalarNode schemaNode) { boolean isInclude = schemaNode.getTag().startsWith(INCLUDE_APPLIED_TAG); return isInclude ? -1 : schemaNode.getStartMark().getLine(); }
protected String asStringScalar(final Node node) throws ParserException { final ScalarNode scalarNode = asScalar(node); if (!scalarNode.getTag().equals(Tag.STR)) { throw new ParserException("Scalar must be a string", node); } return scalarNode.getValue(); }
@Override public void onScalar(ScalarNode node, TupleType tupleType) { if (schemaTuple != null && node instanceof IncludeResolver.IncludeScalarNode) { final String includeName = ((IncludeResolver.IncludeScalarNode) node).getIncludeName(); if (includeName.endsWith(".json")) { try { @SuppressWarnings("unchecked") final Map<String, Object> json = mapper.readValue(node.getValue(), Map.class); if (json.containsKey("$schema") && !json.containsKey("id")) { json.put("id", protocol + ":/" + includeName); super.onScalar(new ScalarNode(node.getTag(), node.isResolved(), mapper.writeValueAsString(json), node.getStartMark(), node.getEndMark(), node.getStyle()), tupleType); return; } } catch (IOException e) { log.warn("Line {}: Could not parse json file '{}' as schema. Relative $refs inside might not work: {}", node.getStartMark().getLine() + 1, includeName, e.getMessage()); } } } super.onScalar(node, tupleType); } }
if (node instanceof ScalarNode) { ScalarNode scalarNode = (ScalarNode) node; if (scalarNode.getTag().equals(Tag.FLOAT)) return Double.parseDouble(scalarNode.getValue()); else if (scalarNode.getTag().equals(Tag.INT)) return Integer.parseInt(scalarNode.getValue()); else if (scalarNode.getTag().equals(Tag.BOOL)) return Boolean.parseBoolean(scalarNode.getValue()); else return scalarNode.getValue();
private String resolveParameterValueInclude(ScalarNode valueNode) { if (valueNode.getTag().equals(INCLUDE_TAG)) { Node resolved = includeResolver.resolve(valueNode, resourceLoader, nodeNandler); if (resolved.getNodeId() != scalar) { addError("Resource type and traits parameters must be scalars", valueNode); return ""; } valueNode = (ScalarNode) resolved; } return valueNode.getValue(); }
private String resolveParameterValueInclude(ScalarNode valueNode) { if (valueNode.getTag().equals(INCLUDE_TAG)) { Node resolved = includeResolver.resolve(valueNode, resourceLoader, nodeNandler); if (resolved.getNodeId() != scalar) { addError("Resource type and traits parameters must be scalars", valueNode); return ""; } valueNode = (ScalarNode) resolved; } return valueNode.getValue(); }
private Object compileSchema(ScalarNode node) { String value = node.getValue(); if (value == null || NodeUtils.isNonStringTag(node.getTag())) { return null; } Object schema = null; String mimeType = getParent() instanceof PojoTupleBuilder ? ((PojoTupleBuilder) getParent()).getFieldName() : null; if (mimeType != null && mimeType.contains("xml")) { schema = SchemaCompiler.getInstance().compile(value); } else if (mimeType != null && mimeType.contains("json") && (node instanceof IncludeScalarNode)) { //in case of json schemas store include path schema = ((IncludeScalarNode) node).getIncludeName(); } return schema; }
@Override protected NodeTuple representJavaBeanProperty(Object bean, Property property, Object value, Tag customTag) { NodeTuple tuple = super.representJavaBeanProperty(bean, property, value, customTag); if (isNullValue(tuple) || isEmptySequence(tuple) || isEmptyMapping(tuple)) { return null; } if ("body".equals(property.getName())) { ScalarNode n = (ScalarNode) tuple.getValueNode(); if (n.getStyle() == PLAIN.getChar()) { return tuple; } else { return new NodeTuple(tuple.getKeyNode(), new ScalarNode(n.getTag(), n.getValue(), n .getStartMark(), n.getEndMark(), LITERAL.getChar())); } } return tuple; }
private Node resolveInclude(Node node, Tag tag) { if (node.getNodeId() == scalar && node.getTag().equals(INCLUDE_TAG)) { if (tag != null && tag.startsWith(INCLUDE_APPLIED_TAG)) { // for multiple levels of includes in the same template recalculate path using // parent include applied tag path ScalarNode scalarNode = (ScalarNode) node; String parentPath = includeResolver.getContextPath().resolveRelativePath(tag); String includePathRecalculated = ContextPath.getPartentPath(parentPath) + scalarNode.getValue(); node = new ScalarNode(scalarNode.getTag(), includePathRecalculated, node.getStartMark(), node.getEndMark(), scalarNode.getStyle()); } return includeResolver.resolve(node, resourceLoader, nodeNandler); } return node; }