KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > webapp > example > WelcomeAction


1 /*
2  * $Id: WelcomeAction.java 54929 2004-10-16 16:38:42Z germuska $
3  *
4  * Copyright 2000-2004 Apache Software Foundation
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.struts.webapp.example;
19
20 import java.util.ArrayList JavaDoc;
21 import javax.servlet.http.HttpServletRequest JavaDoc;
22 import javax.servlet.http.HttpServletResponse JavaDoc;
23 import org.apache.struts.webapp.example.UserDatabase;
24 import org.apache.struts.util.MessageResources;
25 import org.apache.struts.action.ActionForm;
26 import org.apache.struts.action.ActionMapping;
27 import org.apache.struts.action.ActionForward;
28
29
30 /**
31  * <p>
32  * Confirm required resources are available. If a resource is missing,
33  * forward to "failure". Otherwise, forward to "success", where
34  * success is usually the "welcome" page.
35  * </p>
36  * <p>
37  * Since "required resources" includes the application MessageResources
38  * the failure page must not use the standard error or message tags.
39  * Instead, it display the Strings stored in an ArrayList stored under
40  * the request attribute "ERROR".
41  * </p>
42  *
43  * @version $Rev: 54929 $ $Date: 2004-10-16 17:38:42 +0100 (Sat, 16 Oct 2004) $
44  */

45 public final class WelcomeAction extends BaseAction {
46
47     // --------------------------------------------------------- Public Methods
48

49          // See superclass for Javadoc
50
public ActionForward execute(
51         ActionMapping mapping,
52         ActionForm form,
53         HttpServletRequest JavaDoc request,
54         HttpServletResponse JavaDoc response)
55         throws Exception JavaDoc {
56
57         // Setup message array in case there are errors
58
ArrayList JavaDoc messages = new ArrayList JavaDoc();
59
60         // Confirm message resources loaded
61
MessageResources resources = getResources(request);
62         if (resources==null) {
63             messages.add(Constants.ERROR_MESSAGES_NOT_LOADED);
64         }
65
66         // Confirm database loaded
67
UserDatabase userDatabase = getUserDatabase(request);
68         if (userDatabase==null) {
69             messages.add(Constants.ERROR_DATABASE_NOT_LOADED);
70         }
71
72         // If there were errors, forward to our failure page
73
if (messages.size()>0) {
74             request.setAttribute(Constants.ERROR_KEY,messages);
75             return findFailure(mapping);
76         }
77
78         // Forward to our success page
79
return findSuccess(mapping);
80
81     }
82
83 }
84
Popular Tags