001: /* PortletServletContext.java
002:
003: {{IS_NOTE
004: Purpose:
005:
006: Description:
007:
008: History:
009: Thu Jan 12 17:12:44 2006, Created by tomyeh
010: }}IS_NOTE
011:
012: Copyright (C) 2006 Potix Corporation. All Rights Reserved.
013:
014: {{IS_RIGHT
015: This program is distributed under GPL Version 2.0 in the hope that
016: it will be useful, but WITHOUT ANY WARRANTY.
017: }}IS_RIGHT
018: */
019: package org.zkoss.web.portlet;
020:
021: import java.util.Set;
022: import java.util.Enumeration;
023: import java.io.InputStream;
024: import java.net.URL;
025: import java.net.MalformedURLException;
026:
027: import javax.servlet.ServletContext;
028: import javax.servlet.RequestDispatcher;
029: import javax.servlet.Servlet;
030: import javax.portlet.PortletContext;
031: import javax.portlet.PortletRequestDispatcher;
032:
033: /**
034: * A facade servlet context based on a given portlet context.
035: *
036: * @author tomyeh
037: */
038: public class PortletServletContext implements ServletContext {
039: private final PortletContext _ctx;
040:
041: /** Returns an instance of ServletContext that representing
042: * the specified portlet context.
043: * <p>Use this method instead of the constructor.
044: */
045: public static ServletContext getInstance(PortletContext ctx) {
046: return new PortletServletContext(ctx);
047: }
048:
049: private PortletServletContext(PortletContext ctx) {
050: if (ctx == null)
051: throw new IllegalArgumentException("null");
052: _ctx = ctx;
053: }
054:
055: //-- ServletContext --//
056: public Object getAttribute(String name) {
057: return _ctx.getAttribute(name);
058: }
059:
060: public Enumeration getAttributeNames() {
061: return _ctx.getAttributeNames();
062: }
063:
064: public ServletContext getContext(String path) {
065: return null;
066: }
067:
068: public String getInitParameter(String name) {
069: return _ctx.getInitParameter(name);
070: }
071:
072: public Enumeration getInitParameterNames() {
073: return _ctx.getInitParameterNames();
074: }
075:
076: public int getMajorVersion() {
077: return _ctx.getMajorVersion();
078: }
079:
080: public String getMimeType(String file) {
081: return _ctx.getMimeType(file);
082: }
083:
084: public int getMinorVersion() {
085: return _ctx.getMinorVersion();
086: }
087:
088: public RequestDispatcher getNamedDispatcher(String name) {
089: final PortletRequestDispatcher prd = _ctx
090: .getNamedDispatcher(name);
091: return prd != null ? PortletServletDispatcher.getInstance(prd)
092: : null;
093: }
094:
095: public String getRealPath(String path) {
096: return _ctx.getRealPath(path);
097: }
098:
099: public RequestDispatcher getRequestDispatcher(String path) {
100: final PortletRequestDispatcher prd = _ctx
101: .getRequestDispatcher(path);
102: return prd != null ? PortletServletDispatcher.getInstance(prd)
103: : null;
104: }
105:
106: public URL getResource(String path) throws MalformedURLException {
107: return _ctx.getResource(path);
108: }
109:
110: public InputStream getResourceAsStream(String path) {
111: return _ctx.getResourceAsStream(path);
112: }
113:
114: public Set getResourcePaths(String path) {
115: return _ctx.getResourcePaths(path);
116: }
117:
118: public String getServerInfo() {
119: return _ctx.getServerInfo();
120: }
121:
122: /**
123: * @deprecated
124: */
125: public Servlet getServlet(String name) {
126: return null;
127: }
128:
129: /**
130: * @deprecated
131: */
132: public Enumeration getServletNames() {
133: return null;
134: }
135:
136: /**
137: * @deprecated
138: */
139: public Enumeration getServlets() {
140: return null;
141: }
142:
143: public String getServletContextName() {
144: return _ctx.getPortletContextName();
145: }
146:
147: /**
148: * @deprecated
149: */
150: public void log(Exception exception, String msg) {
151: }
152:
153: public void log(String msg) {
154: _ctx.log(msg);
155: }
156:
157: public void log(String message, Throwable throwable) {
158: _ctx.log(message, throwable);
159: }
160:
161: public void removeAttribute(String name) {
162: _ctx.removeAttribute(name);
163: }
164:
165: public void setAttribute(String name, Object object) {
166: _ctx.setAttribute(name, object);
167: }
168: }
|