1 | /* |
2 | * Copyright 2003,2004 The Apache Software Foundation. |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not 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. |
15 | */ |
16 | package org.apache.pluto.driver.core; |
17 | |
18 | import javax.servlet.http.HttpServletRequest; |
19 | import javax.servlet.http.HttpServletResponse; |
20 | |
21 | import org.apache.pluto.driver.url.PortalURL; |
22 | import org.apache.pluto.driver.url.PortalURLFactory; |
23 | |
24 | /** |
25 | * The portal environment of the incoming servlet request and response. |
26 | * |
27 | * @author <a href="mailto:ddewolf@apache.org">David H. DeWolf</a> |
28 | * @author <a href="mailto:zheng@apache.org">ZHENG Zhong</a> |
29 | */ |
30 | public class PortalEnvironment { |
31 | |
32 | /** |
33 | * The attribute key to bind the portal environment instance to servlet |
34 | * request. |
35 | */ |
36 | public final static String REQUEST_PORTALENV = |
37 | PortalEnvironment.class.getName(); |
38 | |
39 | /** The incoming servlet request. */ |
40 | private HttpServletRequest request = null; |
41 | |
42 | /** The incoming servlet response. */ |
43 | private HttpServletResponse response = null; |
44 | |
45 | /** The requested portal URL. */ |
46 | private PortalURL requestedPortalURL = null; |
47 | |
48 | |
49 | // Constructor ------------------------------------------------------------- |
50 | |
51 | /** |
52 | * Creates a PortalEnvironment instance. |
53 | * @param request the incoming servlet request. |
54 | * @param response the incoming servlet response. |
55 | */ |
56 | public PortalEnvironment(HttpServletRequest request, |
57 | HttpServletResponse response) { |
58 | this.request = request; |
59 | this.response = response; |
60 | // Parse servlet request and construct portal URL. |
61 | this.requestedPortalURL = PortalURLFactory.getFactory() |
62 | .createPortalURL(request); |
63 | // Bind the instance to servlet request for later use. |
64 | request.setAttribute(REQUEST_PORTALENV, this); |
65 | } |
66 | |
67 | /** |
68 | * Returns the portal environment from the servlet request. The portal |
69 | * envirionment instance is saved in the request scope. |
70 | * @param request the servlet request. |
71 | * @return the portal environment. |
72 | */ |
73 | public static PortalEnvironment getPortalEnvironment( |
74 | HttpServletRequest request) { |
75 | return (PortalEnvironment) request.getAttribute(REQUEST_PORTALENV); |
76 | } |
77 | |
78 | /** |
79 | * Returns the servlet request. |
80 | * @return the servlet request. |
81 | */ |
82 | public HttpServletRequest getRequest() { |
83 | return request; |
84 | } |
85 | |
86 | /** |
87 | * Returns the servlet response. |
88 | * @return the servlet response. |
89 | */ |
90 | public HttpServletResponse getResponse() { |
91 | return response; |
92 | } |
93 | |
94 | /** |
95 | * Returns the requested portal URL. |
96 | * @return the requested portal URL. |
97 | */ |
98 | public PortalURL getRequestedPortalURL() { |
99 | return requestedPortalURL; |
100 | } |
101 | } |