PageRenderTime 2ms CodeModel.GetById 68ms app.highlight 5ms RepoModel.GetById 16ms app.codeStats 0ms

/src/main/java/org/tuckey/web/filters/urlrewrite/sample/SampleMultiUrlRewriteFilter.java

http://urlrewritefilter.googlecode.com/
Java | 49 lines | 34 code | 10 blank | 5 comment | 1 complexity | beebad69511d2b1840f2f36f8e452461 MD5 | raw file
 1package org.tuckey.web.filters.urlrewrite.sample;
 2
 3import org.tuckey.web.filters.urlrewrite.Conf;
 4import org.tuckey.web.filters.urlrewrite.UrlRewriteFilter;
 5import org.tuckey.web.filters.urlrewrite.UrlRewriter;
 6
 7import javax.servlet.FilterChain;
 8import javax.servlet.FilterConfig;
 9import javax.servlet.ServletException;
10import javax.servlet.ServletRequest;
11import javax.servlet.ServletResponse;
12import java.io.FileInputStream;
13import java.util.ArrayList;
14import java.util.List;
15
16/**
17 * Sample of how you might load multiple configuration files. (NOT to be used verbatim!!)
18 */
19public class SampleMultiUrlRewriteFilter extends UrlRewriteFilter {
20
21    private List urlrewriters = new ArrayList();
22     
23    public void loadUrlRewriter(FilterConfig filterConfig) throws ServletException {
24        // add configurations
25        try {
26            Conf conf1 = new Conf(filterConfig.getServletContext(), new FileInputStream("someconf.xml"), "someconf.xml", "");
27            urlrewriters.add(new UrlRewriter(conf1));
28
29            Conf conf2 = new SampleConfExt();
30            urlrewriters.add(new UrlRewriter(conf2));
31
32        } catch (Exception e) {
33            throw new ServletException(e);
34        }
35    }
36
37    public UrlRewriter getUrlRewriter(ServletRequest request, ServletResponse response, FilterChain chain) {
38        // do some logic to decide what urlrewriter to use (possibly do a reload check on the conf file)
39        return (UrlRewriter) urlrewriters.get(0);
40    }
41
42    public void destroyUrlRewriter() {
43        for (int i = 0; i < urlrewriters.size(); i++) {
44            UrlRewriter urlRewriter = (UrlRewriter) urlrewriters.get(i);
45            urlRewriter.destroy();
46        }
47    }
48
49}