@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)); } } } }
public boolean matches(EncodeContextPathElement theOther) { if (myResource != theOther.isResource()) { return false; } if (myName.equals(theOther.getName())) { return true; } if (myName.equals("*")) { return true; } return false; }
public String getLeafResourcePathFirstField() { String retVal = null; for (int i = getPath().size() - 1; i >= 0; i--) { if (getPath().get(i).isResource()) { break; } else { retVal = getPath().get(i).getName(); } } return retVal; }
if (next.getPath().get(next.getPath().size() - 1).getName().equals("(mandatory)")) { if (myDef.getMin() > 0) { retVal = true;
private boolean checkIfParentShouldBeEncodedAndBuildPath() { List<ElementsPath> encodeElements = myEncodeElements; String currentResourceName = myEncodeContext.getResourcePath().get(myEncodeContext.getResourcePath().size() - 1).getName(); if (myEncodeElementsAppliesToResourceTypes != null && !myEncodeElementsAppliesToResourceTypes.contains(currentResourceName)) { encodeElements = null; } boolean retVal = checkIfPathMatchesForEncoding(encodeElements, true); /* * We force the meta tag to be encoded even if it's not specified as an element in the * elements filter, specifically because we'll need it in order to automatically add * the SUBSETTED tag */ if (!retVal) { if ("meta".equals(myEncodeContext.getLeafResourcePathFirstField()) && shouldAddSubsettedTag(myEncodeContext)) { // The next element is a child of the <meta> element retVal = true; } else if ("meta".equals(myDef.getElementName()) && shouldAddSubsettedTag(myEncodeContext)) { // The next element is the <meta> element retVal = true; } } return retVal; }
protected boolean shouldAddSubsettedTag(EncodeContext theEncodeContext) { if (isSummaryMode()) { return true; } if (isSuppressNarratives()) { return true; } if (myEncodeElements != null) { if (isEncodeElementsAppliesToChildResourcesOnly() && theEncodeContext.getResourcePath().size() < 2) { return false; } String currentResourceName = theEncodeContext.getResourcePath().get(theEncodeContext.getResourcePath().size() - 1).getName(); if (myEncodeElementsAppliesToResourceTypes == null || myEncodeElementsAppliesToResourceTypes.contains(currentResourceName)) { return true; } } return false; }