01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. The ASF licenses this file to You
04: * under the Apache License, Version 2.0 (the "License"); you may not
05: * use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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: package org.apache.roller.ui.core.filters;
19:
20: import java.io.IOException;
21: import java.io.UnsupportedEncodingException;
22: import java.util.Date;
23: import java.util.Locale;
24:
25: import javax.servlet.Filter;
26: import javax.servlet.FilterChain;
27: import javax.servlet.FilterConfig;
28: import javax.servlet.ServletException;
29: import javax.servlet.ServletRequest;
30: import javax.servlet.ServletResponse;
31: import javax.servlet.http.HttpServletRequest;
32: import javax.servlet.http.HttpServletResponse;
33: import javax.servlet.http.HttpSession;
34: import javax.servlet.jsp.jstl.core.Config;
35:
36: import org.apache.commons.logging.Log;
37: import org.apache.commons.logging.LogFactory;
38: import org.apache.struts.Globals;
39: import org.apache.roller.RollerException;
40: import org.apache.roller.config.RollerConfig;
41: import org.apache.roller.business.Roller;
42: import org.apache.roller.business.RollerFactory;
43: import org.apache.roller.business.UserManager;
44: import org.apache.roller.ui.core.RollerContext;
45: import org.apache.roller.ui.core.RollerRequest;
46: import org.apache.roller.ui.core.util.RequestUtil;
47:
48: /**
49: * Entry point filter for Weblog page and Editor UI, this filter
50: * creates a RollerRequest object to parse pathinfo and request parameters.
51: *
52: * @web.filter name="RequestFilter"
53: *
54: * @author David M. Johnson, Matt Raible
55: */
56: public class RequestFilter implements Filter {
57: private FilterConfig mFilterConfig = null;
58: private static Log mLogger = LogFactory.getFactory().getInstance(
59: RequestFilter.class);
60:
61: public void doFilter(ServletRequest req, ServletResponse res,
62: FilterChain chain) throws IOException, ServletException {
63:
64: // NOTE: Setting character encoding and JSTL/Struts locale sync has been
65: // moved to CharEncodingFilter, which is mapped for all URIs in the context.
66:
67: HttpSession session = ((HttpServletRequest) req).getSession();
68: HttpServletRequest request = (HttpServletRequest) req;
69: HttpServletResponse response = (HttpServletResponse) res;
70: Roller roller = RollerFactory.getRoller();
71: RollerRequest rreq = null;
72: try {
73: rreq = RollerRequest.getRollerRequest(request,
74: mFilterConfig.getServletContext());
75: } catch (Throwable e) {
76: // NOTE: this is not a page-not-found problem
77: request.setAttribute("DisplayException", e);
78: mLogger.error(e);
79: return;
80: }
81: chain.doFilter(req, res);
82: }
83:
84: public void init(FilterConfig filterConfig) throws ServletException {
85: mFilterConfig = filterConfig;
86: }
87:
88: public void destroy() {
89: }
90: }
|