Author: husted
Date: Tue Dec  6 15:37:18 2005
New Revision: 354612

URL: http://svn.apache.org/viewcvs?rev=354612&view=rev
Log:
MailReader 
* Refactor configuration to use WildCard mappings as the default 

Removed:
    
struts/apps/trunk/mailreader/src/webapp/WEB-INF/struts-config-registration.xml
Modified:
    
struts/apps/trunk/mailreader/src/java/org/apache/struts/apps/mailreader/Constants.java
    
struts/apps/trunk/mailreader/src/java/org/apache/struts/apps/mailreader/actions/BaseAction.java
    
struts/apps/trunk/mailreader/src/java/org/apache/struts/apps/mailreader/actions/EditRegistrationAction.java
    
struts/apps/trunk/mailreader/src/java/org/apache/struts/apps/mailreader/actions/EditSubscriptionAction.java
    struts/apps/trunk/mailreader/src/webapp/WEB-INF/struts-config.xml
    struts/apps/trunk/mailreader/src/webapp/WEB-INF/web.xml

Modified: 
struts/apps/trunk/mailreader/src/java/org/apache/struts/apps/mailreader/Constants.java
URL: 
http://svn.apache.org/viewcvs/struts/apps/trunk/mailreader/src/java/org/apache/struts/apps/mailreader/Constants.java?rev=354612&r1=354611&r2=354612&view=diff
==============================================================================
--- 
struts/apps/trunk/mailreader/src/java/org/apache/struts/apps/mailreader/Constants.java
 (original)
+++ 
struts/apps/trunk/mailreader/src/java/org/apache/struts/apps/mailreader/Constants.java
 Tue Dec  6 15:37:18 2005
@@ -1,14 +1,14 @@
 /*
- * $Id$ 
+ * $Id$
  *
  * Copyright 1999-2004 The Apache Software Foundation.
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -108,19 +108,33 @@
 
 
     /**
+     * The message to log when forwarding to a result.
+     */
+    public static final String LOG_RESULT = " Forwarding to result: ";
+
+
+    /**
      * The message to log when forwarding to a 'logon' result.
      */
-    public static final String LOG_LOGON = " Forwarding to 'logon' result";
+    public static final String LOG_LOGON = LOG_RESULT  + LOGON ;
+
+
+    /**
+     * The message to log when user is not logged in.
+     */
+    public static final String LOG_LOGON_NONE = " User is not logged on in 
session: ";
+
 
     /**
      * The message to log when forwarding to a 'failure' result.
      */
-    public static final String LOG_FAILURE = " Forwarding to 'failure' result";
+    public static final String LOG_FAILURE = LOG_RESULT  + FAILURE ;
+
 
     /**
      * The message to log when forwarding to a 'success' result.
      */
-    public static final String LOG_SUCCESS = " Forwarding to 'success' result";
+    public static final String LOG_SUCCESS = LOG_RESULT  + SUCCESS ;
 
     
 }

Modified: 
struts/apps/trunk/mailreader/src/java/org/apache/struts/apps/mailreader/actions/BaseAction.java
URL: 
http://svn.apache.org/viewcvs/struts/apps/trunk/mailreader/src/java/org/apache/struts/apps/mailreader/actions/BaseAction.java?rev=354612&r1=354611&r2=354612&view=diff
==============================================================================
--- 
struts/apps/trunk/mailreader/src/java/org/apache/struts/apps/mailreader/actions/BaseAction.java
 (original)
+++ 
struts/apps/trunk/mailreader/src/java/org/apache/struts/apps/mailreader/actions/BaseAction.java
 Tue Dec  6 15:37:18 2005
