Michiel Eggermont pushed to branch feature/wpm at cms-community / 
hippo-site-toolkit


Commits:
ca8e8c29 by Michiel Eggermont at 2017-05-18T14:14:08+02:00
HSTTWO-4016 Replace validation code by recursive method

- - - - -


1 changed file:

- 
components/core/src/main/java/org/hippoecm/hst/configuration/branch/WorkspaceHasher.java


Changes:

=====================================
components/core/src/main/java/org/hippoecm/hst/configuration/branch/WorkspaceHasher.java
=====================================
--- 
a/components/core/src/main/java/org/hippoecm/hst/configuration/branch/WorkspaceHasher.java
+++ 
b/components/core/src/main/java/org/hippoecm/hst/configuration/branch/WorkspaceHasher.java
@@ -21,6 +21,7 @@ import java.util.Set;
 import java.util.SortedSet;
 import java.util.TreeSet;
 
+import javax.jcr.ItemNotFoundException;
 import javax.jcr.Node;
 import javax.jcr.Property;
 import javax.jcr.PropertyType;
@@ -28,7 +29,6 @@ import javax.jcr.RepositoryException;
 import javax.jcr.Value;
 import javax.xml.bind.annotation.adapters.HexBinaryAdapter;
 
-import org.hippoecm.hst.configuration.HstNodeTypes;
 import org.hippoecm.hst.diagnosis.HDC;
 import org.hippoecm.hst.diagnosis.Task;
 import org.hippoecm.hst.statistics.Counter;
@@ -92,19 +92,10 @@ public class WorkspaceHasher implements NodeHasher {
                 hashTask = HDC.getCurrentTask().startSubtask("HashTask Node");
                 hashTask.setAttribute("Node path", node.getPath());
             }
-            if (!node.isNodeType(NODETYPE_HST_WORKSPACE)) {
-                Node current = node;
-                final Node root = node.getSession().getRootNode();
-                while (!current.isSame(root)) {
-                    current = current.getParent();
-                    if (current.isNodeType(NODETYPE_HST_WORKSPACE)) {
-                        break;
-                    }
-                }
-                if (current.isSame(root)) {
-                    throw new BranchException(String.format("Cannot not hash 
the node '%s' because not of type '%s' or " +
-                            "not a descendant of a node of type '%s'.", 
node.getPath(), NODETYPE_HST_WORKSPACE, NODETYPE_HST_WORKSPACE));
-                }
+
+            if (!isOrHasAncestorOfType(node, NODETYPE_HST_WORKSPACE)) {
+                throw new BranchException(String.format("Cannot not hash the 
node '%s' because not of type '%s' or " +
+                        "not a descendant of a node of type '%s'.", 
node.getPath(), NODETYPE_HST_WORKSPACE, NODETYPE_HST_WORKSPACE));
             }
 
             return startHashing(node, setHash, setUpstreamHash, counter);
@@ -123,6 +114,14 @@ public class WorkspaceHasher implements NodeHasher {
         }
     }
 
+    private boolean isOrHasAncestorOfType(final Node node, final String 
nodeType) throws RepositoryException {
+        try {
+            return node.isNodeType(nodeType) || 
isOrHasAncestorOfType(node.getParent(), nodeType);
+        } catch (ItemNotFoundException e) {
+            return false;
+        }
+    }
+
     private String startHashing(final Node node, final boolean setHash,
                               final boolean setUpstreamHash, final Counter 
counter) throws NoSuchAlgorithmException, RepositoryException {
         long start = System.currentTimeMillis();



View it on GitLab: 
https://code.onehippo.org/cms-community/hippo-site-toolkit/commit/ca8e8c29cfac72363cb18bd1284fd69b978af56c
_______________________________________________
Hippocms-svn mailing list
Hippocms-svn@lists.onehippo.org
https://lists.onehippo.org/mailman/listinfo/hippocms-svn

Reply via email to