incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r619398 - in /incubator/sling/trunk: api/ api/src/main/java/org/apache/sling/api/resource/ api/src/main/java/org/apache/sling/api/scripting/ jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/ jcr/resource/src/main/java/org/a...
Date Thu, 07 Feb 2008 13:12:12 GMT
Author: fmeschbe
Date: Thu Feb  7 05:12:10 2008
New Revision: 619398

URL: http://svn.apache.org/viewvc?rev=619398&view=rev
Log:
SLING-236 Implement the getters and setters and adapt all known
uses of the constants

Modified:
    incubator/sling/trunk/api/pom.xml
    incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/NonExistingResource.java
    incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/ResourceMetadata.java
    incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/ResourceWrapper.java
    incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/SyntheticResource.java
    incubator/sling/trunk/api/src/main/java/org/apache/sling/api/scripting/SlingBindings.java
    incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver.java
    incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/bundle/BundleResource.java
    incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java
    incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResource.java
    incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceTest.java
    incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/launchpad/renderers/StreamRendererServlet.java
    incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/SlingIOProvider.java
    incubator/sling/trunk/scripting/resolver/src/main/java/org/apache/sling/scripting/resolver/impl/DefaultSlingScript.java
    incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/request/SlingRequestDispatcher.java
    incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/request/SlingRequestPathInfo.java
    incubator/sling/trunk/sling/core/src/test/java/org/apache/sling/core/impl/request/SlingRequestPathInfoTest.java
    incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/defaults/DefaultServlet.java
    incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/resource/ServletResource.java

Modified: incubator/sling/trunk/api/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/api/pom.xml?rev=619398&r1=619397&r2=619398&view=diff
==============================================================================
--- incubator/sling/trunk/api/pom.xml (original)
+++ incubator/sling/trunk/api/pom.xml Thu Feb  7 05:12:10 2008
@@ -62,6 +62,11 @@
         </dependency>
 
         <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>slf4j-api</artifactId>
+        </dependency>
+
+        <dependency>
             <groupId>junit</groupId>
             <artifactId>junit</artifactId>
         </dependency>

Modified: incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/NonExistingResource.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/NonExistingResource.java?rev=619398&r1=619397&r2=619398&view=diff
==============================================================================
--- incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/NonExistingResource.java
(original)
+++ incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/NonExistingResource.java
Thu Feb  7 05:12:10 2008
@@ -31,7 +31,7 @@
         this.resourceURI = resourceURI;
 
         resourceMetadata = new ResourceMetadata();
-        resourceMetadata.put(ResourceMetadata.RESOLUTION_PATH, resourceURI);
+        resourceMetadata.setResolutionPath(resourceURI);
     }
 
     public String getPath() {
@@ -60,5 +60,9 @@
      */
     public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
         return null;
+    }
+
+    public String toString() {
+        return getClass().getSimpleName() + ", path=" + getPath();
     }
 }

Modified: incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/ResourceMetadata.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/ResourceMetadata.java?rev=619398&r1=619397&r2=619398&view=diff
==============================================================================
--- incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/ResourceMetadata.java
(original)
+++ incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/ResourceMetadata.java
Thu Feb  7 05:12:10 2008
@@ -76,4 +76,121 @@
      */
     public static final String MODIFICATION_TIME = "sling.modificationTime";
 
+    /**
+     * Sets the {@link #CHARACTER_ENCODING} property to <code>encoding</code>
+     * if not <code>null</code>.
+     */
+    public void setCharacterEncoding(String encoding) {
+        if (encoding != null) {
+            put(CHARACTER_ENCODING, encoding);
+        }
+    }
+
+    /**
+     * Returns the {@link #CHARACTER_ENCODING} property if not <code>null</code>
+     * and a <code>String</code> instance. Otherwise <code>null</code>
is
+     * returned.
+     */
+    public String getCharacterEncoding() {
+        Object value = get(CHARACTER_ENCODING);
+        if (value instanceof String) {
+            return (String) value;
+        }
+
+        return null;
+    }
+
+    /**
+     * Sets the {@link #CONTENT_TYPE} property to <code>contentType</code> if
+     * not <code>null</code>.
+     */
+    public void setContentType(String contentType) {
+        if (contentType != null) {
+            put(CONTENT_TYPE, contentType);
+        }
+    }
+
+    /**
+     * Returns the {@link #CONTENT_TYPE} property if not <code>null</code> and
+     * a <code>String</code> instance. Otherwise <code>null</code>
is
+     * returned.
+     */
+    public String getContentType() {
+        Object value = get(CONTENT_TYPE);
+        if (value instanceof String) {
+            return (String) value;
+        }
+
+        return null;
+    }
+
+    /**
+     * Sets the {@link #CREATION_TIME} property to <code>creationTime</code>
+     * if not negative.
+     */
+    public void setCreationTime(long creationTime) {
+        if (creationTime >= 0) {
+            put(CREATION_TIME, creationTime);
+        }
+    }
+
+    /**
+     * Returns the {@link #CREATION_TIME} property if not <code>null</code>
+     * and a <code>long</code>. Otherwise <code>-1</code> is returned.
+     */
+    public long getCreationTime() {
+        Object value = get(CREATION_TIME);
+        if (value instanceof Long) {
+            return (Long) value;
+        }
+
+        return -1;
+    }
+
+    /**
+     * Sets the {@link #MODIFICATION_TIME} property to
+     * <code>modificationTime</code> if not negative.
+     */
+    public void setModificationTime(long modificationTime) {
+        if (modificationTime >= 0) {
+            put(MODIFICATION_TIME, modificationTime);
+        }
+    }
+
+    /**
+     * Returns the {@link #MODIFICATION_TIME} property if not <code>null</code>
+     * and a <code>long</code>. Otherwise <code>-1</code> is returned.
+     */
+    public long getModificationTime() {
+        Object value = get(MODIFICATION_TIME);
+        if (value instanceof Long) {
+            return (Long) value;
+        }
+
+        return -1;
+    }
+
+    /**
+     * Sets the {@link #RESOLUTION_PATH} property to <code>resolutionPath</code>
+     * if not <code>null</code>.
+     */
+    public void setResolutionPath(String resolutionPath) {
+        if (resolutionPath != null) {
+            put(RESOLUTION_PATH, resolutionPath);
+        }
+    }
+
+    /**
+     * Returns the {@link #RESOLUTION_PATH} property if not <code>null</code>
+     * and a <code>String</code> instance. Otherwise <code>null</code>
is
+     * returned.
+     */
+    public String getResolutionPath() {
+        Object value = get(RESOLUTION_PATH);
+        if (value instanceof String) {
+            return (String) value;
+        }
+
+        return null;
+    }
 }

