jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexparvule...@apache.org
Subject svn commit: r1531336 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/ oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/ oak-core/src/test/java/org/apache/jackrabbit/oak/ oak-core/src/test/jav...
Date Fri, 11 Oct 2013 15:53:28 GMT
Author: alexparvulescu
Date: Fri Oct 11 15:53:28 2013
New Revision: 1531336

URL: http://svn.apache.org/r1531336
Log:
OAK-924 Optimize namespace lookups
 - removing the namespace map, now relying on the namespaces tree directly


Added:
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/TestGlobalNameMapper.java
  (with props)
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/GlobalNameMapper.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/LocalNameMapper.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/BuiltInNodeTypes.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/TestNameMapper.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/GlobalNameMapperTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImplTest.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/accesscontrol/AbstractAccessControlListTest.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionContext.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/DocViewImportHandler.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImportHandler.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/SysViewImportHandler.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/TargetImportHandler.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/GlobalNameMapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/GlobalNameMapper.java?rev=1531336&r1=1531335&r2=1531336&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/GlobalNameMapper.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/GlobalNameMapper.java
Fri Oct 11 15:53:28 2013
@@ -16,13 +16,15 @@
  */
 package org.apache.jackrabbit.oak.namepath;
 
-import java.util.Map;
 import javax.annotation.CheckForNull;
 import javax.annotation.Nonnull;
 import javax.jcr.RepositoryException;
 
+import org.apache.jackrabbit.oak.api.Tree;
+
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkNotNull;
+import static org.apache.jackrabbit.oak.plugins.name.Namespaces.getNamespacePrefix;
 
 /**
  * Name mapper with no local prefix remappings. URI to prefix mappings
@@ -37,7 +39,13 @@ import static com.google.common.base.Pre
  * consistency check can be used if needed to locate and fix any Oak names
  * with invalid namespace prefixes.
  */
