jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r513279 [3/3] - in /jackrabbit/trunk/contrib/spi/jcr2spi: ./ src/main/java/org/apache/jackrabbit/jcr2spi/ src/main/java/org/apache/jackrabbit/jcr2spi/hierarchy/ src/main/java/org/apache/jackrabbit/jcr2spi/lock/ src/main/java/org/apache/jack...
Date Thu, 01 Mar 2007 11:17:33 GMT
Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/SessionImporter.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/SessionImporter.java?view=diff&rev=513279&r1=513278&r2=513279
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/SessionImporter.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/SessionImporter.java
Thu Mar  1 03:17:22 2007
@@ -32,6 +32,7 @@
 import org.apache.jackrabbit.jcr2spi.util.ReferenceChangeTracker;
 import org.apache.jackrabbit.jcr2spi.util.LogUtil;
 import org.apache.jackrabbit.jcr2spi.nodetype.EffectiveNodeType;
+import org.apache.jackrabbit.jcr2spi.nodetype.NodeTypeConflictException;
 import org.apache.jackrabbit.jcr2spi.operation.AddNode;
 import org.apache.jackrabbit.jcr2spi.operation.Remove;
 import org.apache.jackrabbit.jcr2spi.operation.AddProperty;
@@ -64,6 +65,7 @@
 import org.apache.jackrabbit.spi.QValue;
 import org.apache.jackrabbit.value.ValueHelper;
 import org.apache.jackrabbit.value.ValueFormat;
+import org.apache.jackrabbit.uuid.UUID;
 
 import java.io.ByteArrayOutputStream;
 import java.io.File;
@@ -73,6 +75,8 @@
 import java.util.Stack;
 import java.util.List;
 import java.util.Iterator;
