KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > portal > portlet > impl > PortletContextImpl


1 /*****************************************
2  * *
3  * JBoss Portal: The OpenSource Portal *
4  * *
5  * Distributable under LGPL license. *
6  * See terms of license at gnu.org. *
7  * *
8  *****************************************/

9 package org.jboss.portal.portlet.impl;
10
11 import java.io.InputStream JavaDoc;
12 import java.net.MalformedURLException JavaDoc;
13 import java.net.URL JavaDoc;
14 import java.util.Enumeration JavaDoc;
15 import java.util.Set JavaDoc;
16
17 import javax.portlet.PortletContext;
18 import javax.portlet.PortletRequestDispatcher;
19 import javax.servlet.RequestDispatcher JavaDoc;
20 import javax.servlet.ServletContext JavaDoc;
21
22 /**
23  * @author <a HREF="mailto:julien@jboss.org">Julien Viet</a>
24  * @version $Revision: 1.2 $
25  */

26 public class PortletContextImpl implements PortletContext
27 {
28
29    private ServletContext JavaDoc servletContext;
30
31    public PortletContextImpl(ServletContext JavaDoc servletContext)
32    {
33       this.servletContext = servletContext;
34    }
35
36    public String JavaDoc getServerInfo()
37    {
38       return "JBossPortal/1.0";
39    }
40
41    public PortletRequestDispatcher getRequestDispatcher(String JavaDoc path)
42    {
43       if (path == null || !path.startsWith("/"))
44       {
45          return null;
46       }
47       RequestDispatcher rd = servletContext.getRequestDispatcher(path);
48       if (rd != null)
49       {
50          return new PortletRequestDispatcherImpl(rd, path);
51       }
52       else
53       {
54          return null;
55       }
56    }
57
58    public PortletRequestDispatcher getNamedDispatcher(String JavaDoc name)
59    {
60       if (name == null)
61       {
62          return null;
63       }
64       RequestDispatcher rd = servletContext.getNamedDispatcher(name);
65       if (rd != null)
66       {
67          return new PortletRequestDispatcherImpl(rd);
68       }
69       else
70       {
71          return null;
72       }
73    }
74
75    public InputStream JavaDoc getResourceAsStream(String JavaDoc s)
76    {
77       return servletContext.getResourceAsStream(s);
78    }
79
80    public int getMajorVersion()
81    {
82       return 1;
83    }
84
85    public int getMinorVersion()
86    {
87       return 0;
88    }
89
90    public String JavaDoc getMimeType(String JavaDoc s)
91    {
92       return servletContext.getMimeType(s);
93    }
94
95    public String JavaDoc getRealPath(String JavaDoc s)
96    {
97       return servletContext.getRealPath(s);
98    }
99
100    public Set JavaDoc getResourcePaths(String JavaDoc s)
101    {
102       return servletContext.getResourcePaths(s);
103    }
104
105    public URL JavaDoc getResource(String JavaDoc s) throws MalformedURLException JavaDoc
106    {
107       if (s == null || !s.startsWith("/"))
108       {
109          throw new MalformedURLException JavaDoc("invalid resource");
110       }
111       URL JavaDoc resource = servletContext.getResource(s);
112       return resource;
113    }
114
115    public Object JavaDoc getAttribute(String JavaDoc s)
116    {
117       if (s == null)
118       {
119          throw new IllegalArgumentException JavaDoc("attribute name must not be null");
120       }
121       return servletContext.getAttribute(s);
122    }
123
124    public Enumeration JavaDoc getAttributeNames()
125    {
126       return servletContext.getAttributeNames();
127    }
128
129    public String JavaDoc getInitParameter(String JavaDoc s)
130    {
131       if (s == null)
132       {
133          throw new IllegalArgumentException JavaDoc("init parameter name must not be null");
134       }
135       return servletContext.getInitParameter(s);
136    }
137
138    public Enumeration JavaDoc getInitParameterNames()
139    {
140       return servletContext.getInitParameterNames();
141    }
142
143    public void log(String JavaDoc s)
144    {
145       servletContext.log(s);
146    }
147
148    public void log(String JavaDoc s, Throwable JavaDoc throwable)
149    {
150       servletContext.log(s, throwable);
151    }
152
153    public void removeAttribute(String JavaDoc s)
154    {
155       if (s == null)
156       {
157          throw new IllegalArgumentException JavaDoc("attribute name must not be null");
158       }
159       servletContext.removeAttribute(s);
160    }
161
162    public void setAttribute(String JavaDoc s, Object JavaDoc o)
163    {
164       servletContext.setAttribute(s, o);
165    }
166
167    public String JavaDoc getPortletContextName()
168    {
169       return servletContext.getServletContextName();
170    }
171 }
172
Popular Tags