Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

IndexServlet.java

00001 /*
00002  *        OpenMobileIS - a free Java Framework for mobile applications
00003  *
00004  *   Copyright (C) 2002  Philippe Delrieu.
00005  *
00006  *   This program is free software; you can redistribute it and/or
00007  *   modify it under the terms of the GNU General Public
00008  *   License as published by the Free Software Foundation; either
00009  *   version 2 of the License, or (at your option) any later version.
00010  *
00011  *   This program is distributed in the hope that it will be useful,
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  *   General Public License for more details.
00015  *
00016  *   You should have received a copy of the GNU Library General Public
00017  *   License along with this library; if not, write to the Free
00018  *   Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  * 
00020  * Philippe Delrieu kept the rigth to distribute all code Copyrighted by philippe Delrieu
00021  *  under other licence term even commercial one.
00022  *  
00023  *  Modifications :
00024  *  2002 Creation P.Delrieu
00025  * 
00026  */
00027 
00028 package org.openmobileis.services.servlet;
00029 
00030 import org.openmobileis.common.util.PropertiesManager;
00031 import org.openmobileis.common.util.collection.Array;
00032 import org.openmobileis.common.util.log.*;
00033 import org.openmobileis.common.context.ApplicationContextManager;
00034 import org.openmobileis.common.context.SessionContext;
00035 import org.openmobileis.common.context.SessionContextManager;
00036 import org.openmobileis.common.intl.IntlResourceManager;
00037 import org.openmobileis.services.TemplateService;
00038 import org.openmobileis.services.common.CallingServiceManager;
00039 import org.openmobileis.services.common.ServiceManager;
00040 import org.openmobileis.services.navigation.NavigationBarManager;
00041 import org.openmobileis.services.navigation.NavigationBarService;
00042 import org.openmobileis.services.security.SecurityManager;
00043 import org.openmobileis.synchro.openmsp.client.OpenMSPSynchroManager;
00044 import org.openmobileis.synchro.openmsp.protocol.Status;
00045 
00046 import freemarker.template.*;
00047 import java.io.*;
00048 
00049 import javax.servlet.ServletException;
00050 import javax.servlet.http.HttpServletRequest;
00051 import javax.servlet.http.HttpServletResponse;
00052 
00064 public class IndexServlet extends TemplateService implements NavigationBarService {
00065 
00066   private static int uniqID = 0;
00067   protected static IndexServlet serverIndexServlet;
00068   private boolean forcePass = false;
00069   
00070   private Array contentListenerMap;
00071   
00072   public IndexServlet() {
00073     LogManager.traceWarning(0, "INIT INDEXSERVLET");
00074       contentListenerMap = new Array(5);
00075       serverIndexServlet = this;
00076       ApplicationContextManager.getManager().addManager(this);
00077         String oslang = PropertiesManager.getManager().getProperty("org.openmobileis.service.forcepass");
00078         if (oslang != null) forcePass = true;
00079         else forcePass = false;
00080   }
00081   
00082   public static IndexServlet getIndexServlet()  {
00083     return serverIndexServlet;
00084   }
00085   
00086   public String getIndexServletTemplateName()   {
00087     return "openmischannel"+java.io.File.separator+"index.htm";
00088   }
00089   
00090   public synchronized void addContentListener(IndexServletContentListener listener) {
00091     contentListenerMap.add(listener);
00092   }
00093 
00094         public String runTemplate(HttpServletRequest req, HttpServletResponse res, TemplateModelRoot modelRoot)
00095                 throws ServletException, IOException {
00096     try {  
00097             // unregister pendding calling service
00098       SessionContext context = SessionContextManager.getManager().getSessionContext();
00099       CallingServiceManager calling = (CallingServiceManager) context.getAttribute("openMIS.CallingServiceManager");
00100       calling.clearStack();
00101       
00102                         NavigationBarManager.getManager().resetServiceTable();
00103             //remove session attribut
00104             SessionContext session = SessionContextManager.getManager().getSessionContext();
00105             session.clearAttribute();
00106             
00107             
00108             //force password fill if need
00109       if ((!SecurityManager.getManager().isInitializedPass())&&(forcePass))     {
00110         ServiceManager.getManager().redirectToServiceURI("/common/showparamform", req, res);
00111                                 return null;
00112       }
00113             
00114             
00115             for (int i=0; i<contentListenerMap.size(); i++) {
00116               IndexServletContentListener listener = (IndexServletContentListener)contentListenerMap.get(i);
00117               listener.addContent(modelRoot);
00118              
00119             } 
00120             // display date
00121             java.text.SimpleDateFormat formatter
00122               = new java.text.SimpleDateFormat ("dd/MM/yyyy", java.util.Locale.FRANCE);
00123             java.util.Date newDate = new java.util.Date(org.openmobileis.embedded.util.SystemAPI.currentTimeInMillis());
00124             modelRoot.put("date", new SimpleScalar(formatter.format(newDate)));
00125             modelRoot.put("uniqID", new SimpleScalar(Integer.toString(uniqID++)));
00126                 
00127                 
00128                   // journal
00129                   if (OpenMSPSynchroManager.getManager().getGlobalSynchroStatut() == Status.STATUS_OK)
00130                     modelRoot.put("journalStatus", new SimpleScalar("journalOK"));
00131                   else
00132                         modelRoot.put("journalStatus", new SimpleScalar("journalNOK"));
00133                 } catch (Exception ex) {
00134                     LogManager.traceAlert(LogServices.WEBSERVICE, ex);
00135                     res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Erreur survenue lors de l'execution du service");
00136                 }
00137                 
00138           return getIndexServletTemplateName();
00139   }
00140 
00141   public String getName() {
00142     return "/index";
00143   }
00144   
00145         public String getNavigationBarLabel(HttpServletRequest req)     {
00146     String home = IntlResourceManager.getManager().getLocalizedProperty("org.openmobileis.services.IndexServlet.name", "Home");
00147                 return home;
00148         }
00149         
00150         public boolean displayFormExitMessage() {
00151                 return false;
00152         }
00153         
00154         public boolean displayRecursive() {
00155                 return false;
00156         }
00157 
00158 }

Generated on Wed Dec 14 21:05:33 2005 for OpenMobileIS by  doxygen 1.4.4