-public abstract class GlobalNameMapper implements NameMapper {
+public class GlobalNameMapper implements NameMapper {
+
+    protected final Tree tree;
+
+    public GlobalNameMapper(Tree tree) {
+        this.tree = tree;
+    }
 
     @Override @Nonnull
     public String getJcrName(@Nonnull String oakName) {
@@ -96,17 +104,9 @@ public abstract class GlobalNameMapper i
         return expandedName; // not an expanded name
     }
 
-    protected abstract Map<String, String> getNamespaceMap();
-
     @CheckForNull
     protected String getOakPrefixOrNull(String uri) {
-        Map<String, String> namespaces = getNamespaceMap();
-        for (Map.Entry<String, String> entry : namespaces.entrySet()) {
-            if (uri.equals(entry.getValue())) {
-                return entry.getKey();
-            }
-        }
-        return null;
+        return getNamespacePrefix(tree, uri);
     }
 
 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/LocalNameMapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/LocalNameMapper.java?rev=1531336&r1=1531335&r2=1531336&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/LocalNameMapper.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/LocalNameMapper.java
Fri Oct 11 15:53:28 2013
@@ -18,16 +18,23 @@ package org.apache.jackrabbit.oak.namepa
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkNotNull;
+import static org.apache.jackrabbit.oak.plugins.name.Namespaces.getNamespaceURI;
 
 import java.util.Map;
 
 import javax.annotation.CheckForNull;
 
+import org.apache.jackrabbit.oak.api.Tree;
+
 /**
  * Name mapper with local namespace mappings.
  */
 public abstract class LocalNameMapper extends GlobalNameMapper {
 
+    public LocalNameMapper(Tree tree) {
+        super(tree);
+    }
+
     private static boolean isExpandedName(String name) {
         if (name.startsWith("{")) {
             int brace = name.indexOf('}', 1);
@@ -47,7 +54,7 @@ public abstract class LocalNameMapper ex
             int colon = oakName.indexOf(':');
             if (colon > 0) {
                 String oakPrefix = oakName.substring(0, colon);
-                String uri = getNamespaceMap().get(oakPrefix);
+                String uri = getNamespaceURI(tree, oakPrefix);
                 if (uri == null) {
                     throw new IllegalStateException(
                             "No namespace mapping found for " + oakName);
@@ -107,7 +114,7 @@ public abstract class LocalNameMapper ex
                 }
 
                 // Check that a global mapping is present and not remapped
-                uri = getNamespaceMap().get(jcrPrefix);
+                uri = getNamespaceURI(tree, jcrPrefix);
                 if (uri == null || local.values().contains(uri)) {
                     return null;
                 }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/BuiltInNodeTypes.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/BuiltInNodeTypes.java?rev=1531336&r1=1531335&r2=1531336&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/BuiltInNodeTypes.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/nodetype/write/BuiltInNodeTypes.java
Fri Oct 11 15:53:28 2013
@@ -21,7 +21,6 @@ import static org.apache.jackrabbit.oak.
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
-import java.util.Map;
 
 import javax.annotation.Nonnull;
 import javax.jcr.NamespaceRegistry;
@@ -29,17 +28,17 @@ import javax.jcr.RepositoryException;
 import javax.jcr.ValueFactory;
 import javax.jcr.nodetype.NodeTypeManager;
 
-import com.google.common.base.Charsets;
 import org.apache.jackrabbit.commons.cnd.CndImporter;
 import org.apache.jackrabbit.commons.cnd.ParseException;
 import org.apache.jackrabbit.oak.api.Root;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.namepath.GlobalNameMapper;
 import org.apache.jackrabbit.oak.namepath.NamePathMapperImpl;
-import org.apache.jackrabbit.oak.plugins.name.Namespaces;
 import org.apache.jackrabbit.oak.plugins.name.ReadWriteNamespaceRegistry;
 import org.apache.jackrabbit.oak.plugins.value.ValueFactoryImpl;
 
+import com.google.common.base.Charsets;
+
 /**
  * {@code BuiltInNodeTypes} is a utility class that registers the built-in
  * node types required for a JCR repository running on Oak.
@@ -78,12 +77,7 @@ class BuiltInNodeTypes {
         };
 
         this.vf = new ValueFactoryImpl(null, new NamePathMapperImpl(
-                new GlobalNameMapper() {
-                    @Override
-                    protected Map<String, String> getNamespaceMap() {
-                        return Namespaces.getNamespaceMap(root.getTree("/"));
-                    }
-                }));
+                new GlobalNameMapper(root.getTree("/"))));
     }
 
     /**

Added: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/TestGlobalNameMapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/TestGlobalNameMapper.java?rev=1531336&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/TestGlobalNameMapper.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/TestGlobalNameMapper.java
Fri Oct 11 15:53:28 2013
@@ -0,0 +1,39 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.jackrabbit.oak;
+
+import java.util.Map;
+
+import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.namepath.GlobalNameMapper;
+import org.apache.jackrabbit.oak.plugins.name.Namespaces;
+
+/**
+ * TestGlobalNameMapper... TODO
+ */
+public final class TestGlobalNameMapper extends GlobalNameMapper {
+
+    public TestGlobalNameMapper(Map<String, String> global) {
+        this(Namespaces.setupTestNamespaces(global));
+    }
+
+    public TestGlobalNameMapper(Tree tree) {
+        super(tree);
+    }
+}
\ No newline at end of file

Propchange: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/TestGlobalNameMapper.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/TestGlobalNameMapper.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/TestNameMapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/TestNameMapper.java?rev=1531336&r1=1531335&r2=1531336&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/TestNameMapper.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/TestNameMapper.java
Fri Oct 11 15:53:28 2013
@@ -21,7 +21,9 @@ package org.apache.jackrabbit.oak;
 import java.util.Collections;
 import java.util.Map;
 
+import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.namepath.LocalNameMapper;
+import org.apache.jackrabbit.oak.plugins.name.Namespaces;
 
 /**
  * TestNameMapper... TODO
@@ -34,32 +36,27 @@ public final class TestNameMapper extend
 
     public static final Map<String, String> LOCAL_MAPPING = Collections.singletonMap(TEST_LOCAL_PREFIX,
TEST_URI);
 
-    private final Map<String, String> global;
     private final Map<String, String> local;
 
     public TestNameMapper() {
-        this.global = Collections.singletonMap(TEST_PREFIX, TEST_URI);
-        this.local = LOCAL_MAPPING;
+        this(Collections.singletonMap(TEST_PREFIX, TEST_URI), LOCAL_MAPPING);
     }
 
-    public TestNameMapper(Map<String, String> global, Map<String, String> local)
{
-        this.global = global;
-        this.local = local;
+    public TestNameMapper(Map<String, String> global) {
+        this(global, global);
     }
 
-    public TestNameMapper(Map<String, String> global) {
-        this.global = global;
-        this.local = global;
+    public TestNameMapper(Map<String, String> global, Map<String, String> local)
{
+        this(Namespaces.setupTestNamespaces(global), local);
     }
 
     public TestNameMapper(TestNameMapper base, Map<String, String> local) {
-        this.global = base.global;
-        this.local = local;
+        this(base.tree, local);
     }
 
-    @Override
-    protected Map<String, String> getNamespaceMap() {
-        return global;
+    public TestNameMapper(Tree tree, Map<String, String> local) {
+        super(tree);
+        this.local = local;
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/GlobalNameMapperTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/GlobalNameMapperTest.java?rev=1531336&r1=1531335&r2=1531336&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/GlobalNameMapperTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/GlobalNameMapperTest.java
Fri Oct 11 15:53:28 2013
@@ -16,18 +16,21 @@
  */
 package org.apache.jackrabbit.oak.namepath;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+
 import javax.jcr.RepositoryException;
 
-import com.google.common.collect.ImmutableMap;
+import org.apache.jackrabbit.oak.TestGlobalNameMapper;
 import org.junit.Test;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.fail;
+import com.google.common.collect.ImmutableMap;
 
 public class GlobalNameMapperTest {
 
@@ -38,12 +41,7 @@ public class GlobalNameMapperTest {
             "foo", "http://www.example.com/foo",
             "quu", "http://www.example.com/quu");
 
-    private NameMapper mapper = new GlobalNameMapper() {
-        @Override
-        protected Map<String, String> getNamespaceMap() {
-            return NAMESPACES;
-        }
-    };
+    private NameMapper mapper = new TestGlobalNameMapper(NAMESPACES);
 
     @Test
     public void testEmptyName() throws RepositoryException {

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImplTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImplTest.java?rev=1531336&r1=1531335&r2=1531336&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImplTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/namepath/NamePathMapperImplTest.java
Fri Oct 11 15:53:28 2013
@@ -28,6 +28,9 @@ import java.util.Map;
 import javax.jcr.RepositoryException;
 
 import com.google.common.collect.ImmutableMap;
+
+import org.apache.jackrabbit.oak.TestGlobalNameMapper;
+import org.apache.jackrabbit.oak.TestNameMapper;
 import org.apache.jackrabbit.oak.plugins.identifier.IdentifierManager;
 import org.junit.Test;
 
@@ -47,17 +50,7 @@ public class NamePathMapperImplTest {
             "foo", "http://www.example.com/foo",
             "quu", "http://www.example.com/quu");
 
-    private final NameMapper mapper = new LocalNameMapper() {
-        @Override
-        protected Map<String, String> getNamespaceMap() {
-            return GLOBAL;
-        }
-
-        @Override
-        protected Map<String, String> getSessionLocalMappings() {
-            return LOCAL;
-        }
-    };
+    private final NameMapper mapper = new TestNameMapper(GLOBAL, LOCAL);
 
     private NamePathMapper npMapper = new NamePathMapperImpl(mapper);
 
@@ -136,12 +129,7 @@ public class NamePathMapperImplTest {
 
     @Test
     public void testJcrToOakKeepIndexNoRemap() {
-        NameMapper mapper = new GlobalNameMapper() {
-            @Override
-            protected Map<String, String> getNamespaceMap() {
-                return GLOBAL;
-            }
-        };
+        NameMapper mapper = new TestGlobalNameMapper(GLOBAL);
         NamePathMapper npMapper = new NamePathMapperImpl(mapper);
 
         assertEquals("/", npMapper.getOakPathKeepIndex("/"));

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/accesscontrol/AbstractAccessControlListTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/accesscontrol/AbstractAccessControlListTest.java?rev=1531336&r1=1531335&r2=1531336&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/accesscontrol/AbstractAccessControlListTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/spi/security/authorization/accesscontrol/AbstractAccessControlListTest.java
Fri Oct 11 15:53:28 2013
@@ -30,18 +30,19 @@ import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
 import javax.jcr.security.Privilege;
 
-import com.google.common.collect.Lists;
+import org.apache.jackrabbit.oak.TestGlobalNameMapper;
 import org.apache.jackrabbit.oak.TestNameMapper;
-import org.apache.jackrabbit.oak.namepath.GlobalNameMapper;
 import org.apache.jackrabbit.oak.namepath.NameMapper;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
 import org.apache.jackrabbit.oak.namepath.NamePathMapperImpl;
-import org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl;
-import org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants;
 import org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionDefinition;
 import org.apache.jackrabbit.oak.spi.security.authorization.restriction.RestrictionProvider;
+import org.apache.jackrabbit.oak.spi.security.principal.PrincipalImpl;
+import org.apache.jackrabbit.oak.spi.security.privilege.PrivilegeConstants;
 import org.junit.Test;
 
+import com.google.common.collect.Lists;
+
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
@@ -107,12 +108,7 @@ public abstract class AbstractAccessCont
 
     @Test
     public void testGetPath() {
-        NameMapper nameMapper = new GlobalNameMapper() {
-            @Override
-            protected Map<String, String> getNamespaceMap() {
-                return Collections.singletonMap("jr", "http://jackrabbit.apache.org");
-            }
-        };
+        NameMapper nameMapper = new TestGlobalNameMapper(Collections.singletonMap("jr", "http://jackrabbit.apache.org"));
         NamePathMapper npMapper = new NamePathMapperImpl(nameMapper);
 
         // map of jcr-path to standard jcr-path

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionContext.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionContext.java?rev=1531336&r1=1531335&r2=1531336&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionContext.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/session/SessionContext.java
Fri Oct 11 15:53:28 2013
@@ -51,7 +51,6 @@ import org.apache.jackrabbit.oak.jcr.ses
 import org.apache.jackrabbit.oak.namepath.LocalNameMapper;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
 import org.apache.jackrabbit.oak.namepath.NamePathMapperImpl;
-import org.apache.jackrabbit.oak.plugins.name.Namespaces;
 import org.apache.jackrabbit.oak.plugins.nodetype.ReadOnlyNodeTypeManager;
 import org.apache.jackrabbit.oak.plugins.observation.Observable;
 import org.apache.jackrabbit.oak.plugins.value.ValueFactoryImpl;
@@ -120,11 +119,7 @@ public class SessionContext implements N
         this.delegate = checkNotNull(delegate);
 
         this.namespaces = new SessionNamespaces(this);
-        LocalNameMapper nameMapper = new LocalNameMapper() {
-            @Override
-            protected Map<String, String> getNamespaceMap() {
-                return Namespaces.getNamespaceMap(delegate.getRoot().getTree("/"));
-            }
+        LocalNameMapper nameMapper = new LocalNameMapper(delegate.getRoot().getTree("/"))
{
 
             @Override
             protected Map<String, String> getSessionLocalMappings() {

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/DocViewImportHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/DocViewImportHandler.java?rev=1531336&r1=1531335&r2=1531336&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/DocViewImportHandler.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/DocViewImportHandler.java
Fri Oct 11 15:53:28 2013
@@ -22,15 +22,14 @@ import java.io.Reader;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Stack;
+
 import javax.jcr.NamespaceRegistry;
 import javax.jcr.Node;
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
-import javax.jcr.ValueFactory;
 import javax.jcr.nodetype.ConstraintViolationException;
 
-import com.google.common.collect.Lists;
-import org.apache.jackrabbit.commons.NamespaceHelper;
+import org.apache.jackrabbit.oak.jcr.session.SessionContext;
 import org.apache.jackrabbit.oak.namepath.JcrNameParser;
 import org.apache.jackrabbit.oak.plugins.name.NamespaceConstants;
 import org.apache.jackrabbit.oak.spi.xml.Importer;
@@ -43,6 +42,8 @@ import org.slf4j.LoggerFactory;
 import org.xml.sax.Attributes;
 import org.xml.sax.SAXException;
 
+import com.google.common.collect.Lists;
+
 /**
  * {@code DocViewImportHandler} processes Document View XML SAX events
  * and 'translates' them into {@code {@link Importer}} method calls.
@@ -64,11 +65,10 @@ class DocViewImportHandler extends Targe
      * Constructs a new {@code DocViewImportHandler}.
      *
      * @param importer     the importer
-     * @param valueFactory a value factory
-     * @param helper The namespace helper
+     * @param sessionContext the session context
      */
-    DocViewImportHandler(Importer importer, ValueFactory valueFactory, NamespaceHelper helper)
{
-        super(importer, valueFactory, helper);
+    DocViewImportHandler(Importer importer, SessionContext sessionContext) {
+        super(importer, sessionContext);
     }
 
     /**
@@ -108,7 +108,7 @@ class DocViewImportHandler extends Targe
     private void appendCharacters(char[] ch, int start, int length)
             throws SAXException {
         if (textHandler == null) {
-            textHandler = new BufferedStringValue(valueFactory, currentNamePathMapper());
+            textHandler = new BufferedStringValue(sessionContext.getValueFactory(), currentNamePathMapper());
         }
         try {
             textHandler.append(ch, start, length);
@@ -158,11 +158,11 @@ class DocViewImportHandler extends Targe
                 }
 
                 NodeInfo node =
-                        new NodeInfo(helper.getJcrName(NamespaceRegistry.NAMESPACE_JCR, "xmltext"),
null, null, null);
+                        new NodeInfo(getJcrName(NamespaceRegistry.NAMESPACE_JCR, "xmltext"),
null, null, null);
                 TextValue[] values =
                         new TextValue[]{textHandler};
                 ArrayList<PropInfo> props = new ArrayList<PropInfo>();
-                props.add(new PropInfo(helper.getJcrName(NamespaceRegistry.NAMESPACE_JCR,
"xmlcharacters"),
+                props.add(new PropInfo(getJcrName(NamespaceRegistry.NAMESPACE_JCR, "xmlcharacters"),
                         PropertyType.STRING, values));
                 // call Importer
                 importer.startNode(node, props);
@@ -181,6 +181,11 @@ class DocViewImportHandler extends Targe
         }
     }
 
+    private String getJcrName(String uri, String name)
+            throws RepositoryException {
+        return sessionContext.getSession().getNamespacePrefix(uri) + ":" + name;
+    }
+
     /**
      * Processes the given {@code name}, i.e. decodes it and checks
      * the format of the decoded name.
@@ -250,7 +255,7 @@ class DocViewImportHandler extends Targe
                 // see also DocViewSAXEventGenerator#leavingProperties(Node, int)
                 // TODO proper multi-value serialization support
                 propValues = new TextValue[1];
-                propValues[0] = new StringValue(attrValue, valueFactory, currentNamePathMapper());
+                propValues[0] = new StringValue(attrValue, sessionContext.getValueFactory(),
currentNamePathMapper());
 
                 if (NamespaceRegistry.NAMESPACE_JCR.equals(propNameInfo.getNamespaceUri())
                         && "primaryType".equals(propNameInfo.getLocalName())) {

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImportHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImportHandler.java?rev=1531336&r1=1531335&r2=1531336&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImportHandler.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/ImportHandler.java
Fri Oct 11 15:53:28 2013
@@ -18,14 +18,14 @@ package org.apache.jackrabbit.oak.jcr.xm
 
 import java.util.HashMap;
 import java.util.Map;
+
 import javax.jcr.RepositoryException;
-import javax.jcr.ValueFactory;
 
 import org.apache.jackrabbit.commons.NamespaceHelper;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
 import org.apache.jackrabbit.oak.api.Root;
-import org.apache.jackrabbit.oak.jcr.session.SessionContext;
 import org.apache.jackrabbit.oak.jcr.delegate.SessionDelegate;
+import org.apache.jackrabbit.oak.jcr.session.SessionContext;
 import org.apache.jackrabbit.oak.plugins.name.NamespaceConstants;
 import org.apache.jackrabbit.oak.spi.xml.Importer;
 import org.slf4j.Logger;
@@ -61,7 +61,6 @@ public class ImportHandler extends Defau
 
     private final SessionContext sessionContext;
     private final Importer importer;
-    private final NamespaceHelper helper;
     private final boolean isWorkspaceImport;
 
     protected Locator locator;
@@ -76,7 +75,6 @@ public class ImportHandler extends Defau
         SessionDelegate sd = sessionContext.getSessionDelegate();
         initialRoot = sd.getContentSession().getLatestRoot();
         root = (isWorkspaceImport) ? sd.getContentSession().getLatestRoot() : sd.getRoot();
-        helper = new NamespaceHelper(sessionContext.getSession());
         importer = new ImporterImpl(absPath, sessionContext, root, initialRoot, uuidBehavior,
isWorkspaceImport);
     }
 
@@ -143,7 +141,8 @@ public class ImportHandler extends Defau
     public void startPrefixMapping(String prefix, String uri)
             throws SAXException {
         try {
-            helper.registerNamespace(prefix, uri);
+            new NamespaceHelper(sessionContext.getSession()).registerNamespace(
+                    prefix, uri);
             if (targetHandler != null) {
                 targetHandler.startPrefixMapping(prefix, uri);
             } else {
@@ -169,11 +168,10 @@ public class ImportHandler extends Defau
         if (targetHandler == null) {
             // the namespace of the first element determines the type of XML
             // (system view/document view)
-            ValueFactory vf = sessionContext.getValueFactory();
             if (NamespaceConstants.NAMESPACE_SV.equals(namespaceURI)) {
-                targetHandler = new SysViewImportHandler(importer, vf, helper);
+                targetHandler = new SysViewImportHandler(importer, sessionContext);
             } else {
-                targetHandler = new DocViewImportHandler(importer, vf, helper);
+                targetHandler = new DocViewImportHandler(importer, sessionContext);
             }
 
             targetHandler.startDocument();

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=1531336&r1=1531335&r2=1531336&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
Fri Oct 11 15:53:28 2013
@@ -16,18 +16,17 @@
  */
 package org.apache.jackrabbit.oak.jcr.xml;
 
-
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Stack;
+
 import javax.jcr.InvalidSerializedDataException;
 import javax.jcr.NamespaceRegistry;
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
-import javax.jcr.ValueFactory;
 
-import org.apache.jackrabbit.commons.NamespaceHelper;
+import org.apache.jackrabbit.oak.jcr.session.SessionContext;
 import org.apache.jackrabbit.oak.plugins.name.NamespaceConstants;
 import org.apache.jackrabbit.oak.spi.xml.Importer;
 import org.apache.jackrabbit.oak.spi.xml.NodeInfo;
@@ -63,11 +62,10 @@ class SysViewImportHandler extends Targe
      * Constructs a new {@code SysViewImportHandler}.
      *
      * @param importer     the underlying importer
-     * @param valueFactory the value factory
-     * @param helper the namespace helper
+     * @param sessionContext the session context
      */
-    SysViewImportHandler(Importer importer, ValueFactory valueFactory, NamespaceHelper helper)
{
-        super(importer, valueFactory, helper);
+    SysViewImportHandler(Importer importer, SessionContext sessionContext) {
+        super(importer, sessionContext);
     }
 
     private void processNode(ImportState state, boolean start, boolean end)
@@ -168,7 +166,7 @@ class SysViewImportHandler extends Targe
             }
         } else if (namespaceURI.equals(NamespaceConstants.NAMESPACE_SV) && "value".equals(localName))
{
             // sv:value element
-            currentPropValue = new BufferedStringValue(valueFactory, currentNamePathMapper());
+            currentPropValue = new BufferedStringValue(sessionContext.getValueFactory(),
currentNamePathMapper());
             String xsiType = atts.getValue("xsi:type");
             currentPropValue.setBase64("xs:base64Binary".equals(xsiType));
         } else {

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/TargetImportHandler.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/TargetImportHandler.java?rev=1531336&r1=1531335&r2=1531336&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/TargetImportHandler.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/xml/TargetImportHandler.java
Fri Oct 11 15:53:28 2013
@@ -22,19 +22,22 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+
 import javax.jcr.RepositoryException;
-import javax.jcr.ValueFactory;
 
-import com.google.common.collect.ArrayListMultimap;
-import com.google.common.collect.ListMultimap;
-import org.apache.jackrabbit.commons.NamespaceHelper;
+import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.jcr.session.SessionContext;
 import org.apache.jackrabbit.oak.namepath.LocalNameMapper;
 import org.apache.jackrabbit.oak.namepath.NamePathMapper;
 import org.apache.jackrabbit.oak.namepath.NamePathMapperImpl;
+import org.apache.jackrabbit.oak.plugins.name.Namespaces;
 import org.apache.jackrabbit.oak.spi.xml.Importer;
 import org.xml.sax.SAXException;
 import org.xml.sax.helpers.DefaultHandler;
 
+import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.ListMultimap;
+
 /**
  * {@code TargetImportHandler} serves as the base class for the concrete
  * classes {@code {@link DocViewImportHandler}} and
@@ -43,15 +46,13 @@ import org.xml.sax.helpers.DefaultHandle
 public abstract class TargetImportHandler extends DefaultHandler {
 
     protected final Importer importer;
-    protected final ValueFactory valueFactory;
-    protected final NamespaceHelper helper;
+    protected final SessionContext sessionContext;
     private final ListMultimap<String, String> documentContext = ArrayListMultimap.create();
     private Map<String, String> documentPrefixMap = Collections.emptyMap();
 
-    protected TargetImportHandler(Importer importer, ValueFactory valueFactory, NamespaceHelper
helper) {
+    protected TargetImportHandler(Importer importer, SessionContext sessionContext) {
         this.importer = importer;
-        this.valueFactory = valueFactory;
-        this.helper = helper;
+        this.sessionContext = sessionContext;
     }
 
     //--------------------------------------------------------< ImportHandler >
@@ -107,15 +108,7 @@ public abstract class TargetImportHandle
     //--------------------------------------------------------
 
     public NamePathMapper currentNamePathMapper() {
-        return new NamePathMapperImpl(new LocalNameMapper() {
-            @Override
-            protected Map<String, String> getNamespaceMap() {
-                try {
-                    return helper.getNamespaces();
-                } catch (RepositoryException e) {
-                    return Collections.emptyMap();
-                }
-            }
+        return new NamePathMapperImpl(new LocalNameMapper(getNSReadTree()) {
 
             @Override
             protected Map<String, String> getSessionLocalMappings() {
@@ -124,6 +117,10 @@ public abstract class TargetImportHandle
         });
     }
 
+    private Tree getNSReadTree() {
+        return sessionContext.getSessionDelegate().getRoot().getTree("/");
+    }
+
     private Map<String, String> createCurrentPrefixMap() {
         Map<String, String> result = new HashMap<String, String>();
         Set<Map.Entry<String, Collection<String>>> entries = documentContext.asMap().entrySet();
@@ -171,11 +168,11 @@ public abstract class TargetImportHandle
             } else {
                 List<String> uris = documentContext.get(docPrefix);
                 if (uris.isEmpty()) {
-                    namespaceUri = helper.getURI(docPrefix);
+                    namespaceUri = Namespaces.getNamespaceURI(getNSReadTree(), docPrefix);
                     repoPrefix = docPrefix;
                 } else {
                     namespaceUri = uris.get(uris.size() - 1);
-                    repoPrefix = helper.getPrefix(namespaceUri);
+                    repoPrefix = Namespaces.getNamespacePrefix(getNSReadTree(), namespaceUri);
                 }
             }
         }



Mime
View raw message