craigmcc    2003/08/30 16:18:56

  Modified:    contrib/struts-chain build.xml
               contrib/struts-chain/src/conf chain-config.xml
               contrib/struts-chain/src/java/org/apache/struts/chain
                        Constants.java
               contrib/struts-chain/src/java/org/apache/struts/chain/legacy
                        CatalogConfiguratorPlugIn.java
                        ComposableRequestProcessor.java
  Added:       contrib/struts-chain/web/example/WEB-INF struts-config.xml
  Removed:     contrib/struts-chain/web/example/WEB-INF web.xml
  Log:
  Tweaks to ComposableRequestProcessor and CatalogConfiguratorPlugIn so that
  the canonical Struts example application works successfully with it (at
  least to a first order of approximation -- not every detail has been
  checked).
  
  The src/conf/chain-config.xml resource now documents the correspondence
  between the standard methods of RequestProcessor versus the Command
  implementations that perform those tasks in this environment.  This will
  also serve as a checklist of what isn't implemeneted yet, so please keep
  it up to date if you add in some of the missing features.
  
  Revision  Changes    Path
  1.3       +16 -31    jakarta-struts/contrib/struts-chain/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/contrib/struts-chain/build.xml,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- build.xml 11 Aug 2003 06:13:07 -0000      1.2
  +++ build.xml 30 Aug 2003 23:18:56 -0000      1.3
  @@ -131,6 +131,10 @@
       <copy   tofile="${build.home}/classes/META-INF/LICENSE.txt"
                 file="LICENSE.txt"/>
   
  +    <!-- Copy standard chain configuration file -->
  +    <copy    todir="${build.home}/classes/org/apache/struts/chain"
  +              file="src/conf/chain-config.xml"/>
  +
     </target>
   
   
  @@ -177,52 +181,32 @@
   
   
     <target name="example.static" depends="example.prepare">
  +
  +    <!-- Copy example webapp from standard build -->
       <copy    todir="${build.home}/webapps/example">
  -      <fileset dir="web/example"/>
  +      <fileset dir="../../target/example"/>
       </copy>
   
  -    <!-- Copy required configuration files -->
  -<!--
  -    <copy       todir="${build.home}/webapps/example/WEB-INF">
  -      <fileset    dir="${build.home}/conf">
  -        <include name="*.tld"/>
  -      </fileset>
  -      <fileset    dir="${struts.home}/lib">
  -        <include name="*.tld"/>
  -        <include name="valid*.xml"/>
  -      </fileset>
  +    <!-- Copy override files from our local directory -->
  +    <copy    todir="${build.home}/webapps/example" overwrite="true">
  +      <fileset dir="web/example"/>
       </copy>
  --->
   
  -    <!-- Copy required library JAR files -->
  +    <!-- Copy additional library JAR files -->
       <mkdir        dir="${build.home}/webapps/example/WEB-INF/lib"/>
  -    <copy       todir="${build.home}/webapps/example/WEB-INF/lib">
  -      <fileset    dir="${build.home}/lib">
  -        <include name="struts-chain.jar"/>
  -      </fileset>
  -    </copy>
  -    <copy       todir="${build.home}/webapps/example/WEB-INF/lib">
  -      <fileset    dir="${struts.home}/lib">
  -        <include name="commons-*.jar"/>
  -        <include name="struts.jar"/>
  -      </fileset>
  -    </copy>
       <copy       todir="${build.home}/webapps/example/WEB-INF/lib"
                    file="${commons-chain.jar}"/>
  -<!--
       <copy       todir="${build.home}/webapps/example/WEB-INF/lib"
  -                 file="${jstl.jar}"/>
  -    <copy       todir="${build.home}/webapps/example/WEB-INF/lib"
  -                 file="${standard.jar}"/>
  --->
  +                 file="${build.home}/lib/struts-chain.jar"/>
   
     </target>
   
   
     <target name="example.compile" depends="example.static">
  +
  +<!--
       <mkdir     dir="${build.home}/webapps/example/WEB-INF/classes"/>
   
  -    <!-- Compile Java Sources -->
       <javac  srcdir="src/example"
              destdir="${build.home}/webapps/example/WEB-INF/classes"
                debug="${compile.debug}"
  @@ -231,12 +215,13 @@
         <classpath refid="classpath" />
       </javac>
   
  -    <!-- Copy non-Java Sources -->
       <copy    todir="${build.home}/webapps/example/WEB-INF/classes">
         <fileset dir="src/example">
           <exclude name="**/*.java"/>
         </fileset>
       </copy>
  +
  +-->
   
     </target>
   
  
  
  
  1.2       +49 -1     jakarta-struts/contrib/struts-chain/src/conf/chain-config.xml
  
  Index: chain-config.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-struts/contrib/struts-chain/src/conf/chain-config.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- chain-config.xml  11 Aug 2003 04:55:34 -0000      1.1
  +++ chain-config.xml  30 Aug 2003 23:18:56 -0000      1.2
  @@ -50,6 +50,54 @@
   
      <chain      name="servlet-standard">
   
  +      <!--
  +           This chain attempts to emulate (most of) the standard request
  +           processing in the standard org.apache.struts.action.RequestProcessor
  +           class, by performing the corresponding tasks in individual Commands
  +           that are composable.  The following list defines a cross reference
  +           between the processXxx methods and the Commands that perform the
  +           corresponding functionality:
  +
  +           processMultipart        NOT SUPPORTED YET (so no file upload support)
  +
  +           processPath             SelectAction (which also does processMapping)
  +
  +           processException        NOT SUPPORTED YET
  +
  +           processLocale           SelectLocale
  +
  +           processContent          NOT SUPPORTED YET
  +
  +           processNoCache          NOT SUPPORTED YET
  +
  +           processPreprocess       LookupCommand with optional="true".  Multiple
  +                                   occurrences of this can easily be added, to
  +                                   support additional processing hooks at any
  +                                   point in the chain without modifying the
  +                                   standard definition.
  +
  +           processMapping          SelectAction (which also does processPath)
  +
  +           processRoles            NOT SUPPORTED YET
  +
  +           processActionForm       CreateActionForm
  +
  +           processPopulate         PopulateActionForm
  +
  +           processValidate         ValidateActionForm
  +
  +           processForward          NOT SUPPORTED YET
  +
  +           processInclude          NOT SUPPORTED YET
  +
  +           processActionCreate     CreateAction
  +
  +           processActionPerform    ExecuteAction
  +
  +           processForwardConfig    PerformForward
  +
  +      -->
  +
   
         <!-- Look up optional preprocess command -->
         <command
  
  
  
  1.2       +11 -3     
jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/Constants.java
  
  Index: Constants.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/Constants.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Constants.java    11 Aug 2003 04:55:34 -0000      1.1
  +++ Constants.java    30 Aug 2003 23:18:56 -0000      1.2
  @@ -155,6 +155,14 @@
   
   
       /**
  +     * <p>The context attribute under which the <code>Catalog</code> containing
  +     * our defined command chains has been stored.</p>
  +     */
  +    public static final String CATALOG_KEY =
  +        "org.apache.struts.chain.CATALOG";
  +
  +
  +    /**
        * <p>The request attribute under which the path information is stored for
        * processing during a RequestDispatcher.include() call.</p>
        */
  
  
  
  1.2       +13 -3     
jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/legacy/CatalogConfiguratorPlugIn.java
  
  Index: CatalogConfiguratorPlugIn.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/legacy/CatalogConfiguratorPlugIn.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CatalogConfiguratorPlugIn.java    30 Aug 2003 22:01:24 -0000      1.1
  +++ CatalogConfiguratorPlugIn.java    30 Aug 2003 23:18:56 -0000      1.2
  @@ -74,6 +74,9 @@
   import org.apache.commons.chain.Catalog;
   import org.apache.commons.chain.config.ConfigParser;
   import org.apache.commons.chain.impl.CatalogBase;
  +import org.apache.commons.logging.Log;
  +import org.apache.commons.logging.LogFactory;
  +
   
   
   /**
  @@ -101,6 +104,7 @@
       // ------------------------------------------------------ Instance Variables
   
   
  +    private static Log log = LogFactory.getLog(CatalogConfiguratorPlugIn.class);
       private String path = null;
       private String resource = null;
   
  @@ -170,6 +174,7 @@
           Catalog catalog = (Catalog)
               servlet.getServletContext().getAttribute(Constants.CATALOG_KEY);
           if (catalog == null) {
  +            log.info("Creating new Catalog instance");
               catalog = new CatalogBase();
               servlet.getServletContext().setAttribute(Constants.CATALOG_KEY,
                                                        catalog);
  @@ -180,9 +185,13 @@
               ConfigParser parser = new ConfigParser();
               URL configResource = null;
               if (path != null) {
  +                log.info("Loading context relative resources from '" +
  +                         path + "'");
                   configResource =
                       servlet.getServletContext().getResource(path);
               } else if (resource != null) {
  +                log.info("Loading classloader resources from '" +
  +                         resource + "'");
                   ClassLoader loader =
                       Thread.currentThread().getContextClassLoader();
                   if (loader == null) {
  @@ -192,6 +201,7 @@
               }
               parser.parse(catalog, configResource);
           } catch (Exception e) {
  +            log.error("Exception loading resources", e);
               throw new ServletException(e);
           }
   
  
  
  
  1.2       +20 -4     
jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/legacy/ComposableRequestProcessor.java
  
  Index: ComposableRequestProcessor.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-struts/contrib/struts-chain/src/java/org/apache/struts/chain/legacy/ComposableRequestProcessor.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ComposableRequestProcessor.java   30 Aug 2003 22:01:24 -0000      1.1
  +++ ComposableRequestProcessor.java   30 Aug 2003 23:18:56 -0000      1.2
  @@ -77,6 +77,8 @@
   import org.apache.commons.chain.Catalog;
   import org.apache.commons.chain.Command;
   import org.apache.commons.chain.web.servlet.ServletWebContext;
  +import org.apache.commons.logging.Log;
  +import org.apache.commons.logging.LogFactory;
   
   
   /**
  @@ -111,6 +113,13 @@
       protected Catalog catalog;
   
   
  +    /**
  +     * <p>The <code>Log</code> instance for this class.</p>
  +     */
  +    protected static final Log log =
  +        LogFactory.getLog(ComposableRequestProcessor.class);
  +
  +
       // ---------------------------------------------------------- Public Methods
   
   
  @@ -137,6 +146,8 @@
                        ModuleConfig moduleConfig)
              throws ServletException {
   
  +        log.info("Initializing composable request processor for module prefix '"
  +                 + moduleConfig.getPrefix() + "'");
           super.init(servlet, moduleConfig);
           this.catalog = (Catalog)
               servlet.getServletContext().getAttribute(Constants.CATALOG_KEY);
  @@ -166,12 +177,17 @@
           ServletWebContext context = new ServletWebContext();
           context.initialize(getServletContext(), request, response);
           context.getAttributes().put("catalog", this.catalog);
  +        context.getAttributes().put(Constants.ACTION_SERVLET_KEY,
  +                                    this.servlet);
           context.getAttributes().put(Constants.MODULE_CONFIG_KEY,
                                       this.moduleConfig);
   
           // Create and execute the command.
           Command command = this.catalog.getCommand("servlet-standard");
           try {
  +            if (log.isDebugEnabled()) {
  +                log.debug("Using processing chain for this request");
  +            }
               command.execute(context);
           } catch (Exception e) {
               // Execute the exception processing chain??
  
  
  
  1.1                  
jakarta-struts/contrib/struts-chain/web/example/WEB-INF/struts-config.xml
  
  Index: struts-config.xml
  ===================================================================
  <?xml version="1.0" encoding="ISO-8859-1" ?>
  
  <!DOCTYPE struts-config PUBLIC
            "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
            "http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd";>
  
  
  <struts-config>
    <display-name><![CDATA[
       account maintaince
    ]]>
    </display-name>
      <description><![CDATA[
       Allows the updating of users accounts and subscriptions.
    ]]>
    </description>
  
  
    <!-- ========== Data Source Configuration =============================== -->
  <!--
   <data-sources>
     <data-source>
       <set-property property="autoCommit"
                        value="false"/>
       <set-property property="description"
                        value="Example Data Source Configuration"/>
       <set-property property="driverClass"
                        value="org.postgresql.Driver"/>
       <set-property property="maxCount"
                        value="4"/>
       <set-property property="minCount"
                        value="2"/>
       <set-property property="password"
                        value="mypassword"/>
       <set-property property="url"
                        value="jdbc:postgresql://localhost/mydatabase"/>
       <set-property property="user"
                        value="myusername"/>
     </data-source>
   </data-sources>
  -->
    <!-- ========== Form Bean Definitions =================================== -->
    <form-beans>
  
      <!-- Logon form bean -->
      <form-bean       name="logonForm"
                       type="org.apache.struts.validator.DynaValidatorForm">
        <form-property name="username" type="java.lang.String"/>
        <form-property name="password" type="java.lang.String"/>
      </form-bean>
  
      <!-- Subscription form bean -->
      <form-bean      name="subscriptionForm"
                      type="org.apache.struts.webapp.example.SubscriptionForm"/>
  
    </form-beans>
  
  
    <!-- ========== Global Forward Definitions ============================== -->
    <global-forwards>
      <forward   name="logoff"               path="/logoff.do"/>
      <forward   name="logon"                path="/logon.jsp"/>
      <forward   name="success"              path="/mainMenu.jsp"/>
    </global-forwards>
  
  
    <!-- ========== Action Mapping Definitions ============================== -->
    <action-mappings>
  
      <!-- Edit mail subscription -->
      <action    path="/editSubscription"
                 type="org.apache.struts.webapp.example.EditSubscriptionAction"
            attribute="subscriptionForm"
                scope="request"
             validate="false">
        <forward name="failure"              path="/mainMenu.jsp"/>
        <forward name="success"              path="/subscription.jsp"/>
      </action>
  
      <!-- Process a user logoff -->
      <action    path="/logoff"
                 type="org.apache.struts.webapp.example.LogoffAction">
        <forward name="success"              path="/index.jsp"/>
      </action>
  
      <!-- Process a user logon -->
      <action    path="/logon"
                 type="org.apache.struts.webapp.example.LogonAction"
                 name="logonForm"
                scope="session"
                input="logon">
        <exception
                  key="expired.password"
                 type="org.apache.struts.webapp.example.ExpiredPasswordException"
                 path="/changePassword.jsp"/>
      </action>
  
      <!-- Save mail subscription -->
      <action    path="/saveSubscription"
                 type="org.apache.struts.webapp.example.SaveSubscriptionAction"
                 name="subscriptionForm"
                scope="request"
                input="subscription">
        <forward name="subscription"    path="/subscription.jsp"/>
        <forward name="success"         path="/editRegistration.do?action=Edit"/>
      </action>
  
  
      <!-- Display the "walking tour" documentation -->
      <action    path="/tour"
              forward="/tour.htm">
      </action>
  
    </action-mappings>
  
  
    <!-- ========== Controller Configuration ================================ -->
  
    <controller>
      <!-- The "input" parameter on "action" elements is the name of a
           local or global "forward" rather than a module-relative path -->
      <set-property property="inputForward" value="true"/>
      <!-- Use the composable request processor implementation -->
      <set-property
            property="processorClass"
               value="org.apache.struts.chain.legacy.ComposableRequestProcessor"/>
    </controller>
  
  
    <!-- ========== Message Resources Definitions =========================== -->
  
    <message-resources
      parameter="org.apache.struts.webapp.example.ApplicationResources"/>
  
    <message-resources
      parameter="org.apache.struts.webapp.example.AlternateApplicationResources"
      key="alternate">
    </message-resources>
  
  
    <!-- ========== Plug Ins Configuration ================================== -->
  
    <plug-in className="org.apache.struts.plugins.ModuleConfigVerifier"/>
  
    <!-- Configure the command chains to be used -->
    <plug-in className="org.apache.struts.chain.legacy.CatalogConfiguratorPlugIn">
      <set-property
                property="resource"
                   value="org/apache/struts/chain/chain-config.xml"/>
    </plug-in>
  
    <plug-in className="org.apache.struts.webapp.example.memory.MemoryDatabasePlugIn">
      <set-property property="pathname" value="/WEB-INF/database.xml"/>
    </plug-in>
  
    <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
      <set-property property="pathnames"
                       value="/WEB-INF/validator-rules.xml,
                              /WEB-INF/validation.xml"/>
    </plug-in>
  
  
  </struts-config>
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to