1 package hero.struts.actions; 2 3 import java.io.IOException ; 4 import javax.servlet.ServletException ; 5 import javax.servlet.http.HttpServletRequest ; 6 import javax.servlet.http.HttpSession ; 7 import javax.servlet.http.HttpServletResponse ; 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 ; 16 17 18 25 public class HookAction extends AbstStrutsActionBase { 26 27 public boolean authenticate(String username, String password) { 28 return (true); 29 } 30 31 39 public ActionForward perform(ActionMapping mapping,ActionForm form, HttpServletRequest request, HttpServletResponse response) 40 throws IOException , ServletException { 41 42 ActionErrors errors = new ActionErrors(); 44 ActionForward actionForward = mapping.findForward(EDITACTIVITY); 45 46 String action = request.getParameter("hookAction"); 47 String hookName = request.getParameter("name"); 48 HttpSession session = request.getSession(); 49 String project = (String ) 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 actionForward = mapping.findForward(EDITACTIVITY); 60 } 61 if (action.equals("Edit") || action.equals("Edit2")) { 62 request.getSession(true).setAttribute("inter", "false"); 63 actionForward = mapping.findForward(CONFIGPROJECT); 65 } 66 if (action.equals("AddNode")) { 67 String name = (String ) session.getAttribute("nodename"); 68 String event = request.getParameter("event"); 69 String 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 actionForward = mapping.findForward(EDITACTIVITY); 85 } 86 if (action.equals("AddNode2")) { 87 String name = (String ) session.getAttribute("nodename"); 88 String event = request.getParameter("event"); 89 String type = request.getParameter("type"); 90 91 if (hookName.length() != 0 && event.length() != 0) { 92 int hookType = 0; 93 String 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 interhooks = new Vector (projectsession.getNodeInterHooks(name)); 116 request.getSession(true).setAttribute("interhooks", interhooks); 117 } else 118 errors.add("hook_error", new ActionError("error.interhook.mismatch")); 119 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 name = (String ) 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 value = hookForm.getValue(); 134 request.getSession(true).setAttribute("val", hookForm.getValue()); 135 String name = (String ) session.getAttribute("nodename"); 136 hookName = (String ) request.getSession(true).getAttribute("hoName"); 137 projectsession.setNodeInterHookValue(name,hookName,value); 138 Vector interhooks = new Vector (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 value = hookFo.getValue(); 155 hookName = (String ) request.getSession(true).getAttribute("hoName"); 156 request.getSession(true).setAttribute("inter", "false"); 157 projectsession.setInterHookValue(hookName,value); 158 session.setAttribute("interHooks", new Vector (projectsession.getInterHooks())); 159 actionForward = mapping.findForward(CONFIGPROJECT); 160 } 161 162 if (action.equals("AddNodeHook")) { 163 HookForm hookForm = (HookForm) form; 164 String value = hookForm.getValue(); 165 String name = (String ) session.getAttribute("nodename"); 166 hookName =(String ) 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 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 value = hookForm.getValue(); 179 hookName = 180 (String ) 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 (projectsession.getInterHooks())); 185 } catch (NumberFormatException 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 event = request.getParameter("event"); 193 String 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 actionForward = mapping.findForward(CONFIGPROJECT); 209 } 210 if (action.equals("Add2")) { 211 String event = request.getParameter("event"); 212 String type = request.getParameter("type"); 213 214 if (hookName.length() != 0 && event.length() != 0) { 215 int hookType = 0; 216 String 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 session.setAttribute("interHooks", new Vector (projectsession.getInterHooks())); 244 actionForward = mapping.findForward(CONFIGPROJECT); 245 request.getSession(true).setAttribute("inter", "true"); 246 } 247 if (action.equals("DeleteNode")) { 248 String name = (String ) session.getAttribute("nodename"); 249 projectsession.deleteNodeInterHook(name, hookName); 250 Vector interhooks = new Vector (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 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 session.setAttribute("interHooks", new Vector (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 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 return (actionForward); 281 } 282 } 283
| Popular Tags
|