Modified: incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/ResourceWrapper.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/ResourceWrapper.java?rev=619398&r1=619397&r2=619398&view=diff
==============================================================================
--- incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/ResourceWrapper.java
(original)
+++ incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/ResourceWrapper.java
Thu Feb  7 05:12:10 2008
@@ -64,4 +64,9 @@
         return resource.adaptTo(type);
     }
 
+    public String toString() {
+        return getClass().getSimpleName() + ", type=" + getResourceType()
+            + ", path=" + getPath() + ", resource=[" + getResource() + "]";
+    }
+
 }

Modified: incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/SyntheticResource.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/SyntheticResource.java?rev=619398&r1=619397&r2=619398&view=diff
==============================================================================
--- incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/SyntheticResource.java
(original)
+++ incubator/sling/trunk/api/src/main/java/org/apache/sling/api/resource/SyntheticResource.java
Thu Feb  7 05:12:10 2008
@@ -18,10 +18,6 @@
  */
 package org.apache.sling.api.resource;
 
-import org.apache.sling.api.resource.Resource;
-import org.apache.sling.api.resource.ResourceMetadata;
-import org.apache.sling.api.resource.ResourceProvider;
-
 /**
  * The <code>SyntheticResource</code> class is a simple implementation of the
  * <code>Resource</code> interface which may be used to provide a resource
@@ -46,7 +42,7 @@
         this.path = path;
         this.resourceType = resourceType;
         this.resourceMetadata = new ResourceMetadata();
-        this.resourceMetadata.put(ResourceMetadata.RESOLUTION_PATH, path);
+        this.resourceMetadata.setResolutionPath(path);
     }
 
     public String getPath() {
@@ -79,6 +75,11 @@
      */
     public <Type> Type adaptTo(Class<Type> type) {
         return null;
+    }
+
+    public String toString() {
+        return getClass().getSimpleName() + ", type=" + getResourceType()
+            + ", path=" + getPath();
     }
 
 }

Modified: incubator/sling/trunk/api/src/main/java/org/apache/sling/api/scripting/SlingBindings.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/api/src/main/java/org/apache/sling/api/scripting/SlingBindings.java?rev=619398&r1=619397&r2=619398&view=diff
==============================================================================
--- incubator/sling/trunk/api/src/main/java/org/apache/sling/api/scripting/SlingBindings.java
(original)
+++ incubator/sling/trunk/api/src/main/java/org/apache/sling/api/scripting/SlingBindings.java
Thu Feb  7 05:12:10 2008
@@ -18,8 +18,14 @@
  */
 package org.apache.sling.api.scripting;
 
+import java.io.PrintWriter;
 import java.util.HashMap;
 
+import org.apache.sling.api.SlingHttpServletRequest;
+import org.apache.sling.api.SlingHttpServletResponse;
+import org.apache.sling.api.resource.Resource;
+import org.slf4j.Logger;
+
 /**
  * The <code>SlingBindings</code> class is used to prepare global variables
  * for script execution. The constants in this class define names of variables
@@ -122,5 +128,169 @@
      * script implementation will bind it before actually evaluating the script.
      */
     public static final String LOG = "log";
