Index: /home/ntoper/workspace/jackrabbit current/src/main/java/org/apache/jackrabbit/core/xml/WorkspaceImporter.java =================================================================== --- /home/ntoper/workspace/jackrabbit current/src/main/java/org/apache/jackrabbit/core/xml/WorkspaceImporter.java (revision 465271) +++ /home/ntoper/workspace/jackrabbit current/src/main/java/org/apache/jackrabbit/core/xml/WorkspaceImporter.java (working copy) @@ -46,6 +46,7 @@ import org.apache.jackrabbit.core.state.ItemState; import org.apache.jackrabbit.core.state.NodeState; import org.apache.jackrabbit.core.state.PropertyState; +import org.apache.jackrabbit.core.state.NodeState.ChildNodeEntry; import org.apache.jackrabbit.core.util.ReferenceChangeTracker; import org.apache.jackrabbit.core.value.InternalValue; import org.apache.jackrabbit.core.version.VersionManager; @@ -164,8 +165,8 @@ * @throws ConstraintViolationException if some constraints checks are not OK */ private boolean checkNode(NodeState parent, NodeInfo nodeInfo, List propInfo) - throws ConstraintViolationException, AccessDeniedException, VersionException, - LockException, ItemNotFoundException, ItemExistsException, RepositoryException { + throws ConstraintViolationException, AccessDeniedException, VersionException, + LockException, ItemNotFoundException, ItemExistsException, RepositoryException { itemOps.checkAddNode(parent, nodeInfo.getName(), nodeInfo.getNodeTypeName(), BatchedItemOperations.CHECK_ACCESS | BatchedItemOperations.CHECK_CONSTRAINTS @@ -231,7 +232,6 @@ itemOps.destroy(conflicting); } } - return true; } @@ -246,8 +246,8 @@ * @throws RepositoryException if issue in the NodeState */ private void createProperties(NodeState myNode, List propInfos) - throws ItemNotFoundException, ItemExistsException, ConstraintViolationException, - ValueFormatException, RepositoryException { + throws ItemNotFoundException, ItemExistsException, ConstraintViolationException, + ValueFormatException, RepositoryException { // process properties Iterator iter = propInfos.iterator(); while (iter.hasNext()) { @@ -272,7 +272,6 @@ // potential uuid conflict NodeState conflicting = null; NodeState node; - try { if (nodeInfo.getId() != null) { conflicting = itemOps.getNodeState(nodeInfo.getId()); @@ -280,7 +279,7 @@ } catch (ItemNotFoundException infe) { conflicting = null; } - if (conflicting != null) { + if (conflicting != null) { // resolve uuid conflict node = resolveUUIDConflict(parent, conflicting, nodeInfo); } @@ -287,7 +286,7 @@ else { // do create new node node = itemOps.createNodeState(parent, nodeInfo.getName(), nodeInfo.getNodeTypeName(), - nodeInfo.getMixinNames(), null, def); + nodeInfo.getMixinNames(), null, def); } return node; } @@ -305,7 +304,7 @@ * @throws RepositoryException */ private NodeState resolveUUIDConflict(NodeState parent, NodeState conflicting, NodeInfo nodeInfo) - throws ItemExistsException, ConstraintViolationException, IllegalStateException, RepositoryException { + throws ItemExistsException, ConstraintViolationException, IllegalStateException, RepositoryException { NodeState node = null; switch (uuidBehavior) { @@ -312,35 +311,36 @@ case ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING: NodeId parentId = conflicting.getParentId(); if (parentId == null) { - String msg = "root node cannot be replaced"; - log.debug(msg); - throw new RepositoryException(msg); + //Shoudn't happen + throw new RepositoryException(); } - // 'replace' current parent with parent of conflicting - try { - parent = itemOps.getNodeState(parentId); - } catch (ItemNotFoundException infe) { - // should never get here... - String msg = "internal error: failed to retrieve parent state"; - log.error(msg, infe); - throw new RepositoryException(msg, infe); + else { + // 'replace' current parent with parent of conflicting + try { + parent = itemOps.getNodeState(parentId); + } catch (ItemNotFoundException infe) { + // should never get here... + String msg = "internal error: failed to retrieve parent state"; + log.error(msg, infe); + throw new RepositoryException(msg, infe); + } + // remove conflicting: + // check if conflicting can be removed + // (access rights, node type constraints, locking & versioning status) + itemOps.checkRemoveNode(conflicting, + BatchedItemOperations.CHECK_ACCESS + | BatchedItemOperations.CHECK_LOCK + | BatchedItemOperations.CHECK_VERSIONING + | BatchedItemOperations.CHECK_CONSTRAINTS); + // do remove conflicting (recursive) + itemOps.removeNodeState(conflicting); + // do create new node + node = itemOps.createNodeState(parent, nodeInfo.getName(), + nodeInfo.getNodeTypeName(), nodeInfo.getMixinNames(), + nodeInfo.getId()); } - // remove conflicting: - // check if conflicting can be removed - // (access rights, node type constraints, locking & versioning status) - itemOps.checkRemoveNode(conflicting, - BatchedItemOperations.CHECK_ACCESS - | BatchedItemOperations.CHECK_LOCK - | BatchedItemOperations.CHECK_VERSIONING - | BatchedItemOperations.CHECK_CONSTRAINTS); - // do remove conflicting (recursive) - itemOps.removeNodeState(conflicting); - // do create new node - node = itemOps.createNodeState(parent, nodeInfo.getName(), - nodeInfo.getNodeTypeName(), nodeInfo.getMixinNames(), - nodeInfo.getId()); break; - + case ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING: // make sure conflicting node is not importTarget or an ancestor thereof Path p0 = hierMgr.getPath(importTarget.getNodeId()); @@ -394,7 +394,7 @@ refTracker.mappedUUID(nodeInfo.getId().getUUID(), node.getNodeId().getUUID()); } break; - //No need for default case. + //No need for default case. } return node; } @@ -478,7 +478,6 @@ } } - //-------------------------------------------------------------< Importer > /** * {@inheritDoc} @@ -514,16 +513,46 @@ return; } - NodeState myNode; - if (existing == null) { - myNode = createNode(parent, nodeInfo); + //Handling of JCR 535: importation of Root node + // with Replace Existing UUID. Should be handled before the importation happen since the logic + // is quite different of the rest of the importer. + if (nodeInfo.getName().equals(QName.JCR_ROOT) + && this.uuidBehavior == ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING) { + //conflicting = itemOps.getNodeState(Path.ROOT); + NodeState root = itemOps.getNodeState(Path.ROOT); + List rootChildren = root.getChildNodeEntries(); + Iterator it = rootChildren.iterator(); + while (it.hasNext()) { + ChildNodeEntry child = (ChildNodeEntry) it.next(); + //Check not jcr:system + if (!child.getName().equals(QName.JCR_SYSTEM)) { + NodeId id = child.getId(); + NodeState toDelete = itemOps.getNodeState(id); + // remove conflicting: + // check if conflicting can be removed + // (access rights, node type constraints, locking & versioning status) + itemOps.checkRemoveNode(toDelete, + BatchedItemOperations.CHECK_ACCESS + | BatchedItemOperations.CHECK_LOCK + | BatchedItemOperations.CHECK_VERSIONING + | BatchedItemOperations.CHECK_CONSTRAINTS); + // do remove conflicting (recursive) + itemOps.removeNodeState(toDelete); + } + } } else { - myNode = existing; - existing = null; + NodeState myNode; + if (existing == null) { + myNode = createNode(parent, nodeInfo); + } + else { + myNode = existing; + existing = null; + } + createProperties(myNode, propInfos); + parents.push(myNode); } - createProperties(myNode, propInfos); - parents.push(myNode); } /** @@ -537,7 +566,7 @@ return; } - if (aborted || skip) { + if (aborted || skip || (nodeInfo.getName().equals(QName.ROOT) && this.uuidBehavior == ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING)) { return; }