File Source: BootstrapFilter.java
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. The ASF licenses this file to You
4 * under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License. For additional information regarding
15 * copyright in this work, please see the NOTICE file in the top level
16 * directory of this distribution.
17 */
18
19 package org.apache.roller.weblogger.ui.core.filters;
20
21 import java.io.IOException;
22 import javax.servlet.Filter;
23 import javax.servlet.FilterChain;
24 import javax.servlet.FilterConfig;
25 import javax.servlet.RequestDispatcher;
26 import javax.servlet.ServletContext;
27 import javax.servlet.ServletException;
28 import javax.servlet.ServletRequest;
29 import javax.servlet.ServletResponse;
30 import javax.servlet.http.HttpServletRequest;
31 import javax.servlet.http.HttpServletResponse;
32 import org.apache.commons.logging.Log;
33 import org.apache.commons.logging.LogFactory;
34 import org.apache.roller.weblogger.business.WebloggerFactory;
35 import org.apache.roller.weblogger.config.WebloggerConfig;
36
37
38 /**
39 * Redirects clients to install page when app is not bootstrapped and install
40 * type is "auto", otherwise does nothing.
41 */
/*
P/P * Method: void org.apache.roller.weblogger.ui.core.filters.BootstrapFilter()
*
* Postconditions:
* this.context == null
*/
42 public class BootstrapFilter implements Filter {
43 private ServletContext context = null;
/*
P/P * Method: org.apache.roller.weblogger.ui.core.filters.BootstrapFilter__static_init
*
* Postconditions:
* init'ed(log)
*/
44 private static Log log = LogFactory.getLog(BootstrapFilter.class);
45
46
47 public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain)
48 throws IOException, ServletException {
49
/*
P/P * Method: void doFilter(ServletRequest, ServletResponse, FilterChain)
*
* Preconditions:
* log != null
* req != null
* (soft) chain != null
* (soft) this.context != null
*
* Presumptions:
* javax.servlet.ServletContext:getRequestDispatcher(...)@60 != null
*
* Test Vectors:
* java.lang.String:equals(...)@55: {0}, {1}
* org.apache.roller.weblogger.business.WebloggerFactory:isBootstrapped(...)@55: {1}, {0}
*/
50 HttpServletRequest request = (HttpServletRequest) req;
51 HttpServletResponse response = (HttpServletResponse) res;
52
53 log.debug("Entered "+request.getRequestURI());
54
55 if (!WebloggerFactory.isBootstrapped() &&
56 "auto".equals(WebloggerConfig.getProperty("installation.type")) &&
57 !isInstallUrl(request.getServletPath())) {
58
59 // we doing an install, so forward to installer
60 RequestDispatcher rd = context.getRequestDispatcher(
61 "/roller-ui/install/install.rol");
62 rd.forward(req, res);
63
64 } else {
65 chain.doFilter(request, response);
66 }
67
68 log.debug("Exiting "+request.getRequestURI());
69 }
70
71
72 private boolean isInstallUrl(String uri) {
/*
P/P * Method: bool isInstallUrl(String)
*
* Postconditions:
* init'ed(return_value)
*/
73 return (uri != null && (uri.startsWith("/roller-ui/install") ||
74 uri.endsWith(".js") || uri.endsWith(".css")));
75 }
76
77
78 public void init(FilterConfig filterConfig) throws ServletException {
/*
P/P * Method: void init(FilterConfig)
*
* Preconditions:
* filterConfig != null
*
* Postconditions:
* init'ed(this.context)
*/
79 context = filterConfig.getServletContext();
80 }
81
/*
P/P * Method: void destroy()
*/
82 public void destroy() {}
83 }
SofCheck Inspector Build Version : 2.18479
| BootstrapFilter.java |
2009-Jan-02 14:25:32 |
| BootstrapFilter.class |
2009-Sep-04 03:12:44 |