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 03:15:08 UTC

svn commit: r389951 - in /struts/sandbox/trunk/action2: ./ apps/mailreader/src/java/ apps/mailreader/src/java/mailreader2/ apps/mailreader/src/webapp/pages/

Author: husted
Date: Wed Mar 29 17:15:06 2006
New Revision: 389951

URL: http://svn.apache.org/viewcvs?rev=389951&view=rev
Log:
Action2 Apps
* Mailreader
** Add an Interceptor to verify resources 

Added:
    struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/VerifyResourcesInterceptor.java   (with props)
Modified:
    struts/sandbox/trunk/action2/README.txt
    struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/Constants.java
    struts/sandbox/trunk/action2/apps/mailreader/src/java/xwork.xml
    struts/sandbox/trunk/action2/apps/mailreader/src/webapp/pages/Error.jsp
    struts/sandbox/trunk/action2/apps/mailreader/src/webapp/pages/tour.html

Modified: struts/sandbox/trunk/action2/README.txt
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/action2/README.txt?rev=389951&r1=389950&r2=389951&view=diff
==============================================================================
--- struts/sandbox/trunk/action2/README.txt (original)
+++ struts/sandbox/trunk/action2/README.txt Wed Mar 29 17:15:06 2006
@@ -195,4 +195,9 @@
 * Another approach would be to instantiate the database via Spring.
 
 
+----
+
+VerifyResourcesInterceptor
+* Could use a better test to detect whether message resources loaded
+
 ====

Modified: struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/Constants.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/Constants.java?rev=389951&r1=389950&r2=389951&view=diff
==============================================================================
--- struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/Constants.java (original)
+++ struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/Constants.java Wed Mar 29 17:15:06 2006
@@ -80,6 +80,31 @@
      */
     public static final String USER_KEY = "user";
 
