KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > environment > portlet > PortletContext


1 /*
2  * Copyright 1999-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 package org.apache.cocoon.environment.portlet;
17
18 import org.apache.cocoon.environment.Context;
19
20 import org.apache.avalon.framework.CascadingRuntimeException;
21
22 import java.io.InputStream JavaDoc;
23 import java.net.MalformedURLException JavaDoc;
24 import java.net.URL JavaDoc;
25 import java.util.Enumeration JavaDoc;
26
27 /**
28  * Implements the {@link org.apache.cocoon.environment.Context} interface
29  * for the JSR-168 (Portlet) environment.
30  *
31  * @author <a HREF="mailto:alex.rudnev@dc.gov">Alex Rudnev</a>
32  * @author <a HREF="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
33  * @version CVS $Id: PortletContext.java 30932 2004-07-29 17:35:38Z vgritsenko $
34  */

35 public final class PortletContext implements Context {
36
37     /**
38      * The PortletContext
39      */

40     private final javax.portlet.PortletContext context;
41
42     /**
43      * Constructs a PortletContext object from a PortletContext object
44      */

45     public PortletContext(javax.portlet.PortletContext context) {
46         this.context = context;
47     }
48
49     public Object JavaDoc getAttribute(String JavaDoc name) {
50         return context.getAttribute(name);
51     }
52
53     public void setAttribute(String JavaDoc name, Object JavaDoc value) {
54         context.setAttribute(name, value);
55     }
56
57     public void removeAttribute(String JavaDoc name) {
58         context.removeAttribute(name);
59     }
60
61     public Enumeration JavaDoc getAttributeNames() {
62         return context.getAttributeNames();
63     }
64
65     public URL JavaDoc getResource(String JavaDoc path) throws MalformedURLException JavaDoc {
66         return context.getResource(path);
67     }
68
69     public InputStream JavaDoc getResourceAsStream(String JavaDoc path) {
70         return context.getResourceAsStream(path);
71     }
72
73     public String JavaDoc getRealPath(String JavaDoc path) {
74         if (path.equals("/")) {
75             String JavaDoc value = context.getRealPath(path);
76             if (value == null) {
77                 // Try to figure out the path of the root from that of WEB-INF
78
try {
79                     value = this.context.getResource("/WEB-INF").toString();
80                 } catch (MalformedURLException JavaDoc mue) {
81                     throw new CascadingRuntimeException("Cannot determine the base URL for " + path, mue);
82                 }
83                 value = value.substring(0, value.length() - "WEB-INF".length());
84             }
85             return value;
86         }
87         return context.getRealPath(path);
88     }
89
90     public String JavaDoc getMimeType(String JavaDoc file) {
91         return context.getMimeType(file);
92     }
93
94     public String JavaDoc getInitParameter(String JavaDoc name) {
95         return context.getInitParameter(name);
96     }
97
98
99     // PortletContext methods
100

101     public Enumeration JavaDoc getInitParameterNames() {
102         return context.getInitParameterNames();
103     }
104
105     public int getMajorVersion() {
106         return context.getMajorVersion();
107     }
108
109     public int getMinorVersion() {
110         return context.getMinorVersion();
111     }
112
113     public String JavaDoc getPortletContextName() {
114         return context.getPortletContextName();
115     }
116
117     public String JavaDoc getServerInfo() {
118         return context.getServerInfo();
119     }
120 }
121
Popular Tags