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 javax.servlet.http.HttpServletRequest;
23  import javax.servlet.http.HttpServletResponse;
24  
25  import jdbcadmin.core.data.Line;
26  import jdbcadmin.core.data.Table;
27  import jdbcadmin.web.ContexteManager;
28  import jdbcadmin.web.util.HttpWrapper;
29  
30  import org.apache.commons.logging.Log;
31  import org.apache.commons.logging.LogFactory;
32  import org.apache.struts.action.ActionError;
33  import org.apache.struts.action.ActionErrors;
34  import org.apache.struts.action.ActionForm;
35  import org.apache.struts.action.ActionForward;
36  import org.apache.struts.action.ActionMapping;
37  
38  /***
39   * Actions on a line (update, delete)
40   * @author Thomas Recloux (trecloux@norsys.fr)
41   * @struts.action
42   * name="actionForm"
43   * path="/lineAction"
44   * @struts.action-forward
45   * name="update"
46   * path="/update.jsp"
47   * @struts.action-forward
48   * name="confirmDelete"
49   * path="/delete.jsp"
50   */
51  public class LineAction extends IndexedAction {
52  
53      /*** Logger */
54      private static Log logger = LogFactory.getLog(LineAction.class);
55  
56      /*** {@inheritDoc} */
57      public ActionForward indexedExec(
58          ActionMapping mapping,
59          ActionForm form,
60          HttpServletRequest request,
61          HttpServletResponse response)
62          throws Exception {
63  
64          ActionErrors errors = new ActionErrors();
65          ActionForward forward = new ActionForward();
66          jdbcadmin.web.forms.ActionForm actionForm = (jdbcadmin.web.forms.ActionForm) form;
67          String strForward = "update";
68          // return value
69  
70          try {
71              Table tab = ContexteManager.getCurrentTable(request);
72              Line ligne = new Line(tab);
73              HttpWrapper.wrapLine(request, ligne);
74  
75              request.setAttribute("line", ligne);
76  
77              if (actionForm.getTypeAction().equals("update")) {
78                  strForward = "update";
79              } else if (actionForm.getTypeAction().equals("delete")) {
80                  strForward = "confirmDelete";
81              }
82  
83          } catch (Exception e) {
84              if (logger.isErrorEnabled()) {
85                  logger.error("Unexpeted error during the action", e);
86              }
87              errors.add(ActionErrors.GLOBAL_ERROR, new ActionError("error.generic", e.getMessage()));
88              strForward = "error";
89          }
90  
91          // If a message is required, save the specified key(s)
92          // into the request for use by the <struts:errors> tag.
93  
94          if (!errors.isEmpty()) {
95              saveErrors(request, errors);
96          }
97          // Write logic determining how the user should be forwarded.
98          forward = mapping.findForward(strForward);
99  
100         // Finish with
101         return (forward);
102     }
103 }