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 GetKeywords 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: boolean newSearch = Util.getParam(params, "pNewSearch").equals(
063: "true");
064: if (newSearch) {
065: // perform the search and save search result into session
066: GeonetContext gc = (GeonetContext) context
067: .getHandlerContext(Geonet.CONTEXT_NAME);
068: ThesaurusManager thesaurusMan = gc.getThesaurusManager();
069:
070: Log.debug("KeywordsManager",
071: "Creating new keywords searcher");
072: searcher = new KeywordsSearcher(thesaurusMan);
073: searcher.search(context, params);
074: searcher.sortResults("label");
075: session.setProperty(Geonet.Session.SEARCH_KEYWORDS_RESULT,
076: searcher);
077: } else {
078: searcher = (KeywordsSearcher) session
079: .getProperty(Geonet.Session.SEARCH_KEYWORDS_RESULT);
080: }
081:
082: // get the results
083: response.addContent(searcher.getResults(params));
084:
085: // If editing
086: if (params.getChild("pMode") != null) {
087: String mode = Util.getParam(params, "pMode");
088: if (mode.equals("edit") || mode.equals("consult")) {
089: String thesaurus = Util.getParam(params, "pThesauri",
090: "");
091:
092: response.addContent(new Element("thesaurus")
093: .addContent(thesaurus));
094:
095: response.addContent((new Element("mode"))
096: .addContent(mode));
097: }
098: }
099:
100: return response;
101: }
102: }
103:
104: // =============================================================================
|