001: /*
002: * $Id: $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021: package org.apache.struts2.portlet.servlet;
022:
023: import java.io.InputStream;
024: import java.net.MalformedURLException;
025: import java.net.URL;
026: import java.util.Enumeration;
027: import java.util.Set;
028:
029: import javax.portlet.PortletContext;
030: import javax.portlet.PortletRequestDispatcher;
031: import javax.servlet.RequestDispatcher;
032: import javax.servlet.Servlet;
033: import javax.servlet.ServletContext;
034: import javax.servlet.ServletException;
035:
036: /**
037: * Wrapper object exposing a {@link PortletContext} as a {@link ServletContext} instance.
038: * Clients accessing this context object will in fact operate on the
039: * {@link PortletContext} object wrapped by this context object.
040: */
041: public class PortletServletContext implements ServletContext {
042:
043: private PortletContext portletContext;
044:
045: public PortletServletContext(PortletContext portletContext) {
046: this .portletContext = portletContext;
047: }
048:
049: /* (non-Javadoc)
050: * @see javax.servlet.ServletContext#getAttribute(java.lang.String)
051: */
052: public Object getAttribute(String name) {
053: return portletContext.getAttribute(name);
054: }
055:
056: /* (non-Javadoc)
057: * @see javax.servlet.ServletContext#getAttributeNames()
058: */
059: public Enumeration getAttributeNames() {
060: return portletContext.getAttributeNames();
061: }
062:
063: /**
064: * @see javax.servlet.ServletContext#getContext(java.lang.String)
065: * @throws IllegalStateException Not supported in a portlet.
066: */
067: public ServletContext getContext(String uripath) {
068: throw new IllegalStateException("Not supported in a portlet");
069: }
070:
071: /* (non-Javadoc)
072: * @see javax.servlet.ServletContext#getInitParameter(java.lang.String)
073: */
074: public String getInitParameter(String name) {
075: return portletContext.getInitParameter(name);
076: }
077:
078: /* (non-Javadoc)
079: * @see javax.servlet.ServletContext#getInitParameterNames()
080: */
081: public Enumeration getInitParameterNames() {
082: return portletContext.getInitParameterNames();
083: }
084:
085: /* (non-Javadoc)
086: * @see javax.servlet.ServletContext#getMajorVersion()
087: */
088: public int getMajorVersion() {
089: return portletContext.getMajorVersion();
090: }
091:
092: /* (non-Javadoc)
093: * @see javax.servlet.ServletContext#getMimeType(java.lang.String)
094: */
095: public String getMimeType(String file) {
096: return portletContext.getMimeType(file);
097: }
098:
099: /* (non-Javadoc)
100: * @see javax.servlet.ServletContext#getMinorVersion()
101: */
102: public int getMinorVersion() {
103: return portletContext.getMinorVersion();
104: }
105:
106: /**
107: * Returns a {@link PortletServletRequestDispatcher} wrapping the {@link PortletRequestDispatcher}
108: * as a {@link RequestDispatcher} instance.
109: * @see javax.servlet.ServletContext#getNamedDispatcher(java.lang.String)
110: * @return PortletServletRequestDispatcher
111: */
112: public RequestDispatcher getNamedDispatcher(String name) {
113: return new PortletServletRequestDispatcher(portletContext
114: .getNamedDispatcher(name));
115: }
116:
117: /* (non-Javadoc)
118: * @see javax.servlet.ServletContext#getRealPath(java.lang.String)
119: */
120: public String getRealPath(String path) {
121: return portletContext.getRealPath(path);
122: }
123:
124: /**
125: * Returns a {@link PortletServletRequestDispatcher} wrapping the {@link PortletRequestDispatcher}
126: * as a {@link RequestDispatcher} instance.
127: * @see javax.servlet.ServletContext#getNamedDispatcher(java.lang.String)
128: * @return PortletServletRequestDispatcher
129: */
130: public RequestDispatcher getRequestDispatcher(String path) {
131: return new PortletServletRequestDispatcher(portletContext
132: .getRequestDispatcher(path));
133: }
134:
135: /* (non-Javadoc)
136: * @see javax.servlet.ServletContext#getResource(java.lang.String)
137: */
138: public URL getResource(String path) throws MalformedURLException {
139: return portletContext.getResource(path);
140: }
141:
142: /* (non-Javadoc)
143: * @see javax.servlet.ServletContext#getResourceAsStream(java.lang.String)
144: */
145: public InputStream getResourceAsStream(String path) {
146: return portletContext.getResourceAsStream(path);
147: }
148:
149: /* (non-Javadoc)
150: * @see javax.servlet.ServletContext#getResourcePaths(java.lang.String)
151: */
152: public Set getResourcePaths(String path) {
153: return portletContext.getResourcePaths(path);
154: }
155:
156: /* (non-Javadoc)
157: * @see javax.servlet.ServletContext#getServerInfo()
158: */
159: public String getServerInfo() {
160: return portletContext.getServerInfo();
161: }
162:
163: /**
164: * @see javax.servlet.ServletContext#getServlet(java.lang.String)
165: * @throws IllegalStateException Not supported in a portlet.
166: */
167: public Servlet getServlet(String name) throws ServletException {
168: throw new IllegalStateException("Not allowed in a portlet");
169: }
170:
171: /* (non-Javadoc)
172: * @see javax.servlet.ServletContext#getServletContextName()
173: */
174: public String getServletContextName() {
175: return portletContext.getPortletContextName();
176: }
177:
178: /**
179: * @see javax.servlet.ServletContext#getServletNames()
180: * @throws IllegalStateException Not supported in a portlet.
181: */
182: public Enumeration getServletNames() {
183: throw new IllegalStateException("Not allowed in a portlet");
184: }
185:
186: /**
187: * @see javax.servlet.ServletContext#getServlets()
188: * @throws IllegalStateException Not supported in a portlet.
189: */
190: public Enumeration getServlets() {
191: throw new IllegalStateException("Not allowed in a portlet");
192: }
193:
194: /* (non-Javadoc)
195: * @see javax.servlet.ServletContext#log(java.lang.String)
196: */
197: public void log(String msg) {
198: portletContext.log(msg);
199: }
200:
201: /* (non-Javadoc)
202: * @see javax.servlet.ServletContext#log(java.lang.Exception, java.lang.String)
203: */
204: public void log(Exception exception, String msg) {
205: log(msg, exception);
206: }
207:
208: /* (non-Javadoc)
209: * @see javax.servlet.ServletContext#log(java.lang.String, java.lang.Throwable)
210: */
211: public void log(String message, Throwable throwable) {
212: portletContext.log(message, throwable);
213: }
214:
215: /* (non-Javadoc)
216: * @see javax.servlet.ServletContext#removeAttribute(java.lang.String)
217: */
218: public void removeAttribute(String name) {
219: portletContext.removeAttribute(name);
220: }
221:
222: /* (non-Javadoc)
223: * @see javax.servlet.ServletContext#setAttribute(java.lang.String, java.lang.Object)
224: */
225: public void setAttribute(String name, Object object) {
226: portletContext.setAttribute(name, object);
227: }
228:
229: /**
230: * Get the wrapped {@link PortletContext} instance.
231: * @return The wrapped {@link PortletContext} instance.
232: */
233: public PortletContext getPortletContext() {
234: return portletContext;
235: }
236:
237: }
|