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 2021/06/30 15:58:45 UTC
[jackrabbit-filevault] 01/01: JCRVLT-544 never create intermediate
nodes of type nt:base or nt:hierarchyNode
This is an automated email from the ASF dual-hosted git repository.
kwin pushed a commit to branch bugfix/JCRVLT-544-use-nt-folder-for-certain-primary-nodetypes
in repository https://gitbox.apache.org/repos/asf/jackrabbit-filevault.git
commit 9b04b30baf83d40998a7b5b45664588370c41848
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Wed Jun 30 17:58:29 2021 +0200
JCRVLT-544 never create intermediate nodes of type nt:base or
nt:hierarchyNode
Both types have too many restrictions to be useful as intermediate node
types
---
.../vault/fs/impl/io/FolderArtifactHandler.java | 62 +++++++++++++---------
1 file changed, 37 insertions(+), 25 deletions(-)
diff --git a/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/FolderArtifactHandler.java b/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/FolderArtifactHandler.java
index c8131b8..cf1b4aa 100644
--- a/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/FolderArtifactHandler.java
+++ b/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/FolderArtifactHandler.java
@@ -18,7 +18,9 @@
package org.apache.jackrabbit.vault.fs.impl.io;
import java.io.IOException;
+import java.util.Arrays;
import java.util.HashSet;
+import java.util.List;
import java.util.Set;
import javax.jcr.Node;
@@ -26,6 +28,7 @@ import javax.jcr.NodeIterator;
import javax.jcr.Property;
import javax.jcr.PropertyIterator;
import javax.jcr.RepositoryException;
+import javax.jcr.nodetype.NodeType;
import org.apache.jackrabbit.vault.fs.api.Artifact;
import org.apache.jackrabbit.vault.fs.api.ArtifactType;
@@ -42,6 +45,11 @@ import org.apache.jackrabbit.vault.util.JcrConstants;
public class FolderArtifactHandler extends AbstractArtifactHandler {
/**
+ * names of those default node type which should not be used for intermediate nodes (as they come with too many restrictions)
+ */
+ private static final List<String> DISALLOWED_PRIMARY_NODE_TYPE_NAMES = Arrays.asList(NodeType.NT_BASE, NodeType.NT_HIERARCHY_NODE);
+
+ /**
* node type to use for the folders
*/
private String nodeType = JcrConstants.NT_FOLDER;
@@ -62,6 +70,18 @@ public class FolderArtifactHandler extends AbstractArtifactHandler {
this.nodeType = nodeType;
}
+ private Node createIntermediateNode(Node parent, String intermediateNodeName) throws RepositoryException {
+ // preferably use default (=primary) node type for intermediate nodes
+ NodeType primaryNodeType = parent.getPrimaryNodeType();
+ final Node node;
+ if (!DISALLOWED_PRIMARY_NODE_TYPE_NAMES.contains(primaryNodeType.getName()) &&
+ parent.getPrimaryNodeType().canAddChildNode(intermediateNodeName)) {
+ node = parent.addNode(intermediateNodeName);
+ } else {
+ node = parent.addNode(intermediateNodeName, nodeType);
+ }
+ return node;
+ }
/**
* {@inheritDoc}
*
@@ -84,18 +104,12 @@ public class FolderArtifactHandler extends AbstractArtifactHandler {
if (wspFilter.contains(parent.getPath() + "/" + dir.getRelativePath())) {
node = parent.addNode(dir.getRelativePath(), nodeType);
} else {
- // preferably use default node type for intermediate nodes
- if (parent.getPrimaryNodeType().canAddChildNode(dir.getRelativePath())) {
- node = parent.addNode(dir.getRelativePath());
- } else {
- node = parent.addNode(dir.getRelativePath(), nodeType);
- }
-
+ node = createIntermediateNode(parent, dir.getRelativePath());
}
info.onCreated(node.getPath());
} else {
// sync nodes
- Set<String> hints = new HashSet<String>();
+ Set<String> hints = new HashSet<>();
String rootPath = parent.getPath();
if (!rootPath.equals("/")) {
rootPath += "/";
@@ -112,26 +126,24 @@ public class FolderArtifactHandler extends AbstractArtifactHandler {
while (iter.hasNext()) {
Node child = iter.nextNode();
String path = child.getPath();
- if (wspFilter.contains(path)) {
- if (wspFilter.getImportMode(path) == ImportMode.REPLACE) {
- if (!hints.contains(path)) {
- // if the child is in the filter, it belongs to
- // this aggregate and needs to be removed
- if (getAclManagement().isACLNode(child)) {
- if (acHandling == AccessControlHandling.OVERWRITE
- || acHandling == AccessControlHandling.CLEAR) {
- info.onDeleted(path);
- getAclManagement().clearACL(node);
- }
- } else {
+ if (wspFilter.contains(path) && wspFilter.getImportMode(path) == ImportMode.REPLACE) {
+ if (!hints.contains(path)) {
+ // if the child is in the filter, it belongs to
+ // this aggregate and needs to be removed
+ if (getAclManagement().isACLNode(child)) {
+ if (acHandling == AccessControlHandling.OVERWRITE
+ || acHandling == AccessControlHandling.CLEAR) {
info.onDeleted(path);
- child.remove();
+ getAclManagement().clearACL(node);
}
- } else if (acHandling == AccessControlHandling.CLEAR
- && getAclManagement().isACLNode(child)) {
+ } else {
info.onDeleted(path);
- getAclManagement().clearACL(node);
+ child.remove();
}
+ } else if (acHandling == AccessControlHandling.CLEAR
+ && getAclManagement().isACLNode(child)) {
+ info.onDeleted(path);
+ getAclManagement().clearACL(node);
}
}
}
@@ -169,7 +181,7 @@ public class FolderArtifactHandler extends AbstractArtifactHandler {
try {
node.checkout();
} catch (RepositoryException e) {
- info.log.warn("error while checkout node (ignored)", e);
+ ImportInfoImpl.log.warn("error while checkout node (ignored)", e);
}
}
}