View Javadoc

1   /* ==============================================================================
2    *   JDBCAdmin, data management software.
3    *   Copyright (C) 2005  Norsys S.A
4    *
5    *   This library is free software; you can redistribute it and/or
6    *   modify it under the terms of the GNU Lesser General Public
7    *   License as published by the Free Software Foundation; either
8    *   version 2.1 of the License, or (at your option) any later version.
9    *
10   *   This library is distributed in the hope that it will be useful,
11   *   but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13   *   Lesser General Public License for more details.
14   *
15   *   You should have received a copy of the GNU Lesser General Public
16   *   License along with this library; if not, write to the Free Software
17   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   * ==============================================================================
19   */
20  package jdbcadmin.web.actions;
21  
22  import java.util.List;
23  
24  import javax.servlet.http.HttpServletRequest;
25  import javax.servlet.http.HttpServletResponse;
26  
27  import jdbcadmin.core.data.Line;
28  import jdbcadmin.core.data.Table;
29  import jdbcadmin.web.ContexteManager;
30  import jdbcadmin.web.util.HttpWrapper;
31  
32  import org.apache.commons.logging.Log;
33  import org.apache.commons.logging.LogFactory;
34  import org.apache.struts.action.ActionError;
35  import org.apache.struts.action.ActionErrors;
36  import org.apache.struts.action.ActionForm;
37  import org.apache.struts.action.ActionForward;
38  import org.apache.struts.action.ActionMapping;
39  
40  /***
41   * @struts.action name="actionForm" path="/delete"
42   * @struts.action-forward name="main" path="/select.jsp"
43   * @struts.action-forward name="failure" path="/delete.jsp"
44   * @author Thomas Recloux (trecloux@norsys.fr)
45   */
46  public class DeleteAction extends IndexedAction {
47  
48      /*** Logger */
49      private static Log logger = LogFactory.getLog(DeleteAction.class);
50  
51      /***
52      * Constructor
53      */
54      public DeleteAction() {
55          super();
56      }
57  
58      /***
59       *  {@inheritDoc}
60       */
61      public ActionForward indexedExec(
62          ActionMapping mapping,
63          ActionForm form,
64          HttpServletRequest request,
65          HttpServletResponse response)
66          throws Exception {
67  
68          ActionErrors errors = new ActionErrors();
69          ActionForward forward = new ActionForward();
70          //jdbcadmin.web.forms.ActionForm actionForm = (jdbcadmin.web.forms.ActionForm) form;
71          String strForward = "main";
72          // return value
73  
74          try {
75              Table tab = ContexteManager.getCurrentTable(request);
76              Line line = new Line(tab);
77              HttpWrapper.wrapLine(request, line);
78  
79              request.setAttribute("line", line);
80  
81              ContexteManager.getManager(request).delete(line);
82              request.setAttribute("messageInfo", getResources(request).getMessage("message.delete.ok"));
83  
84              List lines = ContexteManager.getManager(request).select(tab,
85                  ContexteManager.getIdxDonnees(request),
86                  Constants.NB_LINES_PER_PAGE);
87  
88              request.setAttribute("lines", lines);
89  
90          } catch (Exception e) {
91              if (logger.isErrorEnabled()) {
92                  logger.error("Unexpected error in the delete action", e);
93              }
94              errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.generic", e.getMessage()));
95              strForward = "error";
96          }
97  
98          // If a message is required, save the specified key(s)
99          // into the request for use by the <struts:errors> tag.
100 
101         if (!errors.isEmpty()) {
102             saveErrors(request, errors);
103         }
104 
105         // Write logic determining how the user should be forwarded.
106         forward = mapping.findForward(strForward);
107 
108         // Finish with
109         return (forward);
110 
111     }
112 }