MainSubEditService.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  */
00025 package org.openmobileis.services;
00026 
00027 import java.io.IOException;
00028 
00029 import javax.servlet.ServletException;
00030 import javax.servlet.http.HttpServletRequest;
00031 import javax.servlet.http.HttpServletResponse;
00032 import javax.servlet.http.HttpSession;
00033 
00034 import org.openmobileis.common.util.exception.ServiceException;
00035 import org.openmobileis.common.util.log.LogManager;
00036 import org.openmobileis.services.common.ServiceManager;
00037 
00038 import freemarker.template.TemplateModelRoot;
00039 
00051 public abstract class MainSubEditService extends SimpleEditService {
00052         
00053         public MainSubEditService()     {
00054                 
00055         }
00056 
00057         public String runTemplate (HttpServletRequest req, HttpServletResponse res , TemplateModelRoot templateData) throws ServletException, IOException {
00058                 try     {
00059                         //Look after the session if it's not null
00060                         
00061                         if(req.getSession().getAttribute(this.getSessionDataTempName()) != null){
00062 //                              Object sessionDatas = req.getSession().getAttribute(this.getSessionDataTempName());
00063                                 
00064 //                              Map map2 = req.getParameterMap();
00065 //                              map2.putAll((Map)sessionDatas);
00066                                 //remove the session
00067                                 req.getSession().removeAttribute(this.getSessionDataTempName());
00068                         
00069                         }else{
00070                         
00071                                 String url = req.getParameter("redirectURL");
00072                                 if(url != null){
00073                                         //put the params request in the session and do redirect service
00074                                         HttpSession session = req.getSession(true);
00075                                         session.setAttribute(this.getSessionDataTempName(), req.getParameterMap());
00076                                         ServiceManager.getManager().redirectToServiceURI(url, req, res);
00077                                         return null;
00078                                 }
00079                                 
00080 
00081                         }
00082 
00083                         //run the SimpleEditService()
00084                         return super.runTemplate(req,res,templateData);
00085                         //return this.getTemplateName();
00086                 } catch (Exception ex) {
00087                         LogManager.traceError(0, ex);
00088                         HttpSession session = req.getSession(true);
00089                         session.removeAttribute(this.getSessionDatasName());
00090                         session.removeAttribute(this.getErrorSessionAttributName());
00091                         throw new ServletException(ex);
00092                 }
00093         }
00094         
00095         protected boolean isStoreMode(HttpServletRequest req)   {
00096                 
00097                 String uri = req.getParameter("redirectURL");
00098                 if (uri != null)        {
00099                         EditService service = (EditService)ServiceManager.getManager().getServiceByURI(uri);
00100                         
00101                         if (service.hasSessionData(req))        {
00102                                 service.removeSessionData(req);
00103                                 return false;
00104                         }
00105                 }
00106 
00107                 return true;
00108         }
00109 
00110         private String getSessionDataTempName(){
00111                 return "Session.MultiEdit.temp";
00112         }
00113         
00114         protected abstract void fillTemplateWithSessionData(Object sessionDatas, TemplateModelRoot templateData) throws ServiceException;       
00115         protected abstract void storeSessionObjectInDB(Object sessionDatas, HttpServletRequest req, TemplateModelRoot templateData) throws ServiceException;    
00116         protected abstract void fillSessionObjectWithRequestData(Object sessionDatas, HttpServletRequest req) throws ServiceException;  
00117         protected abstract String getSessionDatasName();
00118         protected abstract String getTemplateName();
00119         protected abstract Object createSessionObject(HttpServletRequest req) throws ServiceException;
00120         protected abstract String getDisplayServiceURI();
00121         
00122 
00123 }

Generated on Mon Jan 14 17:29:48 2008 for OpenMobileIS by  doxygen 1.5.4