/** * Get the constructor to construct the Node. For implicit tags if the * runtime class is known a dedicated Construct implementation is used. * Otherwise the constructor is chosen by the tag. * * @param node {@link Node} to construct an instance from * @return {@link Construct} implementation for the specified node */ protected Construct getConstructor(Node node) { if (node.useClassConstructor()) { return yamlClassConstructors.get(node.getNodeId()); } else { Construct constructor = yamlConstructors.get(node.getTag()); if (constructor == null) { for (String prefix : yamlMultiConstructors.keySet()) { if (node.getTag().startsWith(prefix)) { return yamlMultiConstructors.get(prefix); } } return yamlConstructors.get(null); } return constructor; } }
MergeContext(Class<?> keyNodeType, Tag templateInclude) { this.keyNodeType = keyNodeType; if (templateInclude != null && templateInclude.startsWith(INCLUDE_APPLIED_TAG)) { this.templateInclude = templateInclude; } }
MergeContext(Class<?> keyNodeType, Tag templateInclude) { this.keyNodeType = keyNodeType; if (templateInclude != null && (templateInclude.startsWith(INCLUDE_APPLIED_TAG) || templateInclude.startsWith(INCLUDE_COMPOUND_APPLIED_TAG))) { this.templateInclude = templateInclude; } }
@Override public boolean handles(Tag tag) { return tag.startsWith(INCLUDE_COMPOUND_APPLIED_TAG); }
public static boolean isNonStringTag(Tag tag) { return tag != null && !STR.equals(tag) && !tag.startsWith(INCLUDE_APPLIED_TAG); } }
@Override public boolean handles(Tag tag) { return INCLUDE_TAG.equals(tag) || tag.startsWith(INCLUDE_APPLIED_TAG); }
@Override public boolean handles(Tag tag) { return INCLUDE_TAG.equals(tag) || tag.startsWith(INCLUDE_APPLIED_TAG); }
private boolean isCustomTag(Tag tag) { return tag != null && !STR.equals(tag) && !tag.startsWith(INCLUDE_APPLIED_TAG); }
@Override public void beforeProcessingResolvedNode(Tag tag, Node originalNode, Node resolvedNode) { if (tag.startsWith(INCLUDE_COMPOUND_APPLIED_TAG)) { List<IncludeInfo> includes = unmarshall(tag); for (IncludeInfo include : includes) { contextPath.push(include); } } }
@Override public void afterProcessingResolvedNode(Tag tag, Node originalNode, Node resolvedNode) { if (tag.startsWith(INCLUDE_COMPOUND_APPLIED_TAG)) { List<IncludeInfo> includes = unmarshall(tag); for (IncludeInfo include : includes) { contextPath.pop(); } } }
/** * Calculates the relative path of an include applied tag with respect * to the current context * * e.g.: * context: a/b/c/x.raml * tag: a/b/c/d/y.raml * result: d/y.raml * * @param tag include applied tag * @return the relative path part of the tag */ public String resolveRelativePath(Tag tag) { if (tag == null || !tag.startsWith(INCLUDE_APPLIED_TAG)) { throw new IllegalArgumentException("Tag must be an include applied"); } String partentPath = getPartentPath(); String includePath = new IncludeInfo(tag).getIncludeName(); if (includePath.startsWith(partentPath)) { includePath = includePath.substring(partentPath.length()); } return includePath; }
/** * Get the constructor to construct the Node. For implicit tags if the * runtime class is known a dedicated Construct implementation is used. * Otherwise the constructor is chosen by the tag. * * @param node * Node to be constructed * @return Construct implementation for the specified node */ protected Construct getConstructor(Node node) { if (node.useClassConstructor()) { return yamlClassConstructors.get(node.getNodeId()); } else { Construct constructor = yamlConstructors.get(node.getTag()); if (constructor == null) { for (String prefix : yamlMultiConstructors.keySet()) { if (node.getTag().startsWith(prefix)) { return yamlMultiConstructors.get(prefix); } } return yamlConstructors.get(null); } return constructor; } }
/** * Get the constructor to construct the Node. For implicit tags if the * runtime class is known a dedicated Construct implementation is used. * Otherwise the constructor is chosen by the tag. * * @param node * Node to be constructed * @return Construct implementation for the specified node */ protected Construct getConstructor(Node node) { if (node.useClassConstructor()) { return yamlClassConstructors.get(node.getNodeId()); } else { Construct constructor = yamlConstructors.get(node.getTag()); if (constructor == null) { for (String prefix : yamlMultiConstructors.keySet()) { if (node.getTag().startsWith(prefix)) { return yamlMultiConstructors.get(prefix); } } return yamlConstructors.get(null); } return constructor; } }
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(); }
/** * Get the constructor to construct the Node. For implicit tags if the * runtime class is known a dedicated Construct implementation is used. * Otherwise the constructor is chosen by the tag. * * @param node * Node to be constructed * @return Construct implementation for the specified node */ protected Construct getConstructor(Node node) { if (node.useClassConstructor()) { return yamlClassConstructors.get(node.getNodeId()); } else { Construct constructor = yamlConstructors.get(node.getTag()); if (constructor == null) { for (String prefix : yamlMultiConstructors.keySet()) { if (node.getTag().startsWith(prefix)) { return yamlMultiConstructors.get(prefix); } } return yamlConstructors.get(null); } return constructor; } }
private void updateIncludeTag(Node templateValue, Tag parentTag) { if (parentTag.startsWith(INCLUDE_APPLIED_TAG)) { Tag currentTag = templateValue.getTag(); if (currentTag.startsWith(INCLUDE_APPLIED_TAG)) { String parentTagValue = parentTag.getValue(); String currentTagValue = currentTag.getValue(); templateValue.setTag(new Tag(INCLUDE_COMPOUND_APPLIED_TAG // + parentTagValue.length() + SEPARATOR + parentTagValue // + SEPARATOR // + currentTagValue.length() + SEPARATOR + currentTagValue)); } else { templateValue.setTag(parentTag); } } }
@Override public void beforeProcessingResolvedNode(Tag tag, Node originalValueNode, Node resolvedNode) { if (IncludeResolver.INCLUDE_TAG.equals(tag)) { if (originalValueNode.getNodeId() != NodeId.scalar) { //invalid include return; } contextPath.push((ScalarNode) originalValueNode); } else if (tag.startsWith(IncludeResolver.INCLUDE_APPLIED_TAG)) { contextPath.push(tag); } }
@Override public void beforeProcessingResolvedNode(Tag tag, Node originalValueNode, Node resolvedNode) { if (IncludeResolver.INCLUDE_TAG.equals(tag)) { if (originalValueNode.getNodeId() != NodeId.scalar) { //invalid include return; } contextPath.push((ScalarNode) originalValueNode); } else if (tag.startsWith(IncludeResolver.INCLUDE_APPLIED_TAG)) { contextPath.push(tag); } }
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; }