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             String message = resourceManager.getLocalizedProperty("TemplateService.UnknownError");
00087             ServletTools.sendErrorPage(title, message, "/index", res);
00088           } catch (Exception exi)  {
00089           }
00090           LogManager.traceAlert(LogServices.WEBSERVICE, "Error Template not found name :"+templateName);
00091           LogManager.traceAlert(LogServices.WEBSERVICE, ex);
00092         } catch (Exception ex) {
00093           try {
00094             org.openmobileis.common.intl.IntlResourceManager resourceManager = org.openmobileis.common.intl.IntlResourceManager.getManager();
00095             String title = resourceManager.getLocalizedProperty("TemplateService.ExecError");
00096             String message = resourceManager.getLocalizedProperty("TemplateService.UnknownError");
00097             ServletTools.sendErrorPage(title, message, "/index", res);
00098           } catch (Exception exi)  {
00099           }
00100           LogManager.traceAlert(LogServices.WEBSERVICE, "Error during execution of Service"+this.getServiceUri());
00101           LogManager.traceAlert(LogServices.WEBSERVICE, ex);
00102         }
00103       }
00104     } catch (Exception ex) {
00105                         LogManager.traceAlert(LogServices.WEBSERVICE, "Error during execution of Template Service"+this.getServiceUri());
00106                         LogManager.traceAlert(LogServices.WEBSERVICE, ex);
00107       org.openmobileis.common.intl.IntlResourceManager resourceManager = org.openmobileis.common.intl.IntlResourceManager.getManager();
00108       String message = resourceManager.getLocalizedProperty("TemplateService.UnknownError");
00109       String title = resourceManager.getLocalizedProperty("TemplateService.Title");
00110       ServletTools.sendErrorPage(title, message, "/index", res);
00111     }
00112   }
00113 
00118   public abstract String runTemplate ( HttpServletRequest req, HttpServletResponse res , TemplateModelRoot templateData) throws ServletException, IOException ;
00119 
00120 }

Generated on Mon Jan 11 21:19:17 2010 for OpenMobileIS by  doxygen 1.5.4