001: //=============================================================================
002: //=== Copyright (C) 2001-2007 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
019: //===
020: //=== Contact: Jeroen Ticheler - FAO - Viale delle Terme di Caracalla 2,
021: //=== Rome - Italy. email: geonetwork@osgeo.org
022: //==============================================================================
023:
024: package org.fao.geonet;
025:
026: import java.io.File;
027: import jeeves.interfaces.ApplicationHandler;
028: import jeeves.interfaces.Logger;
029: import jeeves.resources.dbms.Dbms;
030: import jeeves.server.ServiceConfig;
031: import jeeves.server.UserSession;
032: import jeeves.server.context.ServiceContext;
033: import jeeves.utils.Util;
034: import org.fao.geonet.constants.Geonet;
035: import org.fao.geonet.kernel.AccessManager;
036: import org.fao.geonet.kernel.DataManager;
037: import org.fao.geonet.kernel.ThesaurusManager;
038: import org.fao.geonet.kernel.csw.CatalogDispatcher;
039: import org.fao.geonet.kernel.harvest.HarvestManager;
040: import org.fao.geonet.kernel.oaipmh.OaiPmhDispatcher;
041: import org.fao.geonet.kernel.search.SearchManager;
042: import org.fao.geonet.kernel.setting.SettingManager;
043: import org.fao.geonet.services.util.z3950.Server;
044: import org.jdom.Element;
045:
046: //=============================================================================
047:
048: /** This is the main class. It handles http connections and inits the system
049: */
050:
051: public class Geonetwork implements ApplicationHandler {
052: private Logger logger;
053: private SearchManager searchMan;
054: private ThesaurusManager thesaurusMan;
055:
056: //---------------------------------------------------------------------------
057: //---
058: //--- GetContextName
059: //---
060: //---------------------------------------------------------------------------
061:
062: public String getContextName() {
063: return Geonet.CONTEXT_NAME;
064: }
065:
066: //---------------------------------------------------------------------------
067: //---
068: //--- Start
069: //---
070: //---------------------------------------------------------------------------
071:
072: /** Inits the engine, loading all needed data
073: */
074:
075: public Object start(Element config, ServiceContext context)
076: throws Exception {
077: logger = context.getLogger();
078:
079: String path = context.getAppPath();
080: String baseURL = context.getBaseUrl();
081:
082: logger.info("Initializing geonetwork...");
083:
084: ServiceConfig handlerConfig = new ServiceConfig(config
085: .getChildren());
086:
087: Dbms dbms = (Dbms) context.getResourceManager().open(
088: Geonet.Res.MAIN_DB);
089:
090: //------------------------------------------------------------------------
091: //--- initialize settings subsystem
092:
093: logger.info(" - Setting manager...");
094:
095: SettingManager settingMan = new SettingManager(dbms, context
096: .getProviderManager());
097:
098: //------------------------------------------------------------------------
099: //--- Initialize thesaurus
100:
101: logger.info(" - Thesaurus...");
102:
103: String thesauriDir = handlerConfig
104: .getMandatoryValue(Geonet.Config.CODELIST_DIR);
105:
106: thesaurusMan = new ThesaurusManager(path, thesauriDir);
107:
108: //------------------------------------------------------------------------
109: //--- initialize Z39.50
110:
111: logger.info(" - Z39.50...");
112:
113: boolean z3950Enable = settingMan.getValueAsBool(
114: "system/z3950/enable", false);
115: String z3950port = settingMan.getValue("system/z3950/port");
116: String host = settingMan.getValue("system/server/host");
117: String schemaMappings = handlerConfig
118: .getMandatoryValue(Geonet.Config.SCHEMA_MAPPINGS);
119:
120: if (!z3950Enable)
121: logger.info(" disabled");
122: else {
123: logger.info(" Enabled. Schema mappings is : "
124: + schemaMappings);
125:
126: UserSession session = new UserSession();
127: session.authenticate(null, "z39.50", "", "", "Guest");
128: context.setUserSession(session);
129: context.setIpAddress("127.0.0.1");
130: Server.init(host, z3950port, path, schemaMappings, context);
131: }
132:
133: //------------------------------------------------------------------------
134: //--- initialize search and editing
135:
136: logger.info(" - Search...");
137:
138: String luceneDir = handlerConfig
139: .getMandatoryValue(Geonet.Config.LUCENE_DIR);
140:
141: searchMan = new SearchManager(path, luceneDir);
142:
143: //------------------------------------------------------------------------
144: //--- extract intranet ip/mask and initialize AccessManager
145:
146: logger.info(" - Access manager...");
147:
148: AccessManager accessMan = new AccessManager(dbms, settingMan);
149:
150: //------------------------------------------------------------------------
151: //--- get edit params and initialize DataManager
152:
153: logger.info(" - Data manager...");
154:
155: String htmlCacheDir = handlerConfig
156: .getMandatoryValue(Geonet.Config.HTMLCACHE_DIR);
157: File _htmlCacheDir = new File(htmlCacheDir);
158: if (!_htmlCacheDir.isAbsolute()) {
159: htmlCacheDir = path + htmlCacheDir;
160: }
161: DataManager dataMan = new DataManager(searchMan, accessMan,
162: dbms, settingMan, baseURL, htmlCacheDir);
163:
164: String schemasDir = path + Geonet.Path.SCHEMAS;
165: String saSchemas[] = new File(schemasDir).list();
166:
167: if (saSchemas == null)
168: throw new Exception("Cannot scan schemas directory : "
169: + schemasDir);
170: else {
171: for (int i = 0; i < saSchemas.length; i++)
172: if (!saSchemas[i].equals("CVS")
173: && !saSchemas[i].startsWith(".")) {
174: logger.info(" Adding xml schema : "
175: + saSchemas[i]);
176: String schemaFile = schemasDir + saSchemas[i] + "/"
177: + Geonet.File.SCHEMA;
178: String suggestFile = schemasDir + saSchemas[i]
179: + "/" + Geonet.File.SCHEMA_SUGGESTIONS;
180: String substitutesFile = schemasDir + saSchemas[i]
181: + "/" + Geonet.File.SCHEMA_SUBSTITUTES;
182:
183: dataMan.addSchema(saSchemas[i], schemaFile,
184: suggestFile, substitutesFile);
185: }
186: }
187:
188: //------------------------------------------------------------------------
189: //--- initialize harvesting subsystem
190:
191: logger.info(" - Harvest manager...");
192:
193: HarvestManager harvestMan = new HarvestManager(context,
194: settingMan, dataMan);
195: dataMan.setHarvestManager(harvestMan);
196:
197: //------------------------------------------------------------------------
198: //--- initialize catalogue services for the web
199:
200: logger.info(" - Catalogue services for the web...");
201:
202: CatalogDispatcher catalogDis = new CatalogDispatcher();
203:
204: //------------------------------------------------------------------------
205: //--- initialize catalogue services for the web
206:
207: logger.info(" - Open Archive Initiative (OAI-PMH) server...");
208:
209: OaiPmhDispatcher oaipmhDis = new OaiPmhDispatcher();
210:
211: //------------------------------------------------------------------------
212: //--- return application context
213:
214: GeonetContext gnContext = new GeonetContext();
215:
216: gnContext.accessMan = accessMan;
217: gnContext.dataMan = dataMan;
218: gnContext.searchMan = searchMan;
219: gnContext.config = handlerConfig;
220: gnContext.catalogDis = catalogDis;
221: gnContext.settingMan = settingMan;
222: gnContext.harvestMan = harvestMan;
223: gnContext.thesaurusMan = thesaurusMan;
224: gnContext.oaipmhDis = oaipmhDis;
225:
226: logger.info("Site ID is : " + gnContext.getSiteId());
227:
228: return gnContext;
229: }
230:
231: //---------------------------------------------------------------------------
232: //---
233: //--- Stop
234: //---
235: //---------------------------------------------------------------------------
236:
237: public void stop() {
238: logger.info("Stopping geonetwork...");
239:
240: //------------------------------------------------------------------------
241: //--- end search
242:
243: logger.info(" - search...");
244:
245: try {
246: searchMan.end();
247: } catch (Exception e) {
248: logger.error("Raised exception while stopping search");
249: logger.error(" Exception : " + e);
250: logger.error(" Message : " + e.getMessage());
251: logger.error(" Stack : " + Util.getStackTrace(e));
252: }
253:
254: //------------------------------------------------------------------------
255: //--- end Z39.50
256:
257: logger.info(" - Z39.50...");
258: Server.end();
259: }
260: }
261:
262: //=============================================================================
|