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.fao.geonet.services.thesaurus;
025:
026: import jeeves.constants.Jeeves;
027: import jeeves.interfaces.Service;
028: import jeeves.server.ServiceConfig;
029: import jeeves.server.UserSession;
030: import jeeves.server.context.ServiceContext;
031: import jeeves.utils.Util;
032: import jeeves.utils.Log;
033:
034: import org.fao.geonet.GeonetContext;
035: import org.fao.geonet.constants.Geonet;
036: import org.fao.geonet.kernel.ThesaurusManager;
037: import org.fao.geonet.kernel.search.KeywordsSearcher;
038: import org.jdom.Element;
039:
040: /**
041: * Returns a list of keywords given a list of thesaurus
042: */
043:
044: public class GetNarrowerBroader implements Service {
045: public void init(String appPath, ServiceConfig params)
046: throws Exception {
047: }
048:
049: // --------------------------------------------------------------------------
050: // ---
051: // --- Service
052: // ---
053: // --------------------------------------------------------------------------
054:
055: public Element exec(Element params, ServiceContext context)
056: throws Exception {
057: Element response = new Element(Jeeves.Elem.RESPONSE);
058: UserSession session = context.getUserSession();
059:
060: KeywordsSearcher searcher = null;
061:
062: // perform the search and save search result into session
063: // Creation d'un nouveau Keyword searcher
064: // Recupération du thesaurus manager
065: GeonetContext gc = (GeonetContext) context
066: .getHandlerContext(Geonet.CONTEXT_NAME);
067: ThesaurusManager thesaurusMan = gc.getThesaurusManager();
068:
069: Log.debug("KeywordsManager", "Creating new keywords searcher");
070: searcher = new KeywordsSearcher(thesaurusMan);
071:
072: String request = Util.getParam(params, "request");
073:
074: if (request.equals("broader") || request.equals("narrower")
075: || request.equals("related")) {
076: String reqType;
077:
078: if (request.equals("broader")) // If looking for broader search concept in a narrower element
079: reqType = "narrower";
080: else if (request.equals("narrower"))
081: reqType = "broader";
082: else
083: reqType = "related";
084:
085: searcher.searchBN(context, params, reqType);
086:
087: searcher.sortResults("label");
088:
089: // Build response
090: Element keywordType = new Element(reqType);
091: keywordType.addContent(searcher.getResults(params));
092: response.addContent(keywordType);
093: } else
094: throw new Exception("unknown request type: " + request);
095:
096: return response;
097: }
098: }
099:
100: // =============================================================================
|