Index: vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/ChildNodeRecovery.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/ChildNodeRecovery.java	(revision )
+++ vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/ChildNodeRecovery.java	(revision )
@@ -0,0 +1,99 @@
+/*
+ * 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.jackrabbit.vault.fs.impl.io;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+import org.apache.jackrabbit.vault.fs.api.ImportInfo;
+import org.apache.jackrabbit.vault.util.JcrConstants;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Helper class isolating the task of temporarily moving child nodes to a
+ * different location in order to be able to recover (and properly merge) them
+ * later on.
+ */
+class ChildNodeRecovery {
+
+    static final Logger log = LoggerFactory.getLogger(ChildNodeRecovery.class);
+
+    private final Session session;
+
+    private Node tmpNode;
+
+    ChildNodeRecovery(Session session) {
+        this.session = session;
+    }
+
+    void moveChildren(String oldPath) throws RepositoryException {
+        moveChildren(session.getNode(oldPath));
+    }
+
+    void moveChildren(Node oldNode) {
+        try {
+            // if old node exist, try to 'save' the child nodes
+            NodeIterator iter = oldNode.getNodes();
+            while (iter.hasNext()) {
+                Node child = iter.nextNode();
+                if (tmpNode == null) {
+                    // TODO: make location of tmp node configurable
+                    tmpNode = session.getRootNode().addNode("tmp" + System.currentTimeMillis(), JcrConstants.NT_UNSTRUCTURED);
+                }
+                try {
+                    session.move(child.getPath(), tmpNode.getPath() + "/" + child.getName());
+                } catch (RepositoryException e) {
+                    log.error("Error while moving child node to temporary location. Child will be removed.", e);
+                }
+            }
+        } catch (RepositoryException e) {
+            log.warn("error while moving child nodes (ignored)", e);
+        }
+    }
+
+    void recoverChildren(String existingNodePath) throws RepositoryException {
+        recoverChildren(session.getNode(existingNodePath), null);
+    }
+
+    void recoverChildren(Node node, ImportInfo importInfo) throws RepositoryException {
+        // move the old child nodes back
+        if (tmpNode != null) {
+            NodeIterator iter = tmpNode.getNodes();
+            boolean hasErrors = false;
+            while (iter.hasNext()) {
+                Node child = iter.nextNode();
+                String newPath = node.getPath() + "/" + child.getName();
+                try {
+                    session.move(child.getPath(), newPath);
+                } catch (RepositoryException e) {
+                    log.warn("Unable to move child back to new location at {} due to: {}. Node will remain in temporary location: {}",
+                            new Object[]{newPath, e.getMessage(), child.getPath()});
+                    if (importInfo != null) {
+                        importInfo.onError(newPath, e);
+                        hasErrors = true;
+                    }
+                }
+            }
+            if (!hasErrors) {
+                tmpNode.remove();
+            }
+        }
+    }
+}
\ No newline at end of file
Index: vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewSAXImporter.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewSAXImporter.java	(revision 1638065)
+++ vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/DocViewSAXImporter.java	(revision )
@@ -826,25 +826,9 @@
             // check versionable
             new VersioningState(stack, oldNode).ensureCheckedOut();
 
-            // replace node
-            Node tmpNode = null;
-            try {
-                // if old node exist, try to 'save' the child nodes
-                NodeIterator iter = oldNode.getNodes();
-                while (iter.hasNext()) {
-                    Node child = iter.nextNode();
-                    if (tmpNode == null) {
-                        tmpNode = session.getRootNode().addNode("tmp" + System.currentTimeMillis(), JcrConstants.NT_UNSTRUCTURED);
-                    }
-                    try {
-                        session.move(child.getPath(), tmpNode.getPath() + "/" + child.getName());
-                    } catch (RepositoryException e) {
-                        log.error("Error while moving child node to temporary location. Child will be removed.", e);
-                    }
-                }
-            } catch (RepositoryException e) {
-                log.warn("error while moving child nodes (ignored)", e);
-            }
+            ChildNodeRecovery recovery = new ChildNodeRecovery(session);
+            recovery.moveChildren(oldNode);
+
             // ensure that existing binaries are not sourced from a property
             // that is about to be removed
             Map<String, DocViewSAXImporter.BlobInfo> blobs = binaries.get(oldNode.getPath());
