incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r600522 - in /incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core: impl/request/SlingRequestDispatcher.java impl/scripting/DefaultSlingScript.java servlets/DefaultServlet.java
Date Mon, 03 Dec 2007 13:22:19 GMT
Author: fmeschbe
Date: Mon Dec  3 05:22:18 2007
New Revision: 600522

URL: http://svn.apache.org/viewvc?rev=600522&view=rev
Log:
SLING-109 Support Resource adapter

Modified:
    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/scripting/DefaultSlingScript.java
    incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/servlets/DefaultServlet.java

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=600522&r1=600521&r2=600522&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
Mon Dec  3 05:22:18 2007
@@ -19,11 +19,7 @@
 package org.apache.sling.core.impl.request;
 
 import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
 
-import javax.jcr.Node;
 import javax.servlet.RequestDispatcher;
 import javax.servlet.ServletException;
 import javax.servlet.ServletRequest;
@@ -31,13 +27,9 @@
 
 import org.apache.sling.api.SlingHttpServletRequest;
 import org.apache.sling.api.request.RequestDispatcherOptions;
-import org.apache.sling.api.resource.NodeProvider;
-import org.apache.sling.api.resource.ObjectProvider;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceMetadata;
 import org.apache.sling.api.resource.ResourceResolver;
-import org.apache.sling.api.resource.StreamProvider;
-import org.apache.sling.api.resource.URLProvider;
 
 public class SlingRequestDispatcher implements RequestDispatcher {
 
@@ -123,7 +115,7 @@
         return uri + '/' + path;
     }
 
-    private static class ResourceWrapper implements Resource, NodeProvider, ObjectProvider,
StreamProvider, URLProvider {
+    private static class ResourceWrapper implements Resource {
 
         private final Resource delegatee;
         private final String resourceType;
@@ -145,33 +137,8 @@
             return delegatee.getURI();
         }
 
-        public InputStream getInputStream() throws IOException {
-            if (delegatee instanceof StreamProvider) {
-                return ((StreamProvider) delegatee).getInputStream();
-            }
-            return null;
-        }
-
-        public Object getObject() {
-            if (delegatee instanceof ObjectProvider) {
-                return ((ObjectProvider) delegatee).getObject();
-            }
-            return null;
+        public <Type> Type adaptTo(Class<Type> type) {
+            return delegatee.adaptTo(type);
         }
-
-        public Node getNode() {
-            if (delegatee instanceof NodeProvider) {
-                return ((NodeProvider) delegatee).getNode();
-            }
-            return null;
-        }
-
-        public URL getURL() throws MalformedURLException {
-            if (delegatee instanceof URLProvider) {
-                return ((URLProvider) delegatee).getURL();
-            }
-            return null;
-        }
-
     }
 }

Modified: incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/scripting/DefaultSlingScript.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/scripting/DefaultSlingScript.java?rev=600522&r1=600521&r2=600522&view=diff
==============================================================================
--- incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/scripting/DefaultSlingScript.java
(original)
+++ incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/impl/scripting/DefaultSlingScript.java
Mon Dec  3 05:22:18 2007
@@ -26,7 +26,6 @@
 
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceMetadata;
-import org.apache.sling.api.resource.StreamProvider;
 import org.apache.sling.api.scripting.SlingScript;
 import org.apache.sling.api.scripting.SlingScriptEngine;
 
@@ -51,9 +50,10 @@
 
     public Reader getScriptReader() throws IOException {
 
-        if (!(getScriptResource() instanceof StreamProvider)) {
-            throw new IOException("Scriptresource " + getScriptResource()
-                + " is not a StreamProvider");
+        InputStream input = getScriptResource().adaptTo(InputStream.class);
+        if (input == null) {
+            throw new IOException("Cannot get a stream to the script resource "
+                + getScriptResource());
         }
 
         // Now know how to get the input stream, we still have to decide
@@ -70,7 +70,6 @@
         // access the value as a stream and return a buffered reader
         // converting the stream data using UTF-8 encoding, which is
         // the default encoding used
-        InputStream input = ((StreamProvider) getScriptResource()).getInputStream();
         return new BufferedReader(new InputStreamReader(input, encoding));
     }
 }

Modified: incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/servlets/DefaultServlet.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/servlets/DefaultServlet.java?rev=600522&r1=600521&r2=600522&view=diff
==============================================================================
--- incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/servlets/DefaultServlet.java
(original)
+++ incubator/sling/trunk/sling/core/src/main/java/org/apache/sling/core/servlets/DefaultServlet.java
Mon Dec  3 05:22:18 2007
@@ -37,7 +37,6 @@
 import org.apache.sling.api.request.RequestParameter;
 import org.apache.sling.api.request.RequestParameterMap;
 import org.apache.sling.api.resource.NonExistingResource;
-import org.apache.sling.api.resource.ObjectProvider;
 import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.resource.ResourceManager;
 import org.apache.sling.api.servlets.SlingAllMethodsServlet;
@@ -296,8 +295,9 @@
 
     @SuppressWarnings("unchecked")
     private Map<Object, Object> asMap(Resource resource) {
-        if (resource instanceof ObjectProvider) {
-            Object object = ((ObjectProvider) resource).getObject();
+        
+        Object object = resource.adaptTo(Object.class);
+        if (object != null) {
             if (object instanceof Map) {
                 return (Map<Object, Object>) object; // unchecked cast
             }



Mime
View raw message