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