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.PropertiesManager;
00029 import org.openmobileis.common.util.collection.Array;
00030 import org.openmobileis.common.util.log.*;
00031 import org.openmobileis.common.context.ApplicationContextManager;
00032 import org.openmobileis.common.context.SessionContext;
00033 import org.openmobileis.common.context.SessionContextManager;
00034 import org.openmobileis.common.intl.IntlResourceManager;
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.services.security.SecurityManager;
00041 import org.openmobileis.synchro.openmsp.client.OpenMSPSynchroManager;
00042 import org.openmobileis.synchro.openmsp.protocol.Status;
00043 
00044 import HTTPClient.HTTPConnection;
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 import javax.servlet.http.HttpSession;
00053 
00065 public class IndexServlet extends TemplateService implements NavigationBarService {
00066 
00067   private static int uniqID = 0;
00068   protected static IndexServlet serverIndexServlet;
00069   private boolean forcePass = false;
00070   
00071   private Array contentListenerMap;
00072   
00073   public IndexServlet() {
00074     LogManager.traceWarning(0, "INIT INDEXSERVLET");
00075       contentListenerMap = new Array(5);
00076       serverIndexServlet = this;
00077       ApplicationContextManager.getManager().addManager(this);
00078         String oslang = PropertiesManager.getManager().getProperty("org.openmobileis.service.forcepass");
00079         if (oslang != null) forcePass = true;
00080         else forcePass = false;
00081   }
00082   
00083   public static IndexServlet getIndexServlet()  {
00084     return serverIndexServlet;
00085   }
00086   
00087   public String getIndexServletTemplateName()   {
00088     return "openmischannel"+java.io.File.separator+"index.htm";
00089   }
00090   
00091   public synchronized void addContentListener(IndexServletContentListener listener) {
00092     contentListenerMap.add(listener);
00093   }
00094 
00095         public String runTemplate(HttpServletRequest req, HttpServletResponse res, TemplateModelRoot modelRoot)
00096                 throws ServletException, IOException {
00097     try {  
00098             // unregister pendding calling service
00099       CallingServiceManager calling = CallingServiceManager.getManager();
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 getServiceUri() {
00142     return ServiceManager.getManager().getServiceBaseURI()+"/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 Mon Dec 4 11:03:27 2006 for OpenMobileIS by  doxygen 1.5.1-p1