jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From resc...@apache.org
Subject svn commit: r1330177 - in /jackrabbit/oak/trunk: oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/ oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/
Date Wed, 25 Apr 2012 09:52:22 GMT
Author: reschke
Date: Wed Apr 25 09:52:21 2012
New Revision: 1330177

URL: http://svn.apache.org/viewvc?rev=1330177&view=rev
Log:
OAK-61: add NameMapper interface + implementation (WIP)

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/AbstractNameMapper.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NameMapper.java
Modified:
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/AbstractNameMapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/AbstractNameMapper.java?rev=1330177&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/AbstractNameMapper.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/AbstractNameMapper.java
Wed Apr 25 09:52:21 2012
@@ -0,0 +1,87 @@
+/*
+ * 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.namepath;
+
+public abstract class AbstractNameMapper implements NameMapper {
+
+    abstract protected String getJcrPrefix(String oakPrefix);
+
+    abstract protected String getOakPrefix(String jcrPrefix);
+
+    abstract protected String getOakPrefixFromURI(String uri);
+
+    @Override
+    public String getOakName(String jcrName) {
+
+        int pos = jcrName.indexOf(":");
+
+        if (pos < 0) {
+            // no colon
+            return jcrName;
+        } else {
+            if (jcrName.charAt(0) == '{') {
+                int endpos = jcrName.indexOf('}');
+                if (endpos > pos) {
+                    // expanded name
+
+                    String nsuri = jcrName.substring(1, endpos);
+                    String name = jcrName.substring(endpos + 1);
+
+                    String oakPref = getOakPrefixFromURI(nsuri);
+                    if (oakPref == null) {
+                        // TODO
+                        return null;
+                    } else {
+                        return oakPref + ":" + name;
+                    }
+                }
+            }
+
+            // otherwise: not an expanded name
+
+            String pref = jcrName.substring(0, pos);
+            String name = jcrName.substring(pos + 1);
+            String oakPrefix = getOakPrefix(pref);
+            if (oakPrefix == null) {
+                // TODO
+                return null;
+            } else {
+                return oakPrefix + ":" + name;
+            }
+        }
+    }
+
+    @Override
+    public String getJcrName(String oakName) {
+        int pos = oakName.indexOf(":");
+        if (pos < 0) {
+            // non-prefixed
+            return oakName;
+        } else {
+            String pref = oakName.substring(0, pos);
+            String name = oakName.substring(pos + 1);
+            String jcrPrefix = getJcrPrefix(pref);
+            if (jcrPrefix == null) {
+                // TODO
+                return null;
+            } else {
+                return jcrPrefix + ":" + name;
+            }
+        }
+    }
+
+}

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NameMapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NameMapper.java?rev=1330177&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NameMapper.java
(added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/NameMapper.java
Wed Apr 25 09:52:21 2012
@@ -0,0 +1,26 @@
+/*
+ * 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.namepath;
+
+public interface NameMapper {
+
+    // TODO consider error handling
+    String getOakName(String jcrName);
+
+    // TODO consider error handling
+    String getJcrName(String oakName);
+}

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java?rev=1330177&r1=1330176&r2=1330177&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/SessionImpl.java
Wed Apr 25 09:52:21 2012
@@ -16,22 +16,12 @@
  */
 package org.apache.jackrabbit.oak.jcr;
 
-import org.apache.jackrabbit.api.JackrabbitSession;
-import org.apache.jackrabbit.api.security.principal.PrincipalManager;
-import org.apache.jackrabbit.api.security.user.UserManager;
-import org.apache.jackrabbit.commons.AbstractSession;
-import org.apache.jackrabbit.oak.api.CommitFailedException;
-import org.apache.jackrabbit.oak.api.ContentSession;
-import org.apache.jackrabbit.oak.api.Root;
-import org.apache.jackrabbit.oak.api.Tree;
-import org.apache.jackrabbit.oak.jcr.value.ValueFactoryImpl;
-import org.apache.jackrabbit.oak.namepath.Paths;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.xml.sax.ContentHandler;
+import java.io.IOException;
+import java.security.AccessControlException;
 
 import javax.jcr.Credentials;
 import javax.jcr.InvalidItemStateException;
+import javax.jcr.NamespaceRegistry;
 import javax.jcr.Node;
 import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
@@ -44,8 +34,23 @@ import javax.jcr.nodetype.NodeTypeManage
 import javax.jcr.retention.RetentionManager;
 import javax.jcr.security.AccessControlManager;
 import javax.jcr.version.VersionManager;
