Author: reto
Date: Thu May 26 17:37:56 2011
New Revision: 1128001

URL: http://svn.apache.org/viewvc?rev=1128001&view=rev
Log:
CLEREZZA-541: using GraphNodeProviderService in DiscobitsTypeHandler, added 
method that forces assumptions that the URI is local for efficiency and for the 
resources to be accessible even if the baseUri is not configured

Modified:
    incubator/clerezza/trunk/parent/platform.content/pom.xml
    
incubator/clerezza/trunk/parent/platform.content/src/main/java/org/apache/clerezza/platform/content/DiscobitsTypeHandler.java
    
incubator/clerezza/trunk/parent/platform.graphnodeprovider/src/main/scala/org/apache/clerezza/platform/graphnodeprovider/GraphNodeProvider.scala

Modified: incubator/clerezza/trunk/parent/platform.content/pom.xml
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/platform.content/pom.xml?rev=1128001&r1=1128000&r2=1128001&view=diff
==============================================================================
--- incubator/clerezza/trunk/parent/platform.content/pom.xml (original)
+++ incubator/clerezza/trunk/parent/platform.content/pom.xml Thu May 26 
17:37:56 2011
@@ -47,6 +47,10 @@
                        <groupId>org.apache.clerezza</groupId>
                        <artifactId>platform.graphprovider.content</artifactId>
                </dependency>
+               <dependency>
+                       <groupId>org.apache.clerezza</groupId>
+                       <artifactId>platform.graphnodeprovider</artifactId>
+               </dependency>
         <dependency>
                        <groupId>org.apache.clerezza</groupId>
                        <artifactId>platform.usermanager</artifactId>

Modified: 
incubator/clerezza/trunk/parent/platform.content/src/main/java/org/apache/clerezza/platform/content/DiscobitsTypeHandler.java
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/platform.content/src/main/java/org/apache/clerezza/platform/content/DiscobitsTypeHandler.java?rev=1128001&r1=1128000&r2=1128001&view=diff
==============================================================================
--- 
incubator/clerezza/trunk/parent/platform.content/src/main/java/org/apache/clerezza/platform/content/DiscobitsTypeHandler.java
 (original)
+++ 
incubator/clerezza/trunk/parent/platform.content/src/main/java/org/apache/clerezza/platform/content/DiscobitsTypeHandler.java
 Thu May 26 17:37:56 2011
@@ -18,6 +18,7 @@
  */
 package org.apache.clerezza.platform.content;
 
+import org.apache.clerezza.platform.graphnodeprovider.GraphNodeProvider;
 import org.apache.clerezza.rdf.metadata.MetaDataGenerator;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
@@ -120,7 +121,10 @@ public class DiscobitsTypeHandler extend
 
        @Reference
        PageNotFoundService notFoundPageService;
-       
+
+       @Reference
+       GraphNodeProvider graphNodeProvider;
+
        private static final Logger logger = 
LoggerFactory.getLogger(DiscobitsTypeHandler.class);
 
        private final Set<MetaDataGenerator> metaDataGenerators =
@@ -160,28 +164,8 @@ public class DiscobitsTypeHandler extend
        }
 
        private GraphNode getResourceAsGraphNode(UriInfo uriInfo) {
-               final MGraph mGraph = cgProvider.getContentGraph();
                final UriRef uri = new 
UriRef(uriInfo.getAbsolutePath().toString());
-               UriRef allHostsUri = createAnyHostUri(uriInfo);
-               List<TripleCollection> baseTripleCollections = new 
ArrayList<TripleCollection>(2);
-               if (nodeAtUriExists(allHostsUri)) {
-                       GraphNode anyHostGraphNode = new GraphNode(allHostsUri, 
mGraph);
-                       TripleCollection anyHostTriples = new 
UriMutatingTripleCollection(
-                                       anyHostGraphNode.getNodeContext(),
-                                       Constants.ALL_HOSTS_URI_PREFIX+'/', 
uriInfo.getBaseUri().toString());
-                       baseTripleCollections.add(anyHostTriples);
-
-               }
-               if (nodeAtUriExists(uri)) {
-                       baseTripleCollections.add(mGraph);
-               }
-               if (baseTripleCollections.isEmpty()) {
-                       return null;
-               }
-               TripleCollection baseGraph = baseTripleCollections.size() == 2 ?
-                       new UnionMGraph(baseTripleCollections.toArray(new 
TripleCollection[2])) :
-                       baseTripleCollections.get(0);
-               return new GraphNode(uri, baseGraph);
+               return graphNodeProvider.getLocal(uri);
        }
 
 

