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 6, 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.wfs;
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.WFSConfig;
019: import org.vfny.geoserver.global.dto.WFSDTO;
020: import java.net.MalformedURLException;
021: import java.net.URL;
022: import javax.servlet.ServletContext;
023: import javax.servlet.http.HttpServletRequest;
024:
025: /**
026: * DOCUMENT ME!
027: *
028: * @author User To change the template for this generated type comment go to
029: * Window>Preferences>Java>Code Generation>Code and Comments
030: */
031: public class WFSContentForm extends ActionForm {
032: private boolean enabled;
033: private String onlineResource;
034: private String describeURL;
035: private int serviceLevel;
036: private String[] selectedFeatures;
037: private String[] features;
038: private boolean srsXmlStyle;
039: private boolean srsXmlStyleChecked = false;
040: private boolean citeConformanceHacks;
041: private boolean citeConformanceHacksChecked = false;
042: private boolean featureBounding;
043: private boolean featureBoundingChecked = false;
044:
045: /*
046: * Because of the way that STRUTS works, if the user does not check the enabled box,
047: * or unchecks it, setEnabled() is never called, thus we must monitor setEnabled()
048: * to see if it doesn't get called. This must be accessible, as ActionForms need to
049: * know about it -- there is no way we can tell whether we are about to be passed to
050: * an ActionForm or not.
051: *
052: * Probably a better way to do this, but I can't think of one.
053: * -rgould
054: *
055: * TODO: Hey richard Jody here - Struts knows that boolean properties are
056: * not set if the user does nothing. Apparently that is why the reset
057: * method exists.
058: * Reset is called *every* time on ActionForm. Before the populate
059: * process has a go at things.
060: *
061: * The problem is that reset() retrieves the WFS's config enabled value
062: * and uses that to pre-populate the form. Thus, if they deselect it, setEnabled is
063: * never called, and enabled still remains true. The way I have done it isn't simple,
064: * but it works just fine.
065: */
066: private boolean enabledChecked = false;
067:
068: /**
069: * DOCUMENT ME!
070: *
071: * @return
072: */
073: public boolean isEnabled() {
074: return enabled;
075: }
076:
077: /**
078: * DOCUMENT ME!
079: *
080: * @return
081: */
082: public String getOnlineResource() {
083: return onlineResource;
084: }
085:
086: /**
087: * DOCUMENT ME!
088: *
089: * @param string
090: */
091: public void setDescribeURL(String string) {
092: describeURL = string;
093: }
094:
095: /**
096: * DOCUMENT ME!
097: *
098: * @param b
099: */
100: public void setEnabled(boolean b) {
101: enabledChecked = true;
102:
103: //System.out.println("setEnabled: enabledCheck/Enabled now " + b);
104: enabled = b;
105: }
106:
107: /**
108: * DOCUMENT ME!
109: *
110: * @param string
111: */
112: public void setOnlineResource(String string) {
113: onlineResource = string;
114: }
115:
116: /**
117: * DOCUMENT ME!
118: *
119: * @return
120: */
121: public String[] getFeatures() {
122: return features;
123: }
124:
125: /**
126: * DOCUMENT ME!
127: *
128: * @return
129: */
130: public String[] getSelectedFeatures() {
131: return selectedFeatures;
132: }
133:
134: /**
135: * DOCUMENT ME!
136: *
137: * @param strings
138: */
139: public void setFeatures(String[] strings) {
140: features = strings;
141: }
142:
143: /**
144: * DOCUMENT ME!
145: *
146: * @param strings
147: */
148: public void setSelectedFeatures(String[] strings) {
149: selectedFeatures = strings;
150: }
151:
152: public void reset(ActionMapping arg0, HttpServletRequest arg1) {
153: super .reset(arg0, arg1);
154:
155: enabledChecked = false;
156: srsXmlStyleChecked = false;
157: citeConformanceHacksChecked = false;
158: featureBoundingChecked = false;
159:
160: ServletContext context = getServlet().getServletContext();
161: WFSConfig config = (WFSConfig) context
162: .getAttribute(WFSConfig.CONFIG_KEY);
163:
164: citeConformanceHacks = config.getCiteConformanceHacks();
165: featureBounding = config.isFeatureBounding();
166:
167: serviceLevel = config.getServiceLevel();
168: this .enabled = config.isEnabled();
169: this .srsXmlStyle = config.isSrsXmlStyle();
170:
171: URL url = config.getOnlineResource();
172:
173: if (url != null) {
174: this .onlineResource = url.toString();
175: } else {
176: this .onlineResource = "";
177: }
178: }
179:
180: public ActionErrors validate(ActionMapping mapping,
181: HttpServletRequest request) {
182: ActionErrors errors = new ActionErrors();
183:
184: if ((serviceLevel != WFSDTO.BASIC)
185: && (serviceLevel != WFSDTO.TRANSACTIONAL)
186: && (serviceLevel != WFSDTO.COMPLETE)) {
187: errors.add("serviceLevel", new ActionError(
188: "error.serviceLevel.invalid"));
189: }
190:
191: if ((onlineResource == null) || onlineResource.equals("")) {
192: errors.add("onlineResource", new ActionError(
193: "error.wfs.onlineResource.required"));
194: } else {
195: try {
196: URL url = new URL(onlineResource);
197: } catch (MalformedURLException badURL) {
198: errors.add("onlineResource", new ActionError(
199: "error.wfs.onlineResource.malformed", badURL));
200: }
201: }
202:
203: return errors;
204: }
205:
206: /**
207: * DOCUMENT ME!
208: *
209: * @return
210: */
211: public boolean isEnabledChecked() {
212: return enabledChecked;
213: }
214:
215: /**
216: * DOCUMENT ME!
217: *
218: * @param b
219: */
220: public void setEnabledChecked(boolean b) {
221: enabledChecked = b;
222: }
223:
224: /**
225: * DOCUMENT ME!
226: *
227: * @return
228: */
229: public boolean isSrsXmlStyleChecked() {
230: return srsXmlStyleChecked;
231: }
232:
233: /**
234: * DOCUMENT ME!
235: *
236: * @param b
237: */
238: public void setSrsXmlStyleChecked(boolean b) {
239: srsXmlStyleChecked = b;
240: }
241:
242: /**
243: * Access serviceLevel property.
244: *
245: * @return Returns the serviceLevel.
246: */
247: public int getServiceLevel() {
248: return serviceLevel;
249: }
250:
251: /**
252: * Set serviceLevel to serviceLevel.
253: *
254: * @param serviceLevel The serviceLevel to set.
255: */
256: public void setServiceLevel(int serviceLevel) {
257: this .serviceLevel = serviceLevel;
258: }
259:
260: /**
261: * Whether the srs xml attribute should be in the EPSG:4326 (non-xml)
262: * style, or in the http://www.opengis.net/gml/srs/epsg.xml#4326 style.
263: *
264: * @return <tt>true</tt> if the srs is reported with the xml style
265: */
266: public boolean isSrsXmlStyle() {
267: return srsXmlStyle;
268: }
269:
270: /**
271: * Sets whether the srs xml attribute should be in the EPSG:4326 (non-xml)
272: * style, or in the http://www.opengis.net/gml/srs/epsg.xml#4326 style.
273: *
274: * @param doXmlStyle whether the srs style should be xml or not.
275: */
276: public void setSrsXmlStyle(boolean doXmlStyle) {
277: this .srsXmlStyleChecked = true;
278: this .srsXmlStyle = doXmlStyle;
279: }
280:
281: /**
282: * turn on/off the citeConformanceHacks option.
283: *
284: * @param on
285: */
286: public void setCiteConformanceHacks(boolean on) {
287: this .citeConformanceHacksChecked = true; //this function only gets called when the form has it checked...
288: citeConformanceHacks = on;
289: }
290:
291: /**
292: * get the current value of the citeConformanceHacks
293: *
294: * @return
295: */
296: public boolean getCiteConformanceHacks() {
297: return (citeConformanceHacks);
298: }
299:
300: /**
301: * get the current value of the citeConformanceHacksChecked (ie. was it in
302: * the http form?)
303: *
304: * @return
305: */
306: public boolean getCiteConformanceHacksChecked() {
307: return (citeConformanceHacksChecked);
308: }
309:
310: /**
311: * turn on/off the featureBounding option.
312: *
313: * @param on
314: */
315: public void setFeatureBounding(boolean on) {
316: this .featureBoundingChecked = true; //this function only gets called when the form has it checked...
317: featureBounding = on;
318: }
319:
320: /**
321: * get the current value of the featureBounding
322: *
323: * @return
324: */
325: public boolean isFeatureBounding() {
326: return (featureBounding);
327: }
328:
329: /**
330: * get the current value of the featureBoundingChecked (ie. was it in the
331: * http form?)
332: *
333: * @return
334: */
335: public boolean isFeatureBoundingChecked() {
336: return (featureBoundingChecked);
337: }
338: }
|