+
+    /**
+     * Sets the {@link #FLUSH} property to <code>flush</code>.
+     */
+    public void setFlush(boolean flush) {
+        put(FLUSH, flush);
+    }
+
+    /**
+     * Returns the {@link #FLUSH} property if not <code>null</code> and a
+     * <code>boolean</code>. Otherwise <code>false</code> is returned.
+     */
+    public boolean getFlush() {
+        Object value = get(FLUSH);
+        if (value instanceof Boolean) {
+            return (Boolean) value;
+        }
+
+        return false;
+    }
+
+    /**
+     * Sets the {@link #LOG} property to <code>log</code> if not
+     * <code>null</code>.
+     */
+    public void setLog(Logger log) {
+        if (log != null) {
+            put(LOG, log);
+        }
+    }
+
+    /**
+     * Returns the {@link #LOG} property if not <code>null</code> and a
+     * <code>org.slf4j.Logger</code> instance. Otherwise <code>null</code>
+     * is returned.
+     */
+    public Logger getLog() {
+        Object value = get(LOG);
+        if (value instanceof Logger) {
+            return (Logger) value;
+        }
+
+        return null;
+    }
+
+    /**
+     * Sets the {@link #OUT} property to <code>out</code> if not
+     * <code>null</code>.
+     */
+    public void setOut(PrintWriter out) {
+        if (out != null) {
+            put(OUT, out);
+        }
+    }
+
+    /**
+     * Returns the {@link #OUT} property if not <code>null</code> and a
+     * <code>PrintWriter</code> instance. Otherwise <code>null</code>
is
+     * returned.
+     */
+    public PrintWriter getOut() {
+        Object value = get(OUT);
+        if (value instanceof PrintWriter) {
+            return (PrintWriter) value;
+        }
+
+        return null;
+    }
+
+    /**
+     * Sets the {@link #REQUEST} property to <code>request</code> if not
+     * <code>null</code>.
+     */
+    public void setRequest(SlingHttpServletRequest request) {
+        if (request != null) {
+            put(REQUEST, request);
+        }
+    }
+
+    /**
+     * Returns the {@link #REQUEST} property if not <code>null</code> and a
+     * <code>SlingHttpServletRequest</code> instance. Otherwise
+     * <code>null</code> is returned.
+     */
+    public SlingHttpServletRequest getRequest() {
+        Object value = get(REQUEST);
+        if (value instanceof SlingHttpServletRequest) {
+            return (SlingHttpServletRequest) value;
+        }
+
+        return null;
+    }
+
+    /**
+     * Sets the {@link #RESOURCE} property to <code>resource</code> if not
+     * <code>null</code>.
+     */
+    public void setResource(Resource resource) {
+        if (resource != null) {
+            put(RESOURCE, resource);
+        }
+    }
+
+    /**
+     * Returns the {@link #RESOURCE} property if not <code>null</code> and a
+     * <code>Resource</code> instance. Otherwise <code>null</code>
is
+     * returned.
+     */
+    public Resource getResource() {
+        Object value = get(RESOURCE);
+        if (value instanceof Resource) {
+            return (Resource) value;
+        }
+
+        return null;
+    }
+
+    /**
+     * Sets the {@link #RESPONSE} property to <code>response</code> if not
+     * <code>null</code>.
+     */
+    public void setResponse(SlingHttpServletResponse response) {
+        if (response != null) {
+            put(RESPONSE, response);
+        }
+    }
+
+    /**
+     * Returns the {@link #RESPONSE} property if not <code>null</code> and a
+     * <code>SlingHttpServletResponse</code> instance. Otherwise
+     * <code>null</code> is returned.
+     */
+    public SlingHttpServletResponse getResponse() {
+        Object value = get(RESPONSE);
+        if (value instanceof SlingHttpServletResponse) {
+            return (SlingHttpServletResponse) value;
+        }
+
+        return null;
+    }
+
+    /**
+     * Sets the {@link #SLING} property to <code>sling</code> if not
+     * <code>null</code>.
+     */
+    public void setSling(SlingScriptHelper sling) {
+        if (sling != null) {
+            put(SLING, sling);
+        }
+    }
+
+    /**
+     * Returns the {@link #SLING} property if not <code>null</code> and a
+     * <code>SlingScriptHelper</code> instance. Otherwise <code>null</code>
+     * is returned.
+     */
+    public SlingScriptHelper getSling() {
+        Object value = get(SLING);
+        if (value instanceof SlingScriptHelper) {
+            return (SlingScriptHelper) value;
+        }
+
+        return null;
+    }
 
 }

