jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r1387138 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/ oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/
Date Tue, 18 Sep 2012 13:18:05 GMT
Author: mreutegg
Date: Tue Sep 18 13:18:05 2012
New Revision: 1387138

URL: http://svn.apache.org/viewvc?rev=1387138&view=rev
Log:
OAK-311: Remapping a namespace breaks existing content

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NamespaceRegistryImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NamespaceValidator.java
    jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NamespaceRegistryImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NamespaceRegistryImpl.java?rev=1387138&r1=1387137&r2=1387138&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NamespaceRegistryImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NamespaceRegistryImpl.java
Tue Sep 18 13:18:05 2012
@@ -26,6 +26,7 @@ import javax.jcr.RepositoryException;
 
 import org.apache.jackrabbit.JcrConstants;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
+import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.plugins.memory.StringValue;
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.api.Tree;
@@ -81,6 +82,12 @@ public abstract class NamespaceRegistryI
             Root root = getWriteRoot();
             Tree namespaces =
                     getOrCreate(root, JcrConstants.JCR_SYSTEM, REP_NAMESPACES);
+            // remove existing mapping to given uri
+            for (PropertyState p : namespaces.getProperties()) {
+                if (!p.isArray() && p.getValue().getString().equals(uri)) {
+                    namespaces.removeProperty(p.getName());
+                }
+            }
             namespaces.setProperty(prefix, new StringValue(uri));
             root.commit(DefaultConflictHandler.OURS);
             refresh();

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NamespaceValidator.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NamespaceValidator.java?rev=1387138&r1=1387137&r2=1387138&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NamespaceValidator.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/name/NamespaceValidator.java
Tue Sep 18 13:18:05 2012
@@ -49,7 +49,12 @@ class NamespaceValidator extends Default
             } else if (prefix.toLowerCase(Locale.ENGLISH).startsWith("xml")) {
                 throw new NamespaceValidatorException(
                         "XML prefixes are reserved", prefix);
+            } else if (map.containsValue(after.getValue().getString())) {
+                throw modificationNotAllowed(prefix);
             }
+        } else {
+            throw new NamespaceValidatorException(
+                    "Not a valid namespace prefix", prefix);
         }
     }
 
@@ -57,8 +62,7 @@ class NamespaceValidator extends Default
     public void propertyChanged(PropertyState before, PropertyState after)
             throws CommitFailedException {
         if (map.containsKey(after.getName())) {
-            throw new NamespaceValidatorException(
-                    "Namespace modification not allowed", after.getName());
+            throw modificationNotAllowed(after.getName());
         }
     }
 
@@ -70,4 +74,9 @@ class NamespaceValidator extends Default
         }
     }
 
+    private static NamespaceValidatorException modificationNotAllowed(String prefix) {
+        return new NamespaceValidatorException(
+                "Namespace modification not allowed", prefix);
+    }
+
 }

Modified: jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java?rev=1387138&r1=1387137&r2=1387138&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/RepositoryTest.java
Tue Sep 18 13:18:05 2012
@@ -40,6 +40,7 @@ import javax.jcr.Binary;
 import javax.jcr.GuestCredentials;
 import javax.jcr.InvalidItemStateException;
 import javax.jcr.Item;
+import javax.jcr.NamespaceException;
 import javax.jcr.NamespaceRegistry;
 import javax.jcr.NoSuchWorkspaceException;
 import javax.jcr.Node;
@@ -1425,6 +1426,49 @@ public class RepositoryTest extends Abst
     }
 
     @Test
+    public void sessionRemappedNamespace() throws RepositoryException {
+        NamespaceRegistry nsReg =
+                getAdminSession().getWorkspace().getNamespaceRegistry();
+        nsReg.registerNamespace("foo", "file:///foo");
+
+        getAdminSession().getRootNode().addNode("foo:test");
+        getAdminSession().save();
+
+        Session s = createAdminSession();
+        s.setNamespacePrefix("bar", "file:///foo");
+        assertTrue(s.getRootNode().hasNode("bar:test"));
+        Node n = s.getRootNode().getNode("bar:test");
+        assertEquals("bar:test", n.getName());
+        s.logout();
+
+        getAdminSession().getRootNode().getNode("foo:test").remove();
+        getAdminSession().save();
+        nsReg.unregisterNamespace("foo");
+    }
+
+    @Test
+    public void registryRemappedNamespace() throws RepositoryException {
+        NamespaceRegistry nsReg =
+                getAdminSession().getWorkspace().getNamespaceRegistry();
+        nsReg.registerNamespace("foo", "file:///foo");
+
+        getAdminSession().getRootNode().addNode("foo:test");
+        getAdminSession().save();
+
+        try {
+            nsReg.registerNamespace("bar", "file:///foo");
+            fail("Remapping namespace through NamespaceRegistry must not be allowed");
+        } catch (NamespaceException e) {
+            // expected
+        } finally {
+            getAdminSession().getRootNode().getNode("foo:test").remove();
+            getAdminSession().save();
+
+            nsReg.unregisterNamespace("foo");
+        }
+    }
+
+    @Test
     public void mixin() throws RepositoryException {
         NodeTypeManager ntMgr = getAdminSession().getWorkspace().getNodeTypeManager();
         NodeTypeTemplate mixTest = ntMgr.createNodeTypeTemplate();



Mime
View raw message