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.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
00089 CallingServiceManager calling = CallingServiceManager.getManager();
00090 calling.clearStack();
00091
00092 NavigationBarManager.getManager().resetServiceTable();
00093
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
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
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 }