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.wfp.vam.intermap.services.banner;
025:
026: import org.jdom.*;
027:
028: import jeeves.interfaces.*;
029: import jeeves.server.*;
030: import jeeves.server.context.*;
031: import jeeves.constants.*;
032:
033: //=============================================================================
034:
035: /** This service returns all information needed to build the banner with XSL
036: */
037:
038: public class Get implements Service {
039: public void init(String appPath, ServiceConfig params)
040: throws Exception {
041: }
042:
043: //--------------------------------------------------------------------------
044: //---
045: //--- Exec
046: //---
047: //--------------------------------------------------------------------------
048:
049: public Element exec(Element params, ServiceContext context)
050: throws Exception {
051: Element res = new Element(Jeeves.Elem.RESPONSE).addContent(
052: getStack(context)).addContent(getUserInfo(context));
053:
054: //--- add the invert tag if the banner must be flipped
055: //--- used for the arabic language
056:
057: if (getInvertValue(context.getLanguage()))
058: res.addContent(new Element("invert"));
059:
060: return res;
061: }
062:
063: //--------------------------------------------------------------------------
064: //--- Stack building
065: //--------------------------------------------------------------------------
066:
067: private Element getStack(ServiceContext srvContext) {
068: Element stackElem = new Element("stack");
069: String service = srvContext.getService();
070: // Element mainSearchElem = (Element) srvContext.getUserSession().getProperty(Geonet.Session.MAIN_SEARCH);
071:
072: //-----------------------------------------------------------------------
073: //--- build stack according with current service
074:
075: //--- we are in the main.search service
076:
077: stackElem
078: .addContent(new Element("current").addContent(service));
079: stackElem.addContent(new Element("language")
080: .addContent(srvContext.getLanguage()));
081:
082: /* RGFIX: should check session and modality (local/remote)
083: if (mainSearchElem != null && !mainSearchElem.getChildText(Geonet.SRV_MAIN_RESULT_TEXT).equals(""))
084: stackElem.addContent(new Element("result"));
085: */
086: return stackElem;
087: }
088:
089: //--------------------------------------------------------------------------
090: //--- Buttons building
091: //--------------------------------------------------------------------------
092:
093: private Element getUserInfo(ServiceContext srvContext) {
094: UserSession session = srvContext.getUserSession();
095:
096: return new Element("user").addContent(
097: new Element("username").setText(session.getUsername()))
098: .addContent(
099: new Element("name").setText(session.getName()))
100: .addContent(
101: new Element("surname").setText(session
102: .getSurname()));
103: }
104:
105: //--------------------------------------------------------------------------
106:
107: private boolean getInvertValue(String lang) {
108: return lang.equals("ar");
109: }
110: }
111:
112: //=============================================================================
|