Modified: 
incubator/clerezza/trunk/parent/platform.graphnodeprovider/src/main/scala/org/apache/clerezza/platform/graphnodeprovider/GraphNodeProvider.scala
URL: 
http://svn.apache.org/viewvc/incubator/clerezza/trunk/parent/platform.graphnodeprovider/src/main/scala/org/apache/clerezza/platform/graphnodeprovider/GraphNodeProvider.scala?rev=1128001&r1=1128000&r2=1128001&view=diff
==============================================================================
--- 
incubator/clerezza/trunk/parent/platform.graphnodeprovider/src/main/scala/org/apache/clerezza/platform/graphnodeprovider/GraphNodeProvider.scala
 (original)
+++ 
incubator/clerezza/trunk/parent/platform.graphnodeprovider/src/main/scala/org/apache/clerezza/platform/graphnodeprovider/GraphNodeProvider.scala
 Thu May 26 17:37:56 2011
@@ -19,38 +19,51 @@ package org.apache.clerezza.platform.gra
  * under the License.
  */
 
-import org.osgi.service.component.ComponentContext
-import java.io.IOException
 import java.net.{HttpURLConnection, URL}
-import org.apache.clerezza.rdf.core.serializedform.SupportedFormat
-import org.apache.clerezza.rdf.core.serializedform.Parser
 import org.slf4j.scala._
 import org.apache.clerezza.rdf.core.access._
-import org.apache.clerezza.rdf.core.impl.AbstractMGraph
 import org.apache.clerezza.rdf.core._
 import org.apache.clerezza.platform.config.PlatformConfig
 import org.apache.clerezza.platform.Constants
 import org.apache.clerezza.platform.graphprovider.content.ContentGraphProvider
 import org.apache.clerezza.platform.users.WebIdGraphsService
-import javax.ws.rs.core.UriInfo
 import org.apache.clerezza.rdf.utils.{UnionMGraph, 
UriMutatingTripleCollection, GraphNode}
 import java.util.concurrent.locks.Lock
 import org.apache.clerezza.platform.usermanager.UserManager
-import java.security.{PrivilegedAction, PrivilegedExceptionAction, 
PrivilegedActionException, AccessController}
+import java.security.{PrivilegedAction, AccessController}
 
 /**
  * A service that returns a GraphNode for a specified named resource, the 
returned GraphNode has
- * as BaseGraph the ContententGraph provided by the ContentGraphProvider and 
the for remote uris the
+ * as BaseGraph the ContentGraph provided by the ContentGraphProvider and the 
for remote uris the
  * Graphs they dereference to and for local URIs with a path-section starting 
with /user/{username}/
  * the local-public-graph of that user.
  */
 class GraphNodeProvider extends Logging {
 
        /**
-        *Get a GraphNode for the specified resource, see class comments for 
details.
+        * Get a GraphNode for the specified resource, see class comments for 
details.
         */
        def get(uriRef: UriRef): GraphNode = {
+               val uriString = uriRef.getUnicodeString
+               val isLocal: Boolean = {
+                       import scala.collection.JavaConversions._
+                       //we assume all non http* uris to be local
+                       !uriString.toLowerCase.startsWith("http") || 
platformConfig.getBaseUris.exists(baseUri => 
uriString.startsWith(baseUri.getUnicodeString))
+               }
+               get(uriRef, isLocal)
+       }
+
+       /**
+        * Get a GraphNode for the specified resource, The resource is assumed 
to be local, i.e. the method behaves like
+        * get(UriRef) for a Uri with an authority section contained in the Set 
retuned by
+        * 
<code>org.apache.clerezza.platform.config.PlatformConfig#getBaseUris()</code>
+        */
+       def getLocal(uriRef: UriRef): GraphNode = {
+               get(uriRef, true)
+       }
 
+       private def get(uriRef: UriRef, isLocal: Boolean): GraphNode = {
+               val uriString = uriRef.getUnicodeString
                def existsInGraph(nodeUri: UriRef, tc: LockableMGraph): Boolean 
=
                        {
                                var readLock: Lock = tc.getLock.readLock
@@ -63,24 +76,16 @@ class GraphNodeProvider extends Logging 
                                }
                        }
 
-               val uriString = uriRef.getUnicodeString
-
                val uriPath = {
-                       val uri = new java.net.URI(uriRef.getUnicodeString)
+                       val uri = new java.net.URI(uriString)
                        uri.getPath
                }
 
                lazy val uriPrefix = {
-                       val uri = new java.net.URI(uriRef.getUnicodeString)
+                       val uri = new java.net.URI(uriString)
                        uri.getScheme+"://"+uri.getAuthority
                }
 
-               val isLocal: Boolean = {
-                       import scala.collection.JavaConversions._
-                       //we assume all non http* uris to be local
-                       !uriString.toLowerCase.startsWith("http") || 
platformConfig.getBaseUris.exists(baseUri => 
uriString.startsWith(baseUri.getUnicodeString))
-               }
-
                val anyHostUri = new UriRef(Constants.ALL_HOSTS_URI_PREFIX + 
uriPath)
 
                var mGraphs: List[TripleCollection] = Nil


Reply via email to