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 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
00060
00061 if(req.getSession().getAttribute(this.getSessionDataTempName()) != null){
00062
00063
00064
00065
00066
00067 req.getSession().removeAttribute(this.getSessionDataTempName());
00068
00069 }else{
00070
00071 String url = req.getParameter("redirectURL");
00072 if(url != null){
00073
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
00084 return super.runTemplate(req,res,templateData);
00085
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 }