You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by kw...@apache.org on 2019/11/03 16:13:27 UTC

svn commit: r1869339 - in /jackrabbit/commons/filevault/trunk/vault-validation/src: main/java/org/apache/jackrabbit/vault/validation/impl/util/ main/java/org/apache/jackrabbit/vault/validation/spi/ test/java/org/apache/jackrabbit/vault/validation/ test...

Author: kwin
Date: Sun Nov  3 16:13:27 2019
New Revision: 1869339

URL: http://svn.apache.org/viewvc?rev=1869339&view=rev
Log:
JCRVLT-354 do not call NodePathValidator for empty node elements

Added:
    jackrabbit/commons/filevault/trunk/vault-validation/src/test/resources/simple-package/jcr_root/apps/emptyelements/
    jackrabbit/commons/filevault/trunk/vault-validation/src/test/resources/simple-package/jcr_root/apps/emptyelements/.content.xml
Modified:
    jackrabbit/commons/filevault/trunk/vault-validation/src/main/java/org/apache/jackrabbit/vault/validation/impl/util/DocumentViewXmlContentHandler.java
    jackrabbit/commons/filevault/trunk/vault-validation/src/main/java/org/apache/jackrabbit/vault/validation/spi/NodePathValidator.java
    jackrabbit/commons/filevault/trunk/vault-validation/src/test/java/org/apache/jackrabbit/vault/validation/DocumentViewParserValidatorTest.java

Modified: jackrabbit/commons/filevault/trunk/vault-validation/src/main/java/org/apache/jackrabbit/vault/validation/impl/util/DocumentViewXmlContentHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-validation/src/main/java/org/apache/jackrabbit/vault/validation/impl/util/DocumentViewXmlContentHandler.java?rev=1869339&r1=1869338&r2=1869339&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-validation/src/main/java/org/apache/jackrabbit/vault/validation/impl/util/DocumentViewXmlContentHandler.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-validation/src/main/java/org/apache/jackrabbit/vault/validation/impl/util/DocumentViewXmlContentHandler.java Sun Nov  3 16:13:27 2019
@@ -129,7 +129,6 @@ public class DocumentViewXmlContentHandl
         while (iterator.hasNext()) {
             nodePath.append("/").append(iterator.next());
         }
-        nodePathsAndLineNumbers.put(nodePath.toString(), locator.getLineNumber());
         nodePathStack.push(nodePath.toString());
         try {
             DocViewNode node = getDocViewNode(name, label, attributes);
@@ -145,6 +144,10 @@ public class DocumentViewXmlContentHandl
         } catch (IllegalArgumentException e) { // thrown from DocViewProperty.parse()
             violations.add(new ValidationViolation(ValidationMessageSeverity.ERROR, String.format(PARSE_VIOLATION_MESSAGE_STRING, qName, e.getMessage()), filePath, null, nodePath.toString(), locator.getLineNumber(), locator.getColumnNumber(), e));
         }
+        // do not collect node paths for empty elements (as they represent order only)
+        if (attributes.getLength() > 0) {
+            nodePathsAndLineNumbers.put(nodePath.toString(), locator.getLineNumber());
+        }
     }
 
     private DocViewNode getDocViewNode(String name, String label, Attributes attributes) {

Modified: jackrabbit/commons/filevault/trunk/vault-validation/src/main/java/org/apache/jackrabbit/vault/validation/spi/NodePathValidator.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-validation/src/main/java/org/apache/jackrabbit/vault/validation/spi/NodePathValidator.java?rev=1869339&r1=1869338&r2=1869339&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-validation/src/main/java/org/apache/jackrabbit/vault/validation/spi/NodePathValidator.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-validation/src/main/java/org/apache/jackrabbit/vault/validation/spi/NodePathValidator.java Sun Nov  3 16:13:27 2019
@@ -33,6 +33,7 @@ import org.osgi.annotation.versioning.Pr
 public interface NodePathValidator extends Validator {
     /**
      * Called for each node being found in a package.
+     * Empty node elements (in DocView files) are not included as they are only used for ordering purposes.
      * 
      * @param nodePath the absolute node path
      * @return validation messages or {@code null}

Modified: jackrabbit/commons/filevault/trunk/vault-validation/src/test/java/org/apache/jackrabbit/vault/validation/DocumentViewParserValidatorTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-validation/src/test/java/org/apache/jackrabbit/vault/validation/DocumentViewParserValidatorTest.java?rev=1869339&r1=1869338&r2=1869339&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-validation/src/test/java/org/apache/jackrabbit/vault/validation/DocumentViewParserValidatorTest.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-validation/src/test/java/org/apache/jackrabbit/vault/validation/DocumentViewParserValidatorTest.java Sun Nov  3 16:13:27 2019
@@ -111,6 +111,20 @@ public class DocumentViewParserValidator
     }
 
     @Test
+    public void testDocViewWithEmptyElements() throws IOException {
+        try (InputStream input = this.getClass().getResourceAsStream("/simple-package/jcr_root/apps/emptyelements/.content.xml")) {
+            Collection<ValidationMessage> messages = validator.validateJcrData(input, Paths.get("apps", "emptyelements", ".content.xml"), nodePathsAndLineNumbers);
+            Assert.assertThat(messages, AnyValidationMessageMatcher.noValidationInCollection());
+
+            // verify node names
+            Map<String, Integer> expectedNodePathsAndLineNumber = new HashMap<>();
+            expectedNodePathsAndLineNumber.put("/apps/emptyelements", 20);
+            expectedNodePathsAndLineNumber.put("/apps/emptyelements/nonemptyelement", 23);
+            Assert.assertEquals(expectedNodePathsAndLineNumber, nodePathsAndLineNumbers);
+        }
+    }
+    
+    @Test
     public void testDocViewWithRegularFileName()
             throws ParserConfigurationException, SAXException, URISyntaxException, IOException, NamespaceException {
 

Added: jackrabbit/commons/filevault/trunk/vault-validation/src/test/resources/simple-package/jcr_root/apps/emptyelements/.content.xml
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-validation/src/test/resources/simple-package/jcr_root/apps/emptyelements/.content.xml?rev=1869339&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-validation/src/test/resources/simple-package/jcr_root/apps/emptyelements/.content.xml (added)
+++ jackrabbit/commons/filevault/trunk/vault-validation/src/test/resources/simple-package/jcr_root/apps/emptyelements/.content.xml Sun Nov  3 16:13:27 2019
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  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.
+  -->
+
+<jcr:root xmlns:sling="http://sling.apache.org/jcr/sling/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0"
+    jcr:primaryType="sling:Folder">
+    <emptyelement1></emptyelement1>
+    <emptyelement2 />
+    <nonemptyelement jcr:primaryType="sling:Folder" />
+</jcr:root>
\ No newline at end of file