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.apache.struts.util.MessageResources;
13: import org.vfny.geoserver.action.ConfigAction;
14: import org.vfny.geoserver.config.validation.TestConfig;
15: import org.vfny.geoserver.config.validation.TestSuiteConfig;
16: import org.vfny.geoserver.config.validation.ValidationConfig;
17: import org.vfny.geoserver.form.validation.ValidationTestSelectForm;
18: import org.vfny.geoserver.global.UserContainer;
19: import java.util.Locale;
20: import java.util.Map;
21: import javax.servlet.ServletContext;
22: import javax.servlet.ServletException;
23: import javax.servlet.http.HttpServletRequest;
24: import javax.servlet.http.HttpServletResponse;
25:
26: /**
27: * ValidationTestSelectAction purpose.
28: * <p>
29: * Description of ValidationTestSelectAction ...
30: * </p>
31: *
32: * @author rgould, Refractions Research, Inc.
33: * @author $Author: dmzwiers $ (last modification)
34: * @version $Id: ValidationTestSelectAction.java 6177 2007-02-19 10:11:27Z aaime $
35: */
36: public class ValidationTestSelectAction extends ConfigAction {
37: public ActionForward execute(ActionMapping mapping,
38: ActionForm incomingForm, UserContainer user,
39: HttpServletRequest request, HttpServletResponse response)
40: throws ServletException {
41: ValidationTestSelectForm form = (ValidationTestSelectForm) incomingForm;
42:
43: String selectedTest = form.getSelectedTest();
44: String buttonAction = form.getButtonAction();
45:
46: Locale locale = (Locale) request.getLocale();
47: MessageResources messages = getResources(request);
48: String edit = messages.getMessage(locale, "label.edit");
49: String delete = messages.getMessage(locale, "label.delete");
50:
51: ServletContext context = this .getServlet().getServletContext();
52: ValidationConfig validationConfig = (ValidationConfig) context
53: .getAttribute(ValidationConfig.CONFIG_KEY);
54: TestSuiteConfig suiteConfig = (TestSuiteConfig) request
55: .getSession().getAttribute(
56: TestSuiteConfig.CURRENTLY_SELECTED_KEY);
57:
58: if (edit.equals(buttonAction)) {
59: TestConfig testConfig = (TestConfig) suiteConfig.getTests()
60: .get(selectedTest);
61: request.getSession().setAttribute(
62: TestConfig.CURRENTLY_SELECTED_KEY, testConfig);
63:
64: return mapping.findForward("validationTestEditor");
65: } else if (delete.equals(buttonAction)) {
66: Map tests = suiteConfig.getTests();
67: tests.remove(selectedTest);
68: suiteConfig.setTests(tests);
69: getApplicationState().notifyConfigChanged();
70:
71: request.getSession().removeAttribute(
72: TestConfig.CURRENTLY_SELECTED_KEY);
73:
74: return mapping.findForward("validationTest");
75: }
76:
77: throw new ServletException(
78: "Action must be a MessageResource key value of either 'label.edit' or 'label.delete'");
79: }
80: }
|