KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > za > org > coefficient > servlet > HardURLConverterServlet


1 /*
2  * Coefficient - facilitates project based collaboration
3  * Copyright (C) 2003, Dylan Etkin, CSIR icomtek
4  * PO Box 395
5  * Pretoria 0001, RSA
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
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 za.org.coefficient.servlet;
21
22 import za.org.coefficient.util.common.HardURLConverterChainUtil;
23
24 import java.io.IOException JavaDoc;
25
26 import javax.servlet.ServletException JavaDoc;
27 import javax.servlet.http.HttpServlet JavaDoc;
28 import javax.servlet.http.HttpServletRequest JavaDoc;
29 import javax.servlet.http.HttpServletResponse JavaDoc;
30
31 /**
32  * This servlet translates a hard URL to syntax that the coefficient
33  * servlet and a given module can understand. This servlet passes the incomming
34  * URL through a chain of responsibility to allow any modules that think they
35  * can handle the URL to do so.
36  *
37  * @author <a HREF="mailto:detkin@csir.co.za">Dylan Etkin</a>
38  * @version $Revision: 1.2 $
39  * @web.servlet
40  * name="HardURLConverterServlet"
41  * display-name="Hard URL Converter Servlet"
42  * description="This servlet allows access to system elements via a hard url"
43  * @web.servlet-mapping
44  * url-pattern="/"
45  */

46 public class HardURLConverterServlet extends HttpServlet JavaDoc {
47
48     //~ Methods ================================================================
49

50     /**
51      * Entry point for converting a Hard URL to a coefficient URL.
52      *
53      * @param request The HttpServletRequest instance.
54      * @param response The HttpServletResponse instance.
55      *
56      * @see #execute(HttpServletRequest,HttpServletResponse) execute(request,response) execute(request,response).
57      *
58      */

59     protected void doGet(HttpServletRequest JavaDoc request,
60         HttpServletResponse JavaDoc response) throws ServletException JavaDoc, IOException JavaDoc {
61         String JavaDoc pathInfo = request.getPathInfo();
62         String JavaDoc servletPath = request.getServletPath();
63         String JavaDoc contextPath = request.getContextPath();
64         String JavaDoc path =
65             (pathInfo == null) ? contextPath + "/" + servletPath : (contextPath+ "/" + servletPath + "/" + pathInfo);
66
67         String JavaDoc redirectURL = HardURLConverterChainUtil.execute(path);
68         if(redirectURL != null) {
69             response.sendRedirect(redirectURL);
70         } else {
71             response.sendRedirect(contextPath + "/index.html?module=Error&errorMsg=The%20URL "
72                                   + path + "%20is%20not%20recognized%20by%20the%20system");
73         }
74     }
75
76     /**
77      * Called by the servlet container to handle a POST request. This
78      * method calls doGet(request, response) to perform the job.
79      *
80      * @see #doGet(HttpServletRequest, HttpServletResponse)
81      */

82     protected void doPost(HttpServletRequest JavaDoc request,
83         HttpServletResponse JavaDoc response) throws ServletException JavaDoc, IOException JavaDoc {
84         doGet(request, response);
85     }
86
87 }
88
Popular Tags