KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > barracuda > plankton > http > URLRewriter


1 /*
2  * Copyright (C) 2003 Christian Cryder [christianc@granitepeaks.com]
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * $Id: URLRewriter.java,v 1.5 2004/02/01 05:16:28 christianc Exp $
19  */

20 package org.enhydra.barracuda.plankton.http;
21
22 import javax.servlet.*;
23 import javax.servlet.http.*;
24
25
26 /**
27  * This just contains some Servlet utility routines
28  */

29 public class URLRewriter {
30
31     /**
32      * This option is used to control whether or not URL rewriting occurs. It
33      * exists to handle bugs in Enhydra 3.x in which invoking the URL rewriting
34      * methods causes a bogus value to be returned. If you are using Enhydra 3.x,
35      * you will want to set this value to false (you can do this without coding
36      * changes via the your assembler xml file). Defaults to true. To see whether
37      * or not your appserver correctly implements URL rewriting, look at
38      * http://localhost/Barracuda/RedirectEx1
39      */

40     public static boolean REWRITE_URLS = true;
41 // public static boolean REWRITE_URLS = false; //need it false if we're running against Enhydra 3.x
42

43     /**
44      * Encode a URL if the REWRITE_URLS option is set. Using this option
45      * makes it easy to reconfigure Barracuda if your server has problems
46      * with URL rewriting (ie. Enhydra 3.x)
47      *
48      * @param req the servlet request
49      * @param resp the servlet response
50      * @param url the target url
51      * @return an encoded url (unless REWRITE_URLS = false, in which case
52      * it will just return the original url value)
53      */

54     public static String JavaDoc encodeURL(HttpServletRequest req, HttpServletResponse resp, String JavaDoc url) {
55         //jrk_20030508 - should be able to remove the req parameter, but leaving
56
//to avoid issues with an interface change.
57
if (REWRITE_URLS && resp != null) {
58             return resp.encodeURL(url);
59         }
60         return url;
61     }
62
63     /**
64      * Encode a redirect URL if the REWRITE_URLS option is set. Using this option
65      * makes it easy to reconfigure Barracuda if your server has problems
66      * with URL rewriting (ie. Enhydra 3.x)
67      *
68      * @param req the servlet request
69      * @param resp the servlet response
70      * @param url the target url
71      * @return an encoded url (unless REWRITE_URLS = false, in which case
72      * it will just return the original url value)
73      */

74     public static String JavaDoc encodeRedirectURL(HttpServletRequest req, HttpServletResponse resp, String JavaDoc url) {
75         //jrk_20030508 - should be able to remove the req parameter, but leaving
76
//to avoid issues with an interface change.
77
if (REWRITE_URLS && resp != null) {
78             return resp.encodeRedirectURL(url);
79         }
80         return url;
81     }
82
83 }
84
Popular Tags