+    // ---- Error Messages ----
+
+    /**
+     * <p>
+     * A static message in case message resource is not loaded.
+     * </p>
+     */
+    public static final String ERROR_MESSAGES_NOT_LOADED =
+            "ERROR:  Message resources not loaded -- check servlet container logs for error messages.";
+
+    /**
+     * <p>
+     * A static message in case database resource is not loaded.
+     * <p>
+     */
+    public static final String ERROR_DATABASE_NOT_LOADED =
+            "ERROR:  User database not loaded -- check servlet container logs for error messages.";
+
+    /**
+     * <p>
+     * A standard key from the message resources file, to test if it is available.
+     * <p>
+     */
+    public static final String ERRORS_REQUIRED = "errors.required";
+
     // ---- Log Messages ----
 
     /**

Added: struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/VerifyResourcesInterceptor.java
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/VerifyResourcesInterceptor.java?rev=389951&view=auto
==============================================================================
--- struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/VerifyResourcesInterceptor.java (added)
+++ struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/VerifyResourcesInterceptor.java Wed Mar 29 17:15:06 2006
@@ -0,0 +1,70 @@
+package mailreader2;
+
+import com.opensymphony.xwork.interceptor.Interceptor;
+import com.opensymphony.xwork.*;
+
+import java.util.Map;
+
+import org.apache.struts.apps.mailreader.dao.UserDatabase;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class VerifyResourcesInterceptor implements Interceptor  {
+
+    protected static final Log log = LogFactory.getLog(VerifyResourcesInterceptor.class);
+
+    public void destroy () {}
+
+    public void init() {}
+
+    private void addError(ValidationAware validation, String message) {
+        if (validation != null) {
+            validation.addActionError(message);
+        }
+        log.error(message);
+    }
+
+    public String intercept(ActionInvocation invocation) throws Exception {
+
+        int errors = 0;
+
+        Map application = invocation.getInvocationContext().getApplication();
+
+        ValidationAware validation = null;
+
+        final Object action = invocation.getAction();
+        if (action instanceof ValidationAware) {
+            validation = (ValidationAware) action;
+        }
+
+        // Confirm message resources loaded
+        if (action instanceof TextProvider) {
+            TextProvider tp = (TextProvider) action;
+            String message = tp.getText(Constants.ERRORS_REQUIRED);
+            if (null==message) {
+                addError(validation,Constants.ERROR_MESSAGES_NOT_LOADED);
+                errors++;
+            }
+        }
+
+        // Confirm database loaded
+        UserDatabase database = (UserDatabase) application.get(Constants.DATABASE_KEY);
+        if (null==database) {
+              try {
+                  validation.addActionError(Constants.ERROR_DATABASE_NOT_LOADED);
+              }
+              catch (NullPointerException e) {
+                  log.error(e);
+              }
+              errors++;
+        }
+
+        if (errors>0) {
+            return Action.ERROR;
+        }
+        else {
+            return invocation.invoke();
+        }
+
+    }
+}

Propchange: struts/sandbox/trunk/action2/apps/mailreader/src/java/mailreader2/VerifyResourcesInterceptor.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=389951&r1=389950&r2=389951&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 17:15:06 2006
@@ -8,6 +8,7 @@
         <interceptors>
 
             <interceptor name="authenticate" class="mailreader2.AuthenticationInterceptor"/>
+            <interceptor name="verify" class="mailreader2.VerifyResourcesInterceptor"/>
 
             <interceptor-stack name="access" >
                 <interceptor-ref name="authenticate" />
@@ -16,7 +17,12 @@
 
             <interceptor-stack name="submit">
                 <interceptor-ref name="token-session" />
-                <interceptor-ref name="authenticate-access" />
+                <interceptor-ref name="access" />
+            </interceptor-stack>
+
+            <interceptor-stack name="welcome">
+                <interceptor-ref name="defaultStack"/>
+                <interceptor-ref name="verify" />
             </interceptor-stack>
 
         </interceptors>
@@ -46,7 +52,7 @@
          the framework logs an exception.
         -->
         <action name="Welcome" class="mailreader2.MailreaderSupport">
-            <interceptor-ref name="defaultStack"/>
+            <interceptor-ref name="welcome"/>
             <result>/pages/Welcome.jsp</result>
         </action>
 
@@ -94,6 +100,11 @@
 
         <action name="Logoff" class="mailreader2.Logoff">
             <result type="redirect-action">Welcome</result>
+        </action>
+
+        <action name="Tour">
+            <interceptor-ref name="defaultStack"/>
+            <result>/pages/tour.html</result>
         </action>
 
     </package>

Modified: struts/sandbox/trunk/action2/apps/mailreader/src/webapp/pages/Error.jsp
URL: http://svn.apache.org/viewcvs/struts/sandbox/trunk/action2/apps/mailreader/src/webapp/pages/Error.jsp?rev=389951&r1=389950&r2=389951&view=diff
==============================================================================
--- struts/sandbox/trunk/action2/apps/mailreader/src/webapp/pages/Error.jsp (original)
+++ struts/sandbox/trunk/action2/apps/mailreader/src/webapp/pages/Error.jsp Wed Mar 29 17:15:06 2006
@@ -12,7 +12,7 @@
 
 <p>
     Please report this error to your system administrator
-    or appropriate technical suppoert personnel.
+    or appropriate technical support personnel.
     Thank you for your cooperation.
 </p>
 

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=389951&r1=389950&r2=389951&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 17:15:06 2006
@@ -8,12 +8,12 @@
     <meta http-equiv="Content-Type" content="text/html; charset=us-ascii"/>
     <link rel="stylesheet" type="text/css" href="../mailreader.css"/>
 
-    <title>A Walking Tour of the Action2 MailReader Application</title>
+    <title>A Walking Tour of the Action 2 MailReader Application</title>
 </head>
 
 <body>
 <blockquote>
-<h2>A Walking Tour of theAction2 MailReader Application</h2>
+<h2>A Walking Tour of the Action 2 MailReader Application</h2>
 
 <p>
     <i>
@@ -289,31 +289,34 @@
 <hr/>
 
 <p>
-    If someone asked for the Welcome action ("/Welcome.do"), the welcome.jsp
-    page would be displayed in return.
+    If a client asks for the Welcome action ("/Welcome.do"), the /page/Welcome.jsp
+    page would be returned in response.
+    The client does not know, or need to know, that the physical resource is located at
+    "/pages/Welcome.jsp".
+    All the client knows is that it requested the resource "/Welcome.do".
 </p>
 
 <p>
-    But if we peek at the configuration file for the MailReader,
-    we find a slightly more complicated XML element for the Welcome action.
+    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.
 </p>
 <hr/>
 <h5>The Welcome action element</h5>
-<pre><code>        &lt;!-- Display welcome page -->
-    &lt;action
-    path="/Welcome"
-    <strong>
-        type="org.apache.struts.apps.mailreader.actions.WelcomeAction"</strong>
-    >
-    &lt;forward
-    name="Success"
-    path="/Welcome.jsp" />
-    &lt;/action></code></pre>
+<pre><code>        %lt;action name="Welcome" class="mailreader2.MailreaderSupport">
+            %lt;interceptor-ref name="defaultStack"/>
+            %lt;result>/pages/Welcome.jsp%lt;/result>
+        %lt;/action>
+</code></pre>
 <hr/>
 
 <p>
-    Here, the <strong>WelcomeAction</strong> Java class executes whenever
+    Here, the <strong>MailreaderSupport</strong> Java class executes whenever
     someone asks for the Welcome action.
+    The MailreaderSupport class provides a lot of functionality to
+    application, but in this case, it will simply return the token
+
+    The MailreaderSupport class
     As it completes, the Action class can select which "result" is displayed.
     One available result is "Success".
     Another available result, defined at a global scope, is "Failure".



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