View Javadoc
1   /*
2    * This software was designed and created by Jason Carroll.
3    * Copyright (c) 2002, 2003, 2004 Jason Carroll.
4    * The author can be reached at jcarroll@cowsultants.com
5    * ITracker website: http://www.cowsultants.com
6    * ITracker forums: http://www.cowsultants.com/phpBB/index.php
7    *
8    * This program is free software; you can redistribute it and/or modify
9    * it only under the terms of the GNU General Public License as published by
10   * the Free Software Foundation; either version 2 of the License, or
11   * (at your option) any later version.
12   *
13   * This program is distributed in the hope that it will be useful,
14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   * GNU General Public License for more details.
17   */
18  
19  package org.itracker.web.servlets;
20  
21  import org.apache.commons.lang.StringUtils;
22  import org.apache.log4j.Logger;
23  import org.apache.struts.Globals;
24  import org.apache.struts.action.ActionErrors;
25  import org.itracker.model.PermissionType;
26  import org.itracker.model.User;
27  import org.itracker.services.ITrackerServices;
28  import org.itracker.model.util.UserUtilities;
29  import org.itracker.web.util.Constants;
30  import org.itracker.web.util.LoginUtilities;
31  import org.itracker.web.util.RequestHelper;
32  import org.itracker.web.util.ServletContextUtils;
33  
34  import javax.servlet.RequestDispatcher;
35  import javax.servlet.ServletContext;
36  import javax.servlet.ServletException;
37  import javax.servlet.http.HttpServlet;
38  import javax.servlet.http.HttpServletRequest;
39  import javax.servlet.http.HttpServletResponse;
40  import javax.servlet.http.HttpSession;
41  import java.io.IOException;
42  import java.util.Locale;
43  import java.util.Map;
44  import java.util.Set;
45  
46  
47  /**
48   * TODO: Rewrite Javadocs here
49   * This needs documentation.
50   * Is it still used?
51   * What is it used for?
52   * How?
53   * It is referenced by
54   * AttachementDownloadController, (@deprecated Use org.itracker.web.actions.admin.attachment.DownloadAttachmentAction instead.)
55   * ReportChartController,
56   * ReportDownloadController
57   *
58   * @author ready
59   */
60  public abstract class GenericController extends HttpServlet {
61  
62      /**
63       *
64       */
65      private static final long serialVersionUID = 1L;
66      private static final Logger logger = Logger.getLogger(GenericController.class);
67  
68      public GenericController() {
69      }
70  
71      protected static void saveMessages(HttpServletRequest request, ActionErrors errors) {
72  
73          if ((errors == null) || errors.isEmpty()) {
74              request.removeAttribute(Globals.ERROR_KEY);
75              return;
76          }
77          request.setAttribute(Globals.ERROR_KEY, errors);
78      }
79  
80      protected static void forward(String url, HttpServletRequest request, HttpServletResponse response)
81              throws IOException, ServletException {
82          RequestDispatcher rd = request.getRequestDispatcher(url);
83          if (rd == null) {
84              throw new ServletException("RequestDispatcher is null. URL: " + url);
85          }
86  
87          rd.forward(request, response);
88      }
89  
90      protected static void redirect(String url, HttpServletRequest request, HttpServletResponse response)
91              throws IOException, ServletException {
92  
93          String baseURL = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() +
94                  request.getContextPath();
95  
96          response.sendRedirect(baseURL + url);
97      }
98  
99      public static Locale getLocale(HttpServletRequest request) {
100         return LoginUtilities.getCurrentLocale(request);
101     }
102 
103 
104 }