KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jahia > views > engines > helloworld > actions > HelloAction


1 package org.jahia.views.engines.helloworld.actions;
2
3 import java.io.IOException JavaDoc;
4
5 import javax.servlet.ServletException JavaDoc;
6 import javax.servlet.http.HttpServletRequest JavaDoc;
7 import javax.servlet.http.HttpServletResponse JavaDoc;
8
9
10 import org.apache.struts.action.Action;
11 import org.apache.struts.action.ActionForm;
12 import org.apache.struts.action.ActionForward;
13 import org.apache.struts.action.ActionMapping;
14 import org.apache.struts.action.ActionMessage;
15 import org.apache.struts.action.ActionMessages;
16 import org.jahia.views.engines.*;
17 import org.jahia.exceptions.JahiaException;
18 import org.jahia.views.engines.helloworld.forms.HelloForm;
19 import org.jahia.bin.JahiaErrorDisplay;
20
21 /**
22  * Simple test Action class
23  */

24 public final class HelloAction extends Action {
25
26     public static final String JavaDoc ENGINE_NAME = "HelloWorld";
27
28     /**
29     * Process the specified HTTP request, and create the corresponding HTTP
30     * response (or forward to another web component that will create it).
31     * Return an <code>ActionForward</code> instance describing where and how
32     * control should be forwarded, or <code>null</code> if the response has
33     * already been completed.
34     *
35     * @param mapping The ActionMapping used to select this instance
36     * @param actionForm The optional ActionForm bean for this request (if any)
37     * @param request The HTTP request we are processing
38     * @param response The HTTP response we are creating
39     *
40     * @exception IOException if an input/output error occurs
41     * @exception ServletException if a servlet exception occurs
42     */

43     public ActionForward execute(ActionMapping mapping,
44                                  ActionForm form,
45                                  HttpServletRequest JavaDoc request,
46                                  HttpServletResponse JavaDoc response)
47                                  throws IOException JavaDoc, ServletException JavaDoc{
48
49         ActionMessages errors = new ActionMessages();
50
51         // Extract attributes and parameters we will need
52
HelloForm helloForm = (HelloForm) form;
53         if ( helloForm == null ){
54             // return to the original form
55
return (new ActionForward(mapping.getInput()));
56         }
57         String JavaDoc name = helloForm.getName();
58
59         request.setAttribute("helloForm",helloForm);
60
61         try {
62             // business process here
63

64             // engines helpers
65
JahiaEngineCommonData engineCommonData =
66                     new JahiaEngineCommonData(request);
67
68             engineCommonData.setEngineTitle(ENGINE_NAME);
69
70             request.setAttribute(JahiaEngineCommonData.JAHIA_ENGINE_COMMON_DATA,
71                                  engineCommonData);
72
73         } catch ( JahiaException je){
74             JahiaErrorDisplay.DisplayException(request, response,
75                     super.getServlet().getServletContext(), je);
76             return null;
77         }
78
79         // If any messages is required, save the specified error messages keys
80
// into the HTTP request for use by the <struts:errors> tag.
81
if (name == null || "".equals(name.trim())) {
82             errors.add("name",new ActionMessage("error.name.input"));
83         }
84
85         // If any messages is required, save the specified error messages keys
86
// into the HTTP request for use by the <struts:errors> tag.
87
if (!errors.isEmpty()) {
88             saveErrors(request, errors);
89             // return to the original form
90
return (new ActionForward(mapping.getInput()));
91         }
92
93         // Forward control to the specified 'welcome' URI that is in the Action.xml
94
return (mapping.findForward("welcome"));
95     }
96
97 }
98
Popular Tags