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
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
00098 SessionContext context = SessionContextManager.getManager().getSessionContext();
00099 CallingServiceManager calling = (CallingServiceManager) context.getAttribute("openMIS.CallingServiceManager");
00100 calling.clearStack();
00101
00102 NavigationBarManager.getManager().resetServiceTable();
00103
00104 SessionContext session = SessionContextManager.getManager().getSessionContext();
00105 session.clearAttribute();
00106
00107
00108
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
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
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 }