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