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.interfaces.*; 14 15 21 public class NodeAction extends AbstStrutsActionBase 22 { 23 24 public boolean authenticate(String username, String password) 25 { 26 return(true); 27 } 28 29 37 public ActionForward perform(ActionMapping mapping, ActionForm form, 38 HttpServletRequest request, HttpServletResponse response) throws IOException , ServletException 39 { 40 41 ActionForward actionForward = mapping.findForward(PROJECT); 42 ActionErrors errors = new ActionErrors(); 44 45 String action = request.getParameter("nodeAction"); 46 HttpSession session = request.getSession(); 47 String project = (String )session.getAttribute("projectname"); 48 String userName = (String )session.getAttribute("username"); 49 50 try 51 { 52 hero.interfaces.ProjectSessionLocalHome projecth = (ProjectSessionLocalHome)hero.interfaces.ProjectSessionUtil.getLocalHome(); 53 hero.interfaces.ProjectSessionLocal projectsession = projecth.create(); 54 projectsession.initProject(project); 55 56 if (!isCancelled(request)) 57 { 58 if (action.equals("Edit")) 59 { 60 actionForward = mapping.findForward(PROJECT); 62 } 63 if (action.equals("Activity")) 64 { 65 String name = request.getParameter("nodename"); 66 hero.util.StrutsNodeValue node = projectsession.getStrutsNode(name); 67 request.getSession(true).setAttribute("node", node); 68 69 75 76 request.getSession(true).setAttribute("nodename", name); 77 78 actionForward = mapping.findForward(ACTIVITY); 80 } 81 82 if (action.equals("Add")) 83 { 84 String nodeName = request.getParameter("name"); 85 if (nodeName.length()!=0) 86 { 87 projectsession.addNode(nodeName,1); 88 request.getSession(true).setAttribute("project", projectsession); 90 actionForward = mapping.findForward(PROJECT); 92 } 93 else 94 errors.add("node_error", new ActionError("error.node.mismatch")); 95 } 96 if (action.equals("Delete")) 97 { 98 String nodeName = request.getParameter("nodename"); 99 projectsession.deleteNode(nodeName); 100 request.getSession(true).setAttribute("project", projectsession); 101 102 actionForward = mapping.findForward(PROJECT); 104 } 105 } 106 }catch(Exception e1){errors.add("node_error", new ActionError("error.nodeexisting.mismatch"));} 108 109 if (!errors.empty()) { 110 saveErrors(request, errors); 111 } 112 113 return (actionForward); 115 } 116 117 118 } 119
| Popular Tags
|