01: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
02: * This code is licensed under the GPL 2.0 license, availible at the root
03: * application directory.
04: */
05: package org.vfny.geoserver.action.data;
06:
07: import org.apache.struts.action.ActionForm;
08: import org.apache.struts.action.ActionForward;
09: import org.apache.struts.action.ActionMapping;
10: import org.apache.struts.util.MessageResources;
11: import org.vfny.geoserver.action.ConfigAction;
12: import org.vfny.geoserver.action.HTMLEncoder;
13: import org.vfny.geoserver.config.CoverageConfig;
14: import org.vfny.geoserver.config.DataConfig;
15: import org.vfny.geoserver.form.data.DataCoveragesSelectForm;
16: import org.vfny.geoserver.global.UserContainer;
17: import java.io.IOException;
18: import java.util.Locale;
19: import javax.servlet.ServletException;
20: import javax.servlet.http.HttpServletRequest;
21: import javax.servlet.http.HttpServletResponse;
22:
23: /**
24: * DOCUMENT ME!
25: *
26: * @author $Author: Alessio Fabiani (alessio.fabiani@gmail.com) $ (last
27: * modification)
28: * @author $Author: Simone Giannecchini (simboss1@gmail.com) $ (last
29: * modification)
30: */
31: public class DataCoveragesSelectAction extends ConfigAction {
32: public ActionForward execute(ActionMapping mapping,
33: ActionForm incomingForm, UserContainer user,
34: HttpServletRequest request, HttpServletResponse response)
35: throws IOException, ServletException {
36: DataCoveragesSelectForm form = (DataCoveragesSelectForm) incomingForm;
37:
38: String selectedCoverage = form.getSelectedCoverageName();
39: String buttonAction = form.getButtonAction();
40:
41: DataConfig dataConfig = (DataConfig) getServlet()
42: .getServletContext()
43: .getAttribute(DataConfig.CONFIG_KEY);
44:
45: CoverageConfig cvConfig = dataConfig
46: .getCoverageConfig(selectedCoverage);
47:
48: Locale locale = (Locale) request.getLocale();
49: MessageResources messages = getResources(request);
50: String edit = HTMLEncoder.decode(messages.getMessage(locale,
51: "label.edit"));
52: String delete = HTMLEncoder.decode(messages.getMessage(locale,
53: "label.delete"));
54:
55: if (edit.equals(buttonAction)) {
56: request.getSession().setAttribute(
57: DataConfig.SELECTED_COVERAGE, cvConfig);
58: user.setCoverageConfig(cvConfig);
59:
60: return mapping.findForward("config.data.coverage.editor");
61: } else if (delete.equals(buttonAction)) {
62: dataConfig.removeCoverage(selectedCoverage);
63: request.getSession().removeAttribute(
64: DataConfig.SELECTED_COVERAGE);
65: getApplicationState().notifyConfigChanged();
66:
67: return mapping.findForward("config.data.coverage");
68: }
69:
70: throw new ServletException(
71: "Action must be a MessageResource key value of either 'label.edit' or 'label.delete'");
72: }
73: }
|