1 20 package org.openi.web.controller.analysis; 21 22 import org.apache.log4j.Logger; 23 import org.openi.project.ProjectContext; 24 import org.springframework.validation.BindException; 25 import org.springframework.web.servlet.ModelAndView; 26 import org.springframework.web.servlet.mvc.SimpleFormController; 27 import java.util.HashMap ; 28 import java.util.Map ; 29 import javax.servlet.http.HttpServletRequest ; 30 import javax.servlet.http.HttpServletResponse ; 31 import javax.servlet.http.HttpSession ; 32 33 34 41 public class DeleteAnalysisFormController extends SimpleFormController { 42 private static Logger logger = Logger.getLogger(DeleteAnalysisFormController.class); 43 44 53 protected Object formBackingObject(HttpServletRequest request) 54 throws Exception { 55 Map model; 56 String message; 57 58 try { 59 model = new HashMap (); 60 61 String analysisConfigName = (String ) request.getSession() 62 .getAttribute("analysisConfigName"); 63 64 message = "Are you sure you want to delete "; 66 67 if (analysisConfigName.indexOf("public") < 0) { 68 message += "your personal file "; 69 } else { 70 message += "the public file "; 71 } 72 73 analysisConfigName = analysisConfigName.replaceAll("public/", ""); 74 analysisConfigName = analysisConfigName.replaceAll("personal/", ""); 75 analysisConfigName = analysisConfigName.replaceAll(request.getUserPrincipal() 76 .getName() 77 + "/", ""); 78 79 message += analysisConfigName.replaceAll("\\,", "<br>"); 80 message += " ?"; 81 model.put("message", message); 82 83 return model; 84 } catch (Exception e) { 85 logger.error("Exception:", e); 86 throw e; 87 } 88 } 89 90 100 protected ModelAndView onSubmit(HttpServletRequest request, 101 HttpServletResponse response, Object command, BindException errors) 102 throws Exception { 103 try { 104 String action = request.getParameter("action"); 105 106 logger.debug("action:" + action); 107 108 if ("Delete".equals(action)) { 110 return handleDelete(request, response, command, errors); 111 } 112 else if ("Cancel".equals(action)) { 114 return handleCancel(request, response, command, errors); 115 } 116 117 return super.onSubmit(request, response, command, errors); 118 } catch (Exception e) { 119 logger.error("Exception:", e); 120 throw e; 121 } 122 } 123 124 134 protected ModelAndView handleDelete(HttpServletRequest request, 135 HttpServletResponse response, Object command, BindException errors) 136 throws Exception { 137 HttpSession session = request.getSession(); 138 139 ProjectContext projectContext = (ProjectContext) session.getAttribute( 140 "projectContext"); 141 142 String analysisConfigName = (String ) session.getAttribute( 143 "analysisConfigName"); 144 145 projectContext.deleteAnalysis(analysisConfigName); 147 148 session.removeAttribute("analysisConfigName"); 149 150 return new ModelAndView("splashRedirect"); 152 153 } 156 157 167 protected ModelAndView handleCancel(HttpServletRequest request, 168 HttpServletResponse response, Object command, BindException errors) 169 throws Exception { 170 return super.onSubmit(request, response, command, errors); 171 } 172 } 173 | Popular Tags |