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;
006:
007: import org.apache.struts.action.ActionErrors;
008: import org.apache.struts.action.ActionForm;
009: import org.apache.struts.action.ActionMapping;
010: import org.vfny.geoserver.global.GeoserverDataDirectory;
011: import java.io.File;
012: import java.util.ArrayList;
013: import java.util.Collections;
014: import java.util.List;
015: import javax.servlet.ServletContext;
016: import javax.servlet.http.HttpServletRequest;
017:
018: /**
019: * DemoForm collects the list of avialable requests for the demo.
020: * <p>
021: * Stores the request & post for the demo page, to be used by the DemoAction.
022: * </p>
023: *
024: * @author jgarnett, Refractions Research, Inc.
025: * @author $Author: jive $ (last modification)
026: * @version $Id: DemoForm.java 6326 2007-03-15 18:36:40Z jdeolive $
027: */
028: public class DemoForm extends ActionForm {
029: /**
030: * Comment for <code>serialVersionUID</code>
031: */
032: private static final long serialVersionUID = 3978983293029005618L;
033:
034: /**
035: *
036: * @uml.property name="action" multiplicity="(0 1)"
037: */
038: private String action;
039:
040: /**
041: *
042: * @uml.property name="url" multiplicity="(0 1)"
043: */
044: private String url;
045:
046: /**
047: *
048: * @uml.property name="body" multiplicity="(0 1)"
049: */
050: private String body;
051:
052: /**
053: *
054: * @uml.property name="demo" multiplicity="(0 1)"
055: */
056: private String demo;
057:
058: /**
059: *
060: * @uml.property name="dir" multiplicity="(0 1)"
061: */
062: private File dir;
063:
064: /**
065: *
066: * @uml.property name="demoList"
067: * @uml.associationEnd elementType="java.lang.String" multiplicity="(0 -1)"
068: */
069: List demoList;
070:
071: /**
072: * Sets request & post based on file selection.
073: *
074: * @see org.apache.struts.action.ActionForm#reset(org.apache.struts.action.ActionMapping, javax.servlet.http.HttpServletRequest)
075: *
076: * @param arg0
077: * @param request
078: */
079: public void reset(ActionMapping arg0, HttpServletRequest request) {
080: super .reset(arg0, request);
081:
082: ServletContext context = getServlet().getServletContext();
083: //DJB: changed this for geoserver_data_dir
084: // this.dir = new File(context.getRealPath("/data/demo"));
085: this .dir = new File(GeoserverDataDirectory
086: .getGeoserverDataDirectory(), "/data/demo");
087: demoList = new ArrayList();
088: demoList.add("");
089:
090: if (dir.exists() && dir.isDirectory()) {
091: File[] files = dir.listFiles();
092:
093: for (int i = 0; i < files.length; i++) {
094: File file = files[i];
095: demoList.add(file.getName());
096: }
097: }
098:
099: Collections.sort(demoList);
100: }
101:
102: /**
103: *
104: * Verifies that username is not null or empty.
105: * Could potentially do the same for password later.
106: *
107: * @see org.apache.struts.action.ActionForm#validate(org.apache.struts.action.ActionMapping, javax.servlet.http.HttpServletRequest)
108: *
109: * @param mapping
110: * @param request
111: * @return
112: */
113: public ActionErrors validate(ActionMapping mapping,
114: HttpServletRequest request) {
115: ActionErrors errors = new ActionErrors();
116:
117: return errors;
118: }
119:
120: /**
121: * @return Returns the demo.
122: *
123: * @uml.property name="demo"
124: */
125: public String getDemo() {
126: return demo;
127: }
128:
129: /**
130: * @param demo The demo to set.
131: *
132: * @uml.property name="demo"
133: */
134: public void setDemo(String demo) {
135: this .demo = demo;
136: }
137:
138: /**
139: * @return Returns the dir.
140: *
141: * @uml.property name="dir"
142: */
143: public File getDir() {
144: return dir;
145: }
146:
147: /**
148: * @return Returns the url.
149: *
150: * @uml.property name="url"
151: */
152: public String getUrl() {
153: return url;
154: }
155:
156: /**
157: * @param url The url to set.
158: *
159: * @uml.property name="url"
160: */
161: public void setUrl(String url) {
162: this .url = url;
163: }
164:
165: /**
166: * @return Returns the demoList.
167: *
168: * @uml.property name="demoList"
169: */
170: public List getDemoList() {
171: return demoList;
172: }
173:
174: /**
175: * @return Returns the action.
176: *
177: * @uml.property name="action"
178: */
179: public String getAction() {
180: return action;
181: }
182:
183: /**
184: * @param action The action to set.
185: *
186: * @uml.property name="action"
187: */
188: public void setAction(String action) {
189: this .action = action;
190: }
191:
192: /**
193: * @return Returns the body.
194: *
195: * @uml.property name="body"
196: */
197: public String getBody() {
198: return body;
199: }
200:
201: /**
202: * @param body The body to set.
203: *
204: * @uml.property name="body"
205: */
206: public void setBody(String body) {
207: this.body = body;
208: }
209: }
|