001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.environment.portlet;
018:
019: import org.apache.cocoon.environment.Context;
020:
021: import org.apache.avalon.framework.CascadingRuntimeException;
022:
023: import java.io.InputStream;
024: import java.net.MalformedURLException;
025: import java.net.URL;
026: import java.util.Enumeration;
027:
028: /**
029: * Implements the {@link org.apache.cocoon.environment.Context} interface
030: * for the JSR-168 (Portlet) environment.
031: *
032: * @author <a href="mailto:alex.rudnev@dc.gov">Alex Rudnev</a>
033: * @author <a href="mailto:vgritsenko@apache.org">Vadim Gritsenko</a>
034: * @version CVS $Id: PortletContext.java 433543 2006-08-22 06:22:54Z crossley $
035: */
036: public final class PortletContext implements Context {
037:
038: /**
039: * The PortletContext
040: */
041: private final javax.portlet.PortletContext context;
042:
043: /**
044: * Constructs a PortletContext object from a PortletContext object
045: */
046: public PortletContext(javax.portlet.PortletContext context) {
047: this .context = context;
048: }
049:
050: public Object getAttribute(String name) {
051: return context.getAttribute(name);
052: }
053:
054: public void setAttribute(String name, Object value) {
055: context.setAttribute(name, value);
056: }
057:
058: public void removeAttribute(String name) {
059: context.removeAttribute(name);
060: }
061:
062: public Enumeration getAttributeNames() {
063: return context.getAttributeNames();
064: }
065:
066: public URL getResource(String path) throws MalformedURLException {
067: return context.getResource(path);
068: }
069:
070: public InputStream getResourceAsStream(String path) {
071: return context.getResourceAsStream(path);
072: }
073:
074: public String getRealPath(String path) {
075: if (path.equals("/")) {
076: String value = context.getRealPath(path);
077: if (value == null) {
078: // Try to figure out the path of the root from that of WEB-INF
079: try {
080: value = this .context.getResource("/WEB-INF")
081: .toString();
082: } catch (MalformedURLException mue) {
083: throw new CascadingRuntimeException(
084: "Cannot determine the base URL for " + path,
085: mue);
086: }
087: value = value.substring(0, value.length()
088: - "WEB-INF".length());
089: }
090: return value;
091: }
092: return context.getRealPath(path);
093: }
094:
095: public String getMimeType(String file) {
096: return context.getMimeType(file);
097: }
098:
099: public String getInitParameter(String name) {
100: return context.getInitParameter(name);
101: }
102:
103: // PortletContext methods
104:
105: public Enumeration getInitParameterNames() {
106: return context.getInitParameterNames();
107: }
108:
109: public int getMajorVersion() {
110: return context.getMajorVersion();
111: }
112:
113: public int getMinorVersion() {
114: return context.getMinorVersion();
115: }
116:
117: public String getPortletContextName() {
118: return context.getPortletContextName();
119: }
120:
121: public String getServerInfo() {
122: return context.getServerInfo();
123: }
124: }
|