View Javadoc

1   package net.trajano.twiff.internal.servlet;
2   
3   import static net.trajano.twiff.Twiff.REDIRECT_TIMEOUT;
4   import static net.trajano.twiff.Twiff.REDIRECT_WAIT_PAGE;
5   import javax.servlet.ServletConfig;
6   import javax.servlet.ServletContext;
7   import net.trajano.twiff.RedirectConfiguration;
8   import net.trajano.twiff.ViewServletConfiguration;
9   import net.trajano.twiff.Twiff;
10  import net.trajano.twiff.internal.util.InitParamUtil;
11  
12  /***
13   * @author Archimedes Trajano
14   */
15  public class ServletConfiguration implements ViewServletConfiguration, RedirectConfiguration {
16      /***
17       * @param servletConfig
18       *                   servlet configuration to get the servlet context.
19       */
20      public ServletConfiguration(final ServletConfig servletConfig) {
21          this.servletConfig = servletConfig;
22          ServletContext servletContext = servletConfig.getServletContext();
23      }
24  
25      /***
26       * Servlet configuration.
27       */
28      private final ServletConfig servletConfig;
29  
30      /***
31       * @see net.trajano.twiff.ViewServletConfiguration#getTokenFieldName()
32       */
33      public String getTokenFieldName() {
34          return InitParamUtil.getInitParam(servletConfig.getServletContext(), Twiff.TOKEN_FIELD_NAME);
35      }
36  
37      /***
38       * @see net.trajano.twiff.ViewServletConfiguration#getPackageContext()
39       */
40      public String getPackageContext() {
41          return InitParamUtil.getInitParam(servletConfig.getServletContext(), Twiff.PACKAGE_CONTEXT_KEY);
42      }
43  
44      /***
45       * @see net.trajano.twiff.ViewServletConfiguration#getDispatchPattern()
46       */
47      public String getDispatchPattern() {
48          return InitParamUtil.getInitParam(servletConfig, Twiff.DISPATCH_PATTERN_KEY);
49      }
50  
51      /***
52       * @see net.trajano.twiff.RedirectConfiguration#getRedirectPageTimeout()
53       */
54      public int getRedirectPageTimeout() {
55          return Integer.parseInt(InitParamUtil.getInitParam(servletConfig, REDIRECT_TIMEOUT));
56      }
57  
58      /***
59       * @see net.trajano.twiff.RedirectConfiguration#getRedirectPage()
60       */
61      public String getRedirectPage() {
62          return InitParamUtil.safeGetInitParam(servletConfig, REDIRECT_WAIT_PAGE);
63      }
64  
65      /***
66       * @see net.trajano.twiff.RedirectConfiguration#isRedirectPageDefined()
67       */
68      public boolean isRedirectPageDefined() {
69          return InitParamUtil.safeGetInitParam(servletConfig, REDIRECT_WAIT_PAGE) != null;
70      }
71  }