struts-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From craig...@apache.org
Subject svn commit: r234439 - in /struts/shale/trunk: core-library/src/java/org/apache/shale/faces/ use-cases/src/test/org/apache/shale/usecases/remote/
Date Mon, 22 Aug 2005 05:59:05 GMT
Author: craigmcc
Date: Sun Aug 21 22:58:58 2005
New Revision: 234439

URL: http://svn.apache.org/viewcvs?rev=234439&view=rev
Log:
Remove ShaleWebContext dependence on javax.servlet.Filter.  This is one step
in a gradual refactoring to make Shale more adapatable for portlet (JSR-168)
environments.  As a result of this change, the "standard" command chain is
eliminated ... however, the "preprocess" and "postprocess" chains continue to
support per-request preprocessing and postprocessing, as they did before.

Removed:
    struts/shale/trunk/core-library/src/java/org/apache/shale/faces/InvokeCommand.java
Modified:
    struts/shale/trunk/core-library/src/java/org/apache/shale/faces/ShaleApplicationFilter.java
    struts/shale/trunk/core-library/src/java/org/apache/shale/faces/ShaleWebContext.java
    struts/shale/trunk/core-library/src/java/org/apache/shale/faces/shale-config.xml
    struts/shale/trunk/use-cases/src/test/org/apache/shale/usecases/remote/ListCategoriesTestCase.java
    struts/shale/trunk/use-cases/src/test/org/apache/shale/usecases/remote/ListLocalesTestCase.java
    struts/shale/trunk/use-cases/src/test/org/apache/shale/usecases/remote/ListStateNamesTestCase.java

Modified: struts/shale/trunk/core-library/src/java/org/apache/shale/faces/ShaleApplicationFilter.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/core-library/src/java/org/apache/shale/faces/ShaleApplicationFilter.java?rev=234439&r1=234438&r2=234439&view=diff
==============================================================================
--- struts/shale/trunk/core-library/src/java/org/apache/shale/faces/ShaleApplicationFilter.java
(original)
+++ struts/shale/trunk/core-library/src/java/org/apache/shale/faces/ShaleApplicationFilter.java
Sun Aug 21 22:58:58 2005
@@ -122,11 +122,17 @@
 
 
     /**
-     * <p>The name of the <code>Command</code> (in the <code>Catalog</code>
-     * named by <code>CATALOG_NAME</code>) that performs the standard
-     * application scope request processing.</p>
+     * <p>The name of the <code>Command</code> to execute before
+     * the application logic itself is invoked.</p>
      */