@@ -1,14 +1,14 @@
 /*
- * $Id$ 
+ * $Id$
  *
  * Copyright 1999-2004 The Apache Software Foundation.
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -78,7 +78,7 @@
      */
     protected ActionForward findLogon(ActionMapping mapping, HttpSession 
session) {
         if (log.isTraceEnabled()) {
-            log.trace(" User is not logged on in session " + session.getId());
+            log.trace(Constants.LOG_LOGON_NONE  + session.getId());
             log.trace(Constants.LOG_LOGON);
         }
         return (mapping.findForward(Constants.LOGON));
@@ -94,26 +94,17 @@
         if (log.isTraceEnabled()) {
             log.trace(Constants.LOG_SUCCESS);
         }
-        return (mapping.findForward(Constants.SUCCESS));
+        return mapping.findForward(Constants.SUCCESS);
     }
 
 
     /**
-     * If the user is not logged in,
-     * return the "logon" mapping.
-     * @param mapping Our ActionMappings
-     * @param session Our HttpSession
-     * @return Null if user is logged in, otherwise the "logon" forward.
-     */
-    protected ActionForward isUserLoggedOn(ActionMapping mapping, HttpSession 
session) {
-        User user = (User) session.getAttribute(Constants.USER_KEY);
-        if (user == null) {
-            if (log.isTraceEnabled()) {
-                log.trace(" User is not logged on in session " + 
session.getId());
-            }
-            return (mapping.findForward(Constants.LOGON));
-        }
-        return null;
+     * Helper method to obtain User form session (if any).
+     * @param session
+     * @return User object, or null if there is no user.
+     */
+    protected User getUser(HttpSession session) {
+        return (User) session.getAttribute(Constants.USER_KEY);
     }
 
 }

Modified: 
struts/apps/trunk/mailreader/src/java/org/apache/struts/apps/mailreader/actions/EditRegistrationAction.java
URL: 
http://svn.apache.org/viewcvs/struts/apps/trunk/mailreader/src/java/org/apache/struts/apps/mailreader/actions/EditRegistrationAction.java?rev=354612&r1=354611&r2=354612&view=diff
==============================================================================
--- 
struts/apps/trunk/mailreader/src/java/org/apache/struts/apps/mailreader/actions/EditRegistrationAction.java
 (original)
+++ 
struts/apps/trunk/mailreader/src/java/org/apache/struts/apps/mailreader/actions/EditRegistrationAction.java
 Tue Dec  6 15:37:18 2005
