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 java.util.logging.Level;
016: import java.util.logging.Logger;
017: import javax.servlet.ServletContext;
018: import javax.servlet.http.HttpServletRequest;
019:
020: /**
021: * <b>DemoRequestForm</b><br>
022: * Oct 7, 2005<br>
023: *
024: * <b>Purpose:</b><br>
025: * DemoForm collects the list of avialable requests for the demo.
026: * <p>
027: * Stores the request & post for the demo page, to be used by the DemoAction.
028: * </p>
029: *
030: * @author jgarnett, Refractions Research, Inc.
031: * @author Brent Owens (The Open Planning Project)
032: * @version
033: */
034: public class DemoRequestForm extends ActionForm {
035: private static final Logger LOGGER = org.geotools.util.logging.Logging
036: .getLogger("org.vfny.geoserver.form");
037: private String action;
038: private String url;
039: private String body;
040: private String demo;
041: private String username;
042: private String password;
043: private File dir;
044: List demoList;
045:
046: /**
047: * Sets request & post based on file selection.
048: *
049: * @see org.apache.struts.action.ActionForm#reset(org.apache.struts.action.ActionMapping, javax.servlet.http.HttpServletRequest)
050: *
051: * @param arg0
052: * @param request
053: */
054: public void reset(ActionMapping arg0, HttpServletRequest request) {
055: super .reset(arg0, request);
056:
057: ServletContext context = getServlet().getServletContext();
058: demoList = new ArrayList();
059: demoList.add("");
060:
061: //DJB: changed this for geoserver_data_dir
062: // this.dir = new File(context.getRealPath("/data/demo"));
063: try {
064: this .dir = GeoserverDataDirectory
065: .findCreateConfigDir("demo/");
066:
067: //commented out, findConfigDir does this for us.
068: //if( dir.exists() && dir.isDirectory() ){
069: File[] files = dir.listFiles();
070:
071: for (int i = 0; i < files.length; i++) {
072: File file = files[i];
073:
074: if (!file.isDirectory()) {
075: demoList.add(file.getName());
076: }
077: }
078: } catch (org.vfny.geoserver.global.ConfigurationException confE) {
079: if (LOGGER.isLoggable(Level.FINE)) {
080: LOGGER.fine(new StringBuffer("Conf e: ").append(confE)
081: .toString());
082: }
083:
084: //eat this, no demo dir, so we just don't get any demo requests.
085: }
086:
087: Collections.sort(demoList);
088: }
089:
090: /**
091: *
092: * Verifies that username is not null or empty.
093: * Could potentially do the same for password later.
094: *
095: * @see org.apache.struts.action.ActionForm#validate(org.apache.struts.action.ActionMapping, javax.servlet.http.HttpServletRequest)
096: *
097: * @param mapping
098: * @param request
099: * @return
100: */
101: public ActionErrors validate(ActionMapping mapping,
102: HttpServletRequest request) {
103: ActionErrors errors = new ActionErrors();
104:
105: return errors;
106: }
107:
108: /**
109: * @return Returns the demo.
110: */
111: public String getDemo() {
112: return demo;
113: }
114:
115: /**
116: * @param demo The demo to set.
117: */
118: public void setDemo(String demo) {
119: this .demo = demo;
120: }
121:
122: /**
123: * @return Returns the dir.
124: */
125: public File getDir() {
126: return dir;
127: }
128:
129: /**
130: * @return Returns the url.
131: */
132: public String getUrl() {
133: return url;
134: }
135:
136: /**
137: * @param url The url to set.
138: */
139: public void setUrl(String url) {
140: this .url = url;
141: }
142:
143: /**
144: * @return Returns the demoList.
145: */
146: public List getDemoList() {
147: return demoList;
148: }
149:
150: /**
151: * @return Returns the action.
152: */
153: public String getAction() {
154: return action;
155: }
156:
157: /**
158: * @param action The action to set.
159: */
160: public void setAction(String action) {
161: this .action = action;
162: }
163:
164: /**
165: * @return Returns the body.
166: */
167: public String getBody() {
168: return body;
169: }
170:
171: /**
172: * @param body The body to set.
173: */
174: public void setBody(String body) {
175: this .body = body;
176: }
177:
178: public String getPassword() {
179: return password;
180: }
181:
182: public void setPassword(String password) {
183: this .password = password;
184: }
185:
186: public String getUsername() {
187: return username;
188: }
189:
190: public void setUsername(String username) {
191: this.username = username;
192: }
193: }
|