KickJava   Java API By Example, From Geeks To Geeks.

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


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.interfaces.*;
14
15 /**
16  * <strong>NodeAction</strong>
17  * Action that allows the user to add a new node in the current project
18  *
19  *@author Miguel Valdes Faura
20  */

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

37     public ActionForward perform(ActionMapping mapping, ActionForm form,
38         HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws IOException JavaDoc, ServletException JavaDoc
39     {
40
41         ActionForward actionForward = mapping.findForward(PROJECT);
42         // Create the container for any errors that occur
43
ActionErrors errors = new ActionErrors();
44
45     String JavaDoc action = request.getParameter("nodeAction");
46     HttpSession JavaDoc session = request.getSession();
47     String JavaDoc project = (String JavaDoc)session.getAttribute("projectname");
48     String JavaDoc userName = (String JavaDoc)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             // Forward control to the specified 'success' URI specified in the structs-config.xml
61
actionForward = mapping.findForward(PROJECT);
62         }
63         if (action.equals("Activity"))
64         {
65           String JavaDoc name = request.getParameter("nodename");
66           hero.util.StrutsNodeValue node = projectsession.getStrutsNode(name);
67           request.getSession(true).setAttribute("node", node);
68
69           /*if (!node.getDeadline().equals("Deadline needed"))
70           {
71               java.sql.Timestamp deadline = java.sql.Timestamp.valueOf(node.getDeadline());
72               if (deadline.getTime() <= (new java.util.Date()).getTime() && !node.getState().equals("TERMINATED"));
73               errors.add("deadline_error", new ActionError("error.deadline"));
74           }*/

75
76           request.getSession(true).setAttribute("nodename", name);
77
78           // Forward control to the specified 'success' URI specified in the structs-config.xml
79
actionForward = mapping.findForward(ACTIVITY);
80           }
81
82           if (action.equals("Add"))
83           {
84           String JavaDoc nodeName = request.getParameter("name");
85           if (nodeName.length()!=0)
86           {
87               projectsession.addNode(nodeName,1);
88               //request.setAttribute("project", projectsession);
89
request.getSession(true).setAttribute("project", projectsession);
90               // Forward control to the specified 'success' URI specified in the structs-config.xml
91
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 JavaDoc nodeName = request.getParameter("nodename");
99           projectsession.deleteNode(nodeName);
100           request.getSession(true).setAttribute("project", projectsession);
101           
102           // Forward control to the specified 'success' URI specified in the structs-config.xml
103
actionForward = mapping.findForward(PROJECT);
104           }
105       }
106         // }catch(NodeExecutingException e){errors.add("node_error", new ActionError("error.nodeexecuting.mismatch"));
107
}catch(Exception JavaDoc e1){errors.add("node_error", new ActionError("error.nodeexisting.mismatch"));}
108
109     if (!errors.empty()) {
110             saveErrors(request, errors);
111         }
112
113         // Forward control to the appropriate URI as determined by the action.
114
return (actionForward);
115     }
116    
117
118 }
119
Popular Tags