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