TemplateService.java

00001 /*
00002  * OpenMobileIS - a free Java(TM) Framework for mobile applications Java(TM)
00003  * Copyright (C) 2004-2006 Philippe Delrieu
00004  * All rights reserved.
00005  * Contact: pdelrieu@openmobileis.org
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 java.io.IOException;
00033 
00034 import javax.servlet.ServletException;
00035 import javax.servlet.http.HttpServletRequest;
00036 import javax.servlet.http.HttpServletResponse;
00037 
00038 import org.openmobileis.common.util.log.*;
00039 import org.openmobileis.embedded.webserver.templates.TemplateManager;
00040 import org.openmobileis.embedded.webserver.templates.TemplateNotFoundException;
00041 import org.openmobileis.services.common.ServletTools;
00042 import org.openmobileis.services.navigation.NavigationBarManager;
00043 
00044 import freemarker.template.TemplateModelRoot;
00045 
00055 public abstract class TemplateService extends Service {
00056 
00057   public TemplateService() {
00058     TemplateManager.getManager();
00059   }
00060 
00061   /* Process the service
00062  * @param req the servlet request
00063  * @param req the servlet response
00064  *  @exception ServletException when an exception has occurred
00065  */
00066   public void run(HttpServletRequest req, HttpServletResponse res ) throws ServletException, IOException {
00067         //      LogManager.traceNotice(0, "TemplateService :Begin run");
00068     try {
00069         TemplateModelRoot modelRoot = TemplateManager.getManager().getTemplateModelRoot();
00070       String templateName = this.runTemplate(req, res, modelRoot);
00071 
00072                         //manage navigation bar.
00073                         if (this.isNavigationService()) {
00074                                 //manage return
00075                                 String navBar = NavigationBarManager.getManager().getNavigationBar();
00076                                 TemplateManager.getManager().updateTemplateWithNavigationBarData(modelRoot, 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.getServiceUri());
00099           LogManager.traceAlert(LogServices.WEBSERVICE, ex);
00100         }
00101       }
00102     } catch (Exception ex) {
00103                         LogManager.traceAlert(LogServices.WEBSERVICE, "Error during execution of Template Service"+this.getServiceUri());
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 
00116   public abstract String runTemplate ( HttpServletRequest req, HttpServletResponse res , TemplateModelRoot templateData) throws ServletException, IOException ;
00117 
00118 }

Generated on Tue May 22 23:01:12 2007 for OpenMobileIS by  doxygen 1.5.1-p1