KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > portlet > PortletWebRequest


1 // Copyright 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.tapestry.portlet;
16
17 import java.util.List JavaDoc;
18 import java.util.Locale JavaDoc;
19
20 import javax.portlet.PortletRequest;
21 import javax.portlet.PortletSession;
22
23 import org.apache.hivemind.util.Defense;
24 import org.apache.tapestry.describe.DescriptionReceiver;
25 import org.apache.tapestry.web.WebRequest;
26 import org.apache.tapestry.web.WebSession;
27 import org.apache.tapestry.web.WebUtils;
28
29 /**
30  * Implementation of {@link org.apache.tapestry.web.WebRequest}that adapts a
31  * {@link PortletRequest).
32  *
33  * @author Howard M. Lewis Ship
34  * @since 4.0
35  */

36 public class PortletWebRequest implements WebRequest
37 {
38     private final PortletRequest _portletRequest;
39
40     private WebSession _webSession;
41
42     public PortletWebRequest(PortletRequest portletRequest)
43     {
44         Defense.notNull(portletRequest, "portletRequest");
45
46         _portletRequest = portletRequest;
47     }
48
49     public List JavaDoc getParameterNames()
50     {
51         return WebUtils.toSortedList(_portletRequest.getParameterNames());
52     }
53
54     public String JavaDoc getParameterValue(String JavaDoc parameterName)
55     {
56         return _portletRequest.getParameter(parameterName);
57     }
58
59     public String JavaDoc[] getParameterValues(String JavaDoc parameterName)
60     {
61         return _portletRequest.getParameterValues(parameterName);
62     }
63
64     public String JavaDoc getContextPath()
65     {
66         return _portletRequest.getContextPath();
67     }
68
69     public WebSession getSession(boolean create)
70     {
71         if (_webSession != null)
72             return _webSession;
73
74         PortletSession session = _portletRequest.getPortletSession(create);
75
76         if (session != null)
77             _webSession = new PortletWebSession(session);
78
79         return _webSession;
80     }
81
82     public String JavaDoc getScheme()
83     {
84         return _portletRequest.getScheme();
85     }
86
87     public String JavaDoc getServerName()
88     {
89         return _portletRequest.getServerName();
90     }
91
92     public int getServerPort()
93     {
94         return _portletRequest.getServerPort();
95     }
96
97     /**
98      * Returns "<PortletRequest>", because portlets don't have a notion of request URI.
99      */

100
101     public String JavaDoc getRequestURI()
102     {
103         return "<PortletRequest>";
104     }
105
106     public void forward(String JavaDoc URL)
107     {
108         unsupported("forward");
109     }
110
111     public String JavaDoc getActivationPath()
112     {
113         return "";
114     }
115
116     public List JavaDoc getAttributeNames()
117     {
118         return WebUtils.toSortedList(_portletRequest.getAttributeNames());
119     }
120
121     public Object JavaDoc getAttribute(String JavaDoc name)
122     {
123         return _portletRequest.getAttribute(name);
124     }
125
126     public void setAttribute(String JavaDoc name, Object JavaDoc attribute)
127     {
128         if (attribute == null)
129             _portletRequest.removeAttribute(name);
130         else
131             _portletRequest.setAttribute(name, attribute);
132     }
133
134     protected final void unsupported(String JavaDoc methodName)
135     {
136         throw new UnsupportedOperationException JavaDoc(PortletMessages.unsupportedMethod(methodName));
137     }
138
139     public void describeTo(DescriptionReceiver receiver)
140     {
141         receiver.describeAlternate(_portletRequest);
142     }
143
144     public Locale JavaDoc getLocale()
145     {
146         return _portletRequest.getLocale();
147     }
148
149     public String JavaDoc getHeader(String JavaDoc name)
150     {
151         unsupported("getHeader");
152
153         return null;
154     }
155 }
Popular Tags