public void pushRoot(String absoluteFile) { if (includeStack.size() > 0) { throw new IllegalStateException("Non empty stack"); } includeStack.add(new IncludeInfo(absoluteFile)); }
private String getPartentPath() { int idx = includeStack.peek().getIncludeName().lastIndexOf("/") + 1; return includeStack.peek().getIncludeName().substring(0, idx); }
public IncludeInfo(Tag tag) { StringBuilder encodedInclude = new StringBuilder(tag.getValue()); endColumn = popTrailingNumber(encodedInclude); startColumn = popTrailingNumber(encodedInclude); line = popTrailingNumber(encodedInclude); includeName = encodedInclude.substring(IncludeResolver.INCLUDE_APPLIED_TAG.length()); }
/** * 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; }
public void pushRoot(String absoluteFile) { if (includeStack.size() > 0) { throw new IllegalStateException("Non empty stack"); } includeStack.add(new IncludeInfo(absoluteFile)); }
private String getPartentPath() { return getPartentPath(includeStack.peek().getIncludeName()); }
public IncludeInfo(Tag tag) { StringBuilder encodedInclude = new StringBuilder(tag.getValue()); endColumn = popTrailingNumber(encodedInclude); startColumn = popTrailingNumber(encodedInclude); line = popTrailingNumber(encodedInclude); includeName = encodedInclude.substring(IncludeResolver.INCLUDE_APPLIED_TAG.length()); }
public void push(Tag tag) { push(new IncludeInfo(tag)); }
public String getIncludeName() { if (contextPath != null && contextPath.size() > 1) { return contextPath.peek().getIncludeName(); } return null; }
public void push(Tag tag) { push(new IncludeInfo(tag)); }
public String getIncludeName() { if (contextPath != null && contextPath.size() > 1) { return contextPath.peek().getIncludeName(); } return null; }
public static List<IncludeInfo> unmarshall(Tag tag) { String compoundIncludeTag = tag.getValue().substring(INCLUDE_COMPOUND_APPLIED_TAG.length()); int endOfFirstLength = compoundIncludeTag.indexOf(SEPARATOR); int firstIncludeLength = Integer.parseInt(compoundIncludeTag.substring(0, endOfFirstLength)); String firstAppliedInclude = compoundIncludeTag.substring(endOfFirstLength + 1, endOfFirstLength + 1 + firstIncludeLength); IncludeInfo firstIncludeInfo = new IncludeInfo(new Tag(firstAppliedInclude)); String compoundIncludeTag1 = compoundIncludeTag.substring(endOfFirstLength + 1 + firstIncludeLength + 1); int endOfSecondLength = compoundIncludeTag1.indexOf(SEPARATOR); int secondIncludeLength = Integer.parseInt(compoundIncludeTag1.substring(0, endOfSecondLength)); String secondAppliedInclude = compoundIncludeTag1.substring(endOfSecondLength + 1, endOfSecondLength + 1 + secondIncludeLength); IncludeInfo secondIncludeInfo = new IncludeInfo(new Tag(secondAppliedInclude)); return Lists.newArrayList(firstIncludeInfo, secondIncludeInfo); }
/** * @return true if two mapping nodes in the same file * have the same start mark index */ private boolean checkLoop(Node node) { if (node.getStartMark() == null) { return false; } String index = contextPath.peek().getIncludeName() + node.getStartMark().getIndex(); if (loopDetector.contains(index)) { return true; } loopDetector.push(index); return false; }
public void push(ScalarNode node) { push(new IncludeInfo(node, getPartentPath())); }
/** * @return true if two mapping nodes in the same file * have the same start mark index */ private boolean checkLoop(Node node) { if (node.getStartMark() == null) { return false; } String index = contextPath.peek().getIncludeName() + node.getStartMark().getIndex(); if (loopDetector.contains(index)) { return true; } loopDetector.push(index); return false; }
public void push(ScalarNode node) { push(new IncludeInfo(node, getPartentPath())); }
public Schema compile(String schema, String path) { Schema compiledSchema = null; String trimmedSchema = StringUtils.trimToEmpty(schema); if (trimmedSchema.startsWith("<") && trimmedSchema.endsWith(">")) { SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); ContextPath actualContextPath = contextPath; if (path != null) { actualContextPath = new ContextPath(new IncludeInfo(path)); } factory.setResourceResolver(new XsdResourceResolver(actualContextPath, resourceLoader)); try { compiledSchema = factory.newSchema(new StreamSource(new StringReader(trimmedSchema))); } catch (Exception e) { //ignore exception as the error is detected by the validator // and here we cannot tell if the schema is intended for xml or not } } return compiledSchema; }
if (schemaNode.getTag().startsWith(INCLUDE_APPLIED_TAG)) globaSchemaIncludeInfo = new IncludeInfo(schemaNode.getTag());
if (schemaNode.getTag().startsWith(INCLUDE_APPLIED_TAG)) globaSchemaIncludeInfo = new IncludeInfo(schemaNode.getTag()); actualContextPath = new ContextPath(globaSchemaIncludeInfo);