Main Page | Packages | Class Hierarchy | Class List | Directories | File List | Class Members | Related Pages

TemplateService.java

00001 /*
00002  * OpenMobileIS - a free Java(TM) Framework for mobile applications Java(TM)
00003  * Copyright (C) 2004-2005 Philippe Delrieu
00004  * All rights reserved.
00005  * Contact: openmobileis@e-care.fr
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public
00009  * License as published by the Free Software Foundation; either
00010  * version 2.1 of the License, or any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this library; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
00020  * USA
00021  *
00022  *  Author : Philippe Delrieu
00023  *  
00024  *  Modifications :
00025  *  2004 Creation P.Delrieu
00026  *  2004 Modified by Romain Beaugrand
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   /* Process the service
00061  * @param req the servlet request
00062  * @param req the servlet response
00063  *  @exception ServletException when an exception has occurred
00064  */
00065   public void run(HttpServletRequest req, HttpServletResponse res ) throws ServletException, IOException {
00066         //      LogManager.traceNotice(0, "TemplateService :Begin run");
00067     try {
00068       TemplateModelRoot modelRoot = TemplateManager.getManager().getTemplateModelRoot();
00069       String templateName = this.runTemplate(req, res, modelRoot);
00070       
00071                         //manage navigation bar.
00072                         if (this.isNavigationService()) {
00073                                 //manage return
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 }

Generated on Wed Dec 14 21:05:35 2005 for OpenMobileIS by  doxygen 1.4.4