+import java.util.Arrays;
+import java.util.ArrayList;
 
 /**
  * <code>SessionImporter</code>...
@@ -173,32 +177,39 @@
 
        NodeEntry parentEntry = (NodeEntry) parent.getHierarchyEntry();
        NodeState nodeState = null;
+
        if (parentEntry.hasNodeEntry(nodeInfo.getName())) {
-           // a valid child node with that name already exists...
-           NodeEntry entry = parentEntry.getNodeEntry(nodeInfo.getName(), Path.INDEX_DEFAULT);
-           NodeState existing = null;
            try {
-               existing = entry.getNodeState();
-           } catch (ItemStateException e) {
-               // should not occur. existance has been checked before
-               throw new RepositoryException(e);
-           }
-           QNodeDefinition def = existing.getDefinition();
-           if (!def.allowsSameNameSiblings()) {
-               // existing doesn't allow same-name siblings, check for conflicts
-               EffectiveNodeType entExisting = session.getValidator().getEffectiveNodeType(existing);
-               if (def.isProtected() && entExisting.includesNodeType(nodeInfo.getNodeTypeName()))
{
-                   // skip protected node
-                   parents.push(null); // push null onto stack for skipped node
-                   log.debug("skipping protected node " + LogUtil.safeGetJCRPath(existing,
session.getNamespaceResolver()));
-                   return;
-               }
-               if (def.isAutoCreated() && entExisting.includesNodeType(nodeInfo.getNodeTypeName()))
{
-                   // this node has already been auto-created, no need to create it
-                   nodeState = existing;
-               } else {
-                   throw new ItemExistsException(LogUtil.safeGetJCRPath(existing, session.getNamespaceResolver()));
+               // a valid child node with that name already exists
+               NodeEntry entry = parentEntry.getNodeEntry(nodeInfo.getName(), Path.INDEX_DEFAULT);
+               NodeState existing = entry.getNodeState();
+
+               QNodeDefinition def = existing.getDefinition();
+               if (!def.allowsSameNameSiblings()) {
+                   // existing doesn't allow same-name siblings, check for conflicts
+                   EffectiveNodeType entExisting = session.getValidator().getEffectiveNodeType(existing);
+                   if (def.isProtected() && entExisting.includesNodeType(nodeInfo.getNodeTypeName()))
+                   {
+                       // skip protected node
+                       parents.push(null); // push null onto stack for skipped node
+                       log.debug("skipping protected node " + LogUtil.safeGetJCRPath(existing,
session.getNamespaceResolver()));
+                       return;
+                   }
+                   if (def.isAutoCreated() && entExisting.includesNodeType(nodeInfo.getNodeTypeName()))
+                   {
+                       // this node has already been auto-created, no need to create it
+                       nodeState = existing;
+                   } else {
+                       throw new ItemExistsException(LogUtil.safeGetJCRPath(existing, session.getNamespaceResolver()));
+                   }
                }
+           } catch (NoSuchItemStateException e) {
+               // 'existing' doesn't exist any more -> ignore
+           } catch (ItemStateException e) {
+               // undefined internal error
+               String msg = "Internal error. Failed to retrieve existing nodeState.";
+               log.debug(msg);
+               throw new RepositoryException(msg, e);
            }
        }
 
@@ -208,6 +219,10 @@
                // no potential uuid conflict, add new node from given info
                nodeState = importNode(nodeInfo, parent);
            } else {
+               // make sure the import does not define a uuid without having
+               // a primaryType or mixin that makes the new node referenceable
+               checkIncludesMixReferenceable(nodeInfo);
+
                // potential uuid conflict
                try {
                    NodeId conflictingId = session.getIdFactory().createNodeId(nodeInfo.getUUID());
@@ -220,7 +235,7 @@
                    // no conflict: create new with given uuid
                    nodeState = importNode(nodeInfo, parent);
                } catch (ItemStateException e) {
-                   String msg = "Internal error: failed to retrieve node state";
+                   String msg = "Internal error: failed to retrieve conflicting node state";
                    log.debug(msg);
                    throw new RepositoryException(msg, e);
                }
@@ -326,15 +341,13 @@
         switch (uuidBehavior) {
             case ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW:
                 String originalUUID = nodeInfo.getUUID();
+                String newUUID = UUID.randomUUID().toString();
                 // reset id on nodeInfo to force creation with new uuid:
-                nodeInfo.setUUID(null);
+                nodeInfo.setUUID(newUUID);
                 nodeState = importNode(nodeInfo, parent);
                 if (nodeState != null) {
                     // remember uuid mapping
-                    EffectiveNodeType ent = session.getValidator().getEffectiveNodeType(nodeState);
-                    if (ent.includesNodeType(QName.MIX_REFERENCEABLE)) {
-                        refTracker.mappedUUIDs(originalUUID, nodeState.getUniqueID());
-                    }
+                    refTracker.mappedUUIDs(originalUUID, newUUID);
                 }
                 break;
 
@@ -360,7 +373,7 @@
                     throw new RepositoryException(msg, e);
                 }
                 // do remove conflicting (recursive) including validation check
-                Operation op = Remove.create(conflicting.getNodeState(), parent);
+                Operation op = Remove.create(conflicting.getNodeState());
                 stateMgr.execute(op);
                 // create new with given uuid:
                 nodeState = importNode(nodeInfo, parent);
@@ -377,7 +390,7 @@
                 parent = conflicting.getParent().getNodeState();
 
                 // do remove conflicting (recursive), including validation checks
-                op = Remove.create(conflicting.getNodeState(), parent);
+                op = Remove.create(conflicting.getNodeState());
                 stateMgr.execute(op);
                 // create new with given uuid at same location as conflicting
                 nodeState = importNode(nodeInfo, parent);
@@ -438,7 +451,7 @@
 
                     Operation ap = AddProperty.create(parent, newName, conflicting.getType(),
propDef, conflicting.getValues());
                     stateMgr.execute(ap);
-                    Operation rm = Remove.create(conflicting, parent);
+                    Operation rm = Remove.create(conflicting);
                     stateMgr.execute(rm);
                 }
             } catch (ItemStateException e) {
@@ -644,6 +657,32 @@
             String msg = "failed to retrieve serialized value";
             log.debug(msg, e);
             throw new RepositoryException(msg, e);
+        }
+    }
+
+    /**
+     * Validate the given <code>NodeInfo</code>: make sure, that if a uuid is
+     * defined, the primary or the mixin types include mix:referenceable.
+     *
+     * @param nodeInfo
+     * @throws RepositoryException
+     */
+    private void checkIncludesMixReferenceable(Importer.NodeInfo nodeInfo) throws RepositoryException
{
+        List l = new ArrayList();
+        l.add(nodeInfo.getNodeTypeName());
+        l.addAll(Arrays.asList(nodeInfo.getMixinNames()));
+        if (l.contains(QName.MIX_REFERENCEABLE)) {
+            // shortcut
+            return;
+        }
+        QName[] ntNames = (QName[]) l.toArray(new QName[l.size()]);
+        try {
+            EffectiveNodeType ent = session.getValidator().getEffectiveNodeType(ntNames);
+            if (!ent.includesNodeType(QName.MIX_REFERENCEABLE)) {
+                throw new ConstraintViolationException("XML defines jcr:uuid without defining
import node to be referenceable.");
+            }
+        } catch (NodeTypeConflictException e) {
+            throw new RepositoryException("Internal error", e);
         }
     }
 }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/SysViewImportHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/SysViewImportHandler.java?view=diff&rev=513279&r1=513278&r2=513279
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/SysViewImportHandler.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/SysViewImportHandler.java
Thu Mar  1 03:17:22 2007
@@ -69,13 +69,12 @@
         if (!start && !end) {
             return;
         }
