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