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: import hero.struts.forms.*;
014: import hero.interfaces.*;
015: import java.util.Vector;
016:
017: /**
018: * <strong>PropertyAction</strong>
019: * Action that allows the user to add a new property.
020: * This action can be forward project or activity pages
021: *
022: *@author Miguel Valdes Faura
023: */
024: public class PropertyAction extends AbstStrutsActionBase {
025:
026: public boolean authenticate(String username, String password) {
027: return (true);
028: }
029:
030: /**
031: * @param mapping The ActionMapping used to select this instance
032: * @param actionForm The optional AbstActionFormBase bean for this request (if any)
033: * @param request The HTTP request we are processing
034: * @param response The HTTP response we are creating
035: * @exception IOException if an input/output error occurs
036: * @exception ServletException if a servlet exception occurs
037: */
038: public ActionForward perform(ActionMapping mapping,
039: ActionForm form, HttpServletRequest request,
040: HttpServletResponse response) throws IOException,
041: ServletException {
042: ActionForward actionForward = mapping.findForward(EDITACTIVITY);
043: // Create the container for any errors that occur
044: ActionErrors errors = new ActionErrors();
045:
046: String action = request.getParameter("propertyAction");
047: String key = request.getParameter("key");
048:
049: HttpSession session = request.getSession();
050: String project = (String) session.getAttribute("projectname");
051: PropertyForm propForm = (PropertyForm) form;
052:
053: try {
054: hero.interfaces.ProjectSessionLocalHome projecth = (ProjectSessionLocalHome) hero.interfaces.ProjectSessionUtil
055: .getLocalHome();
056: hero.interfaces.ProjectSessionLocal projectsession = projecth
057: .create();
058: projectsession.initProject(project);
059:
060: if (!isCancelled(request)) {
061: if (action.equals("EditNode")) {
062: session.setAttribute("prop", "0");
063: // Forward control to the specified 'success' URI specified in the structs-config.xml
064: actionForward = mapping.findForward(EDITACTIVITY);
065: }
066: if (action.equals("EditNodeProp")) {
067: // Forward control to the specified 'success' URI specified in the structs-config.xml
068: String name = (String) session
069: .getAttribute("nodename");
070: BnNodePropertyValue nodeProperty = projectsession
071: .getNodeProperty(name, key);
072: propForm.setKey(key);
073: propForm.setValue(nodeProperty.getTheValue());
074: session.setAttribute("PROP", propForm);
075: session.setAttribute("prop", "1");
076: actionForward = mapping.findForward(EDITACTIVITY);
077: }
078: if (action.equals("EditProjectProp")) {
079: session.setAttribute("projectProp", "1");
080: String value = request.getParameter("value");
081: propForm.setKey(key);
082: propForm.setValue(value);
083: session.setAttribute("ProjectProp", propForm);
084: request.getSession(true).setAttribute("project",
085: projectsession);
086: session.setAttribute("properties", new Vector(
087: projectsession.getProperties()));
088: actionForward = mapping.findForward(CONFIGPROJECT);
089: }
090: if (action.equals("Edit")) {
091: session.setAttribute("projectProp", "0");
092: // Forward control to the specified 'success' URI specified in the structs-config.xml
093: actionForward = mapping.findForward(CONFIGPROJECT);
094: }
095:
096: if (action.equals("AddNode")) {
097: session.setAttribute("action", "Initial");
098: String value = request.getParameter("value");
099: String name = (String) session
100: .getAttribute("nodename");
101: if (key.length() != 0 && value.length() != 0) {
102: projectsession
103: .setNodeProperty(name, key, value);
104: request.getSession(true).setAttribute("node",
105: projectsession.getStrutsNode(name));
106: Vector prop = new Vector(projectsession
107: .getNodeProperties(name));
108: request.getSession(true).setAttribute(
109: "properties", prop);
110: } else
111: errors.add("property_error", new ActionError(
112: "error.property.mismatch"));
113: // Forward control to the specified 'success' URI specified in the structs-config.xml
114: actionForward = mapping.findForward(EDITACTIVITY);
115: }
116:
117: if (action.equals("Add")) {
118: session.setAttribute("action", "Initial");
119: String value = request.getParameter("value");
120: if (key.length() != 0 && value.length() != 0) {
121: projectsession.setProperty(key, value);
122: request.getSession(true).setAttribute(
123: "project", projectsession);
124: session.setAttribute("properties", new Vector(
125: projectsession.getProperties()));
126: } else
127: errors.add("property_error", new ActionError(
128: "error.property.mismatch"));
129: // Forward control to the specified 'success' URI specified in the structs-config.xml
130: actionForward = mapping.findForward(CONFIGPROJECT);
131: }
132: if (action.equals("DeleteNode")) {
133: String name = (String) session
134: .getAttribute("nodename");
135: projectsession.deleteNodeProperty(name, key);
136: request.getSession(true).setAttribute("node",
137: projectsession.getStrutsNode(name));
138: Vector prop = new Vector(projectsession
139: .getNodeProperties(name));
140: request.getSession(true).setAttribute("properties",
141: prop);
142: // Forward control to the specified 'success' URI specified in the structs-config.xml
143: actionForward = mapping.findForward(EDITACTIVITY);
144: }
145: if (action.equals("Delete")) {
146: projectsession.deleteProperty(key);
147: session.setAttribute("properties", new Vector(
148: projectsession.getProperties()));
149: request.getSession(true).setAttribute("project",
150: projectsession);
151:
152: // Forward control to the specified 'success' URI specified in the structs-config.xml
153: actionForward = mapping.findForward(CONFIGPROJECT);
154: }
155: }
156: if (action.equals("Add"))
157: actionForward = mapping.findForward(CONFIGPROJECT);
158: } catch (Exception e) {
159: errors.add("property_error", new ActionError(
160: "error.property.mismatch"));
161: }
162:
163: if (!errors.empty()) {
164: saveErrors(request, errors);
165: }
166:
167: // Forward control to the appropriate URI as determined by the action.
168: return (actionForward);
169: }
170: }
|