-        Importer.NodeInfo nodeInfo = new Importer.NodeInfo();
-        nodeInfo.setName(state.nodeName);
-        nodeInfo.setNodeTypeName(state.nodeTypeName);
+        QName[] mixins = null;
         if (state.mixinNames != null) {
-            QName[] mixins = (QName[]) state.mixinNames.toArray(new QName[state.mixinNames.size()]);
-            nodeInfo.setMixinNames(mixins);
+            mixins = (QName[]) state.mixinNames.toArray(new QName[state.mixinNames.size()]);
         }
+        Importer.NodeInfo nodeInfo = new Importer.NodeInfo(state.nodeName, state.nodeTypeName,
mixins, state.uuid);
+
         if (state.uuid != null) {
             nodeInfo.setUUID(state.uuid);
         }
@@ -277,11 +276,8 @@
                     throw new SAXException("error while retrieving value", ioe);
                 }
             } else {
-                Importer.PropInfo prop = new Importer.PropInfo();
-                prop.setName(currentPropName);
-                prop.setType(currentPropType);
-                prop.setValues((Importer.TextValue[])
-                        currentPropValues.toArray(new Importer.TextValue[currentPropValues.size()]));
+                Importer.TextValue[] values = (Importer.TextValue[]) currentPropValues.toArray(new
Importer.TextValue[currentPropValues.size()]);
+                Importer.PropInfo prop = new Importer.PropInfo(currentPropName, currentPropType,
values);
                 state.props.add(prop);
             }
             // reset temp fields

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/WorkspaceContentHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/WorkspaceContentHandler.java?view=diff&rev=513279&r1=513278&r2=513279
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/WorkspaceContentHandler.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/xml/WorkspaceContentHandler.java
Thu Mar  1 03:17:22 2007
@@ -19,6 +19,7 @@
 import org.xml.sax.SAXException;
 import org.xml.sax.Locator;
 import org.xml.sax.Attributes;
+import org.xml.sax.helpers.DefaultHandler;
 import org.apache.jackrabbit.util.Text;
 import org.slf4j.LoggerFactory;
 import org.slf4j.Logger;
@@ -30,6 +31,7 @@
 import javax.xml.transform.stream.StreamResult;
 import javax.xml.transform.OutputKeys;
 import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.Transformer;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.FileNotFoundException;
@@ -39,7 +41,7 @@
 /**
  * <code>WorkspaceContentHandler</code>...
  */
-public class WorkspaceContentHandler implements ContentHandler {
+public class WorkspaceContentHandler extends DefaultHandler {
 
     private static Logger log = LoggerFactory.getLogger(WorkspaceContentHandler.class);
 
@@ -62,9 +64,10 @@
             SAXTransformerFactory stf = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
             TransformerHandler th = stf.newTransformerHandler();
             th.setResult(new StreamResult(new FileOutputStream(tmpFile)));
-            th.getTransformer().setParameter(OutputKeys.METHOD, "xml");
-            th.getTransformer().setParameter(OutputKeys.ENCODING, "UTF-8");
-            th.getTransformer().setParameter(OutputKeys.INDENT, "no");
+            Transformer tf = th.getTransformer();
+            tf.setParameter(OutputKeys.METHOD, "xml");
+            tf.setParameter(OutputKeys.ENCODING, "UTF-8");
+            tf.setParameter(OutputKeys.INDENT, "no");
             this.delegatee = th;
 
         } catch (FileNotFoundException e) {
@@ -78,7 +81,6 @@
 
     public void endDocument() throws SAXException {
         delegatee.endDocument();
-
         try {
             workspace.importXML(parentAbsPath, new FileInputStream(tmpFile), uuidBehavior);
         } catch (IOException e) {



Mime
View raw message