jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r190588 - in /incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core: BatchedItemOperations.java xml/SessionImporter.java xml/WorkspaceImporter.java
Date Tue, 14 Jun 2005 13:01:17 GMT
Author: stefan
Date: Tue Jun 14 06:01:16 2005
New Revision: 190588

URL: http://svn.apache.org/viewcvs?rev=190588&view=rev
Log:
JCR-61: Docview import fails, if attribute and childelem have same name

Modified:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/BatchedItemOperations.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/SessionImporter.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/WorkspaceImporter.java

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/BatchedItemOperations.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/BatchedItemOperations.java?rev=190588&r1=190587&r2=190588&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/BatchedItemOperations.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/BatchedItemOperations.java
Tue Jun 14 06:01:16 2005
@@ -1271,6 +1271,21 @@
     }
 
     /**
+     * Retrieves the state of the property with the given id.
+     * <p/>
+     * Note that access rights are <b><i>not</i></b> enforced!
+     *
+     * @param id
+     * @return
+     * @throws ItemNotFoundException
+     * @throws RepositoryException
+     */
+    public PropertyState getPropertyState(PropertyId id)
+            throws ItemNotFoundException, RepositoryException {
+        return (PropertyState) getItemState(stateMgr, id);
+    }
+
+    /**
      * Retrieves the state of the item with the given id.
      * <p/>
      * Note that access rights are <b><i>not</i></b> enforced!

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/SessionImporter.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/SessionImporter.java?rev=190588&r1=190587&r2=190588&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/SessionImporter.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/SessionImporter.java
Tue Jun 14 06:01:16 2005
@@ -92,6 +92,35 @@
                                   String uuid)
             throws RepositoryException {
         NodeImpl node;
+
+        if (parent.hasProperty(nodeName)) {
+            /**
+             * a property with the same name already exists; if this property
+             * has been imported as well (e.g. through document view import
+             * where an element can have the same name as one of the attributes
+             * of its parent element) we have to rename the onflicting property;
+             *
+             * see http://issues.apache.org/jira/browse/JCR-61
+             */
+            Property conflicting = parent.getProperty(nodeName);
+            if (conflicting.isNew()) {
+                // assume this property has been imported as well;
+                // rename conflicting property
+                // @todo use better reversible escaping scheme to create unique name
+                QName newName = new QName(nodeName.getNamespaceURI(), nodeName.getLocalName()
+ "_");
+                if (parent.hasProperty(newName)) {
+                    newName = new QName(newName.getNamespaceURI(), newName.getLocalName()
+ "_");
+                }
+
+                if (conflicting.getDefinition().isMultiple()) {
+                    parent.setProperty(newName, conflicting.getValues());
+                } else {
+                    parent.setProperty(newName, conflicting.getValue());
+                }
+                conflicting.remove();
+            }
+        }
+
         // add node
         node = parent.addNode(nodeName, nodeTypeName, uuid);
         // add mixins

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/WorkspaceImporter.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/WorkspaceImporter.java?rev=190588&r1=190587&r2=190588&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/WorkspaceImporter.java
(original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/xml/WorkspaceImporter.java
Tue Jun 14 06:01:16 2005
@@ -33,6 +33,7 @@
 import org.apache.jackrabbit.core.nodetype.PropDef;
 import org.apache.jackrabbit.core.state.NodeState;
 import org.apache.jackrabbit.core.state.PropertyState;
+import org.apache.jackrabbit.core.state.ItemState;
 import org.apache.jackrabbit.core.util.Base64;
 import org.apache.jackrabbit.core.util.ReferenceChangeTracker;
 import org.apache.jackrabbit.core.util.uuid.UUID;
@@ -115,7 +116,7 @@
 
         // perform preliminary checks
         itemOps.verifyCanWrite(parentPath);
-        this.importTarget = itemOps.getNodeState(parentPath);
+        importTarget = itemOps.getNodeState(parentPath);
 
         this.wsp = wsp;
         this.ntReg = ntReg;
@@ -404,6 +405,35 @@
                         succeeded = true;
                         log.debug("skipping protected node " + nodeName);
                         return;
+                    }
+
+                    if (parent.hasPropertyEntry(nodeName)) {
+                        /**
+                         * a property with the same name already exists; if this property
+                         * has been imported as well (e.g. through document view import
+                         * where an element can have the same name as one of the attributes
+                         * of its parent element) we have to rename the onflicting property;
+                         *
+                         * see http://issues.apache.org/jira/browse/JCR-61
+                         */
+                        PropertyId propId = new PropertyId(parent.getUUID(), nodeName);
+                        PropertyState conflicting = itemOps.getPropertyState(propId);
+                        if (conflicting.getStatus() == ItemState.STATUS_NEW) {
+                            // assume this property has been imported as well;
+                            // rename conflicting property
+                            // @todo use better reversible escaping scheme to create unique
name
+                            QName newName = new QName(nodeName.getNamespaceURI(), nodeName.getLocalName()
+ "_");
+                            if (parent.hasPropertyEntry(newName)) {
+                                newName = new QName(newName.getNamespaceURI(), newName.getLocalName()
+ "_");
+                            }
+                            PropertyState newProp =
+                                    itemOps.createPropertyState(parent, newName,
+                                            conflicting.getType(), conflicting.getValues().length);
+                            newProp.setValues(conflicting.getValues());
+                            parent.removePropertyEntry(nodeName);
+                            itemOps.store(parent);
+                            itemOps.destroy(conflicting);
+                        }
                     }
 
                     // check if new node can be added (check access rights &



Mime
View raw message