KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hero > struts > actions > HookAction


1 package hero.struts.actions;
2
3 import java.io.IOException JavaDoc;
4 import javax.servlet.ServletException JavaDoc;
5 import javax.servlet.http.HttpServletRequest JavaDoc;
6 import javax.servlet.http.HttpSession JavaDoc;
7 import javax.servlet.http.HttpServletResponse JavaDoc;
8 import org.apache.struts.action.ActionError;
9 import org.apache.struts.action.ActionErrors;
10 import org.apache.struts.action.ActionForm;
11 import org.apache.struts.action.ActionMapping;
12 import org.apache.struts.action.ActionForward;
13 import hero.struts.forms.*;
14 import hero.interfaces.*;
15 import java.util.Vector JavaDoc;
16
17
18 /**
19  * <strong>HookAction</strong>
20  * Action that allows the user to add a new hook.
21  * This action can be forward project or activity pages
22  *
23  *@author valdes@loria.fr
24  */

25 public class HookAction extends AbstStrutsActionBase {
26
27     public boolean authenticate(String JavaDoc username, String JavaDoc password) {
28     return (true);
29     }
30     
31     /**
32      * @param mapping The ActionMapping used to select this instance
33      * @param actionForm The optional AbstActionFormBase bean for this request (if any)
34      * @param request The HTTP request we are processing
35      * @param response The HTTP response we are creating
36      * @exception IOException if an input/output error occurs
37      * @exception ServletException if a servlet exception occurs
38      */

39     public ActionForward perform(ActionMapping mapping,ActionForm form, HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response)
40     throws IOException JavaDoc, ServletException JavaDoc {
41     
42     // Create the container for any errors that occur
43
ActionErrors errors = new ActionErrors();
44         ActionForward actionForward = mapping.findForward(EDITACTIVITY);
45     
46     String JavaDoc action = request.getParameter("hookAction");
47     String JavaDoc hookName = request.getParameter("name");
48     HttpSession JavaDoc session = request.getSession();
49     String JavaDoc project = (String JavaDoc) session.getAttribute("projectname");
50     try {
51         hero.interfaces.ProjectSessionLocalHome projecth =(ProjectSessionLocalHome) hero.interfaces.ProjectSessionUtil.getLocalHome();
52         hero.interfaces.ProjectSessionLocal projectsession =projecth.create();
53         projectsession.initProject(project);
54         
55         if (!isCancelled(request)) {
56         if (action.equals("EditNode") || action.equals("EditNode2")) {
57             request.getSession(true).setAttribute("inter", "false");
58             // Forward control to the specified 'success' URI specified in the structs-config.xml
59
actionForward = mapping.findForward(EDITACTIVITY);
60         }
61         if (action.equals("Edit") || action.equals("Edit2")) {
62             request.getSession(true).setAttribute("inter", "false");
63             // Forward control to the specified 'success' URI specified in the structs-config.xml
64
actionForward = mapping.findForward(CONFIGPROJECT);
65         }
66         if (action.equals("AddNode")) {
67             String JavaDoc name = (String JavaDoc) session.getAttribute("nodename");
68             String JavaDoc event = request.getParameter("event");
69             String JavaDoc type = request.getParameter("type");
70             if (hookName.length() != 0 && event.length() != 0) {
71             int hookType = 0;
72             if (type.equals("Java"))
73                 hookType = 0;
74             if (type.equals("Tcl"))
75                 hookType = 4;
76             if (type.equals("BeanShell"))
77                 hookType = 5;
78                 
79             projectsession.addNodeHook(name,hookName,event,hookType);
80             request.getSession(true).setAttribute("node",projectsession.getStrutsNode(name));
81             } else
82             errors.add("hook_error", new ActionError("error.hookparameter.mismatch"));
83             // Forward control to the specified 'success' URI specified in the structs-config.xml
84
actionForward = mapping.findForward(EDITACTIVITY);
85         }
86         if (action.equals("AddNode2")) {
87             String JavaDoc name = (String JavaDoc) session.getAttribute("nodename");
88             String JavaDoc event = request.getParameter("event");
89             String JavaDoc type = request.getParameter("type");
90             
91             if (hookName.length() != 0 && event.length() != 0) {
92             int hookType = 0;
93             String JavaDoc firstValue = "";
94             if (type.equals("InteractionBS"))
95                 hookType = 6;
96             
97             if (event.equals("afterStart"))
98                 firstValue = Constants.AFTERSTART;
99             if (event.equals("beforeStart"))
100                 firstValue = Constants.BEFORESTART;
101             if (event.equals("afterTerminate"))
102                 firstValue = Constants.AFTERTERMINATE;
103             if (event.equals("beforeTerminate"))
104                 firstValue = Constants.BEFORETERMINATE;
105             if (event.equals("anticipate"))
106                 firstValue = Constants.ANTICIPATE;
107             if (event.equals("onCancel"))
108                 firstValue = Constants.ONCANCEL;
109             
110             projectsession.addNodeInterHook(name,hookName,event,hookType,firstValue);
111             request.getSession(true).setAttribute("node",projectsession.getStrutsNode(name));
112             request.getSession(true).setAttribute("hookName",hookName);
113             HookForm hookForm = (HookForm) form;
114             hookForm.setValue(firstValue);
115             Vector JavaDoc interhooks = new Vector JavaDoc(projectsession.getNodeInterHooks(name));
116             request.getSession(true).setAttribute("interhooks", interhooks);
117             } else
118             errors.add("hook_error", new ActionError("error.interhook.mismatch"));
119             // Forward control to the specified 'success' URI specified in the structs-config.xml
120
actionForward = mapping.findForward(EDITACTIVITY);
121             request.getSession(true).setAttribute("inter", "true");
122         }
123                 if (action.equals("editScript")) {
124             request.getSession(true).setAttribute("inter", "false");
125             String JavaDoc name = (String JavaDoc) session.getAttribute("nodename");
126             request.getSession(true).setAttribute("scri", projectsession.getNodeInterHookValue(name,hookName));
127             request.getSession(true).setAttribute("hoName", hookName);
128             actionForward = mapping.findForward(EDITACTIVITY);
129         }
130                 if (action.equals("addEditScript")) {
131             request.getSession(true).setAttribute("inter", "false");
132             HookForm hookForm = (HookForm) form;
133             String JavaDoc value = hookForm.getValue();
134             request.getSession(true).setAttribute("val", hookForm.getValue());
135             String JavaDoc name = (String JavaDoc) session.getAttribute("nodename");
136             hookName = (String JavaDoc) request.getSession(true).getAttribute("hoName");
137             projectsession.setNodeInterHookValue(name,hookName,value);
138             Vector JavaDoc interhooks = new Vector JavaDoc(projectsession.getNodeInterHooks(name));
139                 request.getSession(true).setAttribute("interhooks", interhooks);
140             actionForward = mapping.findForward(EDITACTIVITY);
141         }
142
143         if (action.equals("editProjectScript")) {
144             request.getSession(true).setAttribute("inter", "false");
145             request.getSession(true).setAttribute("scri", projectsession.getInterHookValue(hookName));
146             request.getSession(true).setAttribute("hoName", hookName);
147             request.getSession(true).setAttribute("project", projectsession);
148             System.out.println("PROJECTSEEION");
149             System.out.println(projectsession);
150             actionForward = mapping.findForward(CONFIGPROJECT);
151         }
152                 if (action.equals("addEditProjectScript")) {
153                     HookForm hookFo = (HookForm) form;
154             String JavaDoc value = hookFo.getValue();
155             hookName = (String JavaDoc) request.getSession(true).getAttribute("hoName");
156             request.getSession(true).setAttribute("inter", "false");
157             projectsession.setInterHookValue(hookName,value);
158             session.setAttribute("interHooks", new Vector JavaDoc(projectsession.getInterHooks()));
159                 actionForward = mapping.findForward(CONFIGPROJECT);
160         }
161
162         if (action.equals("AddNodeHook")) {
163             HookForm hookForm = (HookForm) form;
164             String JavaDoc value = hookForm.getValue();
165             String JavaDoc name = (String JavaDoc) session.getAttribute("nodename");
166             hookName =(String JavaDoc) request.getSession(true).getAttribute("hookName");
167             try {
168             projectsession.setNodeInterHookValue(name,hookName,value);
169             request.getSession(true).setAttribute("node",projectsession.getStrutsNode(name));
170             } catch (NumberFormatException JavaDoc etype) {
171             errors.add("hook_error",new ActionError("error.hooktype.mismatch"));
172             }
173             request.getSession(true).setAttribute("inter", "false");
174             actionForward = mapping.findForward(EDITACTIVITY);
175         }
176         if (action.equals("AddHook")) {
177             HookForm hookForm = (HookForm) form;
178             String JavaDoc value = hookForm.getValue();
179             hookName =
180             (String JavaDoc) request.getSession(true).getAttribute("hookName");
181             try {
182             projectsession.setInterHookValue(hookName, value);
183             request.getSession(true).setAttribute("project",projectsession);
184             session.setAttribute("interHooks", new Vector JavaDoc(projectsession.getInterHooks()));
185             } catch (NumberFormatException JavaDoc etype) {
186             errors.add("hook_error",new ActionError("error.hooktype.mismatch"));
187             }
188             request.getSession(true).setAttribute("inter", "false");
189             actionForward = mapping.findForward(CONFIGPROJECT);
190         }
191         if (action.equals("Add")) {
192             String JavaDoc event = request.getParameter("event");
193             String JavaDoc type = request.getParameter("type");
194             if (hookName.length() != 0 && event.length() != 0) {
195             int hookType = 0;
196             if (type.equals("Java"))
197                 hookType = 0;
198             if (type.equals("Tcl"))
199                 hookType = 4;
200             if (type.equals("BeanShell"))
201                 hookType = 5;
202             
203             projectsession.addHook(hookName, event, hookType);
204             request.getSession(true).setAttribute("project",projectsession);
205             } else
206             errors.add("hook_error", new ActionError("error.hookparameter.mismatch"));
207             // Forward control to the specified 'success' URI specified in the structs-config.xml
208
actionForward = mapping.findForward(CONFIGPROJECT);
209                 }
210         if (action.equals("Add2")) {
211             String JavaDoc event = request.getParameter("event");
212             String JavaDoc type = request.getParameter("type");
213             
214             if (hookName.length() != 0 && event.length() != 0) {
215             int hookType = 0;
216             String JavaDoc firstValue = "";
217             if (type.equals("InteractionBS"))
218                 hookType = 6;
219
220                 if (event.equals("afterStart"))
221                 firstValue = Constants.AFTERSTART;
222                 if (event.equals("beforeStart"))
223                 firstValue = Constants.BEFORESTART;
224                 if (event.equals("afterTerminate"))
225                 firstValue = Constants.AFTERTERMINATE;
226                 if (event.equals("beforeTerminate"))
227                 firstValue = Constants.BEFORETERMINATE;
228                 if (event.equals("onCancel"))
229                 firstValue = Constants.ONCANCEL;
230                 if (event.equals("anticipate"))
231                 firstValue = Constants.ANTICIPATE;
232         
233                     
234             projectsession.addInterHook(hookName,event,hookType,firstValue);
235             request.getSession(true).setAttribute("project",projectsession);
236             request.getSession(true).setAttribute("hookName",hookName);
237             HookForm hookForm = (HookForm) form;
238             hookForm.setValue(firstValue);
239                 
240             } else
241             errors.add("hook_error",new ActionError("error.interhook.mismatch"));
242             // Forward control to the specified 'success' URI specified in the structs-config.xml
243
session.setAttribute("interHooks", new Vector JavaDoc(projectsession.getInterHooks()));
244             actionForward = mapping.findForward(CONFIGPROJECT);
245             request.getSession(true).setAttribute("inter", "true");
246         }
247         if (action.equals("DeleteNode")) {
248             String JavaDoc name = (String JavaDoc) session.getAttribute("nodename");
249             projectsession.deleteNodeInterHook(name, hookName);
250             Vector JavaDoc interhooks = new Vector JavaDoc(projectsession.getNodeInterHooks(name));
251             request.getSession(true).setAttribute("interhooks", interhooks);
252             request.getSession(true).setAttribute("node",projectsession.getStrutsNode(name));
253             request.getSession(true).setAttribute("inter", "false");
254             // Forward control to the specified 'success' URI specified in the structs-config.xml
255
actionForward = mapping.findForward(EDITACTIVITY);
256         }
257         if (action.equals("Delete")) {
258             projectsession.deleteInterHook(hookName);
259             request.getSession(true).setAttribute("project",projectsession);
260                 request.getSession(true).setAttribute("inter", "false");
261             // Forward control to the specified 'success' URI specified in the structs-config.xml
262
session.setAttribute("interHooks", new Vector JavaDoc(projectsession.getInterHooks()));
263             actionForward = mapping.findForward(CONFIGPROJECT);
264         }
265         }
266         else if (action.equals("AddHook"))
267         actionForward = mapping.findForward(CONFIGPROJECT);
268         else if (action.equals("AddNodeHook"))
269         request.getSession(true).setAttribute("inter", "false");
270     } catch (Exception JavaDoc e) {
271         errors.add("hook_error", new ActionError("error.interhook.mismatch"));
272         if (action.equals("Add") || action.equals("Add2"))
273         actionForward = mapping.findForward(CONFIGPROJECT);
274     }
275
276     if (!errors.empty()) {
277         saveErrors(request, errors);
278     }
279     // Forward control to the appropriate URI as determined by the action.
280
return (actionForward);
281     }
282 }
283
Popular Tags