-import java.io.IOException;
-import java.security.AccessControlException;
+
+import org.apache.jackrabbit.api.JackrabbitSession;
+import org.apache.jackrabbit.api.security.principal.PrincipalManager;
+import org.apache.jackrabbit.api.security.user.UserManager;
+import org.apache.jackrabbit.commons.AbstractSession;
+import org.apache.jackrabbit.oak.api.CommitFailedException;
+import org.apache.jackrabbit.oak.api.ContentSession;
+import org.apache.jackrabbit.oak.api.Root;
+import org.apache.jackrabbit.oak.api.Tree;
+import org.apache.jackrabbit.oak.jcr.namespace.NamespaceRegistryImpl;
+import org.apache.jackrabbit.oak.jcr.value.ValueFactoryImpl;
+import org.apache.jackrabbit.oak.namepath.AbstractNameMapper;
+import org.apache.jackrabbit.oak.namepath.NameMapper;
+import org.apache.jackrabbit.oak.namepath.Paths;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.xml.sax.ContentHandler;
 
 /**
  * {@code SessionImpl}...
@@ -61,7 +66,9 @@ public class SessionImpl extends Abstrac
     private final ContentSession contentSession;
     private final ValueFactoryImpl valueFactory;
     private final Workspace workspace;
+    private final NamespaceRegistry nsreg;
     private final SessionContext<SessionImpl> sessionContext = new Context();
+    private final NameMapper nameMapper = new SessionNameMapper();
 
     private boolean isAlive = true;
     private Root root;
@@ -70,7 +77,8 @@ public class SessionImpl extends Abstrac
         this.globalContext = globalContext;
         this.contentSession = contentSession;
         this.valueFactory = new ValueFactoryImpl(contentSession.getCoreValueFactory());
-        workspace = new WorkspaceImpl(sessionContext);
+        this.nsreg = new NamespaceRegistryImpl(contentSession);
+        this.workspace = new WorkspaceImpl(sessionContext, this.nsreg);
         this.root = contentSession.getCurrentRoot();
     }
 
@@ -309,6 +317,42 @@ public class SessionImpl extends Abstrac
         throw new UnsupportedOperationException("Implementation missing");
     }
 
+    //--------------------------------------------------< SessionNamespaceResolver >---
+    
+    private class SessionNameMapper extends AbstractNameMapper {
+
+        @Override
+        protected String getJcrPrefix(String oakPrefix) {
+            try {
+                String ns = nsreg.getURI(oakPrefix);
+                return getNamespacePrefix(ns);
+            } catch (RepositoryException e) {
+                // TODO
+                return null;
+            }
+        }
+
+        @Override
+        protected String getOakPrefix(String jcrPrefix) {
+            try {
+                String ns = getNamespaceURI(jcrPrefix);
+                return nsreg.getPrefix(ns);
+            } catch (RepositoryException e) {
+                // TODO
+                return null;
+            }
+        }
+
+        @Override
+        protected String getOakPrefixFromURI(String uri) {
+            try {
+                return nsreg.getPrefix(uri);
+            } catch (RepositoryException e) {
+                // TODO
+                return null;
+            }
+        }
+    }
 
     //--------------------------------------------------------------------------
 

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java?rev=1330177&r1=1330176&r2=1330177&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/WorkspaceImpl.java
Wed Apr 25 09:52:21 2012
@@ -56,10 +56,11 @@ public class WorkspaceImpl implements Ja
 
     private final SessionContext<SessionImpl> sessionContext;
     private QueryManagerImpl queryManager;
-    private NamespaceRegistry nsRegistry;
+    private final NamespaceRegistry nsRegistry;
 
-    public WorkspaceImpl(SessionContext<SessionImpl> sessionContext) {
+    public WorkspaceImpl(SessionContext<SessionImpl> sessionContext, NamespaceRegistry
nsRegistry) {        
         this.sessionContext = sessionContext;
+        this.nsRegistry = nsRegistry;
     }
 
     //----------------------------------------------------------< Workspace >---
@@ -158,10 +159,6 @@ public class WorkspaceImpl implements Ja
     @Override
     public NamespaceRegistry getNamespaceRegistry() throws RepositoryException {
         ensureIsAlive();
-        if (nsRegistry == null) {
-            nsRegistry = new NamespaceRegistryImpl(
-                    sessionContext.getContentSession());
-        }
         return nsRegistry;
     }
 



Mime
View raw message