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.services.TemplateService;
00035 import org.openmobileis.services.common.CallingServiceManager;
00036 import org.openmobileis.services.common.ServiceManager;
00037 import org.openmobileis.services.navigation.NavigationBarManager;
00038 import org.openmobileis.services.navigation.NavigationBarService;
00039 import org.openmobileis.synchro.openmsp.client.OpenMSPSynchroManager;
00040 import org.openmobileis.synchro.openmsp.protocol.Status;
00041 
00042 import freemarker.template.*;
00043 import java.io.*;
00044 
00045 import javax.servlet.ServletException;
00046 import javax.servlet.http.HttpServletRequest;
00047 import javax.servlet.http.HttpServletResponse;
00048 
00060 public class IndexServlet extends TemplateService implements NavigationBarService {
00061 
00062   private static int uniqID = 0;
00063   protected static IndexServlet serverIndexServlet;
00064   
00065   private Array contentListenerMap;
00066   
00067   public IndexServlet() {
00068       contentListenerMap = new Array(5);
00069       serverIndexServlet = this;
00070       ApplicationContextManager.getManager().addManager(this);
00071    }
00072   
00073   public static IndexServlet getIndexServlet()  {
00074     return serverIndexServlet;
00075   }
00076   
00077   public String getIndexServletTemplateName()   {
00078     return "openmischannel"+java.io.File.separator+"index.htm";
00079   }
00080   
00081   public synchronized void addContentListener(IndexServletContentListener listener) {
00082     contentListenerMap.add(listener);
00083   }
00084 
00085         public String runTemplate(HttpServletRequest req, HttpServletResponse res, TemplateModelRoot modelRoot)
00086                 throws ServletException, IOException {
00087     try {  
00088             // unregister pendding calling service
00089       CallingServiceManager calling = CallingServiceManager.getManager();
00090       calling.clearStack();
00091       
00092                         NavigationBarManager.getManager().resetServiceTable();
00093             //remove session attribut
00094             SessionContext session = SessionContextManager.getManager().getSessionContext();
00095             session.clearAttribute();       
00096             
00097             for (int i=0; i<contentListenerMap.size(); i++) {
00098               IndexServletContentListener listener = (IndexServletContentListener)contentListenerMap.get(i);
00099               listener.addContent(modelRoot);
00100              
00101             } 
00102             // display date
00103             java.text.SimpleDateFormat formatter
00104               = new java.text.SimpleDateFormat ("dd/MM/yyyy", java.util.Locale.FRANCE);
00105             java.util.Date newDate = new java.util.Date(org.openmobileis.embedded.util.SystemAPI.currentTimeInMillis());
00106             modelRoot.put("date", new SimpleScalar(formatter.format(newDate)));
00107             modelRoot.put("uniqID", new SimpleScalar(Integer.toString(uniqID++)));
00108                 
00109                 
00110                   // journal
00111                   if (OpenMSPSynchroManager.getManager().getGlobalSynchroStatut() == Status.STATUS_OK)
00112                     modelRoot.put("journalStatus", new SimpleScalar("journalOK"));
00113                   else
00114                         modelRoot.put("journalStatus", new SimpleScalar("journalNOK"));
00115                 } catch (Exception ex) {
00116                     LogManager.traceAlert(LogServices.WEBSERVICE, ex);
00117                     res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Erreur survenue lors de l'execution du service");
00118                 }
00119                 
00120           return getIndexServletTemplateName();
00121   }
00122 
00123   public String getServiceUri() {
00124     return ServiceManager.getManager().getServiceBaseURI()+"/index";
00125   }
00126   
00127         public String getNavigationBarLabel(HttpServletRequest req)     {
00128       String home = IntlResourceManager.getManager().getLocalizedProperty("org.openmobileis.services.IndexServlet.name", "Home");
00129           return home;
00130         }
00131         
00132         public boolean displayFormExitMessage() {
00133                 return false;
00134         }
00135         
00136         public boolean displayRecursive() {
00137                 return false;
00138         }
00139 
00140 }

Generated on Tue May 22 23:01:10 2007 for OpenMobileIS by  doxygen 1.5.1-p1