IndexServlet.java

00001 /*
00002  * OpenMobileIS - a free Java(TM) Framework for mobile applications Java(TM)
00003  * Copyright (C) 2004-2006 Philippe Delrieu
00004  * All rights reserved.
00005  * Contact: pdelrieu@openmobileis.org
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00020  * USA
00021  *
00022  *  Author : Philippe Delrieu
00023  *
00024  */
00025 
00026 package org.openmobileis.services.servlet;
00027 
00028 import org.openmobileis.common.util.collection.Array;
00029 import org.openmobileis.common.util.log.*;
00030 import org.openmobileis.common.context.ApplicationContextManager;
00031 import org.openmobileis.common.context.SessionContext;
00032 import org.openmobileis.common.context.SessionContextManager;
00033 import org.openmobileis.common.intl.IntlResourceManager;
00034 import org.openmobileis.embedded.util.SystemAPI;
00035 import org.openmobileis.services.TemplateService;
00036 import org.openmobileis.services.common.CallingServiceManager;
00037 import org.openmobileis.services.common.ServiceManager;
00038 import org.openmobileis.services.navigation.NavigationBarManager;
00039 import org.openmobileis.services.navigation.NavigationBarService;
00040 import org.openmobileis.synchro.openmsp.client.OpenMSPSynchroManager;
00041 import org.openmobileis.synchro.openmsp.protocol.Status;
00042 
00043 import freemarker.template.*;
00044 import java.io.*;
00045 
00046 import javax.servlet.ServletException;
00047 import javax.servlet.http.HttpServletRequest;
00048 import javax.servlet.http.HttpServletResponse;
00049 
00061 public class IndexServlet extends TemplateService implements NavigationBarService {
00062 
00063   private static int uniqID = 0;
00064   protected static IndexServlet serverIndexServlet;
00065 
00066   private Array contentListenerMap;
00067 
00068   public IndexServlet() {
00069       contentListenerMap = new Array(5);
00070       serverIndexServlet = this;
00071       ApplicationContextManager.getManager().addManager(this);
00072    }
00073 
00074   public static IndexServlet getIndexServlet()  {
00075     return serverIndexServlet;
00076   }
00077 
00078   public String getIndexServletTemplateName()   {
00079     return "openmischannel"+java.io.File.separator+"index.htm";
00080   }
00081 
00082   public synchronized void addContentListener(IndexServletContentListener listener) {
00083     contentListenerMap.add(listener);
00084   }
00085 
00086         public String runTemplate(HttpServletRequest req, HttpServletResponse res, TemplateModelRoot modelRoot)
00087                 throws ServletException, IOException {
00088     try {
00089             // unregister pendding calling service
00090       CallingServiceManager calling = CallingServiceManager.getManager();
00091       calling.clearStack();
00092 
00093                         NavigationBarManager.getManager().resetServiceTable();
00094             //remove session attribut
00095             SessionContext session = SessionContextManager.getManager().getSessionContext();
00096             session.clearAttribute();
00097 
00098             for (int i=0; i<contentListenerMap.size(); i++) {
00099               IndexServletContentListener listener = (IndexServletContentListener)contentListenerMap.get(i);
00100               listener.addContent(modelRoot, req,  res);
00101 
00102             }
00103             // display date
00104             java.text.SimpleDateFormat formatter
00105               = new java.text.SimpleDateFormat ("dd/MM/yyyy", java.util.Locale.FRANCE);
00106             java.util.Date newDate = new java.util.Date(SystemAPI.getManager().currentTimeInMillis());
00107             modelRoot.put("date", new SimpleScalar(formatter.format(newDate)));
00108             modelRoot.put("uniqID", new SimpleScalar(Integer.toString(uniqID++)));
00109 
00110 
00111                   // journal
00112                   if (OpenMSPSynchroManager.getManager().getGlobalSynchroStatut() == Status.STATUS_OK)
00113                     modelRoot.put("journalStatus", new SimpleScalar("journalOK"));
00114                   else
00115                         modelRoot.put("journalStatus", new SimpleScalar("journalNOK"));
00116                 } catch (Exception ex) {
00117                     LogManager.traceAlert(LogServices.WEBSERVICE, ex);
00118                     res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Erreur survenue lors de l'execution du service");
00119                 }
00120 
00121           return getIndexServletTemplateName();
00122   }
00123 
00124   public String getServiceUri() {
00125     return ServiceManager.getManager().getServiceBaseURI()+"/index";
00126   }
00127 
00128         public String getNavigationBarLabel(HttpServletRequest req)     {
00129       String home = IntlResourceManager.getManager().getLocalizedProperty("org.openmobileis.services.IndexServlet.name", "Home");
00130           return home;
00131         }
00132 
00133         public boolean displayFormExitMessage() {
00134                 return false;
00135         }
00136 
00137         public boolean displayRecursive() {
00138                 return false;
00139         }
00140 
00141 }

Generated on Mon Jan 14 17:29:47 2008 for OpenMobileIS by  doxygen 1.5.4