jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tri...@apache.org
Subject svn commit: r1567854 - in /jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io: DocViewSAXImporter.java FileArtifactHandler.java
Date Thu, 13 Feb 2014 07:01:58 GMT
Author: tripod
Date: Thu Feb 13 07:01:57 2014
New Revision: 1567854

URL: http://svn.apache.org/r1567854
Log:
JCRVLT-28 Improve package import for subtrees

Modified:
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewSAXImporter.java
    jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/FileArtifactHandler.java

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewSAXImporter.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewSAXImporter.java?rev=1567854&r1=1567853&r2=1567854&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewSAXImporter.java
(original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewSAXImporter.java
Thu Feb 13 07:01:57 2014
@@ -320,7 +320,7 @@ public class DocViewSAXImporter extends 
     @Override
     public void startDocument() throws SAXException {
         try {
-            stack = new StackElement(null, parentNode);
+            stack = new StackElement(parentNode, parentNode.isNew());
         } catch (RepositoryException e) {
             throw new SAXException(e);
         }
@@ -346,12 +346,12 @@ public class DocViewSAXImporter extends 
                     for (String propName: blobs.keySet()) {
                         DocViewSAXImporter.BlobInfo info = blobs.get(propName);
                         if (node.hasNode(propName)) {
-                            handleBinNode(node.getNode(propName), info);
+                            handleBinNode(node.getNode(propName), info, true);
                         } else if (info.isFile()) {
                             // special case for not existing files
                             Node fNode = node.addNode(propName, JcrConstants.NT_FILE);
                             importInfo.onCreated(fNode.getPath());
-                            handleBinNode(fNode, info);
+                            handleBinNode(fNode, info, false);
                         } else {
                             if (info.isMulti) {
                                 node.setProperty(propName, info.getValues(session));
@@ -374,7 +374,7 @@ public class DocViewSAXImporter extends 
                             }
                             Node fNode = node.addNode(propName, JcrConstants.NT_FILE);
                             importInfo.onCreated(fNode.getPath());
-                            handleBinNode(fNode, info);
+                            handleBinNode(fNode, info, false);
                         }
                     }
                 }
@@ -406,18 +406,23 @@ public class DocViewSAXImporter extends 
         return node;
     }
 
