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: package org.vfny.geoserver.form.wcs;
006:
007: import org.apache.struts.action.ActionError;
008: import org.apache.struts.action.ActionErrors;
009: import org.apache.struts.action.ActionForm;
010: import org.apache.struts.action.ActionMapping;
011: import org.vfny.geoserver.config.WCSConfig;
012: import javax.servlet.ServletContext;
013: import javax.servlet.http.HttpServletRequest;
014:
015: /**
016: * DOCUMENT ME!
017: *
018: * @author $Author: Alessio Fabiani (alessio.fabiani@gmail.com) $ (last modification)
019: * @author $Author: Simone Giannecchini (simboss1@gmail.com) $ (last modification)
020: */
021: public final class WCSDescriptionForm extends ActionForm {
022: /**
023: * Comment for <code>serialVersionUID</code>
024: */
025: private static final long serialVersionUID = 3258692117605068857L;
026:
027: /**
028: *
029: */
030: private String name;
031:
032: /**
033: *
034: */
035: private String title;
036:
037: /**
038: *
039: */
040: private String accessConstraints;
041:
042: /**
043: *
044: */
045: private String fees;
046:
047: /**
048: *
049: */
050: private String maintainer;
051:
052: /**
053: *
054: */
055: private String keywords;
056:
057: /**
058: *
059: */
060: private String _abstract;
061:
062: public WCSDescriptionForm() {
063: }
064:
065: /**
066: * DOCUMENT ME!
067: *
068: * @return
069: */
070: public String getName() {
071: return name;
072: }
073:
074: /**
075: * DOCUMENT ME!
076: *
077: * @return
078: */
079: public String getTitle() {
080: return title;
081: }
082:
083: /**
084: * DOCUMENT ME!
085: *
086: * @param string
087: */
088: public void setName(String string) {
089: name = string;
090: }
091:
092: /**
093: * DOCUMENT ME!
094: *
095: * @param string
096: */
097: public void setTitle(String string) {
098: title = string;
099: }
100:
101: /**
102: * DOCUMENT ME!
103: *
104: * @return
105: */
106: public String get_abstract() {
107: return _abstract;
108: }
109:
110: /**
111: * DOCUMENT ME!
112: *
113: * @return
114: */
115: public String getAccessConstraints() {
116: return accessConstraints;
117: }
118:
119: /**
120: * DOCUMENT ME!
121: *
122: * @return
123: */
124: public String getFees() {
125: return fees;
126: }
127:
128: /**
129: * DOCUMENT ME!
130: *
131: * @return
132: */
133: public String getKeywords() {
134: return keywords;
135: }
136:
137: /**
138: * DOCUMENT ME!
139: *
140: * @return
141: */
142: public String getMaintainer() {
143: return maintainer;
144: }
145:
146: /**
147: * DOCUMENT ME!
148: *
149: * @param string
150: */
151: public void set_abstract(String string) {
152: _abstract = string;
153: }
154:
155: /**
156: * DOCUMENT ME!
157: *
158: * @param string
159: */
160: public void setAccessConstraints(String string) {
161: accessConstraints = string;
162: }
163:
164: /**
165: * DOCUMENT ME!
166: *
167: * @param string
168: */
169: public void setFees(String string) {
170: fees = string;
171: }
172:
173: /**
174: * DOCUMENT ME!
175: *
176: * @param string
177: */
178: public void setKeywords(String string) {
179: keywords = string;
180: }
181:
182: /**
183: * DOCUMENT ME!
184: *
185: * @param string
186: */
187: public void setMaintainer(String string) {
188: maintainer = string;
189: }
190:
191: /* (non-Javadoc)
192: * @see org.apache.struts.action.ActionForm#reset(org.apache.struts.action.ActionMapping, javax.servlet.http.HttpServletRequest)
193: */
194: public void reset(ActionMapping arg0, HttpServletRequest arg1) {
195: super .reset(arg0, arg1);
196:
197: ServletContext context = getServlet().getServletContext();
198: WCSConfig config = (WCSConfig) context
199: .getAttribute(WCSConfig.CONFIG_KEY);
200:
201: this .maintainer = config.getMaintainer();
202: this .title = config.getTitle();
203: this .accessConstraints = config.getAccessConstraints();
204: this .name = config.getName();
205: this ._abstract = config.getAbstract();
206: this .fees = config.getFees();
207:
208: String out = "";
209:
210: for (int i = 0; i < config.getKeywords().size(); i++) {
211: out = out + config.getKeywords().get(i)
212: + System.getProperty("line.separator");
213: }
214:
215: this .keywords = out;
216: }
217:
218: public ActionErrors validate(ActionMapping mapping,
219: HttpServletRequest request) {
220: ActionErrors errors = new ActionErrors();
221:
222: if ((name == null) || (name.length() == 0)) {
223: errors.add("name", new ActionError("error.name.required"));
224: }
225:
226: if ((title == null) || (title.length() == 0)) {
227: errors
228: .add("title", new ActionError(
229: "error.title.required"));
230: }
231:
232: if ((fees == null) || (fees.length() == 0)) {
233: errors.add("fees", new ActionError("error.fees.required"));
234: }
235:
236: if ((accessConstraints == null)
237: || (accessConstraints.length() == 0)) {
238: errors.add("accessConstraints", new ActionError(
239: "error.accessConstraints.required"));
240: }
241:
242: if ((maintainer == null) || (maintainer.length() == 0)) {
243: errors.add("maintainer", new ActionError(
244: "error.maintainer.required"));
245: }
246:
247: if ((_abstract == null) || (_abstract.length() == 0)) {
248: errors.add("abstract", new ActionError(
249: "error.abstract.required"));
250: }
251:
252: String[] array = (keywords != null) ? keywords.split("\n")
253: : new String[0];
254:
255: if (array.length == 0) {
256: errors.add("keywords", new ActionError(
257: "error.keywords.required"));
258: }
259:
260: return errors;
261: }
262: }
|