View Javadoc

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  /* 
17  
18   */
19  
20  package org.apache.pluto.core.impl;
21  
22  import java.net.MalformedURLException;
23  
24  import javax.portlet.PortletContext;
25  
26  import org.apache.pluto.core.InternalPortletContext;
27  import org.apache.pluto.om.portlet.PortletApplicationDefinition;
28  import org.apache.pluto.Environment;
29  
30  public class PortletContextImpl implements PortletContext, InternalPortletContext
31  {
32      private PortletApplicationDefinition portletApplicationDefinition;
33      private javax.servlet.ServletContext servletContext;
34  
35      public PortletContextImpl(javax.servlet.ServletContext servletContext,
36                                PortletApplicationDefinition portletApplicationDefinition)
37      {
38          this.servletContext = servletContext;
39          this.portletApplicationDefinition = portletApplicationDefinition;
40      }
41  
42      // javax.portlet.PortletContext implementation ------------------------------------------------
43      public String getServerInfo()
44      {
45          return Environment.getServerInfo();
46      }
47  
48      public javax.portlet.PortletRequestDispatcher getRequestDispatcher(String path)
49      {
50  		try {
51  	        javax.servlet.RequestDispatcher rd = servletContext.getRequestDispatcher(path);
52      	    return new PortletRequestDispatcherImpl(rd);
53          } catch (Exception e) {
54      		// need to catch exception because of tomcat 4.x bug
55      		// tomcat throws an exception instead of return null
56      		// if the path was not found
57      		return null;
58      	}
59  
60      }
61  
62      public javax.portlet.PortletRequestDispatcher getNamedDispatcher(String name)
63      {
64         	javax.servlet.RequestDispatcher rd = servletContext.getNamedDispatcher(name);
65         	return rd != null ? new PortletRequestDispatcherImpl(rd)
66             	              : null;
67      }
68  
69      public java.io.InputStream getResourceAsStream(String path)
70      {
71          return servletContext.getResourceAsStream(path);
72      }
73      
74      public int getMajorVersion()
75      {
76          return Environment.getMajorSpecificationVersion();
77      }
78  
79      public int getMinorVersion()
80      {
81          return Environment.getMinorSpecificationVersion();
82      }
83  
84      public String getMimeType(String file)
85      {
86          return servletContext.getMimeType(file);
87      }
88  
89      public String getRealPath(String path)
90      {
91          return servletContext.getRealPath(path);
92      }
93  
94      public java.util.Set getResourcePaths(String path)
95      {
96          return servletContext.getResourcePaths(path);
97      }
98  
99      public java.net.URL getResource(String path) throws java.net.MalformedURLException
100     {
101         if (path == null || !path.startsWith("/"))
102         {
103             throw new MalformedURLException("path must start with a '/'");
104         }
105         return servletContext.getResource(path);
106     }
107 
108     public java.lang.Object getAttribute(java.lang.String name)
109     {
110         if (name == null)
111         {
112             throw new IllegalArgumentException("Attribute name == null");
113         }
114 
115         return servletContext.getAttribute(name);
116     }
117 
118     public java.util.Enumeration getAttributeNames()
119     {
120         return servletContext.getAttributeNames();
121     }
122 
123     public java.lang.String getInitParameter(java.lang.String name)
124     {
125         if (name == null)
126         {
127             throw new IllegalArgumentException("Parameter name == null");
128         }
129 
130         return servletContext.getInitParameter(name);
131     }
132 
133     public java.util.Enumeration getInitParameterNames()
134     {
135         return servletContext.getInitParameterNames();
136     }
137 
138     public void log(java.lang.String msg)
139     {
140         servletContext.log(msg);
141     }
142 
143     public void log(java.lang.String message, java.lang.Throwable throwable)
144     {
145         servletContext.log(message, throwable);
146     }
147 
148     public void removeAttribute(java.lang.String name)
149     {
150         if (name == null)
151         {
152             throw new IllegalArgumentException("Attribute name == null");
153         }
154 
155         servletContext.removeAttribute(name);
156     }
157 
158     public void setAttribute(java.lang.String name, java.lang.Object object)
159     {
160         if (name == null)
161         {
162             throw new IllegalArgumentException("Attribute name == null");
163         }
164 
165         servletContext.setAttribute(name, object);
166     }
167 
168     public String getPortletContextName()
169     {
170         return servletContext.getServletContextName();
171     }
172     // --------------------------------------------------------------------------------------------
173 
174     // org.apache.pluto.core.InternalPortletContext implementation --------------------------------
175     public javax.servlet.ServletContext getServletContext()
176     {
177         return servletContext;
178     }
179 
180     public PortletApplicationDefinition getInternalPortletApplicationDefinition()
181     {
182         return portletApplicationDefinition;
183     }
184     // --------------------------------------------------------------------------------------------
185 }
186