@@ -1,14 +1,14 @@
 /*
- * $Id$ 
+ * $Id$
  *
  * Copyright 1999-2004 The Apache Software Foundation.
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -65,32 +65,31 @@
 
         // Is there a currently logged on user?
         User user = null;
-        if (!Constants.CREATE.equals(action)) {
-            user = (User) session.getAttribute(Constants.USER_KEY);
-            if (user == null) {
-                return findLogon(mapping,session);
-            }
+        boolean editing =!Constants.CREATE.equals(action);
+        if (editing) {
+            user = getUser(session);
+            if (user==null) return findLogon(mapping,session);
         }
 
-        RegistrationForm regform = (RegistrationForm) form;
-        if (user != null) {
+        if (editing) {
+            RegistrationForm regform = (RegistrationForm) form;
             if (log.isTraceEnabled()) {
-                log.trace(" Populating form from " + user);
+                log.trace(" Populating form from: " + user);
             }
-            
+
+            // Any ServletExceptions will be caught by the ExceptionHandler
+            // and control will flow to the Error result.
             try {
                 PropertyUtils.copyProperties(regform, user);
                 regform.setAction(action);
                 regform.setPassword(null);
                 regform.setPassword2(null);
-                
             } catch (InvocationTargetException e) {
                 Throwable t = e.getTargetException();
                 if (t == null)
                     t = e;
                 log.error("RegistrationForm.populate", t);
                 throw new ServletException("RegistrationForm.populate", t);
-                
             } catch (Throwable t) {
                 log.error("RegistrationForm.populate", t);
                 throw new ServletException("RegistrationForm.populate", t);

Modified: 
struts/apps/trunk/mailreader/src/java/org/apache/struts/apps/mailreader/actions/EditSubscriptionAction.java
URL: 
http://svn.apache.org/viewcvs/struts/apps/trunk/mailreader/src/java/org/apache/struts/apps/mailreader/actions/EditSubscriptionAction.java?rev=354612&r1=354611&r2=354612&view=diff
==============================================================================
--- 
struts/apps/trunk/mailreader/src/java/org/apache/struts/apps/mailreader/actions/EditSubscriptionAction.java
 (original)
+++ 
struts/apps/trunk/mailreader/src/java/org/apache/struts/apps/mailreader/actions/EditSubscriptionAction.java
 Tue Dec  6 15:37:18 2005
@@ -1,14 +1,14 @@
 /*
- * $Id$ 
+ * $Id$
  *
  * Copyright 1999-2004 The Apache Software Foundation.
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -64,18 +64,8 @@
             log.debug("EditSubscriptionAction:  Processing " + action + " 
action");
         }
 
-        // Is there a currently logged on user?
-        User user = null;
-        if (!Constants.CREATE.equals(action)) {
-             user = (User) session.getAttribute(Constants.USER_KEY);
-             if (user == null) {
-                 if (log.isDebugEnabled()) {
-                     log.debug(
-                         " User is not logged on in session " + 
session.getId());
-                 }
-                 return (mapping.findForward(Constants.LOGON));
-             }
-        }
+        User user = getUser(session);
+        if (user==null) return findLogon(mapping,session);
 
         // Identify the relevant subscription
         Subscription subscription;

Modified: struts/apps/trunk/mailreader/src/webapp/WEB-INF/struts-config.xml
URL: 
http://svn.apache.org/viewcvs/struts/apps/trunk/mailreader/src/webapp/WEB-INF/struts-config.xml?rev=354612&r1=354611&r2=354612&view=diff
==============================================================================
--- struts/apps/trunk/mailreader/src/webapp/WEB-INF/struts-config.xml (original)
+++ struts/apps/trunk/mailreader/src/webapp/WEB-INF/struts-config.xml Tue Dec  
6 15:37:18 2005
@@ -41,6 +41,10 @@
       <form-property name="password" type="java.lang.String"/>
     </form-bean>
 
+    <!-- Registration form bean -->
+    <form-bean      name="RegistrationForm"
+                    
type="org.apache.struts.apps.mailreader.forms.RegistrationForm"/>
+
     <!-- Subscription form bean -->
     <form-bean      name="SubscriptionForm"
                     
type="org.apache.struts.apps.mailreader.forms.SubscriptionForm"/>
@@ -49,20 +53,22 @@
 
   <!-- ========== Global Forward Definitions ============================== -->
   <global-forwards>
-    <forward   name="Welcome"              path="/Welcome.do"/>
-    <forward   name="Logoff"               path="/Logoff.do"/>
-    <forward   name="Logon"                path="/Logon.do"/>
-    <forward   name="Success"              path="/MainMenu.do"/>
+    <forward name="Logoff"               path="/Logoff.do"/>
+    <forward name="Logon"                path="/Logon.do"/>
+    <forward name="Failure"              path="/Error.jsp" />
   </global-forwards>
 
 
   <!-- ========== Action Mapping Definitions ============================== -->
   <action-mappings>
 
+      <!-- Display any other page (Logon, MainMenu) - Must come first! -->
+      <action    path="/*"
+                 forward="/{1}.jsp"/>
+
       <!-- Display welcome page -->
       <action    path="/Welcome"
                  
type="org.apache.struts.apps.mailreader.actions.WelcomeAction">
-          <forward name="Failure" path="/Error.jsp" />
           <forward name="Success" path="/Welcome.jsp" />
       </action>
 
@@ -70,19 +76,9 @@
       <action
           path="/Locale"
           type="org.apache.struts.apps.mailreader.actions.LocaleAction"
-          parameter="Welcome" />
-
-      <!-- Display registration page -->
-      <action    path="/Registration"
-                 forward="/Registration.jsp"/>
-
-      <!-- Display logon page -->
-      <action    path="/MainMenu"
-                 forward="/MainMenu.jsp"/>
-
-      <!-- Display logon page -->
-      <action    path="/Logon"
-                 forward="/Logon.jsp"/>
+          parameter="Success" >
+          <forward name="Success"              path="/Welcome.do"/>
+      </action>
 
        <!-- Process a user logon -->
        <action    path="/SubmitLogon"
@@ -93,7 +89,8 @@
          <exception
                    key="expired.password"
                   
type="org.apache.struts.apps.mailreader.dao.ExpiredPasswordException"
-                  path="/ExpiredPassword.do"/>
+                  path="/ChangePassword.jsp"/>
+           <forward name="Success"              path="/MainMenu.do"/>
        </action>
 
       <!-- Process a user logoff -->
@@ -102,29 +99,34 @@
          <forward name="Success"              path="/Welcome.do"/>
        </action>
 
-      <!-- Edit mail subscription -->
-      <action    path="/EditSubscription"
-                 
type="org.apache.struts.apps.mailreader.actions.EditSubscriptionAction"
-                 name="SubscriptionForm"
+      <!-- Matches all edit actions  -->
+      <action    path="/Edit*"
+                 type="org.apache.struts.apps.mailreader.actions.Edit{1}Action"
+                 name="{1}Form"
                 scope="request"
              validate="false">
-        <forward name="Failure"              path="/MainMenu.do"/>
-        <forward name="Success"              path="/Subscription.jsp"/>
+        <forward name="Success"              path="/{1}.jsp"/>
       </action>
 
-       <!-- Save mail subscription -->
-       <action    path="/SaveSubscription"
-                  
type="org.apache.struts.apps.mailreader.actions.SaveSubscriptionAction"
-                  name="SubscriptionForm"
+      <!-- Matches all other Save actions -->
+      <action    path="/Save*"
+                 type="org.apache.struts.apps.mailreader.actions.Save{1}Action"
+                 name="{1}Form"
                  scope="request"
-                 input="Subscription">
-         <forward name="Subscription"    path="/Subscription.jsp"/>
-         <forward name="Success"         
path="/EditRegistration.do?action=Edit"/>
-       </action>
+                 input="Input" >
+        <forward name="Success"              path="/MainMenu.do"/>
+        <forward name="Input"                path="/(1).jsp"/>
+      </action>
 
-      <!-- Display the change password page when a password expires -->
-      <action    path="/ExpiredPassword"
-              forward="/ChangePassword.jsp">
+      <!-- Matches SaveSubscription action -->
+      <!-- If extends understood wildcards, we could specify only Success 
here. -->
+      <action    path="/SaveSubscription"
+                 extends="/Save*"
+                 
type="org.apache.struts.apps.mailreader.actions.SaveSubscriptionAction"
+                 name="SubscriptionForm"
+                 input="Input" >
+        <forward name="Success"              
path="/EditRegistration.do?action=Edit"/>
+        <forward name="Input"                path="/Subscription.jsp"/>
       </action>
 
       <!-- Display the "walking tour" documentation -->

Modified: struts/apps/trunk/mailreader/src/webapp/WEB-INF/web.xml
URL: 
http://svn.apache.org/viewcvs/struts/apps/trunk/mailreader/src/webapp/WEB-INF/web.xml?rev=354612&r1=354611&r2=354612&view=diff
==============================================================================
--- struts/apps/trunk/mailreader/src/webapp/WEB-INF/web.xml (original)
+++ struts/apps/trunk/mailreader/src/webapp/WEB-INF/web.xml Tue Dec  6 15:37:18 
2005
@@ -13,7 +13,7 @@
     <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
     <init-param>
       <param-name>config</param-name>
-      <param-value>/WEB-INF/struts-config.xml, 
/WEB-INF/struts-config-registration.xml</param-value>
+      <param-value>/WEB-INF/struts-config.xml</param-value>
     </init-param>
     <load-on-startup>1</load-on-startup>
   </servlet>



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

Reply via email to