Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ShaleWebContext |
|
| 1.8;1.8 |
1 | /* | |
2 | * Licensed to the Apache Software Foundation (ASF) under one or more | |
3 | * contributor license agreements. See the NOTICE file distributed with | |
4 | * this work for additional information regarding copyright ownership. | |
5 | * The ASF licenses this file to you under the Apache License, Version 2.0 | |
6 | * (the "License"); you may not use this file except in compliance with | |
7 | * the License. You may obtain a copy of the License at | |
8 | * | |
9 | * http://www.apache.org/licenses/LICENSE-2.0 | |
10 | * | |
11 | * Unless required by applicable law or agreed to in writing, software | |
12 | * distributed under the License is distributed on an "AS IS" BASIS, | |
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 | * See the License for the specific language governing permissions and | |
15 | * limitations under the License. | |
16 | */ | |
17 | ||
18 | package org.apache.shale.application.faces; | |
19 | ||
20 | import javax.faces.context.FacesContext; | |
21 | import javax.servlet.ServletContext; | |
22 | import javax.servlet.http.HttpServletRequest; | |
23 | import javax.servlet.http.HttpServletRequestWrapper; | |
24 | import javax.servlet.http.HttpServletResponse; | |
25 | import javax.servlet.http.HttpServletResponseWrapper; | |
26 | ||
27 | import org.apache.commons.chain.web.servlet.ServletWebContext; | |
28 | import org.apache.shale.util.Messages; | |
29 | ||
30 | /** | |
31 | * <p>Commons Chain <code>Context</code> implementation for Shale.</p> | |
32 | * | |
33 | * $Id: ShaleWebContext.java 465067 2006-10-17 21:45:17Z rahul $ | |
34 | */ | |
35 | public class ShaleWebContext extends ServletWebContext { | |
36 | ||
37 | ||
38 | // ------------------------------------------------------------ Constructors | |
39 | ||
40 | ||
41 | /** | |
42 | * Serial version UID. | |
43 | */ | |
44 | private static final long serialVersionUID = -5177725738581183049L; | |
45 | ||
46 | ||
47 | /** | |
48 | * <p>Construct a new context instance with the specified parameters. | |
49 | * | |
50 | * @param context <code>ServletContext</code> for this application | |
51 | * @param request <code>HttpServetRewquest</code> for this request | |
52 | * @param response <code>HttpServletResponse</code> for this request | |
53 | */ | |
54 | public ShaleWebContext(ServletContext context, | |
55 | HttpServletRequest request, | |
56 | HttpServletResponse response) { | |
57 | ||
58 | 0 | super(context, request, response); |
59 | ||
60 | 0 | } |
61 | ||
62 | ||
63 | // ------------------------------------------------------ Instance Variables | |
64 | ||
65 | ||
66 | /** | |
67 | * <p>The <code>FacesContext</code> for the current request (if any).</p> | |
68 | */ | |
69 | 0 | private FacesContext facesContext = null; |
70 | ||
71 | ||
72 | // -------------------------------------------------------- Static Variables | |
73 | ||
74 | ||
75 | /** | |
76 | * <p>Message resources for this class.</p> | |
77 | */ | |
78 | 0 | private static Messages messages = |
79 | new Messages("org.apache.shale.resources.Bundle", | |
80 | 0 | ShaleWebContext.class.getClassLoader()); |
81 | ||
82 | ||
83 | // -------------------------------------------------------------- Properties | |
84 | ||
85 | ||
86 | /** | |
87 | * <p>Return the <code>FacesContext</code> for the current request, if any; | |
88 | * otherwise, return <code>null</code>.</p> | |
89 | */ | |
90 | public FacesContext getFacesContext() { | |
91 | 0 | return this.facesContext; |
92 | } | |
93 | ||
94 | ||
95 | /** | |
96 | * <p>Set the <code>FacesContext</code> for the current request. This | |
97 | * method should only be called by the framework, once it is determined | |
98 | * that this is actually a JSF request.</p> | |
99 | * | |
100 | * @param facesContext The <code>FacesContext</code> for this request | |
101 | */ | |
102 | public void setFacesContext(FacesContext facesContext) { | |
103 | 0 | this.facesContext = facesContext; |
104 | 0 | } |
105 | ||
106 | ||
107 | /** | |
108 | * <p>Set the <code>HttpServletRequest</code> that will be passed on to the | |
109 | * remainder of the filter chain. If this is different from the request | |
110 | * originally used to create this context, it must be an implementation of | |
111 | * <code>HttpServletRequestWrapper</code> that wraps the original request.</p> | |
112 | * | |
113 | * <p><strong>NOTE</strong> - Setting ths property is only useful if it | |
114 | * occurs in the preprocessing portion of the chain, before the filter | |
115 | * chain has been invoked.</p> | |
116 | * | |
117 | * @param request The request or request wrapper to pass on | |
118 | */ | |
119 | public void setRequest(HttpServletRequest request) { | |
120 | 0 | if (!(request instanceof HttpServletRequestWrapper)) { |
121 | 0 | throw new IllegalArgumentException |
122 | (messages.getMessage("context.requestWrapper")); | |
123 | } | |
124 | 0 | initialize(getContext(), request, getResponse()); |
125 | 0 | } |
126 | ||
127 | ||
128 | /** | |
129 | * <p>Set the <code>HttpServletResponse</code> that will be passed on to the | |
130 | * remainder of the filter chain. If this is different from the response | |
131 | * originally used to create this context, it must be an implementation of | |
132 | * <code>HttpServletResponseWrapper</code> that wraps the original request.</p> | |
133 | * | |
134 | * <p><strong>NOTE</strong> - Setting ths property is only useful if it | |
135 | * occurs in the preprocessing portion of the chain, before the filter | |
136 | * chain has been invoked.</p> | |
137 | * | |
138 | * @param response The response or response wrapper to pass on | |
139 | */ | |
140 | public void setResponse(HttpServletResponse response) { | |
141 | 0 | if (!(response instanceof HttpServletResponseWrapper)) { |
142 | 0 | throw new IllegalArgumentException |
143 | (messages.getMessage("context.responseWrapper")); | |
144 | } | |
145 | 0 | initialize(getContext(), getRequest(), response); |
146 | 0 | } |
147 | ||
148 | ||
149 | } |