001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.portal.kernel.servlet;
022:
023: import com.liferay.portal.kernel.log.Log;
024: import com.liferay.portal.kernel.log.LogFactoryUtil;
025: import com.liferay.portal.kernel.portlet.LiferayPortletSession;
026: import com.liferay.portal.kernel.util.JavaConstants;
027:
028: import java.io.IOException;
029:
030: import javax.portlet.ActionRequest;
031: import javax.portlet.ActionResponse;
032: import javax.portlet.Portlet;
033: import javax.portlet.PortletException;
034: import javax.portlet.PortletRequest;
035: import javax.portlet.PortletResponse;
036: import javax.portlet.RenderRequest;
037: import javax.portlet.RenderResponse;
038:
039: import javax.servlet.ServletException;
040: import javax.servlet.http.HttpServlet;
041: import javax.servlet.http.HttpServletRequest;
042: import javax.servlet.http.HttpServletResponse;
043: import javax.servlet.http.HttpSession;
044:
045: /**
046: * <a href="PortletServlet.java.html"><b><i>View Source</i></b></a>
047: *
048: * @author Brian Wing Shun Chan
049: *
050: */
051: public class PortletServlet extends HttpServlet {
052:
053: public static final String PORTLET_CLASS_LOADER = "PORTLET_CLASS_LOADER";
054:
055: public static final String PORTLET_SERVLET_CONFIG = "com.liferay.portal.kernel.servlet.PortletServletConfig";
056:
057: public static final String PORTLET_SERVLET_REQUEST = "com.liferay.portal.kernel.servlet.PortletServletRequest";
058:
059: public static final String PORTLET_SERVLET_RESPONSE = "com.liferay.portal.kernel.servlet.PortletServletResponse";
060:
061: public void service(HttpServletRequest req, HttpServletResponse res)
062: throws IOException, ServletException {
063:
064: PortletRequest portletReq = (PortletRequest) req
065: .getAttribute(JavaConstants.JAVAX_PORTLET_REQUEST);
066:
067: PortletResponse portletRes = (PortletResponse) req
068: .getAttribute(JavaConstants.JAVAX_PORTLET_RESPONSE);
069:
070: Portlet portlet = (Portlet) req
071: .getAttribute(JavaConstants.JAVAX_PORTLET_PORTLET);
072:
073: LiferayPortletSession portletSes = (LiferayPortletSession) portletReq
074: .getPortletSession();
075:
076: portletReq.setAttribute(PORTLET_SERVLET_CONFIG,
077: getServletConfig());
078: portletReq.setAttribute(PORTLET_SERVLET_REQUEST, req);
079: portletReq.setAttribute(PORTLET_SERVLET_RESPONSE, res);
080:
081: HttpSession ses = req.getSession();
082:
083: PortletSessionTracker.add(ses);
084:
085: portletSes.setHttpSession(ses);
086:
087: try {
088: if (portletReq instanceof ActionRequest) {
089: ActionRequest actionReq = (ActionRequest) portletReq;
090: ActionResponse actionRes = (ActionResponse) portletRes;
091:
092: portlet.processAction(actionReq, actionRes);
093: } else {
094: RenderRequest renderReq = (RenderRequest) portletReq;
095: RenderResponse renderRes = (RenderResponse) portletRes;
096:
097: portlet.render(renderReq, renderRes);
098: }
099: } catch (PortletException pe) {
100: _log.error(pe, pe);
101:
102: throw new ServletException(pe);
103: }
104: }
105:
106: private static Log _log = LogFactoryUtil
107: .getLog(PortletServlet.class);
108:
109: }
|