01: /*
02: * Created on Feb 16, 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.data;
08:
09: import org.apache.struts.Globals;
10: import org.apache.struts.action.ActionError;
11: import org.apache.struts.action.ActionErrors;
12: import org.apache.struts.action.ActionForm;
13: import org.apache.struts.action.ActionForward;
14: import org.apache.struts.action.ActionMapping;
15: import org.vfny.geoserver.action.ConfigAction;
16: import org.vfny.geoserver.config.DataConfig;
17: import org.vfny.geoserver.config.StyleConfig;
18: import org.vfny.geoserver.form.data.StylesNewForm;
19: import org.vfny.geoserver.global.UserContainer;
20: import java.io.IOException;
21: import javax.servlet.ServletException;
22: import javax.servlet.http.HttpServletRequest;
23: import javax.servlet.http.HttpServletResponse;
24:
25: /**
26: * Create a new Style for editing (based on StyleNewForm information).
27: * <p>
28: * The new style will be placed in the UserContainer for editing,
29: * the session will be redirected to the editor.
30: * </p>
31: * <p>
32: * The new Style will not actually be added to the Configuration until
33: * the editor form is submitted.
34: * <p>
35: */
36: public class StylesNewAction extends ConfigAction {
37: public ActionForward execute(ActionMapping mapping,
38: ActionForm form, UserContainer user,
39: HttpServletRequest request, HttpServletResponse response)
40: throws IOException, ServletException {
41: StylesNewForm newForm = (StylesNewForm) form;
42: final String styleID = newForm.getStyleID();
43:
44: DataConfig config = getDataConfig();
45:
46: if (config.getStyles().containsKey(styleID)) {
47: ActionErrors errors = new ActionErrors();
48: errors.add("selectedStyle", new ActionError(
49: "error.style.exists", styleID));
50: request.setAttribute(Globals.ERROR_KEY, errors);
51:
52: return mapping.findForward("config.data.style.new");
53: }
54:
55: // Set up new StyleConfig
56: StyleConfig style = new StyleConfig();
57: style.setId(styleID);
58: style.setDefault(config.getStyles().isEmpty());
59:
60: // Pass style over to the Editor
61: user.setStyle(style);
62:
63: return mapping.findForward("config.data.style.editor");
64: }
65: }
|