001
014
015 package com.liferay.portal.kernel.servlet;
016
017 import javax.portlet.PortletConfig;
018 import javax.portlet.PortletRequest;
019 import javax.portlet.PortletResponse;
020
021 import javax.servlet.ServletConfig;
022 import javax.servlet.http.HttpServletRequest;
023 import javax.servlet.http.HttpServletResponse;
024
025
028 public class PortletServletObjectsFactory implements ServletObjectsFactory {
029
030 @Override
031 public ServletConfig getServletConfig(
032 PortletConfig portletConfig, PortletRequest portletRequest) {
033
034 Object servletConfig = portletConfig.getPortletContext().getAttribute(
035 _PORTLET_CONTAINER_SERVLET_CONFIG);
036
037 if (servletConfig == null) {
038 servletConfig = portletRequest.getAttribute(
039 PortletServlet.PORTLET_SERVLET_CONFIG);
040 }
041
042 return (ServletConfig)servletConfig;
043 }
044
045 @Override
046 public HttpServletRequest getServletRequest(PortletRequest portletRequest) {
047 Object request = portletRequest.getAttribute(
048 _PORTLET_CONTAINER_SERVLET_REQUEST);
049
050 if (request == null) {
051 request = portletRequest.getAttribute(
052 PortletServlet.PORTLET_SERVLET_REQUEST);
053 }
054
055 return (HttpServletRequest)request;
056 }
057
058 @Override
059 public HttpServletResponse getServletResponse(
060 PortletRequest portletRequest, PortletResponse portletResponse) {
061
062 Object response = portletRequest.getAttribute(
063 _PORTLET_CONTAINER_SERVLET_RESPONSE);
064
065 if (response == null) {
066 response = portletRequest.getAttribute(
067 PortletServlet.PORTLET_SERVLET_RESPONSE);
068 }
069
070 return (HttpServletResponse)response;
071 }
072
073 private static final String _PORTLET_CONTAINER_SERVLET_CONFIG =
074 "javax.portlet.portletc.servletConfig";
075
076 private static final String _PORTLET_CONTAINER_SERVLET_REQUEST =
077 "javax.portlet.portletc.httpServletRequest";
078
079 private static final String _PORTLET_CONTAINER_SERVLET_RESPONSE =
080 "javax.portlet.portletc.httpServletResponse";
081
082 }