KickJava   Java API By Example, From Geeks To Geeks.

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


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  * <strong>PropertyAction</strong>
19  * Action that allows the user to add a new property.
20  * This action can be forward project or activity pages
21  *
22  *@author Miguel Valdes Faura
23  */

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

40     public ActionForward perform(ActionMapping mapping, ActionForm form,
41         HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws IOException JavaDoc, ServletException JavaDoc
42     {
43         ActionForward actionForward = mapping.findForward(EDITACTIVITY);
44         // Create the container for any errors that occur
45
ActionErrors errors = new ActionErrors();
46
47     String JavaDoc action = request.getParameter("propertyAction");
48     String JavaDoc key = request.getParameter("key");
49
50     HttpSession JavaDoc session = request.getSession();
51     String JavaDoc project = (String JavaDoc)session.getAttribute("projectname");
52         PropertyForm propForm = (PropertyForm) form;
53
54     try
55     {
56         hero.interfaces.ProjectSessionLocalHome projecth = (ProjectSessionLocalHome)hero.interfaces.ProjectSessionUtil.getLocalHome();
57         hero.interfaces.ProjectSessionLocal projectsession = projecth.create();
58         projectsession.initProject(project);
59         
60         if (!isCancelled(request))
61         {
62         if (action.equals("EditNode"))
63         {
64             session.setAttribute("prop","0");
65             // Forward control to the specified 'success' URI specified in the structs-config.xml
66
actionForward = mapping.findForward(EDITACTIVITY);
67         }
68         if (action.equals("EditNodeProp"))
69         {
70             // Forward control to the specified 'success' URI specified in the structs-config.xml
71
String JavaDoc name = (String JavaDoc)session.getAttribute("nodename");
72             BnNodePropertyValue nodeProperty = projectsession.getNodeProperty(name,key);
73             propForm.setKey(key);
74             propForm.setValue(nodeProperty.getTheValue());
75                     session.setAttribute("PROP", propForm);
76                     session.setAttribute("prop", "1");
77             actionForward = mapping.findForward(EDITACTIVITY);
78         }
79                 if (action.equals("EditProjectProp"))
80         {
81             session.setAttribute("projectProp", "1");
82             String JavaDoc value = request.getParameter("value");
83             propForm.setKey(key);
84             propForm.setValue(value);
85             session.setAttribute("ProjectProp", propForm);
86             request.getSession(true).setAttribute("project", projectsession);
87             session.setAttribute("properties", new Vector JavaDoc(projectsession.getProperties()));
88             actionForward = mapping.findForward(CONFIGPROJECT);
89         }
90         if (action.equals("Edit"))
91         {
92             session.setAttribute("projectProp", "0");
93             // Forward control to the specified 'success' URI specified in the structs-config.xml
94
actionForward = mapping.findForward(CONFIGPROJECT);
95         }
96         
97         if (action.equals("AddNode"))
98         {
99             session.setAttribute("action","Initial");
100             String JavaDoc value = request.getParameter("value");
101             String JavaDoc name = (String JavaDoc)session.getAttribute("nodename");
102             if (key.length()!=0 && value.length()!=0)
103             {
104             projectsession.setNodeProperty(name, key, value);
105             request.getSession(true).setAttribute("node", projectsession.getStrutsNode(name));
106             Vector JavaDoc prop = new Vector JavaDoc(projectsession.getNodeProperties(name));
107             request.getSession(true).setAttribute("properties", prop);
108             }
109             else
110               errors.add("property_error", new ActionError("error.property.mismatch"));
111             // Forward control to the specified 'success' URI specified in the structs-config.xml
112
actionForward = mapping.findForward(EDITACTIVITY);
113         }
114         
115         if (action.equals("Add"))
116         {
117             session.setAttribute("action","Initial");
118             String JavaDoc value = request.getParameter("value");
119             if (key.length()!=0 && value.length()!=0)
120             {
121             projectsession.setProperty(key, value);
122             request.getSession(true).setAttribute("project", projectsession);
123             session.setAttribute("properties", new Vector JavaDoc(projectsession.getProperties()));
124             }
125             else
126             errors.add("property_error", new ActionError("error.property.mismatch"));
127             // Forward control to the specified 'success' URI specified in the structs-config.xml
128
actionForward = mapping.findForward(CONFIGPROJECT);
129         }
130         if (action.equals("DeleteNode"))
131         {
132             String JavaDoc name = (String JavaDoc)session.getAttribute("nodename");
133             projectsession.deleteNodeProperty(name, key);
134             request.getSession(true).setAttribute("node", projectsession.getStrutsNode(name));
135             Vector JavaDoc prop = new Vector JavaDoc(projectsession.getNodeProperties(name));
136             request.getSession(true).setAttribute("properties", prop);
137             // Forward control to the specified 'success' URI specified in the structs-config.xml
138
actionForward = mapping.findForward(EDITACTIVITY);
139         }
140         if (action.equals("Delete"))
141             {
142             projectsession.deleteProperty(key);
143             session.setAttribute("properties", new Vector JavaDoc(projectsession.getProperties()));
144             request.getSession(true).setAttribute("project", projectsession);
145             
146             // Forward control to the specified 'success' URI specified in the structs-config.xml
147
actionForward = mapping.findForward(CONFIGPROJECT);
148             }
149         }
150         if (action.equals("Add"))
151         actionForward = mapping.findForward(CONFIGPROJECT);
152     }catch(Exception JavaDoc e){errors.add("property_error", new ActionError("error.property.mismatch"));}
153     
154     if (!errors.empty()) {
155             saveErrors(request, errors);
156         }
157
158         // Forward control to the appropriate URI as determined by the action.
159
return (actionForward);
160     }
161 }
162
Popular Tags