You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by hu...@apache.org on 2006/03/30 04:08:13 UTC

svn commit: r389964 - in /struts/sandbox/trunk/action2/apps/mailreader/src: java/mailreader2/MailreaderSupport.java java/mailreader2/VerifyResourcesInterceptor.java java/mailreader2/Welcome.java java/xwork.xml webapp/WEB-INF/web.xml webapp/pages/tour.html

Author: husted
Date: Wed Mar 29 18:08:10 2006
New Revision: 389964

URL: http://svn.apache.org/viewcvs?rev=389964&view=rev
Log:
Action2 Apps
* Mailreader
** Change to an action to verify resources

Added:
    struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/Welcome.java   (with props)
Removed:
    struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/VerifyResourcesInterceptor.java
Modified:
    struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/MailreaderSupport.java
    struts/sandbox/trunk/action2/apps/mailreader/src/java/xwork.xml
    struts/sandbox/trunk/action2/apps/mailreader/src/webapp/WEB-INF/web.xml
    struts/sandbox/trunk/action2/apps/mailreader/src/webapp/pages/tour.html

Modified: struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/MailreaderSupport.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/MailreaderSupport.java?rev=389964&r1=389963&r2=389964&view=diff
==============================================================================
--- struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/MailreaderSupport.java (original)
+++ struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/MailreaderSupport.java Wed Mar 29 18:08:10 2006
@@ -263,7 +263,7 @@
     public UserDatabase getDatabase() {
         Object db = getApplication().get(Constants.DATABASE_KEY);
         if (db == null) {
-            this.addActionError("error.database.missing");
+            this.addActionError(getText("error.database.missing"));
         }
         return (UserDatabase) db;
     }

Added: struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/Welcome.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/Welcome.java?rev=389964&view=auto
==============================================================================
--- struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/Welcome.java (added)
+++ struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/Welcome.java Wed Mar 29 18:08:10 2006
@@ -0,0 +1,33 @@
+package mailreader2;
+
+import org.apache.struts.apps.mailreader.dao.UserDatabase;
+import com.opensymphony.xwork.Action;
+import com.opensymphony.xwork.ActionSupport;
+
+/**
+ * Verify that essential resources are available.
+ */
+public class Welcome extends MailreaderSupport {
+
+    public String execute() throws Exception {
+
+        // Confirm message resources loaded
+        String message = getText(Constants.ERRORS_REQUIRED);
+        if (Constants.ERRORS_REQUIRED.equals(message)) {
+            addActionError(Constants.ERROR_MESSAGES_NOT_LOADED);
+        }
+
+        // Confirm database loaded
+        UserDatabase database = getDatabase();
+        if (null==database) {
+             addActionError(Constants.ERROR_DATABASE_NOT_LOADED);
+        }
+
+        if (hasErrors()) {
+            return Action.ERROR;
+        }
+        else {
+            return ActionSupport.SUCCESS;
+        }
+    }
+}

Propchange: struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/Welcome.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: struts/sandbox/trunk/action2/apps/mailreader/src/java/xwork.xml
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/action2/apps/mailreader/src/java/xwork.xml?rev=389964&r1=389963&r2=389964&view=diff
==============================================================================
--- struts/sandbox/trunk/action2/apps/mailreader/src/java/xwork.xml (original)
+++ struts/sandbox/trunk/action2/apps/mailreader/src/java/xwork.xml Wed Mar 29 18:08:10 2006
@@ -8,7 +8,6 @@
         <interceptors>
 
             <interceptor name="authenticate" class="mailreader2.AuthenticationInterceptor"/>
-            <interceptor name="verify" class="mailreader2.VerifyResourcesInterceptor"/>
 
             <interceptor-stack name="access" >
                 <interceptor-ref name="authenticate" />
@@ -20,16 +19,11 @@
                 <interceptor-ref name="access" />
             </interceptor-stack>
 
-            <interceptor-stack name="welcome">
-                <interceptor-ref name="defaultStack"/>
-                <interceptor-ref name="verify" />
-            </interceptor-stack>
-
         </interceptors>
 
         <default-interceptor-ref name="access"/>
         
-        <!-- default-action-ref name="Welcome"/ -->
+        <default-action-ref name="Welcome"/>
 
         <global-results>
             <result name="error">/pages/Error.jsp</result>
@@ -45,14 +39,8 @@
 
         </global-exception-mappings>
 
-        <!--
-          The reference to MailReaderSupport is only needed because
-          we use Welcome as a target for Cancel actions.
-         If the page doesn't have the appropriate input properties,
-         the framework logs an exception.
-        -->
-        <action name="Welcome" class="mailreader2.MailreaderSupport">
-            <interceptor-ref name="welcome"/>
+        <action name="Welcome" class="mailreader2.Welcome">
+            <interceptor-ref name="defaultStack"/>
             <result>/pages/Welcome.jsp</result>
         </action>
 

Modified: struts/sandbox/trunk/action2/apps/mailreader/src/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/action2/apps/mailreader/src/webapp/WEB-INF/web.xml?rev=389964&r1=389963&r2=389964&view=diff
==============================================================================
--- struts/sandbox/trunk/action2/apps/mailreader/src/webapp/WEB-INF/web.xml (original)
+++ struts/sandbox/trunk/action2/apps/mailreader/src/webapp/WEB-INF/web.xml Wed Mar 29 18:08:10 2006
@@ -26,7 +26,7 @@
             mailreader2.ApplicationListener
         </listener-class>
     </listener>
-
+       
     <welcome-file-list>
         <welcome-file>index.html</welcome-file>
     </welcome-file-list>

Modified: struts/sandbox/trunk/action2/apps/mailreader/src/webapp/pages/tour.html
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/action2/apps/mailreader/src/webapp/pages/tour.html?rev=389964&r1=389963&r2=389964&view=diff
==============================================================================
--- struts/sandbox/trunk/action2/apps/mailreader/src/webapp/pages/tour.html (original)
+++ struts/sandbox/trunk/action2/apps/mailreader/src/webapp/pages/tour.html Wed Mar 29 18:08:10 2006
@@ -297,14 +297,23 @@
 </p>
 
 <p>
-    In the application, the Welcome action mapping is slightly
-    more complicated than this,
-    and we will come back to the Welcome action later in the tour.
+    Though, in the application, the Welcome mapping does more than route control
+    to the Welcome server page.
+    We also use the Welcome mapping to verify that some system resources were
+    loaded at startup.
+    The MailReader expects a database object to be available in application scope.
+    We also expect that several standard text messages would loaded from a
+    resource bundle.
+</p>
+
+<p>
+    The Welcome mapping verifies these resources using a custom Interceptor.
+    An Interceptors
 </p>
 <hr/>
 <h5>The Welcome action element</h5>
 <pre><code>        %lt;action name="Welcome" class="mailreader2.MailreaderSupport">
-            %lt;interceptor-ref name="defaultStack"/>
+            %lt;interceptor-ref name="welcome"/>
             %lt;result>/pages/Welcome.jsp%lt;/result>
         %lt;/action>
 </code></pre>



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