001: //=============================================================================
002: //=== Copyright (C) 2001-2005 Food and Agriculture Organization of the
003: //=== United Nations (FAO-UN), United Nations World Food Programme (WFP)
004: //=== and United Nations Environment Programme (UNEP)
005: //===
006: //=== This program is free software; you can redistribute it and/or modify
007: //=== it under the terms of the GNU General Public License as published by
008: //=== the Free Software Foundation; either version 2 of the License, or (at
009: //=== your option) any later version.
010: //===
011: //=== This program is distributed in the hope that it will be useful, but
012: //=== WITHOUT ANY WARRANTY; without even the implied warranty of
013: //=== MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: //=== General Public License for more details.
015: //===
016: //=== You should have received a copy of the GNU General Public License
017: //=== along with this program; if not, write to the Free Software
018: //=== Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
019: //===
020: //=== Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2,
021: //=== Rome - Italy. email: GeoNetwork@fao.org
022: //==============================================================================
023:
024: package org.wfp.vam.intermap;
025:
026: import jeeves.interfaces.ApplicationHandler;
027: import jeeves.interfaces.Logger;
028: import jeeves.server.ServiceConfig;
029: import jeeves.server.context.ServiceContext;
030: import jeeves.utils.Xml;
031: import org.jdom.Element;
032: import org.wfp.vam.intermap.http.ConcurrentHTTPTransactionHandler;
033: import org.wfp.vam.intermap.http.cache.HttpGetFileCache;
034: import org.wfp.vam.intermap.kernel.GlobalTempFiles;
035: import org.wfp.vam.intermap.kernel.TempFiles;
036: import org.wfp.vam.intermap.kernel.map.DefaultMapServers;
037: import org.wfp.vam.intermap.kernel.map.MapMerger;
038: import org.wfp.vam.intermap.kernel.map.mapServices.arcims.AxlRequestBuilder;
039: import org.wfp.vam.intermap.kernel.map.mapServices.wms.CapabilitiesStore;
040: import org.wfp.vam.intermap.services.map.MapUtil;
041:
042: //=============================================================================
043:
044: /** This is the main class. It handles http connections and inits the system
045: */
046:
047: public class Intermap implements ApplicationHandler {
048: private Logger logger;
049: private String path;
050: private String charset;
051: private String stdName;
052: private String stdVersion;
053: private static TempFiles tempFiles;
054:
055: //---------------------------------------------------------------------------
056: //---
057: //--- GetContextName
058: //---
059: //---------------------------------------------------------------------------
060:
061: public String getContextName() {
062: return "intermap";
063: }
064:
065: //---------------------------------------------------------------------------
066: //---
067: //--- Start
068: //---
069: //---------------------------------------------------------------------------
070:
071: /** Inits the engine, loading all needed data
072: */
073:
074: // public Object start(String appPath, Logger l, Element config, ResourceManager resMan) throws Exception
075: public Object start(Element config, ServiceContext context)
076: throws Exception {
077: logger = context.getLogger();
078: String path = context.getAppPath();
079: String baseURL = context.getBaseUrl();
080:
081: logger.info("Initializing intermap...");
082:
083: ServiceConfig handlerConfig = new ServiceConfig(config
084: .getChildren());
085:
086: //------------------------------------------------------------------------
087: //--- initialize map servers informations
088:
089: logger.info("Map servers config...");
090: String mapServersPath = handlerConfig
091: .getMandatoryValue(Constants.MAP_SERVERS_CONFIG);
092: Element mapServersRoot = Xml.loadFile(path + mapServersPath);
093: DefaultMapServers.init(mapServersRoot);
094:
095: //------------------------------------------------------------------------
096: //--- initialize the AXL Element builder
097:
098: logger.info("axlElementBuilder config...");
099: String axlPath = handlerConfig
100: .getMandatoryValue(Constants.AXL_CONFIG);
101: AxlRequestBuilder.init(path + axlPath);
102:
103: // //------------------------------------------------------------------------
104: // //--- initialize WmsService
105: //
106: // log("WmsService config...");
107: // String wmsPath = handlerConfig.getMandatoryValue(Constants.WMS_CONFIG);
108: // WmsService.init(path + wmsPath);
109:
110: //------------------------------------------------------------------------
111: //--- set the proxy server System properties
112:
113: logger.info("Proxy server config...");
114: String useProxy = handlerConfig
115: .getMandatoryValue(Constants.USE_PROXY);
116: logger.info("The useproxy attribute is set to " + useProxy);
117: if ("true".equals(useProxy)) {
118: String proxyHost = handlerConfig
119: .getMandatoryValue(Constants.PROXY_HOST);
120: String proxyPort = handlerConfig
121: .getMandatoryValue(Constants.PROXY_PORT);
122: System.setProperty("http.proxyHost", proxyHost);
123: System.setProperty("http.proxyPort", proxyPort);
124:
125: // new http transaction handler
126: ConcurrentHTTPTransactionHandler.setProxy(proxyHost,
127: Integer.parseInt(proxyPort));
128: }
129:
130: //------------------------------------------------------------------------
131: //--- Start the temporary files clean up thread
132:
133: logger.info("Temporary files config...");
134: String tempDir = handlerConfig
135: .getMandatoryValue(Constants.TEMP_DIR);
136: String tempDelete = handlerConfig
137: .getMandatoryValue(Constants.TEMP_DELETE);
138: int delete = Integer.parseInt(tempDelete);
139: GlobalTempFiles.init(path, tempDir, delete);
140: tempFiles = GlobalTempFiles.getInstance();
141:
142: //------------------------------------------------------------------------
143: //--- Start the cache files clean up thread
144:
145: logger.info("HTTP Cache files config...");
146: String cacheDir = handlerConfig
147: .getMandatoryValue(Constants.CACHE_DIR);
148: String cacheDelete = handlerConfig
149: .getMandatoryValue(Constants.CACHE_DELETE);
150: int deleteCache = Integer.parseInt(cacheDelete);
151: MapMerger.setCache(new HttpGetFileCache(path, cacheDir,
152: deleteCache));
153: String useCache = handlerConfig
154: .getMandatoryValue(Constants.USE_CACHE);
155: CapabilitiesStore.useCache("true".equals(useCache) ? true
156: : false);
157:
158: //------------------------------------------------------------------------
159: //--- Set the temporary files URL
160:
161: logger.info("Temporary URL config...");
162: String tempUrl = handlerConfig
163: .getMandatoryValue(Constants.TEMP_URL);
164: org.wfp.vam.intermap.services.map.MapUtil.setTempUrl(tempUrl);
165:
166: logger.info("Screen DPI config...");
167: String dpi = handlerConfig.getMandatoryValue(Constants.DPI);
168: try {
169: MapMerger.setDefaultDPI(Integer.parseInt(dpi));
170: } catch (NumberFormatException e) {
171: MapMerger.setDefaultDPI(96);
172: }
173:
174: //------------------------------------------------------------------------
175: //--- Set image sizes
176:
177: String stMinh = handlerConfig
178: .getMandatoryValue("smallImageHeight");
179: String stMinw = handlerConfig
180: .getMandatoryValue("smallImageWidth");
181: String stMaxh = handlerConfig
182: .getMandatoryValue("bigImageHeight");
183: String stMaxw = handlerConfig
184: .getMandatoryValue("bigImageWidth");
185: String d = handlerConfig.getMandatoryValue("defaultImageSize");
186:
187: int minh = Integer.parseInt(stMinh);
188: int minw = Integer.parseInt(stMinw);
189: int maxh = Integer.parseInt(stMaxh);
190: int maxw = Integer.parseInt(stMaxw);
191:
192: MapUtil.setImageSizes(minh, minw, maxh, maxw);
193:
194: logger.info("setting default image size to " + d);
195: // set default image size
196: if ("small".equals(d))
197: org.wfp.vam.intermap.services.map.MapUtil
198: .setDefaultImageSize("small");
199: else
200: org.wfp.vam.intermap.services.map.MapUtil
201: .setDefaultImageSize("big");
202:
203: logger.info("...done");
204:
205: return new Object(); // DEBUG
206: }
207:
208: //---------------------------------------------------------------------------
209: //---
210: //--- Stop
211: //---
212: //---------------------------------------------------------------------------
213:
214: public void stop() {
215: logger.info("Stopping intermap...");
216:
217: tempFiles.end();
218: }
219:
220: //---------------------------------------------------------------------------
221: //---
222: //--- Private methods
223: //---
224: //---------------------------------------------------------------------------
225:
226: }
227:
228: //=============================================================================
|