incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r587123 - in /incubator/sling/whiteboard/microsling/src: main/java/org/apache/sling/microsling/api/ main/java/org/apache/sling/microsling/request/helpers/ main/java/org/apache/sling/microsling/resource/ main/java/org/apache/sling/microsling...
Date Mon, 22 Oct 2007 15:02:08 GMT
Author: bdelacretaz
Date: Mon Oct 22 08:02:07 2007
New Revision: 587123

URL: http://svn.apache.org/viewvc?rev=587123&view=rev
Log:
SLING-76 - add ResourceMetadata and use it in SlingRequestPathInfoParser to avoid 'overloading
the semantics' of Resource.getURI

Added:
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/ResourceMetadata.java
  (with props)
Modified:
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/Resource.java
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/request/helpers/SlingRequestPathInfoParser.java
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/resource/JcrNodeResource.java
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/resource/MicroslingResourceResolver.java
    incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/DefaultSlingServlet.java
    incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/request/helpers/SlingRequestPathInfoParserTest.java

Modified: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/Resource.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/Resource.java?rev=587123&r1=587122&r2=587123&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/Resource.java
(original)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/Resource.java
Mon Oct 22 08:02:07 2007
@@ -20,11 +20,9 @@
 
 /** Resources are pieces of content on which Sling acts  */
 public interface Resource {
-    /** The canonical URI that the ResourceResolver used to load this
-     *  Resource. As microsling currently access content over JCR only,
-     *  URIs without a prefix indicate a JCR path in our Repository.
-     *  Microsling uses "/content/xyz" for this URI instead of "jcr:///content/xyz",
-     *  for example.    
+    /** This resource's URI - for now that could be a JCR path, but having
+     *  an URI makes it possible to use other data sources (not sure if we
+     *  really need that though).
      */
     String getURI();
 
@@ -33,7 +31,7 @@
      *  scripts and other tools definitions are found.
      */
     String getResourceType();
-
+    
     /**
      * The JCR item addressed by the {@link #getURI() resource URI} or null
      * if the resource URI does not actually address an item in a repository.
@@ -45,4 +43,7 @@
      * implementation.
      */
     Object getData();
+    
+    /** Content-related and/or Sling-related metadata about this Resource */
+    ResourceMetadata getMetadata();
 }

Added: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/ResourceMetadata.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/ResourceMetadata.java?rev=587123&view=auto
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/ResourceMetadata.java
(added)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/ResourceMetadata.java
Mon Oct 22 08:02:07 2007
@@ -0,0 +1,35 @@
+/*
+ * 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.sling.microsling.api;
+
+import java.util.HashMap;
+
+/** Metadata for the Resource, can hold content-related metadata 
+ *  (last modification time, etc.) as well as Sling-specific 
+ *  metadata (path used to resolve the Resource, etc.)
+ */
+public class ResourceMetadata extends HashMap<String, Object> {
+    private static final long serialVersionUID = 4529624506305380870L;
+
+    /** Use this prefix for Sling-specific metadata */
+    public final static String SLING_PREFIX = "sling.";
+
+    /** Set by the ResourceResolver when resolving the Resource 
+     *  @see ResourceResolver
+     */ 
+    public final static String RESOLUTION_PATH = SLING_PREFIX + "resolutionPath";
+}

Propchange: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/ResourceMetadata.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/api/ResourceMetadata.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/request/helpers/SlingRequestPathInfoParser.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/request/helpers/SlingRequestPathInfoParser.java?rev=587123&r1=587122&r2=587123&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/request/helpers/SlingRequestPathInfoParser.java
(original)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/request/helpers/SlingRequestPathInfoParser.java
Mon Oct 22 08:02:07 2007
@@ -21,6 +21,7 @@
 import java.util.regex.PatternSyntaxException;
 
 import org.apache.sling.microsling.api.Resource;
