KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > portal > generic > HttpPortletContext


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  * Copyright (c) 2001-2004 Caucho Technology, Inc. All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * 1. Redistributions of source code must retain the above copyright
11  * notice, this list of conditions and the following disclaimer.
12  *
13  * 2. Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in
15  * the documentation and/or other materials provided with the
16  * distribution.
17  *
18  * 3. The end-user documentation included with the redistribution, if
19  * any, must include the following acknowlegement:
20  * "This product includes software developed by the
21  * Caucho Technology (http://www.caucho.com/)."
22  * Alternately, this acknowlegement may appear in the software itself,
23  * if and wherever such third-party acknowlegements normally appear.
24  *
25  * 4. The names "Hessian", "Resin", and "Caucho" must not be used to
26  * endorse or promote products derived from this software without prior
27  * written permission. For written permission, please contact
28  * info@caucho.com.
29  *
30  * 5. Products derived from this software may not be called "Resin"
31  * nor may "Resin" appear in their names without prior written
32  * permission of Caucho Technology.
33  *
34  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
35  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
36  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
37  * DISCLAIMED. IN NO EVENT SHALL CAUCHO TECHNOLOGY OR ITS CONTRIBUTORS
38  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
39  * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
40  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
41  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
42  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
43  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
44  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45  *
46  * @author Sam
47  */

48
49
50 package com.caucho.portal.generic;
51
52 import javax.portlet.PortletContext;
53 import javax.portlet.PortletRequestDispatcher;
54 import javax.servlet.ServletContext JavaDoc;
55 import java.io.InputStream JavaDoc;
56 import java.net.URL JavaDoc;
57 import java.util.Enumeration JavaDoc;
58 import java.util.Set JavaDoc;
59 import java.util.logging.Level JavaDoc;
60 import java.util.logging.Logger JavaDoc;
61
62 /**
63  * HttpPortletContext provides the connection to a web application
64  * (ServletContext).
65  */

66 public class HttpPortletContext
67   implements PortletContext
68 {
69   static protected final Logger JavaDoc log =
70     Logger.getLogger(HttpPortletContext.class.getName());
71
72   private ServletContext JavaDoc _servletContext;
73
74   public HttpPortletContext(ServletContext JavaDoc servletContext)
75   {
76     _servletContext = servletContext;
77   }
78
79   /**
80    * {@inheritDoc}
81    */

82   public String JavaDoc getServerInfo()
83   {
84     return _servletContext.getServerInfo();
85   }
86
87   /**
88    * {@inheritDoc}
89    */

90   public int getMinorVersion()
91   {
92     return _servletContext.getMinorVersion();
93   }
94
95   /**
96    * {@inheritDoc}
97    */

98   public int getMajorVersion()
99   {
100     return _servletContext.getMajorVersion();
101   }
102
103   /**
104    * {@inheritDoc}
105    */

106   public PortletRequestDispatcher getRequestDispatcher(String JavaDoc path)
107   {
108     HttpPortletRequestDispatcher portletDispatcher
109       = new HttpPortletRequestDispatcher();
110
111     if (portletDispatcher.startWithPath(_servletContext, path))
112       return portletDispatcher;
113     else {
114       portletDispatcher.finish();
115       return null;
116     }
117   }
118
119   /**
120    * {@inheritDoc}
121    */

122   public PortletRequestDispatcher getNamedDispatcher(String JavaDoc name)
123   {
124     HttpPortletRequestDispatcher portletDispatcher
125       = new HttpPortletRequestDispatcher();
126
127     if (portletDispatcher.startWithName(_servletContext, name)) {
128       return portletDispatcher;
129     }
130     else {
131       portletDispatcher.finish();
132       return null;
133     }
134   }
135
136   /**
137    * {@inheritDoc}
138    */

139   public InputStream JavaDoc getResourceAsStream(String JavaDoc path)
140   {
141     return _servletContext.getResourceAsStream(path);
142   }
143
144   /**
145    * {@inheritDoc}
146    */

147   public String JavaDoc getMimeType(String JavaDoc file)
148   {
149     return _servletContext.getMimeType(file);
150   }
151
152   /**
153    * {@inheritDoc}
154    */

155   public String JavaDoc getRealPath(String JavaDoc path)
156   {
157     return _servletContext.getRealPath(path);
158   }
159
160   /**
161    * {@inheritDoc}
162    */

163   public Set JavaDoc getResourcePaths(String JavaDoc path)
164   {
165     return _servletContext.getResourcePaths(path);
166   }
167
168   /**
169    * {@inheritDoc}
170    */

171   public URL JavaDoc getResource(String JavaDoc path) throws java.net.MalformedURLException JavaDoc
172   {
173     return _servletContext.getResource(path);
174   }
175
176   /**
177    * {@inheritDoc}
178    */

179   public String JavaDoc getInitParameter(String JavaDoc name)
180   {
181     return _servletContext.getInitParameter(name);
182   }
183
184   /**
185    * {@inheritDoc}
186    */

187   public Enumeration JavaDoc getInitParameterNames()
188   {
189     return _servletContext.getInitParameterNames();
190   }
191
192   /**
193    * {@inheritDoc}
194    */

195   public Object JavaDoc getAttribute(String JavaDoc name)
196   {
197     return _servletContext.getAttribute(name);
198   }
199
200   /**
201    * {@inheritDoc}
202    */

203   public Enumeration JavaDoc getAttributeNames()
204   {
205     return _servletContext.getAttributeNames();
206   }
207
208   /**
209    * {@inheritDoc}
210    */

211   public void removeAttribute(String JavaDoc name)
212   {
213     _servletContext.removeAttribute(name);
214   }
215
216   /**
217    * {@inheritDoc}
218    */

219   public void setAttribute(String JavaDoc name, Object JavaDoc object)
220   {
221     if (log.isLoggable(Level.FINEST)) {
222       log.finest("setAttribute(" + name + ")");
223     }
224     _servletContext.setAttribute(name,object);
225   }
226
227   /**
228    * {@inheritDoc}
229    */

230   public void log(String JavaDoc msg)
231   {
232     log(msg, null);
233   }
234
235   /**
236    * {@inheritDoc}
237    */

238   public void log(String JavaDoc message, Throwable JavaDoc e)
239   {
240     if (e != null)
241       log.log(Level.WARNING, message, e);
242     else
243       log.info(message);
244   }
245
246   /**
247    * {@inheritDoc}
248    */

249   public String JavaDoc getPortletContextName()
250   {
251     return _servletContext.getServletContextName();
252   }
253
254 }
255
256
Popular Tags