husted 2004/03/08 20:36:50
Modified: src/example/org/apache/struts/webapp/example
AlternateApplicationResources.properties
ApplicationResources.properties Constants.java
Added: src/example/org/apache/struts/webapp/example BaseAction.java
WelcomeAction.java
Log:
Move resource-test code to WelcomeAction.
Revision Changes Path
1.2 +2 -0
jakarta-struts/src/example/org/apache/struts/webapp/example/AlternateApplicationResources.properties
Index: AlternateApplicationResources.properties
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/example/org/apache/struts/webapp/example/AlternateApplicationResources.properties,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AlternateApplicationResources.properties 4 Nov 2002 06:25:16 -0000 1.1
+++ AlternateApplicationResources.properties 9 Mar 2004 04:36:49 -0000 1.2
@@ -1 +1,3 @@
prompt.password=Enter your Password here ==>
+struts.logo.path=/struts-power.gif
+struts.logo.alt=Powered by Struts
1.11 +1 -1
jakarta-struts/src/example/org/apache/struts/webapp/example/ApplicationResources.properties
Index: ApplicationResources.properties
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/example/org/apache/struts/webapp/example/ApplicationResources.properties,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- ApplicationResources.properties 7 Mar 2004 01:54:55 -0000 1.10
+++ ApplicationResources.properties 9 Mar 2004 04:36:49 -0000 1.11
@@ -36,7 +36,7 @@
index.heading=MailReader Demonstration Application Options
index.logon=Log on to the MailReader Demonstration Application
index.registration=Register with the MailReader Demonstration Application
-index.title=MailReader Demonstration Application (Struts 1.1-dev)
+index.title=MailReader Demonstration Application (Struts 1.2.1-dev)
index.tour=A Walking Tour of the MailReader Demonstration Application
linkSubscription.io=I/O Error: {0}
linkSubscription.noSubscription=No subscription under attribute {0}
1.6 +37 -5
jakarta-struts/src/example/org/apache/struts/webapp/example/Constants.java
Index: Constants.java
===================================================================
RCS file:
/home/cvs/jakarta-struts/src/example/org/apache/struts/webapp/example/Constants.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- Constants.java 13 Jan 2004 12:48:44 -0000 1.5
+++ Constants.java 9 Mar 2004 04:36:49 -0000 1.6
@@ -75,7 +75,19 @@
/**
* The package name for this application.
*/
- public static final String Package = "org.apache.struts.webapp.example";
+ public static final String PACKAGE = "org.apache.struts.webapp.example";
+
+
+ /**
+ * The token representing "failure" for this application.
+ */
+ public static final String FAILURE = "failure";
+
+
+ /**
+ * The token representing "success" for this application.
+ */
+ public static final String SUCCESS = "success";
/**
@@ -98,5 +110,25 @@
*/
public static final String USER_KEY = "user";
+
+ /**
+ * A static message in case database resource is not loaded.
+ */
+ public static final String ERROR_DATABASE_NOT_LOADED =
+ "ERROR: User database not loaded -- check servlet container logs for error
messages.";
+
+
+ /**
+ * A static message in case message resource is not loaded.
+ */
+ public static final String ERROR_MESSAGES_NOT_LOADED =
+ "ERROR: Message resources not loaded -- check servlet container logs for
error messages.";
+
+
+ /**
+ * The request attributes key under the WelcomeAction stores an ArrayList
+ * of error messages, if required resources are missing.
+ */
+ public static final String ERROR_KEY = "ERROR";
}
1.1
jakarta-struts/src/example/org/apache/struts/webapp/example/BaseAction.java
Index: BaseAction.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-struts/src/example/org/apache/struts/webapp/example/BaseAction.java,v
1.1 2004/03/09 04:36:49 husted Exp $
* $Revision: 1.1 $
* $Date: 2004/03/09 04:36:49 $
*
* ====================================================================
*
* The Apache Software License, Version 1.1
*
* Copyright (c) 1999-2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution, if
* any, must include the following acknowledgement:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowlegement may appear in the software itself,
* if and wherever such third-party acknowlegements normally appear.
*
* 4. The names "The Jakarta Project", "Struts", and "Apache Software
* Foundation" must not be used to endorse or promote products derived
* from this software without prior written permission. For written
* permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache"
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
*/
package org.apache.struts.webapp.example;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.webapp.example.UserDatabase;
import javax.servlet.http.HttpServletRequest;
/**
* Base Action for MailReader application.
*
* @version $Revision: 1.1 $ $Date: 2004/03/09 04:36:49 $
*/
public class BaseAction extends Action {
// ----------------------------------------------------- Instance Variables
/**
* The <code>Log</code> instance for this application.
*/
protected Log log = LogFactory.getLog(Constants.PACKAGE);
// ------------------------------------------------------ Protected Methods
/**
* Return a reference to the UserDatabase
* or null if the database is not available.
* @param request The request we are processing
* @return a reference to the UserDatabase or null if the database is not
available
*/
protected UserDatabase getUserDatabase(HttpServletRequest request) {
return (UserDatabase) servlet.getServletContext().getAttribute(
Constants.DATABASE_KEY);
}
/**
* Return the local or global forward named "failure"
* or null if there is no such forward.
* @param mapping Our ActionMapping
* @return Return the mapping named "failure" or null if there is no such
mapping.
*/
protected ActionForward findFailure(ActionMapping mapping) {
return (mapping.findForward(Constants.FAILURE));
}
/**
* Return the mapping labeled "success"
* or null if there is no such mapping.
* @param mapping Our ActionMapping
* @return Return the mapping named "success" or null if there is no such
mapping.
*/
protected ActionForward findSuccess(ActionMapping mapping) {
return (mapping.findForward(Constants.SUCCESS));
}
}
1.1
jakarta-struts/src/example/org/apache/struts/webapp/example/WelcomeAction.java
Index: WelcomeAction.java
===================================================================
/*
* $Header:
/home/cvs/jakarta-struts/src/example/org/apache/struts/webapp/example/WelcomeAction.java,v
1.1 2004/03/09 04:36:49 husted Exp $
* $Revision: 1.1 $
* $Date: 2004/03/09 04:36:49 $
*
* Copyright 2000-2004 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.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.struts.webapp.example;
import java.util.ArrayList;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.webapp.example.UserDatabase;
import org.apache.struts.util.MessageResources;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForward;
/**
* <p>
* Confirm required resources are available. If a resource is missing,
* forward to "failure". Otherwise, forward to "success", where
* success is usually the "welcome" page.
* </p>
* <p>
* Since "required resources" includes the application MessageResources
* the failure page must not use the standard error or message tags.
* Instead, it display the Strings stored in an ArrayList stored under
* the request attribute "ERROR".
* </p>
*
* @version $Revision: 1.1 $ $Date: 2004/03/09 04:36:49 $
*/
public final class WelcomeAction extends BaseAction {
// --------------------------------------------------------- Public Methods
// See superclass for Javadoc
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
// Setup message array in case there are errors
ArrayList messages = new ArrayList();
// Confirm message resources loaded
MessageResources resources = getResources(request);
if (resources==null) {
messages.add(Constants.ERROR_MESSAGES_NOT_LOADED);
}
// Confirm database loaded
UserDatabase userDatabase = getUserDatabase(request);
if (userDatabase==null) {
messages.add(Constants.ERROR_DATABASE_NOT_LOADED);
}
// If there were errors, forward to our failure page
if (messages.size()>0) {
request.setAttribute(Constants.ERROR_KEY,messages);
return findFailure(mapping);
}
// Forward to our success page
return findSuccess(mapping);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]