001: /*
002: * Created on Jan 27, 2004
003: *
004: * To change the template for this generated file go to
005: * Window - Preferences - Java - Code Generation - Code and Comments
006: */
007: package org.vfny.geoserver.action.global;
008:
009: import org.apache.struts.action.ActionError;
010: import org.apache.struts.action.ActionErrors;
011: import org.apache.struts.action.ActionForm;
012: import org.apache.struts.action.ActionForward;
013: import org.apache.struts.action.ActionMapping;
014: import org.vfny.geoserver.action.ConfigAction;
015: import org.vfny.geoserver.config.ContactConfig;
016: import org.vfny.geoserver.config.GlobalConfig;
017: import org.vfny.geoserver.form.global.GeoServerConfigurationForm;
018: import org.vfny.geoserver.global.GeoServer;
019: import org.vfny.geoserver.global.UserContainer;
020: import java.io.File;
021: import java.io.IOException;
022: import java.nio.charset.Charset;
023: import java.util.logging.Level;
024: import javax.servlet.http.HttpServletRequest;
025: import javax.servlet.http.HttpServletResponse;
026:
027: /**
028: * GeoServerConfigurationSubmit purpose.
029: * <p>
030: * Description of GeoServerConfigurationSubmit ...
031: * </p>
032: *
033: * <p>
034: * Capabilities:
035: * </p>
036: * <ul>
037: * <li>
038: * Feature: description
039: * </li>
040: * </ul>
041: * <p>
042: * Example Use:
043: * </p>
044: * <pre><code>
045: * GeoServerConfigurationSubmit x = new GeoServerConfigurationSubmit(...);
046: * </code></pre>
047: *
048: * @author User, Refractions Research, Inc.
049: * @author $Author: cholmesny $ (last modification)
050: * @version $Id: GeoServerConfigurationSubmit.java 7226 2007-07-10 19:28:46Z saul.farber $
051: */
052: public class GeoServerConfigurationSubmit extends ConfigAction {
053: public ActionForward execute(ActionMapping mapping,
054: ActionForm incomingForm, UserContainer user,
055: HttpServletRequest request, HttpServletResponse response) {
056: GeoServerConfigurationForm form = (GeoServerConfigurationForm) incomingForm;
057: int maxFeatures = form.getMaxFeatures();
058:
059: boolean verbose = form.isVerbose();
060:
061: if (form.isVerboseChecked() == false) {
062: verbose = false;
063: }
064:
065: int numDecimals = form.getNumDecimals();
066: String stringCharset = form.getCharset();
067: Charset charset;
068:
069: try {
070: charset = Charset.forName(stringCharset);
071: } catch (IllegalArgumentException uce) {
072: ActionErrors errors = new ActionErrors();
073: errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(
074: "error.badCharSet"));
075: saveErrors(request, errors);
076:
077: return mapping.findForward("config.server");
078: }
079:
080: String baseURL = form.getProxyBaseUrl();
081: String schemaBaseURL = form.getSchemaBaseURL();
082: String log4jConfigFile = form.getLog4jConfigFile();
083: String adminUserName = form.getAdminUserName();
084: String adminPassword = form.getAdminPassword();
085: boolean verboseExceptions = form.isVerboseExceptions();
086:
087: if (form.isVerboseExceptionsChecked() == false) {
088: verboseExceptions = false;
089: }
090:
091: boolean suppressStdOutLogging = form.isSuppressStdOutLogging();
092:
093: if (!form.isSuppressStdOutLoggingChecked()) {
094: suppressStdOutLogging = false;
095: }
096:
097: String logLocation = form.getLogLocation();
098:
099: if ((logLocation != null) && "".equals(logLocation.trim())) {
100: logLocation = null;
101: }
102:
103: if (logLocation != null) {
104: File f = null;
105:
106: try {
107: f = GeoServer.getLogLocation(logLocation);
108: } catch (IOException e) {
109: ActionErrors errors = new ActionErrors();
110: ActionError error = new ActionError(
111: "error.couldNotCreateFile",
112: f.getAbsolutePath(), e.getLocalizedMessage());
113: errors.add(ActionErrors.GLOBAL_ERROR, error);
114: saveErrors(request, errors);
115:
116: return mapping.findForward("config.server");
117: }
118:
119: if (!f.canWrite()) {
120: ActionErrors errors = new ActionErrors();
121: errors.add(ActionErrors.GLOBAL_ERROR, new ActionError(
122: "error.noWritePermission", logLocation));
123: saveErrors(request, errors);
124:
125: return mapping.findForward("config.server");
126: }
127: }
128:
129: double jaiMemoryCapacity = form.getJaiMemoryCapacity();
130: double jaiMemoryThreshold = form.getJaiMemoryThreshold();
131: int jaiTileThreads = form.getJaiTileThreads();
132: int jaiTilePriority = form.getJaiTilePriority();
133: boolean jaiRecycling = form.getJaiRecycling();
134:
135: if (form.isJaiRecyclingChecked() == false) {
136: jaiRecycling = false;
137: }
138:
139: boolean imageIOCache = form.getImageIOCache();
140:
141: if (form.isImageIOCacheChecked() == false) {
142: imageIOCache = false;
143: }
144:
145: boolean jaiJPEGNative = form.getJaiJPEGNative();
146:
147: if (form.isJaiJPEGNativeChecked() == false) {
148: jaiJPEGNative = false;
149: }
150:
151: boolean jaiPNGNative = form.getJaiPNGNative();
152:
153: if (form.isJaiPNGNativeChecked() == false) {
154: jaiPNGNative = false;
155: }
156:
157: String tileCache = form.getTileCache();
158:
159: if ((tileCache == null) || "".equals(tileCache.trim())) {
160: tileCache = null;
161: }
162:
163: GlobalConfig globalConfig = getGlobalConfig();
164: globalConfig.setMaxFeatures(maxFeatures);
165: globalConfig.setVerbose(verbose);
166: globalConfig.setNumDecimals(numDecimals);
167: globalConfig.setProxyBaseUrl(baseURL);
168: globalConfig.setSchemaBaseUrl(schemaBaseURL);
169: globalConfig.setCharSet(charset);
170: globalConfig.setAdminUserName(adminUserName);
171: globalConfig.setAdminPassword(adminPassword);
172: globalConfig.setLog4jConfigFile(log4jConfigFile);
173: globalConfig.setSuppressStdOutLogging(suppressStdOutLogging);
174: globalConfig.setLogLocation(logLocation);
175: globalConfig.setVerboseExceptions(verboseExceptions);
176: globalConfig.setJaiMemoryCapacity(jaiMemoryCapacity);
177: globalConfig.setJaiMemoryThreshold(jaiMemoryThreshold);
178: globalConfig.setJaiTileThreads(jaiTileThreads);
179: globalConfig.setJaiTilePriority(jaiTilePriority);
180: globalConfig.setJaiRecycling(jaiRecycling);
181: globalConfig.setImageIOCache(imageIOCache);
182: globalConfig.setJaiJPEGNative(jaiJPEGNative);
183: globalConfig.setJaiPNGNative(jaiPNGNative);
184: globalConfig.setTileCache(tileCache);
185:
186: ContactConfig contactConfig = globalConfig.getContact();
187: contactConfig.setContactPerson(form.getContactPerson());
188: contactConfig.setContactOrganization(form
189: .getContactOrganization());
190: contactConfig.setContactPosition(form.getContactPosition());
191: contactConfig.setAddressType(form.getAddressType());
192: contactConfig.setAddress(form.getAddress());
193: contactConfig.setAddressCity(form.getAddressCity());
194: contactConfig.setAddressCountry(form.getAddressCountry());
195: contactConfig.setAddressPostalCode(form.getAddressPostalCode());
196: contactConfig.setAddressState(form.getAddressState());
197: contactConfig.setContactVoice(form.getContactVoice());
198: contactConfig.setContactFacsimile(form.getContactFacsimile());
199: contactConfig.setContactEmail(form.getContactEmail());
200: globalConfig.setContact(contactConfig);
201: getApplicationState().notifyConfigChanged();
202:
203: getServlet().getServletContext().setAttribute(
204: GlobalConfig.CONFIG_KEY, globalConfig);
205:
206: return mapping.findForward("config");
207: }
208: }
|