-    public static final String COMMAND_NAME = "standard";
+    public static final String COMMAND_PREPROCESS = "preprocess";
+
+
+    /**
+     * <p>The name of the <code>Command</code> to execute after
+     * the application logic itself is invoked.</p>
+     */
+    public static final String COMMAND_POSTPROCESS = "postprocess";
 
 
     /**
@@ -239,23 +245,52 @@
     public void doFilter(ServletRequest request, ServletResponse response,
       FilterChain chain) throws IOException, ServletException {
 
+      // Define local variables we will need
+      Command command = null;
+      boolean result = false;
+
       // Construct and store a new Context for this request
       ShaleWebContext context =
         new ShaleWebContext(this.context,
           (HttpServletRequest) request,
-          (HttpServletResponse) response, chain);
+          (HttpServletResponse) response);
       request.setAttribute(CONTEXT_ATTR, context);
 
-      // Invoke the standard processing command on this context
-      Command standard = catalog.getCommand(COMMAND_NAME);
-      try {
-          standard.execute(context);
-      } catch (IOException e) {
-          throw e;
-      } catch (ServletException e) {
-          throw e;
-      } catch (Exception e) {
-          throw new ServletException(e);
+      // Invoke the "preprocess" command (if any is defined).  If this
+      // command returns true, the response has been completed already
+      // so we do NOT invoke the actual application.
+      command = catalog.getCommand(COMMAND_PREPROCESS);
+      if (command != null) {
+          try {
+              result = command.execute(context);
+          } catch (IOException e) {
+              throw e;
+          } catch (ServletException e) {
+              throw e;
+          } catch (Exception e) {
+              throw new ServletException(e);
+          }
+          if (result) {
+              return; // Bypass calling the remainder of the application
+          }
+      }
+
+      // Invoke the remainder of the processing for this request
+      // (which will typically be the JSF controller servlet)
+      chain.doFilter(request, response);
+
+      // Invoke the "postprocess" command (if any is defined).
+      command = catalog.getCommand(COMMAND_POSTPROCESS);
+      if (command != null) {
+          try {
+              command.execute(context);
+          } catch (IOException e) {
+              throw e;
+          } catch (ServletException e) {
+              throw e;
+          } catch (Exception e) {
+              throw new ServletException(e);
+          }
       }
 
       // Clean up the stored request attribute
@@ -314,8 +349,16 @@
      */
     private Catalog getCatalog() throws Exception {
 
-        // Look up the "shale" catalog, creating one if necessary
+        // Look up the "shale" catalog, returning any existing instance
+        // if it is fully configured
         Catalog catalog = CatalogFactory.getInstance().getCatalog(CATALOG_NAME);
+        if ((catalog != null) &&
+            (catalog.getCommand(COMMAND_INIT) != null) &&
+            (catalog.getCommand(COMMAND_DESTROY) != null)) {
+            return catalog;
+        }
+
+        // Create a new catalog (if necessary)
         if (catalog == null) {
             if (log.isDebugEnabled()) {
                 log.debug(messages.getMessage("filter.creatingCatalog",
@@ -324,13 +367,8 @@
             catalog = new CatalogBase();
             CatalogFactory.getInstance().addCatalog(CATALOG_NAME, catalog);
         }
-
-        // If the required command exists, just return the catalog
-        if (catalog.getCommand(COMMAND_NAME) != null) {
-            return catalog;
-        }
-
-        // Configure based on our default resource
+        
+        // Configure this catalog based on our default resource
         if (log.isDebugEnabled()) {
             log.debug(messages.getMessage("filter.parsingResource",
                                           new Object[] { RESOURCE_NAME }));
@@ -342,10 +380,6 @@
         }
         parser.parse(url);
 
-        // Ensure that the required command has been configured
-        if (catalog.getCommand(COMMAND_NAME) == null) {
-            throw new IllegalArgumentException(COMMAND_NAME);
-        }
         return catalog;
 
     }

Modified: struts/shale/trunk/core-library/src/java/org/apache/shale/faces/ShaleWebContext.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/core-library/src/java/org/apache/shale/faces/ShaleWebContext.java?rev=234439&r1=234438&r2=234439&view=diff
==============================================================================
--- struts/shale/trunk/core-library/src/java/org/apache/shale/faces/ShaleWebContext.java (original)
+++ struts/shale/trunk/core-library/src/java/org/apache/shale/faces/ShaleWebContext.java Sun
Aug 21 22:58:58 2005
@@ -19,7 +19,6 @@
 package org.apache.shale.faces;
 
 import javax.faces.context.FacesContext;
-import javax.servlet.FilterChain;
 import javax.servlet.ServletContext;
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletRequestWrapper;
@@ -43,15 +42,12 @@
      * @param context <code>ServletContext</code> for this application
      * @param request <code>HttpServetRewquest</code> for this request
      * @param response <code>HttpServletResponse</code> for this request
-     * @param chain <code>FilterChain</code> for this request
      */
     public ShaleWebContext(ServletContext context,
                            HttpServletRequest request,
-                           HttpServletResponse response,
-                           FilterChain chain) {
+                           HttpServletResponse response) {
 
         super(context, request, response);
-        this.chain = chain;
 
     }
     
@@ -60,12 +56,6 @@
 
 
     /**
-     * <p>The <code>FilterChain</code> for the current request.
-     */
-    private FilterChain chain = null;
-
-
-    /**
      * <p>The <code>FacesContext</code> for the current request (if any).</p>
      */
     private FacesContext facesContext = null;
@@ -83,14 +73,6 @@
 
 
     // -------------------------------------------------------------- Properties
-
-
-    /**
-     * <p>Return the <code>FilterChain</code> for the current request.</p>
-     */
-    public FilterChain getChain() {
-        return this.chain;
-    }
 
 
     /**

Modified: struts/shale/trunk/core-library/src/java/org/apache/shale/faces/shale-config.xml
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/core-library/src/java/org/apache/shale/faces/shale-config.xml?rev=234439&r1=234438&r2=234439&view=diff
==============================================================================
--- struts/shale/trunk/core-library/src/java/org/apache/shale/faces/shale-config.xml (original)
+++ struts/shale/trunk/core-library/src/java/org/apache/shale/faces/shale-config.xml Sun Aug
21 22:58:58 2005
@@ -52,6 +52,27 @@
 
   </chain>
 
+  <!-- ========================= Request Processing ======================== -->
+
+  <!-- Configure this chain in your application if you need per-request
+       processing BEFORE the appication is invoked.  If the last executed
+       command of this chain returns "true", it will be assumed that the
+       response has been created already, and that no further processing
+       is required. -->
+<!--  
+  <chain           name="preprocess">
+  </chain>
+-->
+
+  <!-- Configre this chain in your application if you need per-request
+       processing AFTER the application is invoked.  Note that the response
+       will have been created already, so it is not possible to replace
+       the response contents at this point. -->
+<!--
+  <chain           name="postprocess">
+  </chain>
+-->
+
   <!-- ===================== Remote Requests =============================== -->
 
   <chain           name="remote">
@@ -63,36 +84,5 @@
                patterns="\S*\.remote"/>
 
   </chain>
-
-  <!-- ================ Perform Request Processing ========================= -->
-
-  <chain           name="standard">
-
-    <!-- Perform remote request processing for matching requests -->
-    <!-- Successful match will terminate the processing chain -->
-    <!-- FIXME - determine whether we want this before or after -->
-    <!-- the "preprocess" command -->
-    <command  className="org.apache.commons.chain.generic.LookupCommand"
-            catalogName="shale"
-                   name="remote"
-               optional="true"/>
-
-    <!-- Invoke "preprocess" command if it exists -->
-    <command  className="org.apache.commons.chain.generic.LookupCommand"
-            catalogName="shale"
-                   name="preprocess"
-               optional="true"/>
-
-    <!-- Invoke the remainder of the filter chain -->
-    <command  className="org.apache.shale.faces.InvokeCommand"/>
-
-    <!-- Invoke "postprocess" command if it exists -->
-    <command  className="org.apache.commons.chain.generic.LookupCommand"
-            catalogName="shale"
-                   name="postprocess"
-               optional="true"/>
-
-  </chain>
-
 
 </catalog>

Modified: struts/shale/trunk/use-cases/src/test/org/apache/shale/usecases/remote/ListCategoriesTestCase.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/use-cases/src/test/org/apache/shale/usecases/remote/ListCategoriesTestCase.java?rev=234439&r1=234438&r2=234439&view=diff
==============================================================================
--- struts/shale/trunk/use-cases/src/test/org/apache/shale/usecases/remote/ListCategoriesTestCase.java
(original)
+++ struts/shale/trunk/use-cases/src/test/org/apache/shale/usecases/remote/ListCategoriesTestCase.java
Sun Aug 21 22:58:58 2005
@@ -104,7 +104,7 @@
 
         // create a fake shale context
         swcontext = new ShaleWebContext(servletContext,
-                request, response, null);
+                request, response);
 
         //create a catalog, this would be loaded from the chains XML config file        
         Catalog catalog = CatalogFactory.getInstance().getCatalog("remote");

Modified: struts/shale/trunk/use-cases/src/test/org/apache/shale/usecases/remote/ListLocalesTestCase.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/use-cases/src/test/org/apache/shale/usecases/remote/ListLocalesTestCase.java?rev=234439&r1=234438&r2=234439&view=diff
==============================================================================
--- struts/shale/trunk/use-cases/src/test/org/apache/shale/usecases/remote/ListLocalesTestCase.java
(original)
+++ struts/shale/trunk/use-cases/src/test/org/apache/shale/usecases/remote/ListLocalesTestCase.java
Sun Aug 21 22:58:58 2005
@@ -104,7 +104,7 @@
 
         // create a fake shale context
         swcontext = new ShaleWebContext(servletContext,
-                request, response, null);
+                request, response);
 
         //create a catalog, this would be loaded from the chains XML config file        
         Catalog catalog = CatalogFactory.getInstance().getCatalog("remote");

Modified: struts/shale/trunk/use-cases/src/test/org/apache/shale/usecases/remote/ListStateNamesTestCase.java
URL: http://svn.apache.org/viewcvs/struts/shale/trunk/use-cases/src/test/org/apache/shale/usecases/remote/ListStateNamesTestCase.java?rev=234439&r1=234438&r2=234439&view=diff
==============================================================================
--- struts/shale/trunk/use-cases/src/test/org/apache/shale/usecases/remote/ListStateNamesTestCase.java
(original)
+++ struts/shale/trunk/use-cases/src/test/org/apache/shale/usecases/remote/ListStateNamesTestCase.java
Sun Aug 21 22:58:58 2005
@@ -104,7 +104,7 @@
 
         // create a fake shale context
         swcontext = new ShaleWebContext(servletContext,
-                request, response, null);
+                request, response);
 
         //create a catalog, this would be loaded from the chains XML config file        
         Catalog catalog = CatalogFactory.getInstance().getCatalog("remote");



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org


Mime
View raw message