01: /*
02: * Created on Jan 22, 2004
03: *
04: * To change the template for this generated file go to
05: * Window - Preferences - Java - Code Generation - Code and Comments
06: */
07: package org.vfny.geoserver.action.validation;
08:
09: import org.apache.struts.action.ActionForm;
10: import org.apache.struts.action.ActionForward;
11: import org.apache.struts.action.ActionMapping;
12: import org.vfny.geoserver.action.ConfigAction;
13: import org.vfny.geoserver.config.validation.TestConfig;
14: import org.vfny.geoserver.config.validation.TestSuiteConfig;
15: import org.vfny.geoserver.config.validation.ValidationConfig;
16: import org.vfny.geoserver.form.validation.ValidationTestEditorForm;
17: import org.vfny.geoserver.global.UserContainer;
18: import java.util.List;
19: import javax.servlet.ServletContext;
20: import javax.servlet.http.HttpServletRequest;
21: import javax.servlet.http.HttpServletResponse;
22:
23: /**
24: * ValidationTestEditorAction purpose.
25: * <p>
26: * Description of ValidationTestEditorAction ...
27: * </p>
28: *
29: * <p>
30: * Capabilities:
31: * </p>
32: * <ul>
33: * <li>
34: * Feature: description
35: * </li>
36: * </ul>
37: * <p>
38: * Example Use:
39: * </p>
40: * <pre><code>
41: * ValidationTestEditorAction x = new ValidationTestEditorAction(...);
42: * </code></pre>
43: *
44: * @author User, Refractions Research, Inc.
45: * @author $Author: dmzwiers $ (last modification)
46: * @version $Id: ValidationTestEditorAction.java 6177 2007-02-19 10:11:27Z aaime $
47: */
48: public class ValidationTestEditorAction extends ConfigAction {
49: public ActionForward execute(ActionMapping mapping,
50: ActionForm incomingForm, UserContainer user,
51: HttpServletRequest request, HttpServletResponse response) {
52: ValidationTestEditorForm form = (ValidationTestEditorForm) incomingForm;
53:
54: String name = form.getName();
55: String description = form.getDescription();
56: List attributeKeys = form.getAttributeKeys();
57: List attributeValues = form.getAttributeValues();
58:
59: ServletContext context = getServlet().getServletContext();
60: ValidationConfig validationConfig = (ValidationConfig) context
61: .getAttribute(ValidationConfig.CONFIG_KEY);
62: TestSuiteConfig suiteConfig = (TestSuiteConfig) request
63: .getSession().getAttribute(
64: TestSuiteConfig.CURRENTLY_SELECTED_KEY);
65: TestConfig testConfig = (TestConfig) request.getSession()
66: .getAttribute(TestConfig.CURRENTLY_SELECTED_KEY);
67:
68: //this allows renaming. If they change the test's name, we just remove it add a new one
69: suiteConfig.removeTest(testConfig.getName());
70:
71: testConfig.setName(name);
72: testConfig.setDescription(description);
73:
74: for (int i = 0; i < attributeKeys.size(); i++) {
75: System.out.println((String) attributeKeys.get(i) + "="
76: + (String) attributeValues.get(i));
77: System.out.println(testConfig.getArgs());
78:
79: String val = (String) attributeValues.get(i);
80:
81: if ((val != null) && (val != "")) {
82: testConfig.setArgStringValue((String) attributeKeys
83: .get(i), val);
84: }
85: }
86:
87: suiteConfig.addTest(testConfig);
88: getApplicationState().notifyConfigChanged();
89:
90: request.getSession().removeAttribute(
91: TestConfig.CURRENTLY_SELECTED_KEY);
92:
93: return mapping.findForward("validationTest");
94: }
95: }
|