/** * Used for DSTU2 only */ protected boolean shouldEncodePath(IResource theResource, String thePath) { if (myDontEncodeElements != null) { String resourceName = myContext.getResourceDefinition(theResource).getName(); if (myDontEncodeElements.stream().anyMatch(t -> t.equalsPath(resourceName + "." + thePath))) { return false; } else if (myDontEncodeElements.stream().anyMatch(t -> t.equalsPath("*."+ thePath))) { return false; } } return true; }
@Override public void setEncodeElements(Set<String> theEncodeElements) { if (theEncodeElements == null || theEncodeElements.isEmpty()) { myEncodeElements = null; myEncodeElementsAppliesToResourceTypes = null; } else { myEncodeElements = theEncodeElements .stream() .map(ElementsPath::new) .collect(Collectors.toList()); myEncodeElementsAppliesToResourceTypes = new HashSet<>(); for (String next : myEncodeElements.stream().map(t -> t.getPath().get(0).getName()).collect(Collectors.toList())) { if (next.startsWith("*")) { myEncodeElementsAppliesToResourceTypes = null; break; } int dotIdx = next.indexOf('.'); if (dotIdx == -1) { myEncodeElementsAppliesToResourceTypes.add(next); } else { myEncodeElementsAppliesToResourceTypes.add(next.substring(0, dotIdx)); } } } }
for (ElementsPath next : theElements) { if (next.startsWith(currentResourcePath)) { if (theCheckingForEncodeElements || next.getPath().size() == currentResourcePath.getPath().size()) { retVal = true; break; if (next.getPath().get(next.getPath().size() - 1).getName().equals("(mandatory)")) { if (myDef.getMin() > 0) { retVal = true; break; if (currentResourcePath.getPath().size() > next.getPath().size()) { retVal = true; break;
protected boolean shouldEncodeResourceId(IBaseResource theResource, EncodeContext theEncodeContext) { boolean retVal = true; if (isOmitResourceId()) { retVal = false; } else { if (myDontEncodeElements != null) { String resourceName = myContext.getResourceDefinition(theResource).getName(); if (myDontEncodeElements.stream().anyMatch(t -> t.equalsPath(resourceName + ".id"))) { retVal = false; } else if (myDontEncodeElements.stream().anyMatch(t -> t.equalsPath("*.id"))) { retVal = false; } else if (theEncodeContext.getResourcePath().size() == 1 && myDontEncodeElements.stream().anyMatch(t -> t.equalsPath("id"))) { retVal = false; } } } return retVal; }
protected ElementsPath(String thePath) { StringTokenizer tok = new StringTokenizer(thePath, "."); boolean first = true; while (tok.hasMoreTokens()) { String next = tok.nextToken(); if (first && next.equals("*")) { getPath().add(new EncodeContextPathElement("*", true)); } else if (isNotBlank(next)) { getPath().add(new EncodeContextPathElement(next, Character.isUpperCase(next.charAt(0)))); } first = false; } }
public boolean equalsPath(String thePath) { ElementsPath parsedPath = new ElementsPath(thePath); return getPath().equals(parsedPath.getPath()); } }
public boolean startsWith(EncodeContextPath theCurrentResourcePath) { for (int i = 0; i < getPath().size(); i++) { if (theCurrentResourcePath.getPath().size() == i) { return true; } EncodeContextPathElement expected = getPath().get(i); EncodeContextPathElement actual = theCurrentResourcePath.getPath().get(i); if (!expected.matches(actual)) { return false; } } return true; }