PageRenderTime 9ms CodeModel.GetById 1ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/sitebricks/src/main/java/com/google/sitebricks/SitebricksServletModule.java

http://github.com/dhanji/sitebricks
Java | 87 lines | 18 code | 10 blank | 59 comment | 0 complexity | 336ec29295a538fe55cec31286df9f76 MD5 | raw file
 1package com.google.sitebricks;
 2
 3import com.google.inject.servlet.ServletModule;
 4
 5/**
 6 * Provides an optional mechanism for users of Sitebricks to supply {@link javax.servlet.Servlet} and
 7 * {@link javax.servlet.Filter} implementations using the standard Guice Servlet APIs.<br/>
 8 * <br/>
 9 * For example:
10 * <pre>
11  public Injector getInjector() {
12    return Guice.createInjector(new SitebricksModule() {
13
14      @Override
15      protected SitebricksServletModule servletModule() {
16        return new SitebricksServletModule() {
17
18          @Override
19          protected void configurePreFilters() {
20            filter("/*").through(MyPreFilter.class);
21          }
22
23          @Override
24          protected void configurePreFilters() {
25            filter("/*").through(MyPostFilter.class);
26          }
27
28          @Override
29          protected void configureCustomServlets() {
30            serve("/foo").with(FooServlet.class);
31          }
32        };
33      }
34
35
36      @Override
37      protected void configureSitebricks() {
38        ...
39      }
40    }
41 }
42</pre>
43 */
44public class SitebricksServletModule extends ServletModule {
45
46  @Override
47  protected final void configureServlets() {
48    configurePreFilters();
49
50    filter("/*").through(HiddenMethodFilter.class);
51    filter("/*").through(SitebricksFilter.class);
52
53    configurePostFilters();
54    configureCustomServlets();
55  }
56
57  /**
58   * Provides a mechanism for users of Sitebricks to register their own {@link javax.servlet.Servlet} implementations
59   * with Guice Servlet via {@link ServletModule#serve(String, String...) serve} and
60   * {@link ServletModule#serveRegex(String, String...) serveRegex}.<p>
61   */
62  protected void configureCustomServlets() {
63  }
64
65
66  /**
67   * Provides a mechanism for users of Sitebricks to register their own {@link javax.servlet.Filter} implementation with
68   * Guice Servlet via {@link ServletModule#filter(String, String...) filter} and
69   * {@link ServletModule#filterRegex(String, String...) filterRegex}.<p>
70   * <br/>
71   * Filters declared in this method will execute in the filter chain before the Sitebricks filter invokes.
72   */
73  protected void configurePreFilters() {
74  }
75
76  /**
77   * Provides a mechanism for users of Sitebricks to register their own {@link javax.servlet.Filter} implementation with
78   * Guice Servlet via {@link ServletModule#filter(String, String...) filter} and
79   * {@link ServletModule#filterRegex(String, String...) filterRegex}.<p>
80   * <br/>
81   * Filters declared in this method will execute in the filter chain <b>only if Sitebricks determines it will not
82   * handle the request.</b>
83   */
84  protected void configurePostFilters() {
85  }
86
87}