+import org.apache.sling.microsling.api.ResourceMetadata;
 import org.apache.sling.microsling.api.SlingRequestPathInfo;
 
 /** microsling request URI parser that provides SlingRequestPathInfo 
@@ -80,8 +81,8 @@
         if(r==null) {
             resourcePath = null;
         } else {
-            resourcePath = r.getURI();
-            if(pathToParse.length() >= resourcePath.length()) {
+            resourcePath = (String)r.getMetadata().get(ResourceMetadata.RESOLUTION_PATH);
+            if(resourcePath!=null && pathToParse.length() >= resourcePath.length())
{
                 pathToParse = pathToParse.substring(resourcePath.length());
             }
         }

Modified: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/resource/JcrNodeResource.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/resource/JcrNodeResource.java?rev=587123&r1=587122&r2=587123&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/resource/JcrNodeResource.java
(original)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/resource/JcrNodeResource.java
Mon Oct 22 08:02:07 2007
@@ -21,6 +21,7 @@
 import javax.jcr.RepositoryException;
 
 import org.apache.sling.microsling.api.Resource;
+import org.apache.sling.microsling.api.ResourceMetadata;
 
 /** A Resource that wraps a JCR Node */
 class JcrNodeResource implements Resource {
@@ -28,6 +29,7 @@
     private final String path;
     private final String resourceType;
     private Object data;
+    private final ResourceMetadata metadata;
 
     /** JCR Property that defines the resource type of this node
      *  (TODO: use a sling:namespaced property name)
@@ -39,6 +41,7 @@
     JcrNodeResource(javax.jcr.Session s,String path) throws RepositoryException {
         node = (Node)s.getItem(path);
         this.path = node.getPath();
+        metadata = new ResourceMetadata();
         resourceType = getResourceTypeForNode(node);
     }
 
@@ -65,6 +68,10 @@
     // no object mapping yet
     public Object getData() {
         return data;
+    }
+
+    public ResourceMetadata getMetadata() {
+        return metadata;
     }
 
     /** Compute the resource type of the given node, using either the SLING_RESOURCE_TYPE_PROPERTY,

Modified: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/resource/MicroslingResourceResolver.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/resource/MicroslingResourceResolver.java?rev=587123&r1=587122&r2=587123&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/resource/MicroslingResourceResolver.java
(original)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/resource/MicroslingResourceResolver.java
Mon Oct 22 08:02:07 2007
@@ -19,6 +19,7 @@
 import javax.servlet.http.HttpServletRequest;
 
 import org.apache.sling.microsling.api.Resource;
+import org.apache.sling.microsling.api.ResourceMetadata;
 import org.apache.sling.microsling.api.ResourceResolver;
 import org.apache.sling.microsling.api.SlingRequestContext;
 import org.slf4j.Logger;
@@ -44,6 +45,7 @@
             }
             if (ctx.getSession().itemExists(path)) {
                 result = new JcrNodeResource(ctx.getSession(),path);
+                result.getMetadata().put(ResourceMetadata.RESOLUTION_PATH, path);
                 if(log.isInfoEnabled()) {
                     log.info("Found Resource at path '" + path + "'");
                 }

Modified: incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/DefaultSlingServlet.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/DefaultSlingServlet.java?rev=587123&r1=587122&r2=587123&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/DefaultSlingServlet.java
(original)
+++ incubator/sling/whiteboard/microsling/src/main/java/org/apache/sling/microsling/slingservlets/DefaultSlingServlet.java
Mon Oct 22 08:02:07 2007
@@ -31,6 +31,7 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.sling.microsling.api.Resource;
 import org.apache.sling.microsling.api.SlingRequestContext;
 import org.apache.sling.microsling.api.exceptions.HttpStatusCodeException;
 import org.apache.sling.microsling.api.exceptions.SlingException;
@@ -49,19 +50,20 @@
 
         try {
             final SlingRequestContext ctx = SlingRequestContext.Accessor.getSlingRequestContext(req);
-            if (ctx.getResource() == null) {
+            final Resource  r = ctx.getResource();
+            if (r == null) {
                 throw new HttpStatusCodeException(404, "Resource not found: "
                     + req.getPathInfo());
             }
 
-            final Item data = ctx.getResource().getItem();
+            final Item data = r.getItem();
             if (data != null) {
                 final PrintWriter pw = resp.getWriter();
                 try {
                     if (data.isNode()) {
-                        dump(pw, (Node) data);
+                        dump(pw, r, (Node) data);
                     } else {
-                        dump(pw, (Property) data);
+                        dump(pw, r, (Property) data);
                     }
                 } catch (RepositoryException re) {
                     throw new ServletException("Cannot dump contents of "
@@ -171,9 +173,10 @@
         return (parent);
     }
 
-    protected void dump(PrintWriter pw, Node n) throws RepositoryException {
+    protected void dump(PrintWriter pw, Resource r, Node n) throws RepositoryException {
         pw.println("** Node dumped by " + getClass().getSimpleName() + "**");
         pw.println("Node path:" + n.getPath());
+        pw.println("Resource metadata: " + r.getMetadata());
 
         pw.println("\n** Node properties **");
         for (PropertyIterator pi = n.getProperties(); pi.hasNext();) {
@@ -182,9 +185,10 @@
         }
     }
 
-    protected void dump(PrintWriter pw, Property p) throws RepositoryException {
+    protected void dump(PrintWriter pw, Resource r, Property p) throws RepositoryException
{
         pw.println("** Property dumped by " + getClass().getSimpleName() + "**");
         pw.println("Property path:" + p.getPath());
+        pw.println("Resource metadata: " + r.getMetadata());
 
         printPropertyValue(pw, p);
     }

Modified: incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/request/helpers/SlingRequestPathInfoParserTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/request/helpers/SlingRequestPathInfoParserTest.java?rev=587123&r1=587122&r2=587123&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/request/helpers/SlingRequestPathInfoParserTest.java
(original)
+++ incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/request/helpers/SlingRequestPathInfoParserTest.java
Mon Oct 22 08:02:07 2007
@@ -21,6 +21,7 @@
 import junit.framework.TestCase;
 
 import org.apache.sling.microsling.api.Resource;
+import org.apache.sling.microsling.api.ResourceMetadata;
 import org.apache.sling.microsling.api.SlingRequestPathInfo;
 
 /** Test the SlingRequestPathInfoParser */
@@ -28,10 +29,11 @@
 
     static class MockResource implements Resource {
         
-        private final String uri;
+        private final ResourceMetadata metadata;
         
-        MockResource(String uri) {
-            this.uri = uri;
+        MockResource(String resolutionPath) {
+            metadata = new ResourceMetadata();
+            metadata.put(ResourceMetadata.RESOLUTION_PATH, resolutionPath);
         }
 
         public Object getData() {
@@ -47,7 +49,11 @@
         }
 
         public String getURI() {
-            return uri;
+            throw new Error("MockResource does not implement this method");
+        }
+        
+        public ResourceMetadata getMetadata() {
+            return metadata;
         }
         
     }



Mime
View raw message