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.struts.forms.*; 14 import hero.interfaces.*; 15 import java.util.Vector ; 16 17 24 public class PropertyAction extends AbstStrutsActionBase 25 { 26 27 public boolean authenticate(String username, String password) 28 { 29 return(true); 30 } 31 32 40 public ActionForward perform(ActionMapping mapping, ActionForm form, 41 HttpServletRequest request, HttpServletResponse response) throws IOException , ServletException 42 { 43 ActionForward actionForward = mapping.findForward(EDITACTIVITY); 44 ActionErrors errors = new ActionErrors(); 46 47 String action = request.getParameter("propertyAction"); 48 String key = request.getParameter("key"); 49 50 HttpSession session = request.getSession(); 51 String project = (String )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 actionForward = mapping.findForward(EDITACTIVITY); 67 } 68 if (action.equals("EditNodeProp")) 69 { 70 String name = (String )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 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 (projectsession.getProperties())); 88 actionForward = mapping.findForward(CONFIGPROJECT); 89 } 90 if (action.equals("Edit")) 91 { 92 session.setAttribute("projectProp", "0"); 93 actionForward = mapping.findForward(CONFIGPROJECT); 95 } 96 97 if (action.equals("AddNode")) 98 { 99 session.setAttribute("action","Initial"); 100 String value = request.getParameter("value"); 101 String name = (String )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 prop = new Vector (projectsession.getNodeProperties(name)); 107 request.getSession(true).setAttribute("properties", prop); 108 } 109 else 110 errors.add("property_error", new ActionError("error.property.mismatch")); 111 actionForward = mapping.findForward(EDITACTIVITY); 113 } 114 115 if (action.equals("Add")) 116 { 117 session.setAttribute("action","Initial"); 118 String 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 (projectsession.getProperties())); 124 } 125 else 126 errors.add("property_error", new ActionError("error.property.mismatch")); 127 actionForward = mapping.findForward(CONFIGPROJECT); 129 } 130 if (action.equals("DeleteNode")) 131 { 132 String name = (String )session.getAttribute("nodename"); 133 projectsession.deleteNodeProperty(name, key); 134 request.getSession(true).setAttribute("node", projectsession.getStrutsNode(name)); 135 Vector prop = new Vector (projectsession.getNodeProperties(name)); 136 request.getSession(true).setAttribute("properties", prop); 137 actionForward = mapping.findForward(EDITACTIVITY); 139 } 140 if (action.equals("Delete")) 141 { 142 projectsession.deleteProperty(key); 143 session.setAttribute("properties", new Vector (projectsession.getProperties())); 144 request.getSession(true).setAttribute("project", projectsession); 145 146 actionForward = mapping.findForward(CONFIGPROJECT); 148 } 149 } 150 if (action.equals("Add")) 151 actionForward = mapping.findForward(CONFIGPROJECT); 152 }catch(Exception e){errors.add("property_error", new ActionError("error.property.mismatch"));} 153 154 if (!errors.empty()) { 155 saveErrors(request, errors); 156 } 157 158 return (actionForward); 160 } 161 } 162
| Popular Tags
|