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
00029
00030 package org.openmobileis.services;
00031
00032 import freemarker.template.*;
00033 import java.io.IOException;
00034
00035 import javax.servlet.ServletException;
00036 import javax.servlet.http.HttpServletRequest;
00037 import javax.servlet.http.HttpServletResponse;
00038
00039 import org.openmobileis.common.util.log.*;
00040 import org.openmobileis.embedded.webserver.templates.TemplateManager;
00041 import org.openmobileis.embedded.webserver.templates.TemplateNotFoundException;
00042 import org.openmobileis.services.common.ServletTools;
00043 import org.openmobileis.services.navigation.NavigationBarManager;
00044
00054 public abstract class TemplateService extends Service {
00055
00056 public TemplateService() {
00057 TemplateManager.getManager();
00058 }
00059
00060
00061
00062
00063
00064
00065 public void run(HttpServletRequest req, HttpServletResponse res ) throws ServletException, IOException {
00066
00067 try {
00068 TemplateModelRoot modelRoot = TemplateManager.getManager().getTemplateModelRoot();
00069 String templateName = this.runTemplate(req, res, modelRoot);
00070
00071
00072 if (this.isNavigationService()) {
00073
00074 String navBar = NavigationBarManager.getManager().getNavigationBar();
00075 modelRoot.put("navbarNOSY", new SimpleScalar(navBar));
00076 }
00077
00078 if (templateName != null) {
00079 try {
00080 TemplateManager.getManager().sendResponse(templateName, modelRoot, res);
00081 } catch (TemplateNotFoundException ex) {
00082 try {
00083 org.openmobileis.common.intl.IntlResourceManager resourceManager = org.openmobileis.common.intl.IntlResourceManager.getManager();
00084 String title = resourceManager.getLocalizedProperty("TemplateService.ExecError");
00085 res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, title);
00086 } catch (Exception exi) {
00087 }
00088 LogManager.traceAlert(LogServices.WEBSERVICE, "Error Template not found name :"+templateName);
00089 LogManager.traceAlert(LogServices.WEBSERVICE, ex);
00090 } catch (Exception ex) {
00091 try {
00092 org.openmobileis.common.intl.IntlResourceManager resourceManager = org.openmobileis.common.intl.IntlResourceManager.getManager();
00093 String title = resourceManager.getLocalizedProperty("TemplateService.ExecError");
00094 res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, title);
00095 } catch (Exception exi) {
00096 }
00097 LogManager.traceAlert(LogServices.WEBSERVICE, "Error during execution of Service"+this.getName());
00098 LogManager.traceAlert(LogServices.WEBSERVICE, ex);
00099 }
00100 }
00101 } catch (Exception ex) {
00102 LogManager.traceAlert(LogServices.WEBSERVICE, "Error during execution of Template Service"+this.getName());
00103 LogManager.traceAlert(LogServices.WEBSERVICE, ex);
00104 org.openmobileis.common.intl.IntlResourceManager resourceManager = org.openmobileis.common.intl.IntlResourceManager.getManager();
00105 String message = resourceManager.getLocalizedProperty("TemplateService.UnknownError");
00106 String title = resourceManager.getLocalizedProperty("TemplateService.Title");
00107 ServletTools.sendErrorPage(title, message, "/index", res);
00108 }
00109 }
00110
00115 public abstract String runTemplate ( HttpServletRequest req, HttpServletResponse res , TemplateModelRoot templateData) throws ServletException, IOException ;
00116
00117 }