-    private void handleBinNode(Node node, DocViewSAXImporter.BlobInfo info)
+    private void handleBinNode(Node node, DocViewSAXImporter.BlobInfo info, boolean checkIfNtFileOk)
             throws RepositoryException, IOException {
         log.debug("handling binary file at {}", node.getPath());
         if (info.isMulti) {
             throw new IllegalStateException("unable to add MV binary to node " + node.getPath());
         }
-        if (node.isNodeType(JcrConstants.NT_FILE)) {
-            if (node.hasNode(JcrConstants.JCR_CONTENT)) {
-                node = node.getNode(JcrConstants.JCR_CONTENT);
-            } else {
-                node = node.addNode(JcrConstants.JCR_CONTENT, JcrConstants.NT_RESOURCE);
+
+        if (checkIfNtFileOk) {
+            if (node.isNodeType(JcrConstants.NT_FILE)) {
+                if (node.hasNode(JcrConstants.JCR_CONTENT)) {
+                    node = node.getNode(JcrConstants.JCR_CONTENT);
+                } else {
+                    node = node.addNode(JcrConstants.JCR_CONTENT, JcrConstants.NT_RESOURCE);
+                }
             }
+        } else {
+            node = node.addNode(JcrConstants.JCR_CONTENT, JcrConstants.NT_RESOURCE);
         }
 
         Artifact a = info.artifacts.get(0);
@@ -586,7 +591,7 @@ public class DocViewSAXImporter extends 
             stack.addName(label);
             Node node = stack.getNode();
             if (node == null) {
-                stack = stack.push(null);
+                stack = stack.push();
                 DocViewAdapter xform = stack.getAdapter();
                 if (xform != null) {
                     DocViewNode ni = new DocViewNode(name, label, attributes, npResolver);
@@ -598,11 +603,11 @@ public class DocViewSAXImporter extends 
                 if (attributes.getLength() == 0) {
                     // only ordering node. skip
                     log.debug("Skipping empty node {}", node.getPath() + "/" + name);
-                    stack = stack.push(null);
+                    stack = stack.push();
                 } else if (snsNode) {
                     // skip SNS nodes with index > 1
                     log.warn("Skipping unsupported SNS node with index > 1. Some content
will be missing after import: {}", node.getPath() + "/" + label);
-                    stack = stack.push(null);
+                    stack = stack.push();
                 } else {
                     try {
                         DocViewNode ni = new DocViewNode(name, label, attributes, npResolver);
@@ -612,12 +617,12 @@ public class DocViewSAXImporter extends 
                                 if (aclManagement.ensureAccessControllable(node)) {
                                     log.info("Adding ACL element to non ACL parent - adding
mixin: {}", node.getPath());
                                 }
-                                stack = stack.push(null);
+                                stack = stack.push();
                                 stack.adapter = new JackrabbitACLImporter(node, aclHandling);
                                 stack.adapter.startNode(ni);
                                 importInfo.onCreated(node.getPath() + "/" + ni.name);
                             } else {
-                                stack = stack.push(null);
+                                stack = stack.push();
                             }
                         } else if (userManagement != null && userManagement.isAuthorizableNodeType(ni.primary))
{
                             boolean skip = false;
@@ -642,18 +647,17 @@ public class DocViewSAXImporter extends 
                             }
                             if (skip) {
                                 log.info("Skipping import of existing authorizable '{}' due
to MERGE import mode.", id);
-                                stack = stack.push(null);
+                                stack = stack.push();
                                 importInfo.onNop(node.getPath() + "/" + ni.name);
                             } else {
                                 log.debug("Authorizable element detected. starting sysview
transformation {}/{}", node.getPath(), name);
-                                stack = stack.push(null);
+                                stack = stack.push();
                                 stack.adapter = new JcrSysViewTransformer(node);
                                 stack.adapter.startNode(ni);
                                 importInfo.onCreated(node.getPath() + "/" + ni.name);
                             }
                         } else {
-                            Node childNode = addNode(ni);
-                            stack = stack.push(childNode);
+                            stack = stack.push(addNode(ni));
                         }
                     } catch (RepositoryException e) {
                         String errPath = node.getPath();
@@ -663,7 +667,7 @@ public class DocViewSAXImporter extends 
                         errPath += name;
                         log.error("Error during processing of {}: {}", errPath, e.toString());
                         importInfo.onError(errPath, e);
-                        stack = stack.push(null);
+                        stack = stack.push();
                     }
                 }
             }
@@ -672,8 +676,7 @@ public class DocViewSAXImporter extends 
         }
     }
 
-    private Node addNode(DocViewNode ni)
-            throws RepositoryException, IOException {
+    private StackElement addNode(DocViewNode ni) throws RepositoryException, IOException
{
         final Node currentNode = stack.getNode();
 
         // find old node
@@ -683,7 +686,7 @@ public class DocViewSAXImporter extends 
             // special case for root node update
             node = currentNode;
         } else if (ni.uuid == null) {
-            if (currentNode.hasNode(ni.label)) {
+            if (!stack.isNew && currentNode.hasNode(ni.label)) {
                 node = currentNode.getNode(ni.label);
                 if (ni.primary != null && !node.getPrimaryNodeType().getName().equals(ni.primary))
{
                     // if node type mismatches => replace
@@ -710,7 +713,7 @@ public class DocViewSAXImporter extends 
                 // ignore
             }
             if (node == null) {
-                if (currentNode.hasNode(ni.label)) {
+                if (!stack.isNew && currentNode.hasNode(ni.label)) {
                     node = currentNode.getNode(ni.label);
                     if (ni.primary != null && !node.getPrimaryNodeType().getName().equals(ni.primary))
{
                         // if node type mismatches => replace
@@ -796,7 +799,7 @@ public class DocViewSAXImporter extends 
                 }
             }
             importInfo.onReplaced(node.getPath());
-            return node;
+            return new StackElement(node, false);
         }
 
         // check if new node needs to be checked in
@@ -804,6 +807,7 @@ public class DocViewSAXImporter extends 
         boolean isCheckedIn = coProp != null && coProp.values[0].equals("false");
 
         // create or update node
+        boolean isNew = false;
         if (node == null) {
             // workaround for bug in jcr2spi if mixins are empty
             if (!ni.props.containsKey(JcrConstants.JCR_MIXINTYPES)) {
@@ -822,6 +826,7 @@ public class DocViewSAXImporter extends 
                 importInfo.registerToVersion(node.getPath());
             }
             importInfo.onCreated(node.getPath());
+            isNew = true;
 
         } else if (isIncluded(node, node.getDepth() - rootDepth)){
             boolean modified = false;
@@ -918,8 +923,7 @@ public class DocViewSAXImporter extends 
                 importInfo.onNop(node.getPath());
             }
         }
-
-        return node;
+        return new StackElement(node, isNew);
     }
 
     private Node createNode(Node currentNode, DocViewNode ni)
@@ -1228,20 +1232,22 @@ public class DocViewSAXImporter extends 
 
         private final Node node;
 
-        final DocViewSAXImporter.StackElement parent;
+        private DocViewSAXImporter.StackElement parent;
 
         private final NodeNameList childNames = new NodeNameList();
 
         private boolean isCheckedOut;
 
+        private boolean isNew;
+
         /**
          * adapter for special content
          */
         private DocViewAdapter adapter;
 
-        public StackElement(DocViewSAXImporter.StackElement parent, Node node) throws RepositoryException
{
+        public StackElement(Node node, boolean isNew) throws RepositoryException {
             this.node = node;
-            this.parent = parent;
+            this.isNew = isNew;
             isCheckedOut = node == null || !node.isNodeType(JcrConstants.MIX_VERSIONABLE)
|| node.isCheckedOut();
         }
 
@@ -1280,16 +1286,22 @@ public class DocViewSAXImporter extends 
         }
 
         public void restoreOrder() throws RepositoryException {
-            if (childNames.needsReorder(node)) {
+            if (!isNew && childNames.needsReorder(node)) {
                 ensureCheckedOut();
                 childNames.restoreOrder(node);
             }
         }
 
-        public StackElement push(Node node) throws RepositoryException {
-            return new StackElement(this, node);
+        public StackElement push() throws RepositoryException {
+            return push(new StackElement(null, false));
         }
 
+        public StackElement push(StackElement elem) throws RepositoryException {
+            elem.parent = this;
+            return elem;
+        }
+
+
         public StackElement pop() {
             return parent;
         }

Modified: jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/FileArtifactHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/FileArtifactHandler.java?rev=1567854&r1=1567853&r2=1567854&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/FileArtifactHandler.java
(original)
+++ jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/FileArtifactHandler.java
Thu Feb 13 07:01:57 2014
@@ -170,12 +170,13 @@ public class FileArtifactHandler extends
                 if (file.getSerializationType() == SerializationType.GENERIC
                         || file.getSerializationType() == SerializationType.XML_GENERIC)
{
                     // case 1: new file
-                    if (!parent.hasNode(file.getRelativePath())) {
-                        importFile(info, parent, file);
+                    final String fileName = file.getRelativePath();
+                    if (!parent.hasNode(fileName)) {
+                        importFile(info, parent, file, fileName, false);
                     } else {
                         // case 2: same structure, new data
                         if (file instanceof ImportArtifact) {
-                            Node fileNode = parent.getNode(file.getRelativePath());
+                            Node fileNode = parent.getNode(fileName);
                             // check import mode, only replace if not MERGE
                             if (wspFilter.getImportMode(fileNode.getPath()) != ImportMode.MERGE)
{
                                 if (!fileNode.hasNode(JcrConstants.JCR_CONTENT)) {
@@ -264,13 +265,17 @@ public class FileArtifactHandler extends
         }
         return info;
     }
-
     private Node importFile(ImportInfo info, Node parent, Artifact primary)
             throws RepositoryException, IOException {
         String name = primary.getRelativePath();
+        return importFile(info, parent, primary, name, parent.hasNode(name));
+    }
+
+    private Node importFile(ImportInfo info, Node parent, Artifact primary, String name,
boolean exists)
+            throws RepositoryException, IOException {
         Node fileNode;
         Node contentNode;
-        if (parent.hasNode(name)) {
+        if (exists) {
             fileNode = parent.getNode(name);
             if (!fileNode.isNodeType(JcrConstants.NT_FILE)) {
                 parent.refresh(false);



Mime
View raw message