001: /*
002: * (C) Copyright 2000 - 2003 Nabh Information Systems, Inc.
003: *
004: * This program is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU General Public License
006: * as published by the Free Software Foundation; either version 2
007: * of the License, or (at your option) any later version.
008: *
009: * This program is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: *
014: * You should have received a copy of the GNU General Public License
015: * along with this program; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: *
018: */
019:
020: package com.nabhinc.portal.container;
021:
022: import java.io.File;
023: import java.io.InputStream;
024: import java.net.MalformedURLException;
025: import java.net.URL;
026: import java.util.Enumeration;
027: import java.util.Set;
028:
029: import javax.portlet.PortletContext;
030: import javax.portlet.PortletRequestDispatcher;
031: import javax.servlet.ServletContext;
032:
033: import com.nabhinc.util.StringUtil;
034:
035: /**
036: *
037: *
038: * @author Padmanabh dabke
039: * (c) 2003 Nabh Information Systems, Inc. All Rights Reserved.
040: */
041: public class PortletContextImpl implements PortletContext {
042:
043: protected ServletContext pciServletContext = null;
044: private String pciServerInfo = null;
045: private String pciRootDir = null;
046:
047: public PortletContextImpl(ServletContext sContext,
048: String serverInfo, String rootDir) {
049: pciServletContext = sContext;
050: pciRootDir = rootDir;
051: }
052:
053: public ServletContext getServletContext() {
054: return pciServletContext;
055: }
056:
057: /* (non-Javadoc)
058: * @see javax.portlet.PortletContext#getServerInfo()
059: */
060: public String getServerInfo() {
061: return pciServerInfo;
062: }
063:
064: /* (non-Javadoc)
065: * @see javax.portlet.PortletContext#getRequestDispatcher(java.lang.String)
066: */
067: public PortletRequestDispatcher getRequestDispatcher(String path) {
068: return new PortletRequestDispatcherImpl(pciServletContext
069: .getRequestDispatcher(path), path);
070: }
071:
072: /* (non-Javadoc)
073: * @see javax.portlet.PortletContext#getNamedDispatcher(java.lang.String)
074: */
075: public PortletRequestDispatcher getNamedDispatcher(String name) {
076: return new PortletRequestDispatcherImpl(pciServletContext
077: .getNamedDispatcher(name), name);
078: }
079:
080: /* (non-Javadoc)
081: * @see javax.portlet.PortletContext#getResourceAsStream(java.lang.String)
082: */
083: public InputStream getResourceAsStream(String path) {
084: return pciServletContext.getResourceAsStream(path);
085: }
086:
087: /* (non-Javadoc)
088: * @see javax.portlet.PortletContext#getMajorVersion()
089: */
090: public int getMajorVersion() {
091: return 1;
092: }
093:
094: /* (non-Javadoc)
095: * @see javax.portlet.PortletContext#getMinorVersion()
096: */
097: public int getMinorVersion() {
098: return 0;
099: }
100:
101: /* (non-Javadoc)
102: * @see javax.portlet.PortletContext#getMimeType(java.lang.String)
103: */
104: public String getMimeType(String file) {
105: return pciServletContext.getMimeType(file);
106: }
107:
108: /* (non-Javadoc)
109: * @see javax.portlet.PortletContext#getRealPath(java.lang.String)
110: */
111: public String getRealPath(String path) {
112: if (pciRootDir == null)
113: return pciServletContext.getRealPath(path);
114: String realPath = null;
115: if (path.startsWith("/")) {
116: realPath = pciRootDir + path;
117: } else {
118: realPath = pciRootDir + File.separator + path;
119: }
120: realPath = StringUtil.replacePathSeparator(realPath);
121: return realPath;
122: }
123:
124: /* (non-Javadoc)
125: * @see javax.portlet.PortletContext#getResourcePaths(java.lang.String)
126: */
127: public Set getResourcePaths(String path) {
128: return pciServletContext.getResourcePaths(path);
129: }
130:
131: /* (non-Javadoc)
132: * @see javax.portlet.PortletContext#getResource(java.lang.String)
133: */
134: public URL getResource(String path) throws MalformedURLException {
135: return pciServletContext.getResource(path);
136: }
137:
138: /* (non-Javadoc)
139: * @see javax.portlet.PortletContext#getAttribute(java.lang.String)
140: */
141: public Object getAttribute(String name) {
142: return pciServletContext.getAttribute(name);
143: }
144:
145: /* (non-Javadoc)
146: * @see javax.portlet.PortletContext#getAttributeNames()
147: */
148: public Enumeration getAttributeNames() {
149: return pciServletContext.getAttributeNames();
150: }
151:
152: /* (non-Javadoc)
153: * @see javax.portlet.PortletContext#getInitParameter(java.lang.String)
154: */
155: public String getInitParameter(String name) {
156: return pciServletContext.getInitParameter(name);
157: }
158:
159: /* (non-Javadoc)
160: * @see javax.portlet.PortletContext#getInitParameterNames()
161: */
162: public Enumeration getInitParameterNames() {
163: return pciServletContext.getInitParameterNames();
164: }
165:
166: /* (non-Javadoc)
167: * @see javax.portlet.PortletContext#log(java.lang.String)
168: */
169: public void log(String msg) {
170: pciServletContext.log(msg);
171:
172: }
173:
174: /* (non-Javadoc)
175: * @see javax.portlet.PortletContext#log(java.lang.String, java.lang.Throwable)
176: */
177: public void log(String message, Throwable throwable) {
178: pciServletContext.log(message, throwable);
179:
180: }
181:
182: /* (non-Javadoc)
183: * @see javax.portlet.PortletContext#removeAttribute(java.lang.String)
184: */
185: public void removeAttribute(String name) {
186: pciServletContext.removeAttribute(name);
187:
188: }
189:
190: /* (non-Javadoc)
191: * @see javax.portlet.PortletContext#setAttribute(java.lang.String, java.lang.Object)
192: */
193: public void setAttribute(String name, Object object) {
194: pciServletContext.setAttribute(name, object);
195:
196: }
197:
198: /* (non-Javadoc)
199: * @see javax.portlet.PortletContext#getPortletContextName()
200: */
201: public String getPortletContextName() {
202: return pciServletContext.getServletContextName();
203: }
204:
205: }
|