KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openi > web > controller > analysis > DeleteAnalysisFormController


1 /*********************************************************************************
2  * The contents of this file are subject to the OpenI Public License Version 1.0
3  * ("License"); You may not use this file except in compliance with the
4  * License. You may obtain a copy of the License at
5  * http://www.openi.org/docs/LICENSE.txt
6  *
7  * Software distributed under the License is distributed on an "AS IS" basis,
8  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
9  * the specific language governing rights and limitations under the License.
10  *
11  * The Original Code is: OpenI Open Source
12  *
13  * The Initial Developer of the Original Code is Loyalty Matrix, Inc.
14  * Portions created by Loyalty Matrix, Inc. are
15  * Copyright (C) 2005 Loyalty Matrix, Inc.; All Rights Reserved.
16  *
17  * Contributor(s): ______________________________________.
18  *
19  ********************************************************************************/

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 JavaDoc;
28 import java.util.Map JavaDoc;
29 import javax.servlet.http.HttpServletRequest JavaDoc;
30 import javax.servlet.http.HttpServletResponse JavaDoc;
31 import javax.servlet.http.HttpSession JavaDoc;
32
33
34 /**
35  * @author Uddhab Pant <br>
36  * @version $Revision: 1.6 $ $Date: 2006/04/12 00:39:12 $ <br>
37  *
38  * This controller handles delete analysis request.
39  *
40  */

41 public class DeleteAnalysisFormController extends SimpleFormController {
42     private static Logger logger = Logger.getLogger(DeleteAnalysisFormController.class);
43
44     /**
45      * This method will create the command object and set it in its initial state.
46      * This method is called before the user is directed to the first page of the wizard
47      *
48      * @param request HttpServletRequest
49      * @return Object
50      * @throws Exception
51      *
52      */

53     protected Object JavaDoc formBackingObject(HttpServletRequest JavaDoc request)
54         throws Exception JavaDoc {
55         Map JavaDoc model;
56         String JavaDoc message;
57
58         try {
59             model = new HashMap JavaDoc();
60
61             String JavaDoc analysisConfigName = (String JavaDoc) request.getSession()
62                                                         .getAttribute("analysisConfigName");
63
64             // construct message to display on page.
65
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 JavaDoc e) {
85             logger.error("Exception:", e);
86             throw e;
87         }
88     }
89
90     /**
91      * Submit callback with all parameters. Called in case of submit without
92      * errors reported by the registered validator, or on every submit if no validator.
93      * @param request HttpServletRequest
94      * @param response HttpServletResponse
95      * @param command Object
96      * @param errors BindException
97      * @return ModelAndView
98      * @throws Exception
99      */

100     protected ModelAndView onSubmit(HttpServletRequest JavaDoc request,
101         HttpServletResponse JavaDoc response, Object JavaDoc command, BindException errors)
102         throws Exception JavaDoc {
103         try {
104             String JavaDoc action = request.getParameter("action");
105
106             logger.debug("action:" + action);
107
108             // if user selects delete button
109
if ("Delete".equals(action)) {
110                 return handleDelete(request, response, command, errors);
111             }
112             //if user selects cancel button,
113
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 JavaDoc e) {
119             logger.error("Exception:", e);
120             throw e;
121         }
122     }
123
124     /**
125      * This method handles delete action.
126      *
127      * @param request HttpServletRequest
128      * @param response HttpServletResponse
129      * @param command Object
130      * @param errors BindException
131      * @return ModelAndView
132      * @throws Exception
133      */

134     protected ModelAndView handleDelete(HttpServletRequest JavaDoc request,
135         HttpServletResponse JavaDoc response, Object JavaDoc command, BindException errors)
136         throws Exception JavaDoc {
137         HttpSession JavaDoc session = request.getSession();
138
139         ProjectContext projectContext = (ProjectContext) session.getAttribute(
140                 "projectContext");
141
142         String JavaDoc analysisConfigName = (String JavaDoc) session.getAttribute(
143                 "analysisConfigName");
144
145         // delegate delete analysis task to project context.
146
projectContext.deleteAnalysis(analysisConfigName);
147
148         session.removeAttribute("analysisConfigName");
149
150         // redirect to splash page
151
return new ModelAndView("splashRedirect");
152
153         //need to redirect to splash page when splash page is implemented in spring
154
//return super.onSubmit(request, response, command, errors);
155
}
156
157     /**
158      * This method handle cancel action and redirect to analysis page.
159      *
160      * @param request HttpServletRequest
161      * @param response HttpServletResponse
162      * @param command Object
163      * @param errors BindException
164      * @return ModelAndView
165      * @throws Exception
166      */

167     protected ModelAndView handleCancel(HttpServletRequest JavaDoc request,
168         HttpServletResponse JavaDoc response, Object JavaDoc command, BindException errors)
169         throws Exception JavaDoc {
170         return super.onSubmit(request, response, command, errors);
171     }
172 }
173
Popular Tags