001: /*
002: * The Apache Software License, Version 1.1
003: *
004: * Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * 1. Redistributions of source code must retain the above copyright
011: * notice, this list of conditions and the following disclaimer.
012: *
013: * 2. Redistributions in binary form must reproduce the above copyright
014: * notice, this list of conditions and the following disclaimer in
015: * the documentation and/or other materials provided with the
016: * distribution.
017: *
018: * 3. The end-user documentation included with the redistribution, if
019: * any, must include the following acknowlegement:
020: * "This product includes software developed by the
021: * Caucho Technology (http://www.caucho.com/)."
022: * Alternately, this acknowlegement may appear in the software itself,
023: * if and wherever such third-party acknowlegements normally appear.
024: *
025: * 4. The names "Hessian", "Resin", and "Caucho" must not be used to
026: * endorse or promote products derived from this software without prior
027: * written permission. For written permission, please contact
028: * info@caucho.com.
029: *
030: * 5. Products derived from this software may not be called "Resin"
031: * nor may "Resin" appear in their names without prior written
032: * permission of Caucho Technology.
033: *
034: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
035: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
036: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
037: * DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
038: * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
039: * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
040: * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
041: * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
042: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
043: * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
044: * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
045: *
046: * @author Sam
047: */
048:
049: package com.caucho.portal.generic;
050:
051: import javax.portlet.PortletContext;
052: import javax.portlet.PortletRequestDispatcher;
053: import javax.servlet.ServletContext;
054: import java.io.InputStream;
055: import java.net.URL;
056: import java.util.Enumeration;
057: import java.util.Set;
058: import java.util.logging.Level;
059: import java.util.logging.Logger;
060:
061: /**
062: * HttpPortletContext provides the connection to a web application
063: * (ServletContext).
064: */
065: public class HttpPortletContext implements PortletContext {
066: static protected final Logger log = Logger
067: .getLogger(HttpPortletContext.class.getName());
068:
069: private ServletContext _servletContext;
070:
071: public HttpPortletContext(ServletContext servletContext) {
072: _servletContext = servletContext;
073: }
074:
075: /**
076: * {@inheritDoc}
077: */
078: public String getServerInfo() {
079: return _servletContext.getServerInfo();
080: }
081:
082: /**
083: * {@inheritDoc}
084: */
085: public int getMinorVersion() {
086: return _servletContext.getMinorVersion();
087: }
088:
089: /**
090: * {@inheritDoc}
091: */
092: public int getMajorVersion() {
093: return _servletContext.getMajorVersion();
094: }
095:
096: /**
097: * {@inheritDoc}
098: */
099: public PortletRequestDispatcher getRequestDispatcher(String path) {
100: HttpPortletRequestDispatcher portletDispatcher = new HttpPortletRequestDispatcher();
101:
102: if (portletDispatcher.startWithPath(_servletContext, path))
103: return portletDispatcher;
104: else {
105: portletDispatcher.finish();
106: return null;
107: }
108: }
109:
110: /**
111: * {@inheritDoc}
112: */
113: public PortletRequestDispatcher getNamedDispatcher(String name) {
114: HttpPortletRequestDispatcher portletDispatcher = new HttpPortletRequestDispatcher();
115:
116: if (portletDispatcher.startWithName(_servletContext, name)) {
117: return portletDispatcher;
118: } else {
119: portletDispatcher.finish();
120: return null;
121: }
122: }
123:
124: /**
125: * {@inheritDoc}
126: */
127: public InputStream getResourceAsStream(String path) {
128: return _servletContext.getResourceAsStream(path);
129: }
130:
131: /**
132: * {@inheritDoc}
133: */
134: public String getMimeType(String file) {
135: return _servletContext.getMimeType(file);
136: }
137:
138: /**
139: * {@inheritDoc}
140: */
141: public String getRealPath(String path) {
142: return _servletContext.getRealPath(path);
143: }
144:
145: /**
146: * {@inheritDoc}
147: */
148: public Set getResourcePaths(String path) {
149: return _servletContext.getResourcePaths(path);
150: }
151:
152: /**
153: * {@inheritDoc}
154: */
155: public URL getResource(String path)
156: throws java.net.MalformedURLException {
157: return _servletContext.getResource(path);
158: }
159:
160: /**
161: * {@inheritDoc}
162: */
163: public String getInitParameter(String name) {
164: return _servletContext.getInitParameter(name);
165: }
166:
167: /**
168: * {@inheritDoc}
169: */
170: public Enumeration getInitParameterNames() {
171: return _servletContext.getInitParameterNames();
172: }
173:
174: /**
175: * {@inheritDoc}
176: */
177: public Object getAttribute(String name) {
178: return _servletContext.getAttribute(name);
179: }
180:
181: /**
182: * {@inheritDoc}
183: */
184: public Enumeration getAttributeNames() {
185: return _servletContext.getAttributeNames();
186: }
187:
188: /**
189: * {@inheritDoc}
190: */
191: public void removeAttribute(String name) {
192: _servletContext.removeAttribute(name);
193: }
194:
195: /**
196: * {@inheritDoc}
197: */
198: public void setAttribute(String name, Object object) {
199: if (log.isLoggable(Level.FINEST)) {
200: log.finest("setAttribute(" + name + ")");
201: }
202: _servletContext.setAttribute(name, object);
203: }
204:
205: /**
206: * {@inheritDoc}
207: */
208: public void log(String msg) {
209: log(msg, null);
210: }
211:
212: /**
213: * {@inheritDoc}
214: */
215: public void log(String message, Throwable e) {
216: if (e != null)
217: log.log(Level.WARNING, message, e);
218: else
219: log.info(message);
220: }
221:
222: /**
223: * {@inheritDoc}
224: */
225: public String getPortletContextName() {
226: return _servletContext.getServletContextName();
227: }
228:
229: }
|