jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ang...@apache.org
Subject svn commit: r1505715 [2/2] - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/api/ oak-core/src/main/java/org/apache/jackrabbit/oak/spi/xml/ oak-core/src/main/java/org/apache/jackrabbit/oak/util/ oak-jcr/ oak-jcr/src/main/java...
Date Mon, 22 Jul 2013 15:16:58 GMT
Copied: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java
(from r1504432, jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/SessionImporter.java)
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java?p2=jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java&p1=jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/SessionImporter.java&r1=1504432&r2=1505715&rev=1505715&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/SessionImporter.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java
Mon Jul 22 15:16:57 2013
@@ -20,50 +20,62 @@ import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Stack;
-
+import java.util.UUID;
+import javax.annotation.CheckForNull;
+import javax.annotation.Nonnull;
 import javax.jcr.ImportUUIDBehavior;
 import javax.jcr.ItemExistsException;
-import javax.jcr.ItemNotFoundException;
-import javax.jcr.NamespaceRegistry;
-import javax.jcr.Node;
-import javax.jcr.Property;
+import javax.jcr.PathNotFoundException;
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
-import javax.jcr.Session;
 import javax.jcr.Value;
-import javax.jcr.ValueFormatException;
+import javax.jcr.lock.LockException;
 import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.nodetype.NodeDefinition;
-import javax.jcr.nodetype.NodeTypeManager;
 import javax.jcr.nodetype.PropertyDefinition;
+import javax.jcr.version.VersionException;
+import javax.jcr.version.VersionManager;
 
+import com.google.common.collect.Lists;
 import org.apache.jackrabbit.JcrConstants;
-import org.apache.jackrabbit.commons.NamespaceHelper;
+import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Root;
+import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.api.Type;
+import org.apache.jackrabbit.oak.commons.PathUtils;
+import org.apache.jackrabbit.oak.core.IdentifierManager;
 import org.apache.jackrabbit.oak.jcr.SessionContext;
+import org.apache.jackrabbit.oak.jcr.security.AccessManager;
+import org.apache.jackrabbit.oak.plugins.memory.PropertyStates;
+import org.apache.jackrabbit.oak.plugins.nodetype.DefinitionProvider;
 import org.apache.jackrabbit.oak.plugins.nodetype.EffectiveNodeTypeProvider;
+import org.apache.jackrabbit.oak.spi.security.authorization.permission.Permissions;
 import org.apache.jackrabbit.oak.spi.xml.NodeInfo;
 import org.apache.jackrabbit.oak.spi.xml.PropInfo;
 import org.apache.jackrabbit.oak.spi.xml.ProtectedItemImporter;
 import org.apache.jackrabbit.oak.spi.xml.ProtectedNodeImporter;
 import org.apache.jackrabbit.oak.spi.xml.ProtectedPropertyImporter;
 import org.apache.jackrabbit.oak.spi.xml.ReferenceChangeTracker;