@@ -858,26 +842,8 @@
             // now create the new node
             node = createNode(currentNode, ni);
 
-            // move the old child nodes back
-            if (tmpNode != null) {
-                NodeIterator iter = tmpNode.getNodes();
-                boolean hasErrors = false;
-                while (iter.hasNext()) {
-                    Node child = iter.nextNode();
-                    String newPath = node.getPath() + "/" + child.getName();
-                    try {
-                        session.move(child.getPath(), newPath);
-                    } catch (RepositoryException e) {
-                        log.warn("Unable to move child back to new location at {} due to: {}. Node will remain in temporary location: {}",
-                                new Object[]{newPath, e.getMessage(), child.getPath()});
-                        importInfo.onError(newPath, e);
-                        hasErrors = true;
-                    }
-                }
-                if (!hasErrors) {
-                    tmpNode.remove();
-                }
-            }
+            recovery.recoverChildren(node, importInfo);
+
             importInfo.onReplaced(node.getPath());
             return new StackElement(node, false);
         }
\ No newline at end of file
Index: vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/JcrSysViewTransformer.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/JcrSysViewTransformer.java	(revision 1638065)
+++ vault-core/src/main/java/org/apache/jackrabbit/vault/fs/impl/io/JcrSysViewTransformer.java	(revision )
@@ -55,9 +55,9 @@
     private ContentHandler handler;
 
     /**
-     * temporary node when 'rescuing' the child nodes
+     * temporary recovery helper when 'rescuing' the child nodes
      */
-    private Node tmpNode;
+    private ChildNodeRecovery recovery;
 
     private String rootName;
 
@@ -87,27 +87,11 @@
 
         this.existingPath = existingPath;
         if (existingPath != null) {
-            Node existingNode = session.getNode(existingPath);
             // check if there is an existing node with the name
-            try {
-                // if old node exist, try to 'save' the child nodes
-                NodeIterator iter = existingNode.getNodes();
-                while (iter.hasNext()) {
-                    Node child = iter.nextNode();
-                    if (tmpNode == null) {
-                        tmpNode = session.getRootNode().addNode("tmp" + System.currentTimeMillis(), JcrConstants.NT_UNSTRUCTURED);
+            recovery = new ChildNodeRecovery(session);
+            recovery.moveChildren(existingPath);
-                    }
+        }
-                    try {
-                        session.move(child.getPath(), tmpNode.getPath() + "/" + child.getName());
-                    } catch (RepositoryException e) {
-                        log.error("Error while moving child node to temporary location. Child will be removed.", e);
-                    }
+    }
-                }
-            } catch (RepositoryException e) {
-                log.warn("error while moving child nodes (ignored)", e);
-            }
-        }
-    }
 
     public List<String> close() throws SAXException {
         handler.endDocument();
@@ -125,23 +109,9 @@
         }
 
         // check for rescued child nodes
-        // move the old child nodes back
-        if (tmpNode != null) {
+        if (recovery != null) {
             try {
-                Session session = tmpNode.getSession();
-                Node node = session.getNode(existingPath);
-                NodeIterator iter = tmpNode.getNodes();
-                while (iter.hasNext()) {
-                    Node child = iter.nextNode();
-                    String newPath = node.getPath() + "/" + child.getName();
-                    try {
-                        session.move(child.getPath(), newPath);
-                    } catch (RepositoryException e) {
-                        log.warn("Unable to move child back to new location at {} due to: {}. Node will remain in temporary location: {}",
-                                new Object[]{newPath, e.getMessage(), child.getPath()});
-                    }
-                }
-                tmpNode.remove();
+                recovery.recoverChildren(existingPath);
             } catch (RepositoryException e) {
                 log.error("Error while processing rescued child nodes");
             }
\ No newline at end of file
