in src/main/java/org/apache/sling/scriptingbundle/plugin/processor/filevault/VaultContentXmlReader.java [71:124]
public VaultContentXmlReader(@NotNull Path path) throws IOException {
this.path = path;
this.requiredResourceTypes = new HashSet<>();
try (BufferedReader reader = Files.newBufferedReader(path, StandardCharsets.UTF_8)) {
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
Document document = documentBuilder.parse(new InputSource(reader));
NodeList nodeList = document.getElementsByTagNameNS(NameConstants.JCR_ROOT.getNamespaceURI(),
NameConstants.JCR_ROOT.getLocalName());
if (nodeList.getLength() == 1 && nodeList.item(0).equals(document.getDocumentElement())) {
String resourceSuperTypeRawValue = document.getDocumentElement().getAttributeNS(JcrResourceConstants.SLING_NAMESPACE_URI,
Constants.SLING_RESOURCE_SUPER_TYPE_XML_LOCAL_NAME);
if (StringUtils.isNotEmpty(resourceSuperTypeRawValue)) {
DocViewProperty resourceSuperTypeDocViewProperty =
DocViewProperty.parse(JcrResourceConstants.SLING_RESOURCE_SUPER_TYPE_PROPERTY, resourceSuperTypeRawValue);
if ((resourceSuperTypeDocViewProperty.type == PropertyType.STRING ||
resourceSuperTypeDocViewProperty.type == PropertyType.UNDEFINED) && !resourceSuperTypeDocViewProperty.isMulti) {
this.resourceSuperType = resourceSuperTypeDocViewProperty.values[0];
} else {
throw new IllegalArgumentException(String.format("Invalid %s property value (%s) in file %s.",
JcrResourceConstants.SLING_RESOURCE_SUPER_TYPE_PROPERTY, resourceSuperTypeRawValue, path));
}
} else {
this.resourceSuperType = null;
}
String requiredResourceTypesRawValue =
document.getDocumentElement().getAttributeNS(JcrResourceConstants.SLING_NAMESPACE_URI
, Constants.SLING_REQUIRED_RESOURCE_TYPES_XML_LOCAL_NAME);
if (StringUtils.isNotEmpty(requiredResourceTypesRawValue)) {
DocViewProperty requiredResourceTypesDocViewProperty =
DocViewProperty.parse(Constants.SLING_REQUIRED_RESOURCE_TYPES,
requiredResourceTypesRawValue);
if (requiredResourceTypesDocViewProperty.isMulti &&
(requiredResourceTypesDocViewProperty.type == PropertyType.STRING ||
requiredResourceTypesDocViewProperty.type == PropertyType.UNDEFINED)) {
requiredResourceTypes.addAll(Arrays.asList(requiredResourceTypesDocViewProperty.values));
} else {
throw new IllegalArgumentException(String.format("Invalid %s property value (%s) in file %s.",
Constants.SLING_REQUIRED_RESOURCE_TYPES, requiredResourceTypesRawValue, path));
}
}
} else {
throw new IllegalArgumentException(String.format(
"Path %s does not seem to provide a Docview format - https://jackrabbit.apache.org/filevault/docview.html.",
path));
}
} catch (ParserConfigurationException | SAXException e) {
throw new IOException(e);
}
}