+import org.apache.jackrabbit.oak.util.TreeUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-/**
- * {@code SessionImporter} ...
- */
-public class SessionImporter implements Importer {
-    private static final Logger log = LoggerFactory.getLogger(SessionImporter.class);
-
-    private final Session session;
-    private final Node importTargetNode;
-    private final Root root;
+import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.NODE_TYPES_PATH;
+
+public class ImporterImpl implements Importer {
+    private static final Logger log = LoggerFactory.getLogger(ImporterImpl.class);
+
+    private final Tree importTargetTree;
+    private final Tree ntTypesRoot;
     private final int uuidBehavior;
 
-    private final NamespaceHelper namespaceHelper;
-    private final Stack<Node> parents;
+    private final String userID;
+    private final AccessManager accessManager;
+    private final IdentifierManager idManager;
+    private final EffectiveNodeTypeProvider effectiveNodeTypeProvider;
+    private final DefinitionProvider definitionProvider;
+
+    private final Stack<Tree> parents;
 
     /**
      * helper object that keeps track of remapped uuid's and imported reference
@@ -71,7 +83,6 @@ public class SessionImporter implements 
      */
     private final ReferenceChangeTracker refTracker;
 
-    //TODO clarify how to provide ProtectedItemImporters
     private final List<ProtectedItemImporter> pItemImporters = new ArrayList<ProtectedItemImporter>();
 
     /**
@@ -82,108 +93,105 @@ public class SessionImporter implements 
     /**
      * Creates a new {@code SessionImporter} instance.
      */
-    public SessionImporter(Node importTargetNode,
-                           SessionContext sessionContext,
-                           NamespaceHelper helper,
-                           int uuidBehavior) {
-        this.importTargetNode = importTargetNode;
-        this.session = sessionContext.getSession();
-        this.root = sessionContext.getSessionDelegate().getRoot();
-        this.namespaceHelper = helper;
+    public ImporterImpl(String absPath,
+                        SessionContext sessionContext,
+                        Root root,
+                        int uuidBehavior,
+                        boolean isWorkspaceImport) throws RepositoryException {
+        if (!PathUtils.isAbsolute(absPath)) {
+            throw new RepositoryException("Not an absolute path: " + absPath);
+        }
+        String oakPath = sessionContext.getOakPathKeepIndex(absPath);
+        if (oakPath == null) {
+            throw new RepositoryException("Invalid name or path: " + absPath);
+        }
+        importTargetTree = root.getTree(absPath);
+        if (!importTargetTree.exists()) {
+            throw new PathNotFoundException(absPath);
+        }
+
+        VersionManager vMgr =  sessionContext.getVersionManager();
+        if (!vMgr.isCheckedOut(absPath)) {
+            throw new VersionException("Target node is checked in.");
+        }
+        if (sessionContext.getLockManager().isLocked(absPath)) {
+            throw new LockException("Target node is locked.");
+        }
+
+        ntTypesRoot = root.getTree(NODE_TYPES_PATH);
+
         this.uuidBehavior = uuidBehavior;
 
+        userID = sessionContext.getSessionDelegate().getAuthInfo().getUserID();
+        accessManager = sessionContext.getAccessManager();
+        idManager = new IdentifierManager(root);
+        effectiveNodeTypeProvider = sessionContext.getEffectiveNodeTypeProvider();
+        definitionProvider = sessionContext.getDefinitionProvider();
+
         refTracker = new ReferenceChangeTracker();
 
-        parents = new Stack<Node>();
-        parents.push(importTargetNode);
+        parents = new Stack<Tree>();
+        parents.push(importTargetTree);
 
         pItemImporters.clear();
 
-        //TODO clarify how to provide ProtectedItemImporters
         for (ProtectedItemImporter importer : sessionContext.getProtectedItemImporters())
{
-            if (importer.init(session, root, sessionContext, false, uuidBehavior, refTracker))
{
+            if (importer.init(sessionContext.getSession(), root, sessionContext, isWorkspaceImport,
uuidBehavior, refTracker)) {
                 pItemImporters.add(importer);
             }
         }
     }
 
-    protected Node createNode(Node parent,
-                              String nodeName,
-                              String nodeTypeName,
-                              String[] mixinNames,
-                              String uuid)
-            throws RepositoryException {
-        Node node;
-
-        // add node
-        node = parent.addNode(nodeName, nodeTypeName == null ? namespaceHelper.getJcrName(NamespaceRegistry.NAMESPACE_NT,
"unstructured") : nodeTypeName);
+    protected Tree createTree(@Nonnull Tree parent, @Nonnull NodeInfo nInfo, @CheckForNull
String uuid) throws RepositoryException {
+        String ntName = nInfo.getPrimaryTypeName();
+        String value = (ntName != null) ? ntName : TreeUtil.getDefaultChildType(ntTypesRoot,
parent, nInfo.getName());
+        Tree child = TreeUtil.addChild(parent, nInfo.getName(), value, ntTypesRoot, userID);
+        if (ntName != null) {
+            accessManager.checkPermissions(child, child.getProperty(JcrConstants.JCR_PRIMARYTYPE),
Permissions.NODE_TYPE_MANAGEMENT);
+        }
         if (uuid != null) {
-            root.getTree(node.getPath()).setProperty(NamespaceRegistry.PREFIX_JCR + ":uuid",
uuid);
+            child.setProperty(JcrConstants.JCR_UUID, uuid);
         }
-        // add mixins
-        if (mixinNames != null) {
-            for (String mixinName : mixinNames) {
-                node.addMixin(mixinName);
-            }
+        for (String mixin : nInfo.getMixinTypeNames()) {
+            TreeUtil.addMixin(child, mixin, ntTypesRoot, userID);
         }
-        return node;
+        return child;
     }
 
-
-    protected void createProperty(Node node, PropInfo pInfo, PropertyDefinition def) throws
RepositoryException {
-        // convert serialized values to Value objects
-        Value[] va = pInfo.getValues(pInfo.getTargetType(def));
-
-        // multi- or single-valued property?
+    protected void
+    createProperty(Tree tree, PropInfo pInfo, PropertyDefinition def) throws RepositoryException
{
+        List<Value> values = pInfo.getValues(pInfo.getTargetType(def));
+        PropertyState propertyState;
         String name = pInfo.getName();
         int type = pInfo.getType();
-        if (va.length == 1 && !def.isMultiple()) {
-            Exception e = null;
-            try {
-                // set single-value
-                node.setProperty(name, va[0]);
-            } catch (ValueFormatException vfe) {
-                e = vfe;
-            } catch (ConstraintViolationException cve) {
-                e = cve;
-            }
-            if (e != null) {
-                // setting single-value failed, try setting value array
-                // as a last resort (in case there are ambiguous property
-                // definitions)
-                node.setProperty(name, va, type);
-            }
+        if (values.size() == 1 && !def.isMultiple()) {
+            propertyState = PropertyStates.createProperty(name, values.get(0));
         } else {
-            // can only be multi-valued (n == 0 || n > 1)
-            node.setProperty(name, va, type);
+            propertyState = PropertyStates.createProperty(name, values);
         }
+        tree.setProperty(propertyState);
         if (type == PropertyType.REFERENCE || type == PropertyType.WEAKREFERENCE) {
             // store reference for later resolution
-            refTracker.processedReference(node.getProperty(name));
+            refTracker.processedReference(new Reference(tree, name));
         }
     }
 
-    protected Node resolveUUIDConflict(Node parent,
+    protected Tree resolveUUIDConflict(Tree parent,
                                        String conflictingId,
                                        NodeInfo nodeInfo)
             throws RepositoryException {
-        Node node;
-        Node conflicting;
-        try {
-            conflicting = session.getNodeByIdentifier(conflictingId);
-        } catch (ItemNotFoundException infe) {
-            // conflicting node can't be read,
-            // most likely due to lack of read permission
+        Tree tree;
+        Tree conflicting = idManager.getTree(conflictingId);
+        if (conflicting != null && !conflicting.exists()) {
             conflicting = null;
         }
 
         if (uuidBehavior == ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW) {
             // create new with new uuid
-            node = createNode(parent, nodeInfo.getName(),
-                    nodeInfo.getPrimaryTypeName(), nodeInfo.getMixinTypeNames(), null);
+            tree = createTree(parent, nodeInfo, UUID.randomUUID().toString());
             // remember uuid mapping
-            if (node.isNodeType(JcrConstants.MIX_REFERENCEABLE)) {
-                refTracker.put(nodeInfo.getUUID(), node.getIdentifier());
+            if (isNodeType(tree, JcrConstants.MIX_REFERENCEABLE)) {
+                refTracker.put(nodeInfo.getUUID(), TreeUtil.getString(tree, JcrConstants.JCR_UUID));
             }
         } else if (uuidBehavior == ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW) {
             // if conflicting node is shareable, then clone it
@@ -200,7 +208,7 @@ public class SessionImporter implements 
             }
 
             // make sure conflicting node is not importTargetNode or an ancestor thereof
-            if (importTargetNode.getPath().startsWith(conflicting.getPath())) {
+            if (importTargetTree.getPath().startsWith(conflicting.getPath())) {
                 String msg = "cannot remove ancestor node";
                 log.debug(msg);
                 throw new ConstraintViolationException(msg);
@@ -208,8 +216,7 @@ public class SessionImporter implements 
             // remove conflicting
             conflicting.remove();
             // create new with given uuid
-            node = createNode(parent, nodeInfo.getName(),
-                    nodeInfo.getPrimaryTypeName(), nodeInfo.getMixinTypeNames(), nodeInfo.getUUID());
+            tree = createTree(parent, nodeInfo, nodeInfo.getUUID());
         } else if (uuidBehavior == ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING)
{
             if (conflicting == null) {
                 // since the conflicting node can't be read,
@@ -219,7 +226,7 @@ public class SessionImporter implements 
                 throw new RepositoryException(msg);
             }
 
-            if (conflicting.getDepth() == 0) {
+            if (conflicting.isRoot()) {
                 String msg = "root node cannot be replaced";
                 log.debug(msg);
                 throw new RepositoryException(msg);
@@ -230,17 +237,16 @@ public class SessionImporter implements 
             // replace child node
             //TODO ordering! (what happened to replace?)
             conflicting.remove();
-            node = createNode(parent, nodeInfo.getName(),
-                    nodeInfo.getPrimaryTypeName(), nodeInfo.getMixinTypeNames(), nodeInfo.getUUID());
+            tree = createTree(parent, nodeInfo, nodeInfo.getUUID());
         } else {
             String msg = "unknown uuidBehavior: " + uuidBehavior;
             log.debug(msg);
             throw new RepositoryException(msg);
         }
-        return node;
+        return tree;
     }
 
-    //-------------------------------------------------------------< Importer >
+    //-----------------------------------------------------------< Importer >---
 
     @Override
     public void start() throws RepositoryException {
@@ -250,15 +256,11 @@ public class SessionImporter implements 
     @Override
     public void startNode(NodeInfo nodeInfo, List<PropInfo> propInfos)
             throws RepositoryException {
-        Node parent = parents.peek();
-
-        // process node
-
-        Node node = null;
+        Tree parent = parents.peek();
+        Tree tree = null;
         String id = nodeInfo.getUUID();
         String nodeName = nodeInfo.getName();
         String ntName = nodeInfo.getPrimaryTypeName();
-        String[] mixins = nodeInfo.getMixinTypeNames();
 
         if (parent == null) {
             log.debug("Skipping node: " + nodeName);
@@ -271,7 +273,8 @@ public class SessionImporter implements 
             return;
         }
 
-        if (parent.getDefinition().isProtected()) {
+        NodeDefinition parentDef = getDefinition(parent);
+        if (parentDef.isProtected()) {
             // skip protected node
             parents.push(null);
             log.debug("Skipping protected node: " + nodeName);
@@ -288,7 +291,7 @@ public class SessionImporter implements 
                 // start of a item tree that is protected by this parent. If it
                 // potentially is able to deal with it, notify it about the child node.
                 for (ProtectedItemImporter pni : pItemImporters) {
-                    if (pni instanceof ProtectedNodeImporter && ((ProtectedNodeImporter)
pni).start(root.getTree(parent.getPath()))) {
+                    if (pni instanceof ProtectedNodeImporter && ((ProtectedNodeImporter)
pni).start(parent)) {
                         log.debug("Protected node -> delegated to ProtectedNodeImporter");
                         pnImporter = (ProtectedNodeImporter) pni;
                         pnImporter.startChildInfo(nodeInfo, propInfos);
@@ -301,14 +304,14 @@ public class SessionImporter implements 
             return;
         }
 
-        if (parent.hasNode(nodeName)) {
+        if (parent.hasChild(nodeName)) {
             // a node with that name already exists...
-            Node existing = parent.getNode(nodeName);
-            NodeDefinition def = existing.getDefinition();
+            Tree existing = parent.getChild(nodeName);
+            NodeDefinition def = getDefinition(existing);
             if (!def.allowsSameNameSiblings()) {
                 // existing doesn't allow same-name siblings,
                 // check for potential conflicts
-                if (def.isProtected() && existing.isNodeType(ntName)) {
+                if (def.isProtected() && isNodeType(existing, ntName)) {
                     /*
                      use the existing node as parent for the possible subsequent
                      import of a protected tree, that the protected node importer
@@ -326,13 +329,14 @@ public class SessionImporter implements 
                     parents.push(existing);
                     return;
                 }
-                if (def.isAutoCreated() && existing.isNodeType(ntName)) {
+                if (def.isAutoCreated() && isNodeType(existing, ntName)) {
                     // this node has already been auto-created, no need to create it
-                    node = existing;
+                    tree = existing;
                 } else {
                     // edge case: colliding node does have same uuid
                     // (see http://issues.apache.org/jira/browse/JCR-1128)
-                    if (!(existing.getIdentifier().equals(id)
+                    String uuid = TreeUtil.getString(existing, JcrConstants.JCR_UUID);
+                    if (uuid != null && !(uuid.equals(id)
                             && (uuidBehavior == ImportUUIDBehavior.IMPORT_UUID_COLLISION_REMOVE_EXISTING
                             || uuidBehavior == ImportUUIDBehavior.IMPORT_UUID_COLLISION_REPLACE_EXISTING)))
{
                         throw new ItemExistsException(
@@ -343,30 +347,17 @@ public class SessionImporter implements 
             }
         }
 
-        if (node == null) {
+        if (tree == null) {
             // create node
             if (id == null) {
                 // no potential uuid conflict, always add new node
-                node = createNode(parent, nodeName, ntName, mixins, id);
+                tree = createTree(parent, nodeInfo, id);
             } else {
-                // potential uuid conflict
-                boolean isConflicting;
-                try {
-                    // the following is a fail-fast test whether
-                    // an item exists (regardless of access control)
-                    session.getNodeByIdentifier(id);
-                    isConflicting = true;
-                } catch (ItemNotFoundException e) {
-                    isConflicting = false;
-                } catch (RepositoryException e) {
-                    log.warn("Access Control Issues?", e);
-                    isConflicting = true;
-                }
-
-                if (isConflicting) {
+                Tree conflicting = idManager.getTree(id);
+                if (conflicting != null && conflicting.exists()) {
                     // resolve uuid conflict
-                    node = resolveUUIDConflict(parent, id, nodeInfo);
-                    if (node == null) {
+                    tree = resolveUUIDConflict(parent, id, nodeInfo);
+                    if (tree == null) {
                         // no new node has been created, so skip this node
                         parents.push(null); // push null onto stack for skipped node
                         log.debug("Skipping existing node " + nodeInfo.getName());
@@ -374,70 +365,51 @@ public class SessionImporter implements 
                     }
                 } else {
                     // create new with given uuid
-                    node = createNode(parent, nodeName, ntName, mixins, id);
+                    tree = createTree(parent, nodeInfo, id);
                 }
             }
         }
 
         // process properties
-
-        //TODO remove hack that processes principal name first
-        int principalNameIndex = -1;
-        for (int k = 0; k < propInfos.size(); k++) {
-            PropInfo propInfo = propInfos.get(k);
-            if ("rep:principalName".equals(propInfo.getName())) {
-                principalNameIndex = k;
-                break;
-            }
-        }
-        if (principalNameIndex >= 0) {
-            propInfos.add(0, propInfos.remove(principalNameIndex));
-        }
         for (PropInfo pi : propInfos) {
             // find applicable definition
-            //TODO find a proper way to get the EffectiveNodeTypeProvider
-            NodeTypeManager nodeTypeManager = session.getWorkspace().getNodeTypeManager();
-            if (nodeTypeManager instanceof EffectiveNodeTypeProvider) {
-                EffectiveNodeTypeProvider entp = (EffectiveNodeTypeProvider) nodeTypeManager;
-
-                //TODO find better heuristics?
-                PropertyDefinition def = pi.getPropertyDef(entp.getEffectiveNodeType(node));
-                if (def.isProtected()) {
-                    // skip protected property
-                    log.debug("Skipping protected property " + pi.getName());
-
-                    // notify the ProtectedPropertyImporter.
-                    for (ProtectedItemImporter ppi : pItemImporters) {
-                        if (ppi instanceof ProtectedPropertyImporter && ((ProtectedPropertyImporter)
ppi).handlePropInfo(root.getTree(node.getPath()), pi, def)) {
-                            log.debug("Protected property -> delegated to ProtectedPropertyImporter");
-                            break;
-                        } /* else: p-i-Importer isn't able to deal with this property.
+            //TODO find better heuristics?
+            PropertyDefinition def = pi.getPropertyDef(effectiveNodeTypeProvider.getEffectiveNodeType(tree));
+
+            if (def.isProtected()) {
+                // skip protected property
+                log.debug("Skipping protected property " + pi.getName());
+
+                // notify the ProtectedPropertyImporter.
+                for (ProtectedItemImporter ppi : pItemImporters) {
+                    if (ppi instanceof ProtectedPropertyImporter
+                            && ((ProtectedPropertyImporter) ppi).handlePropInfo(tree,
pi, def)) {
+                        log.debug("Protected property -> delegated to ProtectedPropertyImporter");
+                        break;
+                    } /* else: p-i-Importer isn't able to deal with this property.
                              try next pp-importer */
 
-                    }
-                } else {
-                    // regular property -> create the property
-                    createProperty(node, pi, def);
                 }
             } else {
-                log.warn("missing EffectiveNodeTypeProvider");
+                // regular property -> create the property
+                createProperty(tree, pi, def);
             }
         }
 
-        parents.push(node);
+        parents.push(tree);
     }
 
 
     @Override
     public void endNode(NodeInfo nodeInfo) throws RepositoryException {
-        Node parent = parents.pop();
+        Tree parent = parents.pop();
         if (parent == null) {
             if (pnImporter != null) {
                 pnImporter.endChildInfo();
             }
-        } else if (parent.getDefinition().isProtected()) {
+        } else if (getDefinition(parent).isProtected()) {
             if (pnImporter != null) {
-                pnImporter.end(root.getTree(parent.getPath()));
+                pnImporter.end(parent);
                 // and reset the pnImporter field waiting for the next protected
                 // parent -> selecting again from available importers
                 pnImporter = null;
@@ -461,42 +433,69 @@ public class SessionImporter implements 
         Iterator<Object> iter = refTracker.getProcessedReferences();
         while (iter.hasNext()) {
             Object ref = iter.next();
-            if (!(ref instanceof Property)) {
+            if (!(ref instanceof Reference)) {
                 continue;
             }
 
-            Property prop = (Property) ref;
-            // being paranoid...
-            if (prop.getType() != PropertyType.REFERENCE
-                    && prop.getType() != PropertyType.WEAKREFERENCE) {
-                continue;
-            }
-            if (prop.isMultiple()) {
-                Value[] values = prop.getValues();
-                Value[] newVals = new Value[values.length];
-                for (int i = 0; i < values.length; i++) {
-                    Value val = values[i];
-                    String original = val.getString();
+            Reference reference = (Reference) ref;
+            if (reference.isMultiple()) {
+                Iterable<String> values = reference.property.getValue(Type.STRINGS);
+                List<String> newValues = Lists.newArrayList();
+                for (String original : values) {
                     String adjusted = refTracker.get(original);
                     if (adjusted != null) {
-                        newVals[i] = session.getValueFactory().createValue(
-                                session.getNodeByIdentifier(adjusted),
-                                prop.getType() != PropertyType.REFERENCE);
+                        newValues.add(adjusted);
                     } else {
                         // reference doesn't need adjusting, just copy old value
-                        newVals[i] = val;
+                        newValues.add(original);
                     }
                 }
-                prop.setValue(newVals);
+                reference.setProperty(newValues);
             } else {
-                Value val = prop.getValue();
-                String original = val.getString();
+                String original = reference.property.getValue(Type.STRING);
                 String adjusted = refTracker.get(original);
                 if (adjusted != null) {
-                    prop.setValue(session.getNodeByIdentifier(adjusted).getIdentifier());
+                    reference.setProperty(adjusted);
                 }
             }
         }
         refTracker.clear();
     }
+
+    private boolean isNodeType(Tree tree, String ntName) throws RepositoryException {
+        return effectiveNodeTypeProvider.isNodeType(tree, ntName);
+    }
+
+    private NodeDefinition getDefinition(Tree tree) throws RepositoryException {
+        if (tree.isRoot()) {
+            return definitionProvider.getRootDefinition();
+        } else {
+            return definitionProvider.getDefinition(tree.getParent(), tree);
+        }
+    }
+
+    private class Reference {
+
+        private final Tree tree;
+        private final PropertyState property;
+
+        private Reference(Tree tree, String propertyName) {
+            this.tree = tree;
+            this.property = tree.getProperty(propertyName);
+        }
+
+        private boolean isMultiple() {
+            return property.isArray();
+        }
+
+        private void setProperty(String newValue) {
+            PropertyState prop = PropertyStates.createProperty(property.getName(), newValue,
property.getType().tag());
+            tree.setProperty(prop);
+        }
+
+        private void setProperty(Iterable<String> newValues) {
+            PropertyState prop = PropertyStates.createProperty(property.getName(), newValues,
property.getType());
+            tree.setProperty(prop);
+        }
+    }
 }

Propchange: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImporterImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/SysViewImportHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/SysViewImportHandler.java?rev=1505715&r1=1505714&r2=1505715&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/SysViewImportHandler.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/SysViewImportHandler.java
Mon Jul 22 15:16:57 2013
@@ -73,14 +73,8 @@ class SysViewImportHandler extends Targe
         if (!start && !end) {
             return;
         }
-        String[] mixinNames = null;
-        if (state.mixinNames != null) {
-            mixinNames = state.mixinNames.toArray(
-                    new String[state.mixinNames.size()]);
-        }
         String id = state.uuid;
-        NodeInfo node =
-                new NodeInfo(state.nodeName, state.nodeTypeName, mixinNames, id);
+        NodeInfo node = new NodeInfo(state.nodeName, state.nodeTypeName, state.mixinNames,
id);
         // call Importer
         try {
             if (start) {

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/authorization/QueryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/authorization/QueryTest.java?rev=1505715&r1=1505714&r2=1505715&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/authorization/QueryTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/security/authorization/QueryTest.java
Mon Jul 22 15:16:57 2013
@@ -16,9 +16,9 @@
  */
 package org.apache.jackrabbit.oak.jcr.security.authorization;
 
+import java.security.AccessControlException;
 import javax.jcr.Node;
 import javax.jcr.NodeIterator;
-import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.ValueFactory;
 import javax.jcr.query.Query;
@@ -49,7 +49,7 @@ public class QueryTest extends AbstractE
         try {
             testSession.checkPermission(invisible.getPath(), Session.ACTION_READ);      
 
             fail();
-        } catch (RepositoryException e) {
+        } catch (AccessControlException e) {
             // expected
         }
         Node x = testSession.getNode(visible.getPath());



Mime
View raw message