kwin commented on a change in pull request #8:
URL: 
https://github.com/apache/sling-scriptingbundle-maven-plugin/pull/8#discussion_r708130483



##########
File path: 
src/main/java/org/apache/sling/scriptingbundle/plugin/processor/Constants.java
##########
@@ -53,6 +53,10 @@ private Constants() {}
     public static final String BND_SCRIPT_ENGINE_MAPPINGS = 
"scriptEngineMappings";
     public static final String BND_SEARCH_PATHS = "searchPaths";
 
+    public static final String VAULT_CONTEXT_XML = ".content.xml";

Review comment:
       There is a constant in FileVault

##########
File path: 
src/main/java/org/apache/sling/scriptingbundle/plugin/processor/filevault/VaultContentXmlReader.java
##########
@@ -0,0 +1,123 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements.  See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership.  The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License.  You may obtain a copy of the License at
+ ~
+ ~   http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied.  See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+package org.apache.sling.scriptingbundle.plugin.processor.filevault;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+
+import javax.xml.XMLConstants;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.jackrabbit.vault.util.DocViewProperty;
+import org.apache.sling.scriptingbundle.plugin.processor.Constants;
+import org.jetbrains.annotations.NotNull;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+public class VaultContentXmlReader {
+
+    private static final DocumentBuilderFactory documentBuilderFactory;
+
+    static {
+        try {
+            documentBuilderFactory = DocumentBuilderFactory.newInstance();
+            
documentBuilderFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
+            
documentBuilderFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
+            
documentBuilderFactory.setAttribute(XMLConstants.FEATURE_SECURE_PROCESSING, 
Boolean.TRUE);
+            documentBuilderFactory.setExpandEntityReferences(false);
+        } catch (IllegalArgumentException e) {
+            throw new IllegalStateException("Cannot disable DTD features.", e);
+        }
+    }
+
+    private final Path path;
+    private final String resourceSuperType;
+    private final Set<String> requiredResourceTypes;
+
+    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));
+            Element documentElement = document.getDocumentElement();
+            if ("jcr:root".equals(documentElement.getTagName())) {
+                this.resourceSuperType = 
document.getDocumentElement().getAttribute(Constants.SLING_RESOURCE_SUPER_TYPE);

Review comment:
       You need to consider namespaces defined in the xml and check against the 
fully qualified element name. Docview XMLs might use other url prefixes than 
"sling"

##########
File path: 
src/main/java/org/apache/sling/scriptingbundle/plugin/processor/ResourceTypeFolderAnalyser.java
##########
@@ -66,6 +66,8 @@ public Capabilities getCapabilities(@NotNull Path 
resourceTypeDirectory) {
                                 fileProcessor.processExtendsFile(resourceType, 
entry, providedCapabilities, requiredCapabilities);
                             } else if 
(Constants.REQUIRES_FILE.equals(file.toString())) {
                                 fileProcessor.processRequiresFile(entry, 
requiredCapabilities);
+                            } else if 
(Constants.VAULT_CONTEXT_XML.equals(file.toString())) {

Review comment:
       Every docview file may be relevant, not only the ones named 
".content.xml". You should check for extension .xml first and then you need to 
parse the first bytes to check if it is docview. Filevault provides a utility 
method for that.

##########
File path: 
src/main/java/org/apache/sling/scriptingbundle/plugin/processor/filevault/VaultContentXmlReader.java
##########
@@ -0,0 +1,123 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements.  See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership.  The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License.  You may obtain a copy of the License at
+ ~
+ ~   http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied.  See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+package org.apache.sling.scriptingbundle.plugin.processor.filevault;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+
+import javax.xml.XMLConstants;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.jackrabbit.vault.util.DocViewProperty;
+import org.apache.sling.scriptingbundle.plugin.processor.Constants;
+import org.jetbrains.annotations.NotNull;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+public class VaultContentXmlReader {
+
+    private static final DocumentBuilderFactory documentBuilderFactory;
+
+    static {
+        try {
+            documentBuilderFactory = DocumentBuilderFactory.newInstance();
+            
documentBuilderFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
+            
documentBuilderFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
+            
documentBuilderFactory.setAttribute(XMLConstants.FEATURE_SECURE_PROCESSING, 
Boolean.TRUE);
+            documentBuilderFactory.setExpandEntityReferences(false);
+        } catch (IllegalArgumentException e) {
+            throw new IllegalStateException("Cannot disable DTD features.", e);
+        }
+    }
+
+    private final Path path;
+    private final String resourceSuperType;
+    private final Set<String> requiredResourceTypes;
+
+    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));
+            Element documentElement = document.getDocumentElement();
+            if ("jcr:root".equals(documentElement.getTagName())) {
+                this.resourceSuperType = 
document.getDocumentElement().getAttribute(Constants.SLING_RESOURCE_SUPER_TYPE);
+                String requiredResourceTypesValue = 
document.getDocumentElement().getAttribute(Constants.SLING_REQUIRED_RESOURCE_TYPES);
+                if (requiredResourceTypesValue != null) {
+                    DocViewProperty requiredResourceTypesDocView = 
DocViewProperty.parse(Constants.SLING_REQUIRED_RESOURCE_TYPES,
+                            requiredResourceTypesValue);
+                    
requiredResourceTypes.addAll(Arrays.asList(requiredResourceTypesDocView.values));
+                }
+            } else {
+                throw new IllegalArgumentException(String.format("Path %s does 
not seem to be a valid Vault .content.xml file.", path));

Review comment:
       Not sure this is really invalid. Usually jcr:root means node name comes 
from file name, every other value means the file name's value is not considered 
for the node name but only the given tag name.

##########
File path: 
src/main/java/org/apache/sling/scriptingbundle/plugin/processor/filevault/VaultContentXmlReader.java
##########
@@ -0,0 +1,123 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements.  See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership.  The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License.  You may obtain a copy of the License at
+ ~
+ ~   http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied.  See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+package org.apache.sling.scriptingbundle.plugin.processor.filevault;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+
+import javax.xml.XMLConstants;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.jackrabbit.vault.util.DocViewProperty;
+import org.apache.sling.scriptingbundle.plugin.processor.Constants;
+import org.jetbrains.annotations.NotNull;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+public class VaultContentXmlReader {
+
+    private static final DocumentBuilderFactory documentBuilderFactory;
+
+    static {
+        try {
+            documentBuilderFactory = DocumentBuilderFactory.newInstance();
+            
documentBuilderFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
+            
documentBuilderFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
+            
documentBuilderFactory.setAttribute(XMLConstants.FEATURE_SECURE_PROCESSING, 
Boolean.TRUE);
+            documentBuilderFactory.setExpandEntityReferences(false);
+        } catch (IllegalArgumentException e) {
+            throw new IllegalStateException("Cannot disable DTD features.", e);
+        }
+    }
+
+    private final Path path;
+    private final String resourceSuperType;
+    private final Set<String> requiredResourceTypes;
+
+    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();

Review comment:
       I would prefer a SaxParser as it requires less memory. 

##########
File path: 
src/main/java/org/apache/sling/scriptingbundle/plugin/processor/Constants.java
##########
@@ -53,6 +53,10 @@ private Constants() {}
     public static final String BND_SCRIPT_ENGINE_MAPPINGS = 
"scriptEngineMappings";
     public static final String BND_SEARCH_PATHS = "searchPaths";
 
+    public static final String VAULT_CONTEXT_XML = ".content.xml";
+    public static final String SLING_RESOURCE_SUPER_TYPE = 
"sling:resourceSuperType";
+    public static final String SLING_REQUIRED_RESOURCE_TYPES = 
"sling:requiredResourceTypes";

Review comment:
       This requires some documentation as this is not a standard attribute.

##########
File path: 
src/main/java/org/apache/sling/scriptingbundle/plugin/processor/filevault/VaultContentXmlReader.java
##########
@@ -0,0 +1,123 @@
+/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ ~ Licensed to the Apache Software Foundation (ASF) under one
+ ~ or more contributor license agreements.  See the NOTICE file
+ ~ distributed with this work for additional information
+ ~ regarding copyright ownership.  The ASF licenses this file
+ ~ to you under the Apache License, Version 2.0 (the
+ ~ "License"); you may not use this file except in compliance
+ ~ with the License.  You may obtain a copy of the License at
+ ~
+ ~   http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing,
+ ~ software distributed under the License is distributed on an
+ ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ~ KIND, either express or implied.  See the License for the
+ ~ specific language governing permissions and limitations
+ ~ under the License.
+ 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+package org.apache.sling.scriptingbundle.plugin.processor.filevault;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Set;
+
+import javax.xml.XMLConstants;
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.jackrabbit.vault.util.DocViewProperty;
+import org.apache.sling.scriptingbundle.plugin.processor.Constants;
+import org.jetbrains.annotations.NotNull;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+public class VaultContentXmlReader {
+
+    private static final DocumentBuilderFactory documentBuilderFactory;
+
+    static {
+        try {
+            documentBuilderFactory = DocumentBuilderFactory.newInstance();
+            
documentBuilderFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
+            
documentBuilderFactory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
+            
documentBuilderFactory.setAttribute(XMLConstants.FEATURE_SECURE_PROCESSING, 
Boolean.TRUE);
+            documentBuilderFactory.setExpandEntityReferences(false);
+        } catch (IllegalArgumentException e) {
+            throw new IllegalStateException("Cannot disable DTD features.", e);
+        }
+    }
+
+    private final Path path;
+    private final String resourceSuperType;
+    private final Set<String> requiredResourceTypes;
+
+    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));
+            Element documentElement = document.getDocumentElement();
+            if ("jcr:root".equals(documentElement.getTagName())) {
+                this.resourceSuperType = 
document.getDocumentElement().getAttribute(Constants.SLING_RESOURCE_SUPER_TYPE);
+                String requiredResourceTypesValue = 
document.getDocumentElement().getAttribute(Constants.SLING_REQUIRED_RESOURCE_TYPES);
+                if (requiredResourceTypesValue != null) {
+                    DocViewProperty requiredResourceTypesDocView = 
DocViewProperty.parse(Constants.SLING_REQUIRED_RESOURCE_TYPES,
+                            requiredResourceTypesValue);

Review comment:
       Values from docview need to be unescaped.

##########
File path: 
src/main/java/org/apache/sling/scriptingbundle/plugin/processor/Constants.java
##########
@@ -53,6 +53,10 @@ private Constants() {}
     public static final String BND_SCRIPT_ENGINE_MAPPINGS = 
"scriptEngineMappings";
     public static final String BND_SEARCH_PATHS = "searchPaths";
 
+    public static final String VAULT_CONTEXT_XML = ".content.xml";
+    public static final String SLING_RESOURCE_SUPER_TYPE = 
"sling:resourceSuperType";

Review comment:
       There is a constant in Sling API

##########
File path: pom.xml
##########
@@ -54,7 +54,7 @@
     </properties>
 
     <prerequisites>
-        <maven>${mavenVersion}</maven>
+        <maven>${maven.version}</maven>

Review comment:
       We should use the property name from ASF parent.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to