Modified: incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver.java?rev=619398&r1=619397&r2=619398&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver.java
(original)
+++ incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/JcrResourceResolver.java
Thu Feb  7 05:12:10 2008
@@ -302,11 +302,10 @@
             if (resource != null) {
 
                 ResourceMetadata rm = resource.getResourceMetadata();
-                String path = (String) rm.get(ResourceMetadata.RESOLUTION_PATH);
+                String path = rm.getResolutionPath();
                 String uriPath = mappings[i].mapHandle(path);
                 if (uriPath != null && !uriPath.equals(path)) {
-                    resource.getResourceMetadata().put(
-                        ResourceMetadata.RESOLUTION_PATH, uriPath);
+                    resource.getResourceMetadata().setResolutionPath(uriPath);
                 }
 
                 return resource;
@@ -348,8 +347,7 @@
 
         Resource resource = rootProvider.getResource(path);
         if (resource != null) {
-            resource.getResourceMetadata().put(
-                ResourceMetadata.RESOLUTION_PATH, path);
+            resource.getResourceMetadata().setResolutionPath(path);
             return resource;
         }
 

Modified: incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/bundle/BundleResource.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/bundle/BundleResource.java?rev=619398&r1=619397&r2=619398&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/bundle/BundleResource.java
(original)
+++ incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/bundle/BundleResource.java
Thu Feb  7 05:12:10 2008
@@ -18,9 +18,6 @@
 
 import static org.apache.jackrabbit.JcrConstants.NT_FILE;
 import static org.apache.jackrabbit.JcrConstants.NT_FOLDER;
-import static org.apache.sling.api.resource.ResourceMetadata.CREATION_TIME;
-import static org.apache.sling.api.resource.ResourceMetadata.MODIFICATION_TIME;
-import static org.apache.sling.api.resource.ResourceMetadata.RESOLUTION_PATH;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -84,9 +81,9 @@
         this.resourceType = path.endsWith("/") ? NT_FOLDER : NT_FILE;
 
         metadata = new ResourceMetadata();
-        metadata.put(RESOLUTION_PATH, path);
-        metadata.put(CREATION_TIME, bundle.getLastModified());
-        metadata.put(MODIFICATION_TIME, bundle.getLastModified());
+        metadata.setResolutionPath(path);
+        metadata.setCreationTime(bundle.getLastModified());
+        metadata.setModificationTime(bundle.getLastModified());
     }
 
     public String getPath() {
@@ -118,7 +115,8 @@
     }
 
     public String toString() {
-        return "BundleResource, type=" + resourceType + ", path=" + path;
+        return getClass().getSimpleName() + ", type=" + getResourceType()
+            + ", path=" + getPath();
     }
 
     // ---------- internal -----------------------------------------------------

Modified: incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java?rev=619398&r1=619397&r2=619398&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java
(original)
+++ incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResource.java
Thu Feb  7 05:12:10 2008
@@ -23,11 +23,6 @@
 import static org.apache.jackrabbit.JcrConstants.JCR_LASTMODIFIED;
 import static org.apache.jackrabbit.JcrConstants.JCR_MIMETYPE;
 import static org.apache.jackrabbit.JcrConstants.NT_FILE;
-import static org.apache.sling.api.resource.ResourceMetadata.CHARACTER_ENCODING;
-import static org.apache.sling.api.resource.ResourceMetadata.CONTENT_TYPE;
-import static org.apache.sling.api.resource.ResourceMetadata.CREATION_TIME;
-import static org.apache.sling.api.resource.ResourceMetadata.MODIFICATION_TIME;
-import static org.apache.sling.api.resource.ResourceMetadata.RESOLUTION_PATH;
 import static org.apache.sling.jcr.resource.JcrResourceConstants.SLING_RESOURCE_TYPE_PROPERTY;
 
 import java.io.InputStream;
@@ -72,7 +67,7 @@
         this.node = node;
         this.path = node.getPath();
         metadata = new ResourceMetadata();
-        metadata.put(RESOLUTION_PATH, path);
+        metadata.setResolutionPath(path);
         resourceType = getResourceTypeForNode(node);
 
         // check for nt:file metadata
