You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pluto-scm@portals.apache.org by at...@apache.org on 2009/03/06 17:11:52 UTC
svn commit: r750954 [3/5] - in /portals/pluto/trunk:
pluto-container/src/main/java/org/apache/pluto/core/
pluto-container/src/main/java/org/apache/pluto/descriptors/portlet/
pluto-container/src/main/java/org/apache/pluto/descriptors/services/jaxb/
plut...
Modified: portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/internal/impl/PortletRequestDispatcherImpl.java
URL: http://svn.apache.org/viewvc/portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/internal/impl/PortletRequestDispatcherImpl.java?rev=750954&r1=750953&r2=750954&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/internal/impl/PortletRequestDispatcherImpl.java (original)
+++ portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/internal/impl/PortletRequestDispatcherImpl.java Fri Mar 6 16:11:51 2009
@@ -18,6 +18,7 @@
import java.io.IOException;
+import javax.portlet.MimeResponse;
import javax.portlet.PortletException;
import javax.portlet.PortletRequest;
import javax.portlet.PortletRequestDispatcher;
@@ -26,37 +27,33 @@
import javax.portlet.RenderResponse;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequestWrapper;
+import javax.servlet.http.HttpServletResponseWrapper;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.pluto.internal.InternalPortletRequest;
-import org.apache.pluto.internal.InternalPortletResponse;
+import org.apache.pluto.Constants;
+import org.apache.pluto.internal.RequestDispatcherPathInfo;
+import org.apache.pluto.spi.optional.PortletRequestContext;
/**
* Implementation of the <code>PortletRequestDispatcher</code> interface.
- * The portlet request dispatcher is used to dispatch <b>RenderRequest</b> and
- * <b>RenderResponse</b> to a URI. Note that ActionRequest and ActionResponse
- * can never be dispatched.
+ * The portlet request dispatcher is used to dispatch <b>PortletRequest</b> and
+ * <b>PortletResponse</b> to a URI.
*
*/
-public class PortletRequestDispatcherImpl implements PortletRequestDispatcher {
-
+public class PortletRequestDispatcherImpl implements PortletRequestDispatcher, RequestDispatcher
+{
/** Logger. */
private static final Log LOG = LogFactory.getLog(PortletRequestDispatcherImpl.class);
-
// Private Member Variables ------------------------------------------------
/** The nested servlet request dispatcher instance. */
private RequestDispatcher requestDispatcher;
-
- /** The included/forwarded query string. */
- private String queryString;
- private String servlet_path;
- private String path_info;
- private boolean namedDispatcher = true;
+ private RequestDispatcherPathInfo pathInfo;
// Constructors ------------------------------------------------------------
@@ -69,7 +66,8 @@
*/
public PortletRequestDispatcherImpl(RequestDispatcher requestDispatcher) {
this.requestDispatcher = requestDispatcher;
- if (LOG.isDebugEnabled()) {
+ if (LOG.isDebugEnabled())
+ {
LOG.debug("Named dispatcher created.");
}
}
@@ -78,141 +76,190 @@
* Creates an instance. This constructor should be called to construct a
* portlet request dispatcher.
* @param requestDispatcher the servlet request dispatcher.
- * @param queryString the included query string.
+ * @param pathInfo
* @see javax.portlet.PortletContext#getRequestDispatcher(String)
*/
- public PortletRequestDispatcherImpl(RequestDispatcher requestDispatcher,
- String path) {
- this(requestDispatcher);
- namedDispatcher = false;
-
- //Extract servlet_path
- int index1 = path.indexOf("/", 1);
- if (index1 > 0 && index1 < path.length() - 1) {
- servlet_path = path.substring(0, index1);
- }
+ public PortletRequestDispatcherImpl(RequestDispatcher requestDispatcher, RequestDispatcherPathInfo pathInfo)
+ {
+ this.requestDispatcher = requestDispatcher;
+ this.pathInfo = pathInfo;
- //Extract query string which contains appended parameters.
- queryString = null;
- int index2 = path.indexOf("?");
- if (index2 > 0 && index2 < path.length() - 1) {
- queryString = path.substring(index2 + 1);
+ if (LOG.isDebugEnabled())
+ {
+ LOG.debug("Request dispatcher created.");
}
+ }
+
+ private static HttpServletPortletRequestWrapper getWrappedRequest(ServletRequest request)
+ {
+ HttpServletPortletRequestWrapper req = null;
- //Extract path_info
- if (index1 > 0 && index1 < index2 && index2 > 0 && index2 < path.length() - 1) {
- path_info = path.substring(index1, index2);
+ do
+ {
+ if (request instanceof HttpServletPortletRequestWrapper)
+ {
+ req = (HttpServletPortletRequestWrapper)request;
+ }
+ else if (request instanceof HttpServletRequestWrapper)
+ {
+ request = ((HttpServletRequestWrapper)request).getRequest();
+ }
+ else
+ {
+ request = null;
+ }
}
+ while (request != null && req == null);
+ return req;
+ }
+
+ private static HttpServletPortletResponseWrapper getWrappedResponse(ServletResponse response)
+ {
+ HttpServletPortletResponseWrapper res = null;
- if (LOG.isDebugEnabled()) {
- LOG.debug("Request dispatcher created.");
+ do
+ {
+ if (response instanceof HttpServletPortletResponseWrapper)
+ {
+ res = (HttpServletPortletResponseWrapper)response;
+ }
+ else if (response instanceof HttpServletResponseWrapper)
+ {
+ response = ((HttpServletResponseWrapper)response).getResponse();
+ }
+ else
+ {
+ response = null;
+ }
}
+ while (response != null && res == null);
+ return res;
}
+ private void doDispatch(PortletRequest request, PortletResponse response, boolean included) throws PortletException, IOException
+ {
+ if (!included)
+ {
+ String lifecyclePhase = (String)request.getAttribute(PortletRequest.LIFECYCLE_PHASE);
+ if (PortletRequest.RENDER_PHASE.equals(lifecyclePhase) || PortletRequest.RESOURCE_PHASE.equals(lifecyclePhase))
+ {
+ ((MimeResponse)response).resetBuffer();
+ }
+ }
+
+ PortletRequestContext requestContext = (PortletRequestContext)request.getAttribute(Constants.REQUEST_CONTEXT);
+ HttpServletPortletRequestWrapper req = new HttpServletPortletRequestWrapper(requestContext.getServletRequest(),
+ requestContext.getPortletConfig().getPortletContext().getServletContext(),
+ null, // TODO: ProxySession if javax.portlet.servletDefaultSessionScope == PORTLET_SCOPE
+ request,
+ pathInfo,
+ included);
+ HttpServletPortletResponseWrapper res = new HttpServletPortletResponseWrapper(requestContext.getServletResponse(),
+ request,
+ response,
+ included);
+ try
+ {
+ if (!included && req.isForwardingPossible())
+ {
+ requestDispatcher.forward(req, res);
+ }
+ else
+ {
+ requestDispatcher.include(req, res);
+ }
+ }
+ catch (ServletException sex)
+ {
+ if (sex.getRootCause() != null)
+ {
+ throw new PortletException(sex.getRootCause());
+ }
+ else
+ {
+ throw new PortletException(sex);
+ }
+ }
+ }
+
+ private void doDispatch(ServletRequest request, ServletResponse response, HttpServletPortletRequestWrapper req,
+ HttpServletPortletResponseWrapper res, boolean included) throws ServletException, IOException
+ {
+ if (!included)
+ {
+ res.resetBuffer();
+ }
+
+ RequestDispatcherPathInfo currentMethodPathInfo = req.getMethodPathInfo();
+ RequestDispatcherPathInfo currentForwardedPathInfo = req.getForwardedPathInfo();
+ RequestDispatcherPathInfo currentIncludedPathInfo = req.getIncludedPathInfo();
+ boolean currentIncluded = req.isIncluded();
+ try
+ {
+ RequestDispatcherPathInfo methodPathInfo = null;
+ if (currentMethodPathInfo.isNamedRequestDispatcher() || !(included || pathInfo.isNamedRequestDispatcher()))
+ {
+ methodPathInfo = pathInfo;
+ }
+ else
+ {
+ methodPathInfo = currentMethodPathInfo;
+ }
+ RequestDispatcherPathInfo attributesPathInfo = null;
+ if (included)
+ {
+ attributesPathInfo = pathInfo;
+ }
+ else if (currentForwardedPathInfo != null && !currentForwardedPathInfo.isNamedRequestDispatcher())
+ {
+ attributesPathInfo = currentForwardedPathInfo;
+ }
+ else
+ {
+ attributesPathInfo = pathInfo;
+ }
+ req.setNewPathInfo(methodPathInfo, attributesPathInfo, included);
+ if (!included && req.isForwardingPossible())
+ {
+ requestDispatcher.forward(request, response);
+ }
+ else
+ {
+ requestDispatcher.include(request, response);
+ }
+ }
+ finally
+ {
+ req.restorePathInfo(currentMethodPathInfo, currentIncludedPathInfo, currentForwardedPathInfo, currentIncluded);
+ }
+ }
// PortletRequestDispatcher Impl -------------------------------------------
- public void include(PortletRequest request, PortletResponse response) throws PortletException, IOException {
- InternalPortletRequest internalRequest = InternalImplConverter.getInternalRequest(request);
- InternalPortletResponse internalResponse = InternalImplConverter.getInternalResponse(response);
- internalInclude(internalRequest,internalResponse);
+ public void forward(PortletRequest request, PortletResponse response) throws PortletException, IOException
+ {
+ doDispatch(request, response, false);
+ }
+
+ public void include(PortletRequest request, PortletResponse response) throws PortletException, IOException
+ {
+ doDispatch(request, response, true);
}
-
-
- public void include(RenderRequest request, RenderResponse response)
- throws PortletException, IOException {
- InternalPortletRequest internalRequest = InternalImplConverter.getInternalRequest(request);
- InternalPortletResponse internalResponse = InternalImplConverter.getInternalResponse(response);
- internalInclude(internalRequest,internalResponse);
+ public void include(RenderRequest request, RenderResponse response) throws PortletException, IOException
+ {
+ doDispatch(request, response, true);
}
- public void forward(PortletRequest request, PortletResponse response) throws PortletException, IOException, IllegalStateException {
- InternalPortletRequest internalRequest = InternalImplConverter.getInternalRequest(request);
- InternalPortletResponse internalResponse = InternalImplConverter.getInternalResponse(response);
- if (!internalResponse.isForwardedAllowed()){
- throw new IllegalStateException("Response has been committed, this isn't allowed before forward" +
- " method. Content must delete before service from servlet is called.");
- }
- boolean isForwarded = (internalRequest.isForwarded()||internalResponse.isForwarded());
- try {
- internalRequest.setForwarded(true);
- internalRequest.setForwardedQueryString(queryString);
- if (!namedDispatcher){
- setAttributesForward(internalRequest);
- internalRequest.setNamedRequestDispatcher(false);
- }
- else{
- internalRequest.setNamedRequestDispatcher(true);
- }
- internalResponse.setForwarded(true);
-
- requestDispatcher.forward((HttpServletRequest) internalRequest,
- (HttpServletResponse) internalResponse);
- } catch (IOException ex) {
- throw ex;
- } catch (ServletException ex) {
- if (ex.getRootCause() != null) {
- throw new PortletException(ex.getRootCause());
- } else {
- throw new PortletException(ex);
- }
- } finally {
- internalRequest.setForwarded(isForwarded);
- internalResponse.setForwarded(isForwarded);
- internalResponse.setRequestForwarded();
- }
- }
-
- private void internalInclude(InternalPortletRequest internalRequest, InternalPortletResponse internalResponse)
- throws PortletException, IOException {
- boolean isIncluded = (internalRequest.isIncluded()
- || internalResponse.isIncluded());
- try {
- internalRequest.setIncluded(true);
- internalRequest.setIncludedQueryString(queryString);
- if (!namedDispatcher){
- setAttributesInclude(internalRequest);
- }
- else{
-
- internalRequest.setNamedRequestDispatcher(true);
- }
- internalResponse.setIncluded(true);
-
- requestDispatcher.include(
- (HttpServletRequest) internalRequest,
- (HttpServletResponse) internalResponse);
- } catch (IOException ex) {
- throw ex;
- } catch (ServletException ex) {
- if (ex.getRootCause() != null) {
- throw new PortletException(ex.getRootCause());
- } else {
- throw new PortletException(ex);
- }
- } finally {
- internalRequest.setIncluded(isIncluded);
- internalResponse.setIncluded(isIncluded);
- }
- }
- private void setAttributesForward(InternalPortletRequest internalRequest){
- String context_path = internalRequest.getContextPath();
- String request_uri = context_path + servlet_path + path_info;
- internalRequest.setAttribute("javax.servlet.forward.request_uri", request_uri);
- internalRequest.setAttribute("javax.servlet.forward.context_path", context_path);
- internalRequest.setAttribute("javax.servlet.forward.servlet_path", servlet_path);
- internalRequest.setAttribute("javax.servlet.forward.path_info", path_info);
- internalRequest.setAttribute("javax.servlet.forward.query_string", queryString);
- }
+ // RequestDispatcher Impl -------------------------------------------
- private void setAttributesInclude(InternalPortletRequest internalRequest){
- String context_path = internalRequest.getContextPath();
- String request_uri = context_path + servlet_path + path_info;
- internalRequest.setAttribute("javax.servlet.include.request_uri", request_uri);
- internalRequest.setAttribute("javax.servlet.include.context_path", context_path);
- internalRequest.setAttribute("javax.servlet.include.servlet_path", servlet_path);
- internalRequest.setAttribute("javax.servlet.include.path_info", path_info);
- internalRequest.setAttribute("javax.servlet.include.query_string", queryString);
- }
+ public void forward(ServletRequest request, ServletResponse response) throws ServletException, IOException
+ {
+ doDispatch(request, response, getWrappedRequest(request), getWrappedResponse(response), false);
+ }
+
+ public void include(ServletRequest request, ServletResponse response) throws ServletException, IOException
+ {
+ doDispatch(request, response, getWrappedRequest(request), getWrappedResponse(response), true);
+ }
}
Modified: portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/internal/impl/PortletRequestImpl.java
URL: http://svn.apache.org/viewvc/portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/internal/impl/PortletRequestImpl.java?rev=750954&r1=750953&r2=750954&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/internal/impl/PortletRequestImpl.java (original)
+++ portals/pluto/trunk/pluto-container/src/main/java/org/apache/pluto/internal/impl/PortletRequestImpl.java Fri Mar 6 16:11:51 2009
@@ -16,39 +16,27 @@
*/
package org.apache.pluto.internal.impl;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.UnsupportedEncodingException;
import java.security.Principal;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
-import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
-import java.util.Vector;
import javax.ccpp.Profile;
+import javax.portlet.CacheControl;
+import javax.portlet.MimeResponse;
import javax.portlet.PortalContext;
import javax.portlet.PortletMode;
import javax.portlet.PortletPreferences;
import javax.portlet.PortletRequest;
import javax.portlet.PortletSession;
import javax.portlet.WindowState;
-import javax.servlet.RequestDispatcher;
-import javax.servlet.ServletException;
-import javax.servlet.ServletInputStream;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletRequestWrapper;
import javax.servlet.http.HttpSession;
import org.apache.commons.logging.Log;
@@ -59,18 +47,14 @@
import org.apache.pluto.PortletEntity;
import org.apache.pluto.PortletWindow;
import org.apache.pluto.internal.InternalPortletContext;
-import org.apache.pluto.internal.InternalPortletRequest;
-import org.apache.pluto.internal.InternalPortletSession;
import org.apache.pluto.om.portlet.PortletDefinition;
import org.apache.pluto.om.portlet.SecurityRoleRef;
import org.apache.pluto.om.portlet.Supports;
-import org.apache.pluto.spi.PortletURLProvider;
-import org.apache.pluto.spi.PropertyManager;
import org.apache.pluto.spi.optional.PortletEnvironmentService;
-import org.apache.pluto.spi.optional.RequestAttributeService;
+import org.apache.pluto.spi.optional.PortletRequestContext;
import org.apache.pluto.util.ArgumentUtility;
+import org.apache.pluto.util.Enumerator;
import org.apache.pluto.util.StringManager;
-import org.apache.pluto.util.StringUtils;
/**
@@ -78,166 +62,333 @@
* This class also implements InternalPortletRequest.
*
*/
-public abstract class PortletRequestImpl extends HttpServletRequestWrapper
- implements PortletRequest, InternalPortletRequest
+public abstract class PortletRequestImpl implements PortletRequest
{
+ public static final String ACCEPT_LANGUAGE = "Accept-Language";
+
private static final Log LOG = LogFactory.getLog(PortletRequestImpl.class);
-
+
private static final StringManager EXCEPTIONS =
StringManager.getManager(PortletRequestImpl.class.getPackage().getName());
-
+
private static final List<String> EMPTY_STRING_LIST = Collections.unmodifiableList(new ArrayList<String>(0));
- /**
- * Cache for parsed dateHeader values.
- */
- protected static final HashMap<String,Long> dateHeaderParseCache = new HashMap<String,Long>();
-
- /**
- * The set of SimpleDateFormat formats to use in getDateHeader().
- *
- * Notice that because SimpleDateFormat is not thread-safe, we can't
- * declare formats[] as a static variable.
- */
- protected SimpleDateFormat dateHeaderFormats[] = {
- new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US),
- new SimpleDateFormat("EEEEEE, dd-MMM-yy HH:mm:ss zzz", Locale.US),
- new SimpleDateFormat("EEE MMMM d HH:mm:ss yyyy", Locale.US)
- };
-
+
// Private Member Variables ------------------------------------------------
-
- /** The parent container within which this request was created. */
- protected PortletContainer container;
-
- /** The portlet window which is the target of this portlet request. */
- protected PortletWindow portletWindow;
-
- /**
- * The PortletContext associated with this Request. This PortletContext must
- * be initialized from within the <code>PortletServlet</code>.
- */
- protected InternalPortletContext portletContext;
-
+
/** The PortalContext within which this request is occuring. */
- protected PortalContext portalContext;
-
+ private PortalContext portalContext;
+
+ private PortletRequestContext requestContext;
+
/** The portlet session. */
- private InternalPortletSession portletSession;
+ private PortletSession portletSession;
/** Response content types. */
- protected Vector<String> contentTypes;
-
- /** FIXME: do we really need this?
- * Flag indicating if the HTTP-Body has been accessed. */
- protected boolean bodyAccessed = false;
-
- /** True if we are in an include call. */
- protected boolean included = false;
-
- /** True if we are in an forwarded call. */
- protected boolean forwarded = false;
-
- protected boolean namedRequestDispatcher;
-
- /** The corresponding servlet request. */
- protected HttpServletRequest servletRequest = null;
+ private ArrayList<String> contentTypes;
+
+ private PortletPreferences portletPreferences;
+
+ private Map<String, String[]> parameters = null;
+
+ private Map<String, String[]> requestProperties = null;
+ private List<String> requestPropertyNames = null;
+
+ private Cookie[] requestCookies = null;
+
+ private Map<String, String> userInfo = null;
+
+ private Profile ccppProfile = null;
+
+ private final String lifecyclePhase;
+
+ public PortletRequestImpl(PortletRequestContext requestContext, String lifecyclePhase)
+ {
+ this.requestContext = requestContext;
+ this.lifecyclePhase = lifecyclePhase;
+ this.portalContext = getPortletContainer().getRequiredContainerServices().getPortalContext();
+ }
+
+ private void retrieveRequestProperties()
+ {
+ Map<String, String[]> properties = requestContext.getProperties();
+ requestPropertyNames = new ArrayList<String>(properties.size());
+ requestProperties = new HashMap<String, String[]>(properties.size());
+ for (Map.Entry<String, String[]> entry : properties.entrySet())
+ {
+ requestPropertyNames.add(entry.getKey());
+ requestProperties.put(entry.getKey().toLowerCase(), entry.getValue());
+ }
+ }
+
+ private void checkInitParameterMap()
+ {
+ if (parameters == null)
+ {
+ parameters = initParameterMap();
+ }
+ }
- protected PortletPreferences portletPreferences;
+ private boolean isPortletModeAllowedByPortlet(PortletMode mode)
+ {
+ if(PortletMode.VIEW.equals(mode))
+ {
+ return true;
+ }
- protected PortletURLProvider urlProvider;
+ PortletDefinition dd = getPortletWindow().getPortletEntity().getPortletDefinition();
- protected Map<String, String[]> parameters = null;
+ for (Supports sup : dd.getSupports())
+ {
+ for (String m : sup.getPortletModes())
+ {
+ if (m.equalsIgnoreCase(mode.toString()))
+ {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
- protected Map<String, String[]> requestProperties = null;
- protected List<String> requestPropertyNames = null;
+ private boolean isPortletModeAllowedByPortal(PortletMode mode)
+ {
+ Enumeration<PortletMode> supportedModes = portalContext.getSupportedPortletModes();
+ while (supportedModes.hasMoreElements())
+ {
+ if (supportedModes.nextElement().toString().equalsIgnoreCase(
+ (mode.toString())))
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ protected static Map<String, String[]> cloneParameterMap(Map<String, String[]> map)
+ {
+ if (!map.isEmpty())
+ {
+ Map<String, String[]> result = new HashMap<String, String[]>(map.size());
+ for (Map.Entry<String,String[]> entry : map.entrySet())
+ {
+ if (entry.getValue() != null)
+ {
+ result.put(entry.getKey(), entry.getValue().clone());
+ }
+ }
+ return Collections.unmodifiableMap(result);
+ }
+ else
+ {
+ return Collections.emptyMap();
+ }
+ }
+
+ protected Map<String, String[]> initParameterMap()
+ {
+ String[] values = null;
+ Map<String, String[]> parameters = requestContext.getPrivateParameterMap();
+ Map<String, String[]> publicParameters = requestContext.getPublicParameterMap();
+ if (!publicParameters.isEmpty())
+ {
+ parameters = new HashMap<String, String[]>(parameters);
+ for (Map.Entry<String,String[]> entry : publicParameters.entrySet())
+ {
+ values = parameters.get(entry.getKey());
+ if (values == null)
+ {
+ parameters.put(entry.getKey(), entry.getValue().clone());
+ }
+ else
+ {
+ String[] copy = new String[values.length+entry.getValue().length];
+ System.arraycopy(values, 0, copy, 0, values.length);
+ System.arraycopy(entry.getValue(), 0, copy, values.length, entry.getValue().length);
+ parameters.put(entry.getKey(), copy);
+ }
+ }
+ }
+ return parameters;
+ }
+
+ protected PortletRequestContext getRequestContext()
+ {
+ return requestContext;
+ }
- protected Cookie[] requestCookies = null;
+ protected InternalPortletContext getPortletContext()
+ {
+ return requestContext.getPortletConfig().getPortletContext();
+ }
+
+ protected PortletWindow getPortletWindow()
+ {
+ return requestContext.getPortletWindow();
+ }
- protected String queryString = null;
+ protected PortletContainer getPortletContainer()
+ {
+ return requestContext.getContainer();
+ }
- // Constructors ------------------------------------------------------------
+ protected HttpServletRequest getServletRequest()
+ {
+ return requestContext.getServletRequest();
+ }
+
+ protected String getMimeRequestProperty(String name, CacheControl cacheControl)
+ {
+ if (MimeResponse.ETAG.equals(name))
+ {
+ return cacheControl.getETag();
+ }
+ else if (MimeResponse.CACHE_SCOPE.equals(name))
+ {
+ return cacheControl.isPublicScope() ? MimeResponse.PUBLIC_SCOPE : MimeResponse.PRIVATE_SCOPE;
+ }
+ else if (MimeResponse.USE_CACHED_CONTENT.equals(name))
+ {
+ return cacheControl.useCachedContent() ? "true" : null;
+ }
+ else if (MimeResponse.EXPIRATION_CACHE.equals(name))
+ {
+ return Integer.toString(cacheControl.getExpirationTime());
+ }
+ return getProperty(name);
+ }
+
+ // PortletRequest Impl -----------------------------------------------------
- public PortletRequestImpl(InternalPortletRequest internalPortletRequest)
+ public Object getAttribute(String name)
{
- this(internalPortletRequest.getPortletContainer(),
- internalPortletRequest.getPortletWindow(),
- internalPortletRequest.getHttpServletRequest());
+ ArgumentUtility.validateNotNull("attributeName", name);
+ if (name.equals(PortletRequest.LIFECYCLE_PHASE))
+ {
+ return lifecyclePhase;
+ }
+ else if (name.equals(PortletRequest.USER_INFO))
+ {
+ if (userInfo == null)
+ {
+ try
+ {
+ userInfo = getPortletContainer().getOptionalContainerServices().getUserInfoService().getUserInfo(this, getPortletWindow());
+ }
+ catch (Exception e)
+ {
+ userInfo = Collections.emptyMap();
+ }
+ }
+ return userInfo;
+ }
+ else if (name.equals(Constants.REQUEST_CONTEXT))
+ {
+ return requestContext;
+ }
+ else if (name.equals(PortletRequest.CCPP_PROFILE))
+ {
+ if (ccppProfile == null)
+ {
+ ccppProfile = getPortletContainer().getRequiredContainerServices().getCCPPProfileService().getCCPPProfile(getServletRequest());
+ }
+ return ccppProfile;
+ }
+ return requestContext.getAttribute(name);
}
- /**
- * Creates a PortletRequestImpl instance.
- * @param container the portlet container.
- * @param portletWindow the internal portlet window.
- * @param servletRequest the underlying servlet request.
- */
- public PortletRequestImpl(PortletContainer container,
- PortletWindow portletWindow,
- HttpServletRequest servletRequest)
- {
- super(servletRequest);
- this.container = container;
- this.portletWindow = portletWindow;
- this.portalContext = container.getRequiredContainerServices().getPortalContext();
- this.servletRequest = servletRequest;
- this.urlProvider = container
- .getRequiredContainerServices()
- .getPortalCallbackService()
- .getPortletURLProvider(getHttpServletRequest(), portletWindow);
+ public Enumeration<String> getAttributeNames()
+ {
+ return requestContext.getAttributeNames();
+ }
+
+ public String getAuthType()
+ {
+ return getServletRequest().getAuthType();
}
- protected abstract Integer getRequestMethod();
+ public String getContextPath()
+ {
+ return getPortletContext().getContextPath();
+ }
- // PortletRequest Impl -----------------------------------------------------
+ public Cookie[] getCookies()
+ {
+ if (requestCookies == null)
+ {
+ requestCookies = requestContext.getCookies();
+ if (requestCookies == null)
+ {
+ requestCookies = new Cookie[0];
+ }
+ }
+ return requestCookies.length > 0 ? requestCookies.clone() : null;
+ }
- /* (non-Javadoc)
- * @see javax.portlet.PortletRequest#getWindowId()
- */
- public String getWindowId()
- {
- return portletWindow.getId().getStringId();
- }
+ public Locale getLocale()
+ {
+ return requestContext.getPreferredLocale();
+ }
- /**
- * Determine whether or not the specified WindowState is allowed for this
- * portlet.
- *
- * @param state the state in question
- * @return true if the state is allowed.
- */
- public boolean isWindowStateAllowed(WindowState state)
+ @SuppressWarnings("unchecked")
+ public Enumeration<Locale> getLocales()
{
- for (Enumeration<WindowState> en = portalContext.getSupportedWindowStates();
- en.hasMoreElements(); )
- {
- if (en.nextElement().toString().equalsIgnoreCase(state.toString()))
+ Locale preferredLocale = getLocale();
+ ArrayList<Locale> locales = new ArrayList<Locale>();
+ locales.add(preferredLocale);
+ for (Enumeration e = getServletRequest().getLocales(); e.hasMoreElements(); )
+ {
+ Locale locale = (Locale)e.nextElement();
+ if (!locale.equals(preferredLocale))
{
- return true;
+ locales.add((Locale)e.nextElement());
}
}
- return false;
+ return Collections.enumeration(locales);
}
- public boolean isPortletModeAllowed(PortletMode mode)
+ public String getParameter(String name)
{
- return (isPortletModeAllowedByPortlet(mode)
- && isPortletModeAllowedByPortal(mode));
+ ArgumentUtility.validateNotNull("parameterName", name);
+ checkInitParameterMap();
+ String[] values = parameters.get(name);
+ return values != null && values.length > 0 ? values[0] : null;
}
- public PortletMode getPortletMode()
+ public Map<String, String[]> getParameterMap()
+ {
+ checkInitParameterMap();
+ return cloneParameterMap(parameters);
+ }
+
+ public Enumeration<String> getParameterNames()
{
- return portletWindow.getPortletMode();
+ checkInitParameterMap();
+ return Collections.enumeration(parameters.keySet());
}
- public WindowState getWindowState()
+ public String[] getParameterValues(String name)
+ {
+ ArgumentUtility.validateNotNull("parameterName", name);
+ checkInitParameterMap();
+ String[] values = parameters.get(name);
+ return values != null ? values.clone() : null;
+ }
+
+ public PortalContext getPortalContext()
{
- return portletWindow.getWindowState();
+ return portalContext;
}
- public PortletSession getPortletSession()
+ public PortletMode getPortletMode()
+ {
+ return getPortletWindow().getPortletMode();
+ }
+
+ public PortletSession getPortletSession()
{
return getPortletSession(true);
}
-
+
/**
* Returns the portlet session.
* <p>
@@ -246,9 +397,9 @@
* by the request instance is also re-created for each incoming request.
* </p>
*/
- public PortletSession getPortletSession(boolean create)
+ public PortletSession getPortletSession(boolean create)
{
- if (LOG.isDebugEnabled())
+ if (LOG.isDebugEnabled())
{
LOG.debug("Retreiving portlet session (create=" + create + ")");
}
@@ -258,7 +409,7 @@
// having a cached version which is invalid for the context within
// which it exists.
//
- if (portletContext == null)
+ if (getPortletContext() == null)
{
throw new IllegalStateException(
EXCEPTIONS.getString("error.session.illegalState"));
@@ -273,25 +424,25 @@
// true) -- We just cannot depend on the implementation of
// javax.servlet.http.HttpSession!
//
- HttpSession httpSession = getHttpServletRequest().getSession(create);
- if (httpSession != null)
+ HttpSession httpSession = getServletRequest().getSession(create);
+ if (httpSession != null)
{
- // HttpSession is not null does NOT mean that it is valid.
+ // HttpSession is not null does NOT mean that it is valid.
int maxInactiveInterval = httpSession.getMaxInactiveInterval();
long lastAccesstime = httpSession.getLastAccessedTime();//lastAccesstime checks added for PLUTO-436
- if (maxInactiveInterval >= 0 && lastAccesstime > 0)
+ if (maxInactiveInterval >= 0 && lastAccesstime > 0)
{ // < 0 => Never expires.
long maxInactiveTime = httpSession.getMaxInactiveInterval() * 1000L;
long currentInactiveTime = System.currentTimeMillis() - lastAccesstime;
- if (currentInactiveTime > maxInactiveTime)
+ if (currentInactiveTime > maxInactiveTime)
{
- if (LOG.isDebugEnabled())
+ if (LOG.isDebugEnabled())
{
LOG.debug("The underlying HttpSession is expired and "
+ "should be invalidated.");
}
httpSession.invalidate();
- httpSession = getHttpServletRequest().getSession(create);
+ httpSession = getServletRequest().getSession(create);
//Added for PLUTO-436
// a cached portletSession is no longer useable.
// a new one will be created below.
@@ -299,12 +450,12 @@
}
}
}
- if (httpSession == null)
+ if (httpSession == null)
{
- if (LOG.isDebugEnabled())
+ if (LOG.isDebugEnabled())
{
LOG.debug("The underlying HttpSession is not available: "
- + "no session will be returned.");
+ + "no session will be returned.");
}
return null;
}
@@ -313,69 +464,92 @@
// available. If we haven't created and cached a portlet session
// instance, we will create and cache one now.
//
- if (portletSession == null)
+ if (portletSession == null)
{
- if (LOG.isDebugEnabled())
- {
- LOG.debug("Creating new portlet session...");
- }
- final OptionalContainerServices optionalContainerServices = container.getOptionalContainerServices();
+ if (LOG.isDebugEnabled())
+ {
+ LOG.debug("Creating new portlet session...");
+ }
+ final OptionalContainerServices optionalContainerServices = getPortletContainer().getOptionalContainerServices();
final PortletEnvironmentService portletEnvironmentService = optionalContainerServices.getPortletEnvironmentService();
-
- portletSession = portletEnvironmentService.createPortletSession(container,
- getHttpServletRequest(),
- portletContext,
- httpSession,
- portletWindow);
- }
+
+ portletSession = portletEnvironmentService.createPortletSession(getPortletContext(), getPortletWindow(), httpSession);
+ }
return portletSession;
}
-
- protected void retrieveRequestProperties()
+
+ public PortletPreferences getPreferences()
{
- PropertyManager propertyManager = container.getRequiredContainerServices().getPortalCallbackService().getPropertyManager();
- Map<String, String[]> properties = propertyManager.getRequestProperties(getHttpServletRequest(), portletWindow);
- requestPropertyNames = new ArrayList<String>(properties.size());
- requestProperties = new HashMap<String, String[]>(properties.size());
- for (Map.Entry<String, String[]> entry : properties.entrySet())
+ if (portletPreferences == null)
{
- requestPropertyNames.add(entry.getKey());
- requestProperties.put(entry.getKey().toLowerCase(), entry.getValue());
+ portletPreferences = new PortletPreferencesImpl(
+ getPortletContainer(),getPortletWindow(),
+ this);
}
+ return portletPreferences;
+ }
+
+ public Map<String, String[]> getPrivateParameterMap()
+ {
+ return cloneParameterMap(requestContext.getPrivateParameterMap());
}
- public String getProperty(String name)
+ @SuppressWarnings("unchecked")
+ public Enumeration<String> getProperties(String name)
{
- ArgumentUtility.validateNotNull("propertyName", name);
- if (requestProperties == null)
- {
- retrieveRequestProperties();
- }
- String property = null;
+ ArgumentUtility.validateNotNull("propertyName", name);
+
+ if(ACCEPT_LANGUAGE.equalsIgnoreCase(name))
+ {
+ Locale preferredLocale = getLocale();
+ ArrayList<String> locales = new ArrayList<String>();
+ locales.add(preferredLocale.toString());
+ for (Enumeration e = getServletRequest().getLocales(); e.hasMoreElements(); )
+ {
+ Locale locale = (Locale)e.nextElement();
+ if (!locale.equals(preferredLocale))
+ {
+ locales.add(e.nextElement().toString());
+ }
+ }
+ return Collections.enumeration(locales);
+ }
+
+ if (requestProperties == null)
+ {
+ retrieveRequestProperties();
+ }
String[] properties = requestProperties.get(name.toLowerCase());
- if (properties != null && properties.length > 0)
+ if (properties == null)
{
- property = properties[0];
+ return Collections.enumeration(EMPTY_STRING_LIST);
}
- return property;
+ return Collections.enumeration(Arrays.asList(properties));
}
- public Enumeration<String> getProperties(String name)
+ public String getProperty(String name)
{
- ArgumentUtility.validateNotNull("propertyName", name);
+ ArgumentUtility.validateNotNull("name", name);
+
+ if(ACCEPT_LANGUAGE.equalsIgnoreCase(name))
+ {
+ return getLocale().toString();
+ }
+
if (requestProperties == null)
{
retrieveRequestProperties();
}
+ String property = null;
String[] properties = requestProperties.get(name.toLowerCase());
- if (properties == null)
+ if (properties != null && properties.length > 0)
{
- return Collections.enumeration(EMPTY_STRING_LIST);
+ property = properties[0];
}
- return Collections.enumeration(Arrays.asList(properties));
+ return property;
}
- public Enumeration<String> getPropertyNames()
+ public Enumeration<String> getPropertyNames()
{
if (requestProperties == null)
{
@@ -384,29 +558,88 @@
return Collections.enumeration(requestPropertyNames);
}
- public PortalContext getPortalContext()
+ public Map<String, String[]> getPublicParameterMap()
+ {
+ return cloneParameterMap(requestContext.getPublicParameterMap());
+ }
+
+ public String getRemoteUser()
+ {
+ return getServletRequest().getRemoteUser();
+ }
+
+ public String getRequestedSessionId()
+ {
+ return getServletRequest().getRequestedSessionId();
+ }
+
+ public String getResponseContentType()
+ {
+ return getResponseContentTypes().nextElement();
+ }
+
+ public Enumeration<String> getResponseContentTypes()
+ {
+ if (contentTypes == null)
+ {
+ contentTypes = new ArrayList<String>();
+ PortletDefinition dd = getPortletWindow().getPortletEntity().getPortletDefinition();
+ for (Supports sup : dd.getSupports())
+ {
+ contentTypes.add(sup.getMimeType());
+ }
+ if (contentTypes.isEmpty())
+ {
+ contentTypes.add("text/html");
+ }
+ }
+ return Collections.enumeration(contentTypes);
+ }
+
+ public String getScheme()
{
- return container.getRequiredContainerServices().getPortalContext();
+ return getServletRequest().getScheme();
}
- public String getAuthType()
+ public String getServerName()
{
- return this.getHttpServletRequest().getAuthType();
+ return getServletRequest().getServerName();
}
- public String getContextPath()
+ public int getServerPort()
+ {
+ return getServletRequest().getServerPort();
+ }
+
+ public Principal getUserPrincipal()
{
- return portletContext.getContextPath();
+ return getServletRequest().getUserPrincipal();
}
- public String getRemoteUser()
+ public String getWindowID()
+ {
+ return getPortletWindow().getId().getStringId();
+ }
+
+ public WindowState getWindowState()
+ {
+ return getPortletWindow().getWindowState();
+ }
+
+ public boolean isPortletModeAllowed(PortletMode mode)
{
- return this.getHttpServletRequest().getRemoteUser();
+ return (isPortletModeAllowedByPortlet(mode)
+ && isPortletModeAllowedByPortal(mode));
}
- public Principal getUserPrincipal()
+ public boolean isRequestedSessionIdValid()
+ {
+ return getServletRequest().isRequestedSessionIdValid();
+ }
+
+ public boolean isSecure()
{
- return this.getHttpServletRequest().getUserPrincipal();
+ return getServletRequest().isSecure();
}
/**
@@ -419,848 +652,55 @@
* @param roleName the name of the role
* @return true if it is determined the user has the given role.
*/
- public boolean isUserInRole(String roleName)
+ public boolean isUserInRole(String roleName)
{
- PortletEntity entity = portletWindow.getPortletEntity();
+ PortletEntity entity = getPortletWindow().getPortletEntity();
PortletDefinition def = entity.getPortletDefinition();
+ String link = roleName;
- SecurityRoleRef ref = null;
- Iterator refs = def.getSecurityRoleRefs().iterator();
- while (refs.hasNext())
+ for (SecurityRoleRef r : def.getSecurityRoleRefs())
{
- SecurityRoleRef r = (SecurityRoleRef) refs.next();
if (r.getRoleName().equals(roleName))
{
- ref = r;
+ if (r.getRoleLink() != null)
+ {
+ link = r.getRoleLink();
+ }
break;
}
}
-
- String link;
- if (ref != null && ref.getRoleLink() != null)
- {
- link = ref.getRoleLink();
- } else
- {
- link = roleName;
- }
- return this.getHttpServletRequest().isUserInRole(link);
+ return getServletRequest().isUserInRole(link);
}
- public Object getAttribute(String name)
+ /**
+ * Determine whether or not the specified WindowState is allowed for this
+ * portlet.
+ *
+ * @param state the state in question
+ * @return true if the state is allowed.
+ */
+ public boolean isWindowStateAllowed(WindowState state)
{
- ArgumentUtility.validateNotNull("attributeName", name);
-
- if (namedRequestDispatcher && (name.startsWith("javax.servlet.forward") || name.startsWith("javax.servlet.include")))
- {
- // PLT.19.3.1
- if (name.equals("javax.servlet.include.request_uri")||name.equals("javax.servlet.include.context_path")||
- name.equals("javax.servlet.include.servlet_path")||name.equals("javax.servlet.include.path_info")||
- name.equals("javax.servlet.include.query_string"))
+ for (Enumeration<WindowState> en = portalContext.getSupportedWindowStates();
+ en.hasMoreElements(); )
+ {
+ if (en.nextElement().toString().equalsIgnoreCase(state.toString()))
{
- return null;
- }
- // PLT.19.4.2, ccxlii
- if (name.equals("javax.servlet.forward.request_uri")||name.equals("javax.servlet.forward.context_path")||
- name.equals("javax.servlet.forward.servlet_path")||name.equals("javax.servlet.forward.path_info")||
- name.equals("javax.servlet.forward.query_string"))
- {
- return null;
- }
- }
-
- final OptionalContainerServices optionalContainerServices = container.getOptionalContainerServices();
- final RequestAttributeService requestAttributeService = optionalContainerServices.getRequestAttributeService();
- return requestAttributeService.getAttribute(this, this.getHttpServletRequest(), this.portletWindow, name);
- }
-
- public Enumeration<String> getAttributeNames()
- {
- final OptionalContainerServices optionalContainerServices = container.getOptionalContainerServices();
- final RequestAttributeService requestAttributeService = optionalContainerServices.getRequestAttributeService();
- return requestAttributeService.getAttributeNames(this, this.getHttpServletRequest(), this.portletWindow);
- }
-
- public String getParameter(String name)
- {
- ArgumentUtility.validateNotNull("parameterName", name);
- String[] values = null;
- if (parameters != null)
- {
- values = parameters.get(name);
- }
- else
- {
- List<String> publicRenderParameterNames = portletWindow.getPortletEntity().getPortletDefinition().getSupportedPublicRenderParameters();
- if (publicRenderParameterNames != null)
- {
- if (publicRenderParameterNames.contains(name))
- values = urlProvider.getPublicRenderParameters(name);
- else
- values = baseGetParameterMap().get(name);
- }
- else
- {
- values = baseGetParameterMap().get(name);
- }
- }
- if (values != null && values.length > 0)
- {
- return values[0];
- }
- else
- {
- return null;
- }
- }
-
- public Enumeration<String> getParameterNames()
- {
- return Collections.enumeration(baseGetParameterMap().keySet());
- }
-
- public String[] getParameterValues(String name)
- {
- ArgumentUtility.validateNotNull("parameterName", name);
- String[] values = null;
- if (parameters != null)
- {
- values = parameters.get(name);
- }
- else
- {
- List<String> publicRenderParameterNames = portletWindow.getPortletEntity().getPortletDefinition().getSupportedPublicRenderParameters();
- if (publicRenderParameterNames != null)
- {
- if (publicRenderParameterNames.contains(name))
- values = urlProvider.getPublicRenderParameters(name);
- else
- values = baseGetParameterMap().get(name);
- }
- else
- {
- values = baseGetParameterMap().get(name);
- }
- }
- if (values != null)
- {
- values = values.clone();
- }
- return values;
- }
-
- public Map<String, String[]> getParameterMap()
- {
- if (parameters != null)
- {
- return parameters;
- }
- else
- {
- String[] values = null;
- Map<String, String[]>map = StringUtils.copyParameters(baseGetParameterMap());
- List<String> publicRenderParameterNames = portletWindow.getPortletEntity().getPortletDefinition().getSupportedPublicRenderParameters();
- if (publicRenderParameterNames!=null)
- {
- for (String string : publicRenderParameterNames)
- {
- values = urlProvider.getPublicRenderParameters(string);
- if (values != null)
- {
- map.put(string, values);
- }
- }
- }
- parameters = Collections.unmodifiableMap(map);
- return parameters;
- }
- }
-
- public boolean isSecure()
- {
- return this.getHttpServletRequest().isSecure();
- }
-
- public void setAttribute(String name, Object value)
- {
- ArgumentUtility.validateNotNull("attributeName", name);
- final OptionalContainerServices optionalContainerServices = container.getOptionalContainerServices();
- final RequestAttributeService requestAttributeService = optionalContainerServices.getRequestAttributeService();
- requestAttributeService.setAttribute(this, this.getHttpServletRequest(), this.portletWindow, name, value);
- }
-
- public void removeAttribute(String name)
- {
- ArgumentUtility.validateNotNull("attributeName", name);
-
- final OptionalContainerServices optionalContainerServices = container.getOptionalContainerServices();
- final RequestAttributeService requestAttributeService = optionalContainerServices.getRequestAttributeService();
- requestAttributeService.removeAttribute(this, this.getHttpServletRequest(), this.portletWindow, name);
- }
-
- public String getRequestedSessionId()
- {
- return this.getHttpServletRequest().getRequestedSessionId();
- }
-
- public boolean isRequestedSessionIdValid()
- {
- if (LOG.isDebugEnabled())
- {
- LOG.debug(" ***** IsRequestedSessionIdValid? "+getHttpServletRequest().isRequestedSessionIdValid());
- }
- return getHttpServletRequest().isRequestedSessionIdValid();
- }
-
- public String getResponseContentType()
- {
- Enumeration<String> enumeration = getResponseContentTypes();
- while (enumeration.hasMoreElements())
- {
- return enumeration.nextElement();
- }
- return "text/html";
- }
-
- public Enumeration<String> getResponseContentTypes()
- {
- if (contentTypes == null)
- {
- contentTypes = new Vector<String>();
- PortletDefinition dd = portletWindow.getPortletEntity().getPortletDefinition();
- Iterator supports = dd.getSupports().iterator();
- while (supports.hasNext())
- {
- Supports sup = (Supports) supports.next();
- contentTypes.add(sup.getMimeType());
- }
- if (contentTypes.size() < 1)
- {
- contentTypes.add("text/html");
- }
- }
- return contentTypes.elements();
- }
-
- public Locale getLocale()
- {
- return this.getHttpServletRequest().getLocale();
- }
-
- @SuppressWarnings("unchecked")
- public Enumeration<Locale> getLocales()
- {
- return this.getHttpServletRequest().getLocales();
- }
-
- public String getScheme()
- {
- return this.getHttpServletRequest().getScheme();
- }
-
- public String getServerName()
- {
- return this.getHttpServletRequest().getServerName();
- }
-
- public int getServerPort()
- {
- return this.getHttpServletRequest().getServerPort();
- }
-
-
- // Protected Methods -------------------------------------------------------
-
- protected void setBodyAccessed()
- {
- bodyAccessed = true;
- }
-
- // InternalPortletRequest Impl ---------------------------------------------
-
- public PortletWindow getPortletWindow()
- {
- return portletWindow;
- }
-
- public PortletContainer getPortletContainer()
- {
- return container;
- }
-
- public HttpServletRequest getHttpServletRequest()
- {
- return (HttpServletRequest) super.getRequest();
- }
-
- public void init(InternalPortletContext portletContext, HttpServletRequest req)
- {
- this.portletContext = portletContext;
- setRequest(req);
- setCCPPProfile();
- setLifecyclePhase();
- }
-
- public PortletPreferences getPreferences()
- {
- if (portletPreferences == null)
- {
- portletPreferences = new PortletPreferencesImpl(
- getPortletContainer(),
- getPortletWindow(),
- this,
- this.getRequestMethod());
- }
- return portletPreferences;
- }
-
- /**
- * TODO: Implement this properly. Not required now
- */
- public void release()
- {
- // FIXME: This needs to be implemented
- }
-
-
- // TODO: Additional Methods of HttpServletRequestWrapper -------------------
-
- public BufferedReader getReader()
- throws UnsupportedEncodingException, IOException
- {
- // the super class will ensure that a IllegalStateException is thrown
- // if getInputStream() was called earlier
- BufferedReader reader = getHttpServletRequest().getReader();
- bodyAccessed = true;
- return reader;
- }
-
- public ServletInputStream getInputStream() throws IOException
- {
- ServletInputStream stream = getHttpServletRequest().getInputStream();
- bodyAccessed = true;
- return stream;
- }
-
- public RequestDispatcher getRequestDispatcher(String path)
- {
- return new ServletRequestDispatcher(getHttpServletRequest().getRequestDispatcher(path));
- }
-
- /**
- * TODO: why check bodyAccessed?
- */
- public void setCharacterEncoding(String encoding)
- throws UnsupportedEncodingException
- {
- if (bodyAccessed)
- {
- throw new IllegalStateException("Cannot set character encoding "
- + "after HTTP body is accessed.");
- }
- super.setCharacterEncoding(encoding);
- }
-
- // Private Methods ---------------------------------------------------------
-
- private boolean isPortletModeAllowedByPortlet(PortletMode mode)
- {
- if(PortletMode.VIEW.equals(mode))
- {
- return true;
- }
-
- PortletDefinition dd = portletWindow.getPortletEntity()
- .getPortletDefinition();
-
- Iterator mimes = dd.getSupports().iterator();
- while (mimes.hasNext())
- {
- Iterator modes = ((Supports) mimes.next()).getPortletModes().iterator();
- while (modes.hasNext())
- {
- String m = (String) modes.next();
- if (m.equalsIgnoreCase(mode.toString()))
- {
- return true;
- }
+ return true;
}
}
return false;
}
-
- private boolean isPortletModeAllowedByPortal(PortletMode mode)
- {
- Enumeration supportedModes = portalContext.getSupportedPortletModes();
- while (supportedModes.hasMoreElements())
- {
- if (supportedModes.nextElement().toString().equalsIgnoreCase(
- (mode.toString())))
- {
- return true;
- }
- }
- return false;
- }
-
-// InternalRenderRequest Impl ----------------------------------------------
-
- public String getMethod()
- {
- return super.getMethod();
- }
-
-
- public boolean isForwarded()
- {
- return forwarded;
- }
-
- public void setForwarded(boolean forwarded)
- {
- this.forwarded = forwarded;
- if (LOG.isDebugEnabled())
- {
- LOG.debug("Portlet request's forwarded mode: " + forwarded);
- }
- }
-
- public void setIncluded(boolean included)
- {
- this.included = included;
-// if (!included)
-// {
-// this.parameters = null;
-// }
- if (LOG.isDebugEnabled())
- {
- LOG.debug("Render request's included mode: " + included);
- }
- }
-
- public boolean isIncluded()
- {
- return included;
- }
-
- /**
- * The base method that returns the parameter map in this portlet request.
- * All parameter-related methods call this base method. Subclasses may just
- * overwrite this protected method to change behavior of all parameter-
- * related methods.
- * @return the base parameter map from which parameters are retrieved.
- */
- protected Map<String, String[]> baseGetParameterMap()
- {
- if (isIncluded())
- {
- setBodyAccessed();
- }
- Map<String, String[]> parameters = urlProvider.getRenderParameters();
- if (parameters == null)
- {
- if (getRequestMethod().equals(Constants.METHOD_RENDER) || getRequestMethod().equals(Constants.METHOD_EVENT))
- {
- parameters = urlProvider.parseRenderParameters(this.getHttpServletRequest().getParameterMap(), queryString);
- queryString = null;
- }
- else
- {
- parameters = urlProvider.parseRenderParameters(this.getHttpServletRequest().getParameterMap(), null);
- }
- }
- return parameters;
- }
-
- public void setForwardedQueryString(String queryString)
- {
- if (!forwarded)
- {
- throw new IllegalStateException(
- "Parameters cannot be appended to "
- + "render request which is not included in a dispatch.");
- }
- this.parameters = null;
- this.queryString = queryString;
-// this.urlProvider.parseRenderParameters(super.getParameterMap(), queryString);
- this.urlProvider.parseRenderParameters(null,null);
- }
-
- public void setIncludedQueryString(String queryString)
- throws IllegalStateException
- {
- if (!included)
- {
- throw new IllegalStateException(
- "Parameters cannot be appended to "
- + "render request which is not included in a dispatch.");
- }
- this.parameters = null;
- this.queryString = queryString;
-// this.urlProvider.parseRenderParameters(super.getParameterMap(), queryString);
- this.urlProvider.parseRenderParameters(null,null);
- }
-
-
- public Map<String, String[]> getPrivateParameterMap()
- {
- return Collections.unmodifiableMap(StringUtils
- .copyParameters(baseGetParameterMap()));
- }
-
- public Map<String, String[]> getPublicParameterMap()
- {
- Map<String, String[]> map = new HashMap<String, String[]>();
- List<String> publicRenderParameterNames = portletWindow
- .getPortletEntity().getPortletDefinition()
- .getSupportedPublicRenderParameters();
- String[] values = null;
- if (publicRenderParameterNames != null)
- {
- for (String string : publicRenderParameterNames)
- {
- values = urlProvider.getPublicRenderParameters(string);
- if (values != null)
- {
- map.put(string, values);
- }
- }
- }
- return Collections.unmodifiableMap(map);
- }
-
- public String getWindowID()
- {
- return portletWindow.getId().getStringId();
- }
-
- private void setLifecyclePhase()
- {
- String lifecyclePhase = getLifecyclePhase();
- this.setAttribute(LIFECYCLE_PHASE, lifecyclePhase);
- }
-
- @Override
- public String getLocalAddr()
- {
- return (isIncluded() || isForwarded()) ? null : super.getLocalAddr();
- }
-
- @Override
- public String getLocalName()
- {
- return (isIncluded() || isForwarded()) ? null : super.getLocalName();
- }
-
- @Override
- public int getLocalPort()
- {
- return (isIncluded() || isForwarded()) ? 0 : super.getLocalPort();
- }
-
- public String getProtocol()
- {
- return (isIncluded() || isForwarded()) ? "HTTP/1.1" : super
- .getProtocol();
- }
-
- @Override
- public String getRealPath(String arg0)
- {
- return (isIncluded() || isForwarded()) ? null : super.getRealPath(arg0);
- }
-
- @Override
- public String getRemoteAddr()
- {
- return (isIncluded() || isForwarded()) ? null : super.getRemoteAddr();
- }
-
- @Override
- public String getRemoteHost()
- {
- return (isIncluded() || isForwarded()) ? null : super.getRemoteHost();
- }
-
- @Override
- public int getRemotePort()
- {
- return (isIncluded() || isForwarded()) ? 0 : super.getRemotePort();
- }
-
- @Override
- public Cookie[] getCookies()
- {
- if (requestCookies == null)
- {
- PropertyManager propertyManager = container.getRequiredContainerServices().getPortalCallbackService().getPropertyManager();
- requestCookies = propertyManager.getRequestCookies(getHttpServletRequest(), portletWindow);
- if (requestCookies == null)
- {
- requestCookies = new Cookie[0];
- }
- }
- return requestCookies.length > 0 ? requestCookies.clone() : null;
- }
-
- @Override
- public long getDateHeader(String arg0)
+
+ public void setAttribute(String name, Object value)
{
- if (isIncluded() || isForwarded())
- {
-
- String value = getHeader(arg0);
- if (value == null) { return (-1L); }
- // Attempt to convert the date header in a variety of formats
- return parseDateHeader(value);
- }
- else
- return super.getDateHeader(arg0);
+ ArgumentUtility.validateNotEmpty("name", name);
+ requestContext.setAttribute(name, value);
}
- @Override
- public String getHeader(String arg0)
+ public void removeAttribute(String name)
{
- if (isIncluded() || isForwarded())
- {
- return getProperty(arg0);
- }
- else
- return super.getHeader(arg0);
+ ArgumentUtility.validateNotEmpty("name", name);
+ requestContext.setAttribute(name, null);
}
-
- @Override
- public Enumeration getHeaderNames()
- {
- if (isIncluded() || isForwarded())
- {
- return getPropertyNames();
- }
- else
- return super.getHeaderNames();
- }
-
- @Override
- public Enumeration getHeaders(String arg0)
- {
- if (isIncluded() || isForwarded())
- {
- return getProperties(arg0);
- }
- else
- return super.getHeaders(arg0);
- }
-
- @Override
- public int getIntHeader(String arg0)
- {
- if (isIncluded() || isForwarded())
- {
- String property = getProperty(arg0);
- if (property == null)
- {
- return -1;
- }
- else
- {
- return Integer.parseInt(property);
- }
- }
- else
- return super.getIntHeader(arg0);
- }
-
- public String getPathInfo()
- {
- if (isIncluded())
- return (String) super
- .getAttribute("javax.servlet.include.path_info");
- else if (isForwarded())
- return (String) super
- .getAttribute("javax.servlet.forward.path_info");
- else
- return super.getPathInfo();
- }
-
- public String getQueryString()
- {
- if (isIncluded())
- return (String) super
- .getAttribute("javax.servlet.include.query_string");
- else if (isForwarded())
- return (String) super
- .getAttribute("javax.servlet.forward.query_string");
- else
- return super.getQueryString();
- }
-
- public String getPathTranslated()
- {
- if (isIncluded() || isForwarded())
- {
- String path = getServletPath() + getPathInfo() + "?"
- + getQueryString();
- return getRealPath(path);
- }
- return super.getPathTranslated();
- }
-
- public String getRequestURI()
- {
- if (isIncluded())
- return (String) super
- .getAttribute("javax.servlet.include.request_uri");
- else if (isForwarded())
- return (String) super
- .getAttribute("javax.servlet.forward.request_uri");
- else
- return super.getRequestURI();
- }
-
- public String getServletPath()
- {
- if (isIncluded())
- return (String) super
- .getAttribute("javax.servlet.include.servlet_path");
- else if (isForwarded())
- return (String) super
- .getAttribute("javax.servlet.forward.servlet_path");
- else
- return super.getServletPath();
- }
-
- public StringBuffer getRequestURL()
- {
- return (isIncluded() || isForwarded()) ? null : super.getRequestURL();
- }
-
- @Override
- public HttpSession getSession()
- {
- if (isIncluded() || isForwarded())
- {
- // ensure cached PortletSession is created (with proper HttpSession
- // invalidation check performed)
- getPortletSession();
- if (portletSession != null)
- {
- return portletSession.getHttpSession();
- }
- else
- {
- return null;
- }
- }
- return super.getSession();
- }
-
- @Override
- public HttpSession getSession(boolean create)
- {
- if (isIncluded() || isForwarded())
- {
- // ensure cached PortletSession is created (with proper HttpSession
- // invalidation check performed)
- getPortletSession(create);
- if (portletSession != null)
- {
- return portletSession.getHttpSession();
- }
- else
- {
- return null;
- }
- }
- return super.getSession();
- }
-
- // ============= private methods ==================
-
- /**
- * Try to parse the given date as a HTTP date. Borrowed and adapted from
- * Tomcat FastHttpDateFormat
- */
- private long parseDateHeader(String value)
- {
- Long dateValue = null;
- try
- {
- dateValue = dateHeaderParseCache.get(value);
- }
- catch (Exception e)
- {
- }
- if (dateValue == null)
- {
- for (int i = 0; i < dateHeaderFormats.length; i++)
- {
- try
- {
- Date date = dateHeaderFormats[i].parse(value);
- dateValue = new Long(date.getTime());
- }
- catch (ParseException e)
- {
- }
- }
- if (dateValue != null)
- {
- synchronized (dateHeaderParseCache)
- {
- if (dateHeaderParseCache.size() > 1000)
- {
- dateHeaderParseCache.clear();
- }
- dateHeaderParseCache.put(value, dateValue);
- }
- }
- else
- {
- throw new IllegalArgumentException(value);
- }
- }
- return dateValue.longValue();
- }
-
- public String getLifecyclePhase()
- {
- return null;
- }
-
- private void setCCPPProfile()
- {
- Profile profile = container.getRequiredContainerServices()
- .getCCPPProfileService().getCCPPProfile(servletRequest);
- this.setAttribute(CCPP_PROFILE, profile);
- }
-
- public void setNamedRequestDispatcher(boolean named)
- {
- namedRequestDispatcher = named;
- }
-}
-
-class ServletRequestDispatcher implements RequestDispatcher
-{
-
- javax.servlet.RequestDispatcher dispatcher;
-
- public ServletRequestDispatcher(javax.servlet.RequestDispatcher dispatcher)
- {
- this.dispatcher = dispatcher;
- }
-
- public void forward(ServletRequest arg0, ServletResponse arg1)
- throws ServletException, IOException
- {
- dispatcher.include(arg0, arg1);
-
- }
-
- public void include(ServletRequest arg0, ServletResponse arg1)
- throws ServletException, IOException
- {
- dispatcher.include(arg0, arg1);
- }
-
}