incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jus...@apache.org
Subject svn commit: r953549 - in /sling/trunk/bundles: api/src/main/java/org/apache/sling/api/scripting/SlingScriptHelper.java scripting/core/pom.xml scripting/core/src/main/java/org/apache/sling/scripting/core/ScriptHelper.java
Date Fri, 11 Jun 2010 03:17:30 GMT
Author: justin
Date: Fri Jun 11 03:17:27 2010
New Revision: 953549

URL: http://svn.apache.org/viewvc?rev=953549&view=rev
Log:
SLING-1552 - implementing include/forward methods using Resource objects

Modified:
    sling/trunk/bundles/api/src/main/java/org/apache/sling/api/scripting/SlingScriptHelper.java
    sling/trunk/bundles/scripting/core/pom.xml
    sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/ScriptHelper.java

Modified: sling/trunk/bundles/api/src/main/java/org/apache/sling/api/scripting/SlingScriptHelper.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/api/src/main/java/org/apache/sling/api/scripting/SlingScriptHelper.java?rev=953549&r1=953548&r2=953549&view=diff
==============================================================================
--- sling/trunk/bundles/api/src/main/java/org/apache/sling/api/scripting/SlingScriptHelper.java
(original)
+++ sling/trunk/bundles/api/src/main/java/org/apache/sling/api/scripting/SlingScriptHelper.java
Fri Jun 11 03:17:27 2010
@@ -21,6 +21,7 @@ package org.apache.sling.api.scripting;
 import org.apache.sling.api.SlingHttpServletRequest;
 import org.apache.sling.api.SlingHttpServletResponse;
 import org.apache.sling.api.request.RequestDispatcherOptions;
