001: /* Copyright (c) 2001 - 2007 TOPP - www.openplans.org. All rights reserved.
002: * This code is licensed under the GPL 2.0 license, availible at the root
003: * application directory.
004: */
005:
006: /*
007: * Created on Jan 8, 2004
008: *
009: * To change the template for this generated file go to
010: * Window>Preferences>Java>Code Generation>Code and Comments
011: */
012: package org.vfny.geoserver.form.data;
013:
014: import org.apache.struts.action.ActionError;
015: import org.apache.struts.action.ActionErrors;
016: import org.apache.struts.action.ActionForm;
017: import org.apache.struts.action.ActionMapping;
018: import org.vfny.geoserver.config.ConfigRequests;
019: import org.vfny.geoserver.config.DataConfig;
020: import org.vfny.geoserver.config.StyleConfig;
021: import org.vfny.geoserver.global.UserContainer;
022: import org.vfny.geoserver.util.Requests;
023: import java.util.Iterator;
024: import java.util.TreeSet;
025: import javax.servlet.ServletContext;
026: import javax.servlet.http.HttpServletRequest;
027:
028: /**
029: * Holds the current selection, and set of styles.
030: * <p>
031: * Current style selection is held in the UserContainer.
032: * </p>
033: * @author jgarnett, Refractions Research
034: */
035: public class StylesSelectForm extends ActionForm {
036: /** Selected style ID */
037: private String selectedStyle;
038:
039: /** Action requested on selectedStyle */
040: private String action;
041:
042: /** Sorted set of styles IDs */
043: private TreeSet styles;
044:
045: public void reset(ActionMapping arg0, HttpServletRequest request) {
046: super .reset(arg0, request);
047:
048: ServletContext context = getServlet().getServletContext();
049: DataConfig config = ConfigRequests.getDataConfig(request);
050:
051: styles = new TreeSet();
052:
053: Iterator i = config.getStyles().values().iterator();
054: boolean defaultSet = false;
055:
056: while (i.hasNext()) {
057: StyleConfig sc = (StyleConfig) i.next();
058:
059: if (sc.isDefault()) {
060: styles.add(sc.getId() + "*");
061: defaultSet = true;
062: } else {
063: styles.add(sc.getId());
064: }
065: }
066:
067: StyleConfig sConfig;
068:
069: UserContainer user = Requests.getUserContainer(request);
070: selectedStyle = "";
071: }
072:
073: public ActionErrors validate(ActionMapping mapping,
074: HttpServletRequest request) {
075: ActionErrors errors = new ActionErrors();
076:
077: if ((selectedStyle == null) || selectedStyle.equals("")) {
078: errors.add("selectedStyle", new ActionError(
079: "error.style.required", selectedStyle));
080: }
081:
082: if (!styles.contains(selectedStyle)) {
083: errors.add("selectedStyle", new ActionError(
084: "error.style.invalid", selectedStyle));
085: }
086:
087: return errors;
088: }
089:
090: /**
091: * Access selectedStyle property.
092: *
093: * @return Returns the selectedStyle.
094: */
095: public String getSelectedStyle() {
096: return selectedStyle;
097: }
098:
099: /**
100: * Set selectedStyle to selectedStyle.
101: *
102: * @param selectedStyle The selectedStyle to set.
103: */
104: public void setSelectedStyle(String selectedStyle) {
105: this .selectedStyle = selectedStyle;
106: }
107:
108: /**
109: * Access action property.
110: *
111: * @return Returns the action.
112: */
113: public String getAction() {
114: return action;
115: }
116:
117: /**
118: * Set action to action.
119: *
120: * @param action The action to set.
121: */
122: public void setAction(String action) {
123: this .action = action;
124: }
125:
126: /**
127: * Access styles property.
128: *
129: * @return Returns the styles.
130: */
131: public TreeSet getStyles() {
132: return styles;
133: }
134: }
|