001: package hero.struts.actions;
002:
003: import java.io.IOException;
004: import javax.servlet.ServletException;
005: import javax.servlet.http.HttpServletRequest;
006: import javax.servlet.http.HttpSession;
007: import javax.servlet.http.HttpServletResponse;
008: import org.apache.struts.action.ActionError;
009: import org.apache.struts.action.ActionErrors;
010: import org.apache.struts.action.ActionForm;
011: import org.apache.struts.action.ActionMapping;
012: import org.apache.struts.action.ActionForward;
013:
014: import hero.interfaces.*;
015:
016: /**
017: * <strong>EdgeAction</strong>
018: * Action that allows the user to add a new edge in the current project
019: *
020: *@author Miguel Valdes Faura
021: */
022: public class EdgeAction extends AbstStrutsActionBase {
023:
024: public boolean authenticate(String username, String password) {
025: return (true);
026: }
027:
028: /**
029: * @param mapping The ActionMapping used to select this instance
030: * @param actionForm The optional AbstActionFormBase bean for this request (if any)
031: * @param request The HTTP request we are processing
032: * @param response The HTTP response we are creating
033: * @exception IOException if an input/output error occurs
034: * @exception ServletException if a servlet exception occurs
035: */
036: public ActionForward perform(ActionMapping mapping,
037: ActionForm form, HttpServletRequest request,
038: HttpServletResponse response) throws IOException,
039: ServletException {
040:
041: ActionForward actionForward = mapping.findForward(PROJECT);
042: // Create the container for any errors that occur
043: ActionErrors errors = new ActionErrors();
044:
045: String action = request.getParameter("edgeAction");
046: HttpSession session = request.getSession();
047: String project = (String) session.getAttribute("projectname");
048:
049: try {
050: hero.interfaces.ProjectSessionLocalHome projecth = (ProjectSessionLocalHome) hero.interfaces.ProjectSessionUtil
051: .getLocalHome();
052: hero.interfaces.ProjectSessionLocal projectsession = projecth
053: .create();
054: projectsession.initProject(project);
055:
056: if (!isCancelled(request)) {
057: if (action.equals("Edit")) {
058: // Forward control to the specified 'success' URI specified in the structs-config.xml
059: actionForward = mapping.findForward(PROJECT);
060: }
061: if (action.equals("Add")) {
062:
063: String in = request.getParameter("nodeIn");
064: String out = request.getParameter("nodeOut");
065: projectsession.addEdge(in, out);
066: request.getSession(true).setAttribute("project",
067: projectsession);
068:
069: // Forward control to the specified 'success' URI specified in the structs-config.xml
070: actionForward = mapping.findForward(PROJECT);
071: }
072: if (action.equals("Delete")) {
073: try {
074: String edgeName = request.getParameter("name");
075: projectsession.deleteEdge(edgeName);
076: } catch (Exception e3) {
077: errors.add("edge_error", new ActionError(
078: "error.deleteedge.mismatch"));
079: }
080: request.getSession(true).setAttribute("project",
081: projectsession);
082:
083: // Forward control to the specified 'success' URI specified in the structs-config.xml
084: actionForward = mapping.findForward(PROJECT);
085: }
086: }
087: // }catch(DuplicatedEdgeException e){errors.add("edge_error", new ActionError("error.duplicateedge.mismatch"));
088: //}catch(NodeStartedException e1){errors.add("edge_error", new ActionError("error.startededge.mismatch"));
089: } catch (Exception e2) {
090: errors.add("edge_error", new ActionError(
091: "error.edge.mismatch"));
092: }
093:
094: if (!errors.empty()) {
095: saveErrors(request, errors);
096: }
097:
098: // Forward control to the appropriate URI as determined by the action.
099: return (actionForward);
100: }
101:
102: }
|