+import org.apache.sling.api.resource.Resource;
 
 /**
  * The <code>SlingScriptHelper</code> interface defines the API of a helper
@@ -114,6 +115,73 @@ public interface SlingScriptHelper {
     void include(String path, RequestDispatcherOptions options);
 
     /**
+     * Same as {@link #include(Resource,RequestDispatcherOptions)}, but using
+     * empty options.
+     *
+     * @throws org.apache.sling.api.SlingIOException Wrapping a <code>IOException</code>
thrown
+     *             while handling the include.
+     * @throws org.apache.sling.api.SlingServletException Wrapping a <code>ServletException</code>
+     *             thrown while handling the include.
+     */
+    void include(Resource resource);
+
+    /**
+     * Helper method to include the result of processing the request for the
+     * given <code>resource</code> and <code>requestDispatcherOptions</code>.
+     * This method is intended to be implemented as follows:
+     *
+     * <pre>
+     * RequestDispatcher dispatcher = getRequest().getRequestDispatcher(resource,
+     *     &quot;option:xyz&quot;);
+     * if (dispatcher != null) {
+     *     dispatcher.include(getRequest(), getResponse());
+     * }
+     * </pre>
+     *
+     * <p>
+     * This method creates a <code>RequestDispatcherOptions</code> object by
+     * calling the
+     * {@link RequestDispatcherOptions#RequestDispatcherOptions(String)}
+     * constructor.
+     *
+     * @param resource The resource to include.
+     * @param requestDispatcherOptions influence the rendering of the included
+     *            Resource
+     * @throws org.apache.sling.api.SlingIOException Wrapping a <code>IOException</code>
thrown
+     *             while handling the include.
+     * @throws org.apache.sling.api.SlingServletException Wrapping a <code>ServletException</code>
+     *             thrown while handling the include.
+     * @see RequestDispatcherOptions#RequestDispatcherOptions(String)
+     * @see #include(String, RequestDispatcherOptions)
+     */
+    void include(Resource resource, String requestDispatcherOptions);
+
+    /**
+     * Helper method to include the result of processing the request for the
+     * given <code>resource</code> and <code>options</code>. This
method is
+     * intended to be implemented as follows:
+     *
+     * <pre>
+     * RequestDispatcherOptions opts = new RequestDispatcherOptions();
+     * opts.put(&quot;option&quot;, &quot;xyz&quot;);
+     * RequestDispatcher dispatcher = getRequest().getRequestDispatcher(resource, opts);
+     * if (dispatcher != null) {
+     *     dispatcher.include(getRequest(), getResponse());
+     * }
+     * </pre>
+     *
+     * @param path The resource to include.
+     * @param options influence the rendering of the included Resource
+     * @throws org.apache.sling.api.SlingIOException Wrapping a <code>IOException</code>
thrown
+     *             while handling the include.
+     * @throws org.apache.sling.api.SlingServletException Wrapping a <code>ServletException</code>
+     *             thrown while handling the include.
+     * @see RequestDispatcherOptions
+     * @see #include(String, String)
+     */
+    void include(Resource resource, RequestDispatcherOptions options);
+
+    /**
      * Same as {@link #forward(String,RequestDispatcherOptions)}, but using
      * empty options.
      *
@@ -181,6 +249,73 @@ public interface SlingScriptHelper {
     void forward(String path, RequestDispatcherOptions options);
 
     /**
+     * Same as {@link #forward(Resource,RequestDispatcherOptions)}, but using
+     * empty options.
+     *
+     * @throws org.apache.sling.api.SlingIOException Wrapping a <code>IOException</code>
thrown
+     *             while handling the forward.
+     * @throws org.apache.sling.api.SlingServletException Wrapping a <code>ServletException</code>
+     *             thrown while handling the forward.
+     */
+    void forward(Resource resource);
+
+    /**
+     * Helper method to forward the request to a Servlet or script for the given
+     * <code>resource</code> and <code>requestDispatcherOptions</code>.
This method
+     * is intended to be implemented as follows:
+     *
+     * <pre>
+     * RequestDispatcher dispatcher = getRequest().getRequestDispatcher(resource,
+     *     &quot;option:xyz&quot;);
+     * if (dispatcher != null) {
+     *     dispatcher.forward(getRequest(), getResponse());
+     * }
+     * </pre>
+     *
+     * <p>
+     * This method creates a <code>RequestDispatcherOptions</code> object by
+     * calling the
+     * {@link RequestDispatcherOptions#RequestDispatcherOptions(String)}
+     * constructor.
+     *
+     * @param path The resource to forward to.
+     * @param requestDispatcherOptions influence the rendering of the forwarded
+     *            Resource
+     * @throws org.apache.sling.api.SlingIOException Wrapping a <code>IOException</code>
thrown
+     *             while handling the forward.
+     * @throws org.apache.sling.api.SlingServletException Wrapping a <code>ServletException</code>
+     *             thrown while handling the forward.
+     * @see RequestDispatcherOptions#RequestDispatcherOptions(String)
+     * @see #forward(String, RequestDispatcherOptions)
+     */
+    void forward(Resource resource, String requestDispatcherOptions);
+
+    /**
+     * Helper method to forward the request to a Servlet or script for the given
+     * <code>resource</code> and <code>options</code>. This method
is intended
+     * to be implemented as follows:
+     *
+     * <pre>
+     * RequestDispatcherOptions opts = new RequestDispatcherOptions();
+     * opts.put(&quot;option&quot;, &quot;xyz&quot;);
+     * RequestDispatcher dispatcher = getRequest().getRequestDispatcher(resource, opts);
+     * if (dispatcher != null) {
+     *     dispatcher.forward(getRequest(), getResponse());
+     * }
+     * </pre>
+     *
+     * @param path The resource to forward the request to.
+     * @param options influence the rendering of the forwarded Resource
+     * @throws org.apache.sling.api.SlingIOException Wrapping a <code>IOException</code>
thrown
+     *             while handling the forward.
+     * @throws org.apache.sling.api.SlingServletException Wrapping a <code>ServletException</code>
+     *             thrown while handling the forward.
+     * @throws IllegalStateException If the respoonse has already been committed
+     * @see RequestDispatcherOptions
+     */
+    void forward(Resource resource, RequestDispatcherOptions options);
+
+    /**
      * Lookup a single service
      *
      * @param serviceType The type (interface) of the service.

Modified: sling/trunk/bundles/scripting/core/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/core/pom.xml?rev=953549&r1=953548&r2=953549&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/core/pom.xml (original)
+++ sling/trunk/bundles/scripting/core/pom.xml Fri Jun 11 03:17:27 2010
@@ -91,7 +91,7 @@
         <dependency>
             <groupId>org.apache.sling</groupId>
             <artifactId>org.apache.sling.api</artifactId>
-            <version>2.0.8</version>
+            <version>2.0.9-SNAPSHOT</version>
             <scope>provided</scope>
         </dependency>
         <dependency>

Modified: sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/ScriptHelper.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/ScriptHelper.java?rev=953549&r1=953548&r2=953549&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/ScriptHelper.java
(original)
+++ sling/trunk/bundles/scripting/core/src/main/java/org/apache/sling/scripting/core/ScriptHelper.java
Fri Jun 11 03:17:27 2010
@@ -33,6 +33,7 @@ import org.apache.sling.api.SlingHttpSer
 import org.apache.sling.api.SlingIOException;
 import org.apache.sling.api.SlingServletException;
 import org.apache.sling.api.request.RequestDispatcherOptions;
+import org.apache.sling.api.resource.Resource;
 import org.apache.sling.api.scripting.InvalidServiceFilterSyntaxException;
 import org.apache.sling.api.scripting.SlingScript;
 import org.apache.sling.api.scripting.SlingScriptHelper;
@@ -265,4 +266,69 @@ public class ScriptHelper implements Sli
             this.services.clear();
         }
     }
+
+    /**
+     * @see org.apache.sling.api.scripting.SlingScriptHelper#forward(org.apache.sling.api.resource.Resource)
+     */
+    public void forward(Resource resource) {
+        forward(resource, (RequestDispatcherOptions) null);
+    }
+
+
+    /**
+     * @see org.apache.sling.api.scripting.SlingScriptHelper#forward(org.apache.sling.api.resource.Resource,
java.lang.String)
+     */
+    public void forward(Resource resource, String options) {
+        forward(resource, new RequestDispatcherOptions(options));
+    }
+
+    /**
+     * @see org.apache.sling.api.scripting.SlingScriptHelper#forward(org.apache.sling.api.resource.Resource,
org.apache.sling.api.request.RequestDispatcherOptions)
+     */
+    public void forward(Resource resource, RequestDispatcherOptions options) {
+        final RequestDispatcher dispatcher = getRequest().getRequestDispatcher(
+            resource, options);
+
+        if (dispatcher != null) {
+            try {
+                dispatcher.forward(getRequest(), getResponse());
+            } catch (IOException ioe) {
+                throw new SlingIOException(ioe);
+            } catch (ServletException se) {
+                throw new SlingServletException(se);
+            }
+        }
+    }
+
+    /**
+     * @see org.apache.sling.api.scripting.SlingScriptHelper#forward(org.apache.sling.api.resource.Resource)
+     */
+    public void include(Resource resource) {
+        include(resource, (RequestDispatcherOptions) null);
+    }
+
+    /**
+     * @see org.apache.sling.api.scripting.SlingScriptHelper#include(org.apache.sling.api.resource.Resource,
java.lang.String)
+     */
+    public void include(Resource resource, String options) {
+        include(resource, new RequestDispatcherOptions(options));
+    }
+
+    /**
+     * @see org.apache.sling.api.scripting.SlingScriptHelper#include(org.apache.sling.api.resource.Resource,
org.apache.sling.api.request.RequestDispatcherOptions)
+     */
+    public void include(Resource resource, RequestDispatcherOptions options) {
+        final RequestDispatcher dispatcher = getRequest().getRequestDispatcher(
+            resource, options);
+
+        if (dispatcher != null) {
+            try {
+                dispatcher.include(getRequest(), getResponse());
+            } catch (IOException ioe) {
+                throw new SlingIOException(ioe);
+            } catch (ServletException se) {
+                throw new SlingServletException(se);
+            }
+        }
+    }
 }



Mime
View raw message