@@ -106,7 +101,8 @@
     }
 
     public String toString() {
-        return "JcrNodeResource, type=" + resourceType + ", path=" + path;
+        return getClass().getSimpleName() + ", type=" + getResourceType()
+            + ", path=" + getPath();
     }
 
     public ResourceProvider getResourceProvider() {
@@ -130,13 +126,15 @@
             try {
                 // find the content node: for nt:file it is jcr:content
                 // otherwise it is the node of this resource
-                Node content = node.isNodeType(NT_FILE) ? node.getNode(JCR_CONTENT) : node;
-                
+                Node content = node.isNodeType(NT_FILE)
+                        ? node.getNode(JCR_CONTENT)
+                        : node;
+
                 // if the node has a jcr:data property, use that property
                 if (content.hasProperty(JCR_DATA)) {
                     return content.getProperty(JCR_DATA).getStream();
                 }
-                
+
                 // otherwise try to follow default item trail
                 try {
                     Item item = content.getPrimaryItem();
@@ -149,7 +147,7 @@
                     log.debug("getInputStream: No primary items for "
                         + toString(), infe);
                 }
-                
+
             } catch (RepositoryException re) {
                 log.error("getInputStream: Cannot get InputStream for " + this,
                     re);
@@ -187,7 +185,7 @@
             }
 
             log.error("getResource: There is no node at {} below {}", path,
-                    getPath());
+                getPath());
             return null;
         } catch (RepositoryException re) {
             log.error("getResource: Problem accessing relative resource at "
@@ -218,31 +216,27 @@
 
     private void setMetaData(Node node, ResourceMetadata metadata) {
         try {
-            
+
             // check stuff for nt:file nodes
             if (node.isNodeType(NT_FILE)) {
-                metadata.put(CREATION_TIME,
-                    node.getProperty(JCR_CREATED).getLong());
+                metadata.setCreationTime(node.getProperty(JCR_CREATED).getLong());
 
                 // continue our stuff with the jcr:content node
-                // which might be  nt:resource, which we support below
+                // which might be nt:resource, which we support below
                 node = node.getNode(JCR_CONTENT);
             }
-            
+
             // check stuff for nt:resource (or similar) nodes
             if (node.hasProperty(JCR_MIMETYPE)) {
-                metadata.put(CONTENT_TYPE,
-                    node.getProperty(JCR_MIMETYPE).getString());
+                metadata.setContentType(node.getProperty(JCR_MIMETYPE).getString());
             }
 
             if (node.hasProperty(JCR_ENCODING)) {
-                metadata.put(CHARACTER_ENCODING,
-                    node.getProperty(JCR_ENCODING).getString());
+                metadata.setCharacterEncoding(node.getProperty(JCR_ENCODING).getString());
             }
 
             if (node.hasProperty(JCR_LASTMODIFIED)) {
-                metadata.put(MODIFICATION_TIME, node.getProperty(
-                    JCR_LASTMODIFIED).getLong());
+                metadata.setModificationTime(node.getProperty(JCR_LASTMODIFIED).getLong());
             }
         } catch (RepositoryException re) {
             log.info(

Modified: incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResource.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResource.java?rev=619398&r1=619397&r2=619398&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResource.java
(original)
+++ incubator/sling/trunk/jcr/resource/src/main/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrPropertyResource.java
Thu Feb  7 05:12:10 2008
@@ -18,8 +18,6 @@
  */
 package org.apache.sling.jcr.resource.internal.helper.jcr;
 
-import static org.apache.sling.api.resource.ResourceMetadata.RESOLUTION_PATH;
-
 import java.util.Calendar;
 
 import javax.jcr.Item;
@@ -35,23 +33,24 @@
 public class JcrPropertyResource implements Resource {
 
     private final ResourceProvider resourceProvider;
+
     private final String path;
 
     private final Property property;
 
     private final String resourceType;
-    
+
     private final ResourceMetadata metadata;
 
-    public JcrPropertyResource(ResourceProvider resourceProvider, String path, Property property)
-            throws RepositoryException {
+    public JcrPropertyResource(ResourceProvider resourceProvider, String path,
+            Property property) throws RepositoryException {
         this.resourceProvider = resourceProvider;
         this.path = path;
         this.property = property;
         this.resourceType = JcrNodeResource.getResourceTypeForNode(property.getParent())
             + "/" + property.getName();
         this.metadata = new ResourceMetadata();
-        this.metadata.put(RESOLUTION_PATH, path);
+        this.metadata.setResolutionPath(path);
     }
 
     public String getPath() {
@@ -69,7 +68,7 @@
     public ResourceProvider getResourceProvider() {
         return resourceProvider;
     }
-    
+
     @SuppressWarnings("unchecked")
     public <AdapterType> AdapterType adaptTo(Class<AdapterType> type) {
 
@@ -96,12 +95,17 @@
         } catch (RepositoryException re) {
             // TODO: log
         }
-        
+
         // no adapter here
         return null;
     }
 
     public Property getProperty() {
         return property;
+    }
+
+    public String toString() {
+        return getClass().getSimpleName() + ", type=" + getResourceType()
+            + ", path=" + getPath();
     }
 }

Modified: incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceTest.java?rev=619398&r1=619397&r2=619398&view=diff
==============================================================================
--- incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceTest.java
(original)
+++ incubator/sling/trunk/jcr/resource/src/test/java/org/apache/sling/jcr/resource/internal/helper/jcr/JcrNodeResourceTest.java
Thu Feb  7 05:12:10 2008
@@ -152,10 +152,9 @@
     private void assertResourceMetaData(ResourceMetadata rm) {
         assertNotNull(rm);
 
-        assertEquals(new Long(TEST_MODIFIED),
-            rm.get(ResourceMetadata.MODIFICATION_TIME));
-        assertEquals(TEST_TYPE, rm.get(ResourceMetadata.CONTENT_TYPE));
-        assertEquals(TEST_ENCODING, rm.get(ResourceMetadata.CHARACTER_ENCODING));
+        assertEquals(TEST_MODIFIED, rm.getModificationTime());
+        assertEquals(TEST_TYPE, rm.getContentType());
+        assertEquals(TEST_ENCODING, rm.getCharacterEncoding());
     }
 
     private void assertEquals(byte[] expected, InputStream actual)

Modified: incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/launchpad/renderers/StreamRendererServlet.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/launchpad/renderers/StreamRendererServlet.java?rev=619398&r1=619397&r2=619398&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/launchpad/renderers/StreamRendererServlet.java
(original)
+++ incubator/sling/trunk/launchpad/launchpad-servlets/src/main/java/org/apache/sling/launchpad/renderers/StreamRendererServlet.java
Thu Feb  7 05:12:10 2008
@@ -61,7 +61,7 @@
         ResourceMetadata meta = resource.getResourceMetadata();
 
         // check the last modification time and If-Modified-Since header
-        Long modifTime = (Long) meta.get(ResourceMetadata.MODIFICATION_TIME);
+        long modifTime = meta.getModificationTime();
         if (unmodified(request, modifTime)) {
             response.setStatus(SC_NOT_MODIFIED);
             return;
@@ -77,12 +77,12 @@
         // finally stream the resource
         try {
 
-            if (modifTime != null) {
+            if (modifTime > 0) {
                 response.setDateHeader(HEADER_LAST_MODIFIED, modifTime);
             }
 
             final String defaultContentType = "application/octet-stream";
-            String contentType = (String) meta.get(ResourceMetadata.CONTENT_TYPE);
+            String contentType = meta.getContentType();
             if (contentType == null || defaultContentType.equals(contentType)) {
                 // if repository doesn't provide a content-type, or
                 // provides the
@@ -98,7 +98,7 @@
                 response.setContentType(contentType);
             }
 
-            String encoding = (String) meta.get(ResourceMetadata.CHARACTER_ENCODING);
+            String encoding = meta.getCharacterEncoding();
             if (encoding != null) {
                 response.setCharacterEncoding(encoding);
             }
@@ -132,8 +132,8 @@
      *         or equal to the time of the <code>If-Modified-Since</code>
      *         header.
      */
-    private boolean unmodified(HttpServletRequest request, Long modifTime) {
-        if (modifTime != null) {
+    private boolean unmodified(HttpServletRequest request, long modifTime) {
+        if (modifTime > 0) {
             long modTime = modifTime / 1000; // seconds
             long ims = request.getDateHeader(HEADER_IF_MODIFIED_SINCE) / 1000;
             return modTime <= ims;

Modified: incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/SlingIOProvider.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/SlingIOProvider.java?rev=619398&r1=619397&r2=619398&view=diff
==============================================================================
--- incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/SlingIOProvider.java
(original)
+++ incubator/sling/trunk/scripting/jsp/src/main/java/org/apache/sling/scripting/jsp/SlingIOProvider.java
Thu Feb  7 05:12:10 2008
@@ -16,8 +16,6 @@
  */
 package org.apache.sling.scripting.jsp;
 
-import static org.apache.sling.api.resource.ResourceMetadata.MODIFICATION_TIME;
-
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.FileNotFoundException;
@@ -123,8 +121,8 @@
             Resource resource = getResourceInternal(fileName);
             if (resource != null) {
                 ResourceMetadata meta = resource.getResourceMetadata();
-                Long modTime = (Long) meta.get(MODIFICATION_TIME);
-                return (modTime != null) ? modTime.longValue() : 0;
+                long modTime = meta.getModificationTime();
+                return (modTime > 0) ? modTime : 0;
             }
 
         } catch (SlingException se) {

Modified: incubator/sling/trunk/scripting/resolver/src/main/java/org/apache/sling/scripting/resolver/impl/DefaultSlingScript.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/scripting/resolver/src/main/java/org/apache/sling/scripting/resolver/impl/DefaultSlingScript.java?rev=619398&r1=619397&r2=619398&view=diff
==============================================================================
--- incubator/sling/trunk/scripting/resolver/src/main/java/org/apache/sling/scripting/resolver/impl/DefaultSlingScript.java
(original)
+++ incubator/sling/trunk/scripting/resolver/src/main/java/org/apache/sling/scripting/resolver/impl/DefaultSlingScript.java
Thu Feb  7 05:12:10 2008
@@ -18,8 +18,6 @@
  */
 package org.apache.sling.scripting.resolver.impl;
 
-import static java.lang.Boolean.TRUE;
-import static org.apache.sling.api.scripting.SlingBindings.FLUSH;
 import static org.apache.sling.api.scripting.SlingBindings.LOG;
 import static org.apache.sling.api.scripting.SlingBindings.OUT;
 import static org.apache.sling.api.scripting.SlingBindings.REQUEST;
@@ -48,7 +46,6 @@
 import javax.servlet.Servlet;
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletContext;
-import javax.servlet.ServletException;
 import javax.servlet.ServletRequest;
 import javax.servlet.ServletResponse;
 
@@ -95,7 +92,7 @@
 
         try {
             Bindings bindings = verifySlingBindings(scriptName, props);
-            
+
             ScriptContext ctx = new SimpleScriptContext();
             ctx.setBindings(bindings, ScriptContext.ENGINE_SCOPE);
             ctx.setReader(((SlingHttpServletRequest) bindings.get(REQUEST)).getReader());
@@ -109,8 +106,7 @@
 
             // optionall flush the output channel
             Object flushObject = bindings.get(SlingBindings.FLUSH);
-            if (flushObject instanceof Boolean
-                && ((Boolean) flushObject).booleanValue()) {
+            if (flushObject instanceof Boolean && (Boolean) flushObject) {
                 ctx.getWriter().flush();
             }
 
@@ -120,7 +116,7 @@
         } catch (IOException ioe) {
             throw new ScriptEvaluationException(scriptName, ioe.getMessage(),
                 ioe);
-            
+
         } catch (ScriptException se) {
             Throwable cause = (se.getCause() == null) ? se : se.getCause();
             throw new ScriptEvaluationException(scriptName, se.getMessage(),
@@ -138,22 +134,21 @@
                 String value = servletConfig.getInitParameter(name);
                 params.put(name, value);
             }
-            
+
             servletContext = servletConfig.getServletContext();
         }
     }
 
-    public void service(ServletRequest req, ServletResponse res)
-            throws ServletException, IOException {
+    public void service(ServletRequest req, ServletResponse res) {
 
         SlingHttpServletRequest request = (SlingHttpServletRequest) req;
 
         try {
             // prepare the properties for the script
             SlingBindings props = new SlingBindings();
-            props.put(REQUEST, req);
-            props.put(RESPONSE, res);
-            props.put(FLUSH, TRUE);
+            props.setRequest((SlingHttpServletRequest) req);
+            props.setResponse((SlingHttpServletResponse) res);
+            props.setFlush(true);
 
             res.setCharacterEncoding("UTF-8");
             res.setContentType(request.getResponseContentType());
@@ -218,7 +213,7 @@
         // we try to get a jcr:encoding property besides the data property
         // to provide a possible encoding
         ResourceMetadata meta = getScriptResource().getResourceMetadata();
-        String encoding = (String) meta.get(ResourceMetadata.CHARACTER_ENCODING);
+        String encoding = meta.getCharacterEncoding();
         if (encoding == null) {
             encoding = "UTF-8";
         }
@@ -231,14 +226,14 @@
 
     private Bindings verifySlingBindings(String scriptName,
             SlingBindings slingBindings) throws IOException {
-        
-        Object requestObject = slingBindings.get(REQUEST);
-        if (!(requestObject instanceof SlingHttpServletRequest)) {
+
+        SlingHttpServletRequest request = slingBindings.getRequest();
+        if (request == null) {
             throw fail(scriptName, REQUEST, "Missing or wrong type");
         }
 
-        Object responseObject = slingBindings.get(RESPONSE);
-        if (!(responseObject instanceof SlingHttpServletResponse)) {
+        SlingHttpServletResponse response = slingBindings.getResponse();
+        if (response == null) {
             throw fail(scriptName, RESPONSE, "Missing or wrong type");
         }
 
@@ -257,20 +252,18 @@
         Object slingObject = slingBindings.get(SLING);
         if (slingObject == null) {
 
-            sling = new ScriptHelper(this,
-                (SlingHttpServletRequest) requestObject,
-                (SlingHttpServletResponse) responseObject);
+            sling = new ScriptHelper(this, request, response);
 
         } else if (slingObject instanceof SlingScriptHelper) {
 
             sling = (SlingScriptHelper) slingObject;
 
-            if (sling.getRequest() != requestObject) {
+            if (sling.getRequest() != request) {
                 throw fail(scriptName, REQUEST,
                     "Not the same as request field of SlingScriptHelper");
             }
 
-            if (sling.getResponse() != responseObject) {
+            if (sling.getResponse() != response) {
                 throw fail(scriptName, RESPONSE,
                     "Not the same as response field of SlingScriptHelper");
             }

Modified: incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/request/SlingRequestDispatcher.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/request/SlingRequestDispatcher.java?rev=619398&r1=619397&r2=619398&view=diff
==============================================================================
--- incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/request/SlingRequestDispatcher.java
(original)
+++ incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/request/SlingRequestDispatcher.java
Thu Feb  7 05:12:10 2008
@@ -32,6 +32,7 @@
 import org.apache.sling.api.resource.ResourceMetadata;
 import org.apache.sling.api.resource.ResourceProvider;
 import org.apache.sling.api.resource.ResourceResolver;
+import org.apache.sling.api.resource.ResourceWrapper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -39,7 +40,7 @@
 
     /** default log */
     private final Logger log = LoggerFactory.getLogger(getClass());
-    
+
     private Resource resource;
 
     private RequestDispatcherOptions options;
@@ -76,10 +77,11 @@
         // if the response is not an HttpServletResponse, fail gracefully not
         // doing anything
         if (!(sResponse instanceof HttpServletResponse)) {
-            log.error("include: Failed to include {}, response has wrong type", absPath);
+            log.error("include: Failed to include {}, response has wrong type",
+                absPath);
             return;
         }
-        
+
         final HttpServletResponse response = (HttpServletResponse) sResponse;
 
         if (resource == null) {
@@ -92,10 +94,12 @@
             // resolve the absolute path in the resource resolver, using
             // only those parts of the path as if it would be request path
             resource = cRequest.getResourceResolver().resolve(absPath);
-            
+
             // if the resource could not be resolved, fail gracefully
             if (resource == null) {
-                log.error("include: Could not resolve {} to a resource, not including", absPath);
+                log.error(
+                    "include: Could not resolve {} to a resource, not including",
+                    absPath);
                 return;
             }
         }
@@ -112,12 +116,13 @@
             String rtOverwrite = options.getForceResourceType();
             if (rtOverwrite != null
                 && !rtOverwrite.equals(resource.getResourceType())) {
-                resource = new ResourceWrapper(resource, rtOverwrite);
+                resource = new TypeOverwritingResourceWrapper(resource,
+                    rtOverwrite);
             }
         }
 
-        rd.getSlingMainServlet().includeContent(request, response,
-            resource, info);
+        rd.getSlingMainServlet().includeContent(request, response, resource,
+            info);
     }
 
     public void forward(ServletRequest request, ServletResponse response)
@@ -143,35 +148,18 @@
         return uri + '/' + path;
     }
 
-    private static class ResourceWrapper implements Resource {
-
-        private final Resource delegatee;
+    private static class TypeOverwritingResourceWrapper extends ResourceWrapper {
 
         private final String resourceType;
 
-        ResourceWrapper(Resource delegatee, String resourceType) {
-            this.delegatee = delegatee;
+        TypeOverwritingResourceWrapper(Resource delegatee, String resourceType) {
+            super(delegatee);
             this.resourceType = resourceType;
         }
 
-        public String getPath() {
-            return delegatee.getPath();
-        }
-
         public String getResourceType() {
             return resourceType;
         }
 
-        public ResourceMetadata getResourceMetadata() {
-            return delegatee.getResourceMetadata();
-        }
-
-        public ResourceProvider getResourceProvider() {
-            return delegatee.getResourceProvider();
-        }
-
-        public <Type> Type adaptTo(Class<Type> type) {
-            return delegatee.adaptTo(type);
-        }
     }
 }

Modified: incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/request/SlingRequestPathInfo.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/request/SlingRequestPathInfo.java?rev=619398&r1=619397&r2=619398&view=diff
==============================================================================
--- incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/request/SlingRequestPathInfo.java
(original)
+++ incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/request/SlingRequestPathInfo.java
Thu Feb  7 05:12:10 2008
@@ -59,8 +59,7 @@
             pathToParse = "";
         }
 
-        resourcePath = (String) r.getResourceMetadata().get(
-            ResourceMetadata.RESOLUTION_PATH);
+        resourcePath = r.getResourceMetadata().getResolutionPath();
         if (resourcePath != null && !"/".equals(resourcePath)
             && pathToParse.length() >= resourcePath.length()) {
             pathToParse = pathToParse.substring(resourcePath.length());

Modified: incubator/sling/trunk/sling/core/src/test/java/org/apache/sling/core/impl/request/SlingRequestPathInfoTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/core/src/test/java/org/apache/sling/core/impl/request/SlingRequestPathInfoTest.java?rev=619398&r1=619397&r2=619398&view=diff
==============================================================================
--- incubator/sling/trunk/sling/core/src/test/java/org/apache/sling/core/impl/request/SlingRequestPathInfoTest.java
(original)
+++ incubator/sling/trunk/sling/core/src/test/java/org/apache/sling/core/impl/request/SlingRequestPathInfoTest.java
Thu Feb  7 05:12:10 2008
@@ -272,7 +272,7 @@
 
         MockResource(String resolutionPath) {
             metadata = new ResourceMetadata();
-            metadata.put(ResourceMetadata.RESOLUTION_PATH, resolutionPath);
+            metadata.setResolutionPath(resolutionPath);
         }
 
         public String getResourceType() {

Modified: incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/defaults/DefaultServlet.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/defaults/DefaultServlet.java?rev=619398&r1=619397&r2=619398&view=diff
==============================================================================
--- incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/defaults/DefaultServlet.java
(original)
+++ incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/defaults/DefaultServlet.java
Thu Feb  7 05:12:10 2008
@@ -223,7 +223,7 @@
         
         ResourceMetadata meta = resource.getResourceMetadata();
         
-        String contentType = (String) meta.get(ResourceMetadata.CONTENT_TYPE);
+        String contentType = meta.getContentType();
         if (contentType == null) {
             contentType = getServletContext().getMimeType(resource.getPath());
         }
@@ -231,7 +231,7 @@
             response.setContentType(contentType);
         }
         
-        String encoding = (String) meta.get(ResourceMetadata.CHARACTER_ENCODING);
+        String encoding = meta.getCharacterEncoding();
         if (encoding != null) {
             response.setCharacterEncoding(encoding);
         }

Modified: incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/resource/ServletResource.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/resource/ServletResource.java?rev=619398&r1=619397&r2=619398&view=diff
==============================================================================
--- incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/resource/ServletResource.java
(original)
+++ incubator/sling/trunk/sling/servlet-resolver/src/main/java/org/apache/sling/servlet/resolver/resource/ServletResource.java
Thu Feb  7 05:12:10 2008
@@ -42,7 +42,7 @@
         this.path = path;
 
         this.metadata = new ResourceMetadata();
-        metadata.put(ResourceMetadata.RESOLUTION_PATH, path);
+        metadata.setResolutionPath(path);
     }
 
     public ResourceMetadata getResourceMetadata() {
@@ -69,6 +69,23 @@
         }
 
         return super.adaptTo(type);
+    }
+
+    public String toString() {
+        // prepare the servlet name
+        String servletName = null;
+        if (servlet.getServletConfig() != null) {
+            servletName = servlet.getServletConfig().getServletName();
+        }
+        if (servletName == null) {
+            servletName = servlet.getServletInfo();
+        }
+        if (servletName == null) {
+            servletName = servlet.getClass().getName();
+        }
+        
+        return getClass().getSimpleName() + ", servlet=" + servletName
+            + ", path=" + getPath();
     }
 
 }



Mime
View raw message