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.common;
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.Service;
00043 import org.openmobileis.services.ServletTools;
00044 import org.openmobileis.services.navigation.NavigationBarManager;
00045
00055 public abstract class TemplateService extends Service {
00056
00057 public TemplateService() {
00058 TemplateManager.getManager();
00059 }
00060
00061
00062
00063
00064
00065
00066 public void run(HttpServletRequest req, HttpServletResponse res ) throws ServletException, IOException {
00067
00068 try {
00069 TemplateModelRoot modelRoot = TemplateManager.getManager().getTemplateModelRoot();
00070 String templateName = this.runTemplate(req, res, modelRoot);
00071
00072
00073 if (this.isNavigationService()) {
00074
00075 String navBar = NavigationBarManager.getManager().getNavigationBar();
00076 modelRoot.put("navbarNOSY", new SimpleScalar(navBar));
00077 }
00078
00079 if (templateName != null) {
00080 try {
00081 TemplateManager.getManager().sendResponse(templateName, modelRoot, res);
00082 } catch (TemplateNotFoundException ex) {
00083 try {
00084 org.openmobileis.common.intl.IntlResourceManager resourceManager = org.openmobileis.common.intl.IntlResourceManager.getManager();
00085 String title = resourceManager.getLocalizedProperty("TemplateService.ExecError");
00086 res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, title);
00087 } catch (Exception exi) {
00088 }
00089 LogManager.traceAlert(LogServices.WEBSERVICE, "Error Template not found name :"+templateName);
00090 LogManager.traceAlert(LogServices.WEBSERVICE, ex);
00091 } catch (Exception ex) {
00092 try {
00093 org.openmobileis.common.intl.IntlResourceManager resourceManager = org.openmobileis.common.intl.IntlResourceManager.getManager();
00094 String title = resourceManager.getLocalizedProperty("TemplateService.ExecError");
00095 res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, title);
00096 } catch (Exception exi) {
00097 }
00098 LogManager.traceAlert(LogServices.WEBSERVICE, "Error during execution of Service"+this.getName());
00099 LogManager.traceAlert(LogServices.WEBSERVICE, ex);
00100 }
00101 }
00102 } catch (Exception ex) {
00103 LogManager.traceAlert(LogServices.WEBSERVICE, "Error during execution of Template Service"+this.getName());
00104 LogManager.traceAlert(LogServices.WEBSERVICE, ex);
00105 org.openmobileis.common.intl.IntlResourceManager resourceManager = org.openmobileis.common.intl.IntlResourceManager.getManager();
00106 String message = resourceManager.getLocalizedProperty("TemplateService.UnknownError");
00107 String title = resourceManager.getLocalizedProperty("TemplateService.Title");
00108 ServletTools.sendErrorPage(title, message, "/index", res);
00109 }
00110 }
00111
00112 public void init (String name) {
00113 super.init(name);
00114 }
00115
00120 public abstract String runTemplate ( HttpServletRequest req, HttpServletResponse res , TemplateModelRoot templateData) throws ServletException, IOException ;
00121
00122 }