Subversion Repositories bacoAlunos

Rev

Rev 1310 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
406 jmachado 1
package pt.estgp.estgweb.web.filters;
2
 
1350 jmachado 3
import org.apache.commons.httpclient.util.URIUtil;
406 jmachado 4
 
5
import javax.servlet.*;
6
import javax.servlet.http.HttpServletRequest;
7
import java.io.IOException;
8
 
9
/**
10
 *
11
 * @author  Jorge Machado
12
 */
13
 
14
public class RequestURLFilter implements 1.5.0/docs/api/java/util/logging/Filter.html">Filter
15
{
16
 
17
    public static final 1.5.0/docs/api/java/lang/String.html">String REQUESTED_URL = "pt.estgp.estgweb.web.filters.RequestURLFilter.REQUESTED_URL";
18
 
19
    public RequestURLFilter()
20
    {
21
    }
22
 
23
    public void init(FilterConfig config)
24
    {
25
 
26
    }
27
 
28
    /**
29
     *
30
     * @param request The servlet request we are processing
31
     * @param chain The filter chain we are processing
32
     *
33
     * @exception java.io.IOException if an input/output error occurs
34
     * @exception javax.servlet.ServletException if a servlet error occurs
35
     */
36
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
37
            throws 1.5.0/docs/api/java/io/IOException.html">IOException, ServletException
38
    {
39
        HttpServletRequest hrequest = (HttpServletRequest) request;
40
        1.5.0/docs/api/java/lang/String.html">String relativePath = hrequest.getServletPath();
41
        if (relativePath == null)
42
            relativePath = "";
1350 jmachado 43
        else
44
            relativePath = URIUtil.encodePath(relativePath, "ISO-8859-1");
406 jmachado 45
 
46
        if (hrequest.getPathInfo() != null && hrequest.getPathInfo().length() > 0)
47
        {
1350 jmachado 48
            relativePath += URIUtil.encodePath(hrequest.getPathInfo(), "ISO-8859-1");
406 jmachado 49
        }
50
        if(hrequest.getQueryString() != null && hrequest.getQueryString().length()>0)
1350 jmachado 51
            relativePath += "?" + URIUtil.encodePath(hrequest.getQueryString(), "ISO-8859-1");
406 jmachado 52
 
53
 
54
        1.5.0/docs/api/java/lang/String.html">String url = relativePath;
55
 
56
        hrequest.setAttribute(REQUESTED_URL,url);
57
 
58
        chain.doFilter(request,response);
59
    }
60
 
61
    public void destroy()
62
    {
63
        // Nothing
64
    }
65
}