00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
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
00090 CallingServiceManager calling = CallingServiceManager.getManager();
00091 calling.clearStack();
00092
00093 NavigationBarManager.getManager().resetServiceTable();
00094
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
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
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 }