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.services.main;
025:
026: import jeeves.interfaces.Service;
027: import jeeves.server.ServiceConfig;
028: import jeeves.server.UserSession;
029: import jeeves.server.context.ServiceContext;
030: import org.fao.geonet.GeonetContext;
031: import org.fao.geonet.constants.Geonet;
032: import org.fao.geonet.kernel.search.MetaSearcher;
033: import org.fao.geonet.kernel.search.SearchManager;
034: import org.fao.geonet.services.util.MainUtil;
035: import org.jdom.Element;
036:
037: //=============================================================================
038:
039: public class XmlSearch implements Service {
040: private ServiceConfig _config;
041:
042: //--------------------------------------------------------------------------
043: //---
044: //--- Init
045: //---
046: //--------------------------------------------------------------------------
047:
048: public void init(String appPath, ServiceConfig config)
049: throws Exception {
050: _config = config;
051: }
052:
053: //--------------------------------------------------------------------------
054: //---
055: //--- Service
056: //---
057: //--------------------------------------------------------------------------
058:
059: public Element exec(Element params, ServiceContext context)
060: throws Exception {
061: GeonetContext gc = (GeonetContext) context
062: .getHandlerContext(Geonet.CONTEXT_NAME);
063:
064: SearchManager searchMan = gc.getSearchmanager();
065:
066: Element elData = MainUtil.getDefaultSearch(context, params);
067: String sRemote = elData
068: .getChildText(Geonet.SearchResult.REMOTE);
069: boolean remote = sRemote != null
070: && sRemote.equals(Geonet.Text.ON);
071:
072: // possibly close old searcher
073: UserSession session = context.getUserSession();
074: MetaSearcher oldSearcher = (MetaSearcher) session
075: .getProperty(Geonet.Session.SEARCH_RESULT);
076:
077: if (oldSearcher != null)
078: oldSearcher.close();
079:
080: // perform the search and save search result into session
081: MetaSearcher searcher;
082:
083: context.info("Creating searchers");
084:
085: if (remote)
086: searcher = searchMan.newSearcher(SearchManager.Z3950,
087: Geonet.File.SEARCH_Z3950_CLIENT);
088: else
089: searcher = searchMan.newSearcher(SearchManager.LUCENE,
090: Geonet.File.SEARCH_LUCENE);
091:
092: searcher.search(context, params, _config);
093:
094: params.addContent(new Element("fast").setText("true"));
095: params.addContent(new Element("from").setText("1"));
096: params.addContent(new Element("to").setText(searcher.getSize()
097: + ""));
098:
099: return searcher.present(context, params, _config);
100: }
101: }
102:
103: //=============================================================================
|