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.apache.bridges.struts;
022:
023: import com.liferay.portal.kernel.servlet.HttpHeaders;
024: import com.liferay.portal.kernel.servlet.ServletContextProvider;
025: import com.liferay.portal.kernel.util.ContentTypes;
026: import com.liferay.portlet.ActionRequestImpl;
027: import com.liferay.portlet.ActionResponseImpl;
028: import com.liferay.portlet.PortletContextImpl;
029: import com.liferay.portlet.RenderRequestImpl;
030: import com.liferay.portlet.RenderResponseImpl;
031: import com.liferay.util.servlet.UploadServletRequest;
032:
033: import java.io.IOException;
034:
035: import javax.portlet.GenericPortlet;
036: import javax.portlet.PortletRequest;
037: import javax.portlet.PortletResponse;
038:
039: import javax.servlet.ServletContext;
040: import javax.servlet.http.HttpServletRequest;
041: import javax.servlet.http.HttpServletResponse;
042:
043: /**
044: * <a href="LiferayServletContextProvider.java.html"><b><i>View Source</i></b>
045: * </a>
046: *
047: * @author James Schopp
048: * @author Michael Young
049: *
050: */
051: public class LiferayServletContextProvider implements
052: ServletContextProvider {
053:
054: public ServletContext getServletContext(GenericPortlet portlet) {
055: PortletContextImpl portletCtxImpl = (PortletContextImpl) portlet
056: .getPortletContext();
057:
058: return getServletContext(portletCtxImpl.getServletContext());
059: }
060:
061: public ServletContext getServletContext(ServletContext ctx) {
062: return new LiferayServletContext(ctx);
063: }
064:
065: public HttpServletRequest getHttpServletRequest(
066: GenericPortlet portlet, PortletRequest req) {
067:
068: HttpServletRequest httpReq = null;
069:
070: if (req instanceof ActionRequestImpl) {
071: httpReq = ((ActionRequestImpl) req).getHttpServletRequest();
072:
073: String contentType = httpReq
074: .getHeader(HttpHeaders.CONTENT_TYPE);
075:
076: if ((contentType != null)
077: && (contentType
078: .startsWith(ContentTypes.MULTIPART_FORM_DATA))) {
079:
080: try {
081: httpReq = new UploadServletRequest(httpReq);
082: } catch (IOException ioe) {
083: }
084:
085: httpReq = new LiferayStrutsRequestImpl(httpReq);
086: } else {
087: httpReq = new LiferayStrutsRequestImpl(
088: (ActionRequestImpl) req);
089: }
090: } else {
091: httpReq = new LiferayStrutsRequestImpl(
092: (RenderRequestImpl) req);
093: }
094:
095: return httpReq;
096: }
097:
098: public HttpServletResponse getHttpServletResponse(
099: GenericPortlet portlet, PortletResponse res) {
100:
101: if (res instanceof RenderResponseImpl) {
102: return ((RenderResponseImpl) res).getHttpServletResponse();
103: } else {
104: return ((ActionResponseImpl) res).getHttpServletResponse();
105: }
106: }
107:
108: }
|