You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by iv...@apache.org on 2008/10/21 22:12:45 UTC
svn commit: r706750 - in
/wicket/trunk/wicket/src/main/java/org/apache/wicket: ./ protocol/http/
protocol/http/portlet/ request/target/resource/
Author: ivaynberg
Date: Tue Oct 21 13:12:44 2008
New Revision: 706750
URL: http://svn.apache.org/viewvc?rev=706750&view=rev
Log:
partial WICKET-1875
Modified:
wicket/trunk/wicket/src/main/java/org/apache/wicket/RequestContext.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/Resource.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/SharedResources.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/ContextParamWebApplicationFactory.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/WicketServlet.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/EmbeddedPortletHeaderResponse.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/FilterRequestContext.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletActionServletResponseWrapper.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletInvalidMarkupFilter.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletRenderServletResponseWrapper.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletRequestContext.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletServletRequestWrapper.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletServletResponseWrapper.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/WicketFilterPortletContext.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/WicketPortlet.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/WicketResponseState.java
wicket/trunk/wicket/src/main/java/org/apache/wicket/request/target/resource/ISharedResourceRequestTarget.java
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/RequestContext.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/RequestContext.java?rev=706750&r1=706749&r2=706750&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/RequestContext.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/RequestContext.java Tue Oct 21 13:12:44 2008
@@ -17,8 +17,26 @@
package org.apache.wicket;
import org.apache.wicket.markup.html.IHeaderResponse;
+import org.apache.wicket.protocol.http.portlet.PortletRequestContext;
+import org.apache.wicket.request.target.resource.ISharedResourceRequestTarget;
/**
+ * Handles url rewriting, provides access to the namespace for markup Ids and isolated session
+ * state.
+ *
+ * <p>
+ * This is the base strategy for encoding URLs, which is to leave them as is. This is mainly so that
+ * PortletRequestContext can implement it's portlet encoding strategies as portlets need to have
+ * special URLs encoded with portal information and portlet namespace.
+ *
+ * <p>
+ * For url rewriting, only three methods are needed to support creating Portlet ActionURLs, Portlet
+ * RenderURLs and Resource/Ajax URLs.
+ *
+ * FIXME Class name. Perhaps RequestContext isn't a good name, as it's confusing with the 'context'
+ * meanings as there are many, and it doesn't address the abilities of the class to encode URLS.
+ *
+ * @see PortletRequestContext
* @author Ate Douma
*/
public class RequestContext
@@ -48,7 +66,7 @@
}
/**
- *
+ * Resets the {@link RequestContext} for the current threads active request.
*/
public static final void unset()
{
@@ -56,6 +74,7 @@
}
/**
+ * Sets the {@link RequestContext} for the current threads active request.
*
* @param context
*/
@@ -65,7 +84,9 @@
}
/**
- * @return CharSequence
+ * @see PortletRequestContext#getNamespace()
+ * @return CharSequence the namespace of this request, typically overridden by the portlet
+ * implementation.
*/
public CharSequence getNamespace()
{
@@ -73,8 +94,15 @@
}
/**
+ * FIXME javadoc
+ *
+ * <p>
+ * Encodes markup Ids, typically overridden by the portlet implementation.
+ *
+ * @see PortletRequestContext#encodeMarkupId(String)
* @param markupId
- * @return The encoded markup
+ * the markup Id to encode
+ * @return the encoded markup
*/
public String encodeMarkupId(String markupId)
{
@@ -82,8 +110,15 @@
}
/**
+ * FIXME javadoc
+ *
+ * <p>
+ * Encodes URL's for action URLs, typically overridden by the portlet implementation.
+ *
+ * @see PortletRequestContext#encodeActionURL(CharSequence)
* @param path
- * @return The encoded url
+ * the URL to encode
+ * @return the encoded url
*/
public CharSequence encodeActionURL(CharSequence path)
{
@@ -91,8 +126,15 @@
}
/**
+ * FIXME javadoc
+ *
+ * <p>
+ * Encodes URL's for render URLs, typically overridden by the portlet implementation.
+ *
+ * @see PortletRequestContext#encodeRenderURL(CharSequence)
* @param path
- * @return The encoded url
+ * the URL to encode
+ * @return the encoded url
*/
public CharSequence encodeRenderURL(CharSequence path)
{
@@ -100,8 +142,12 @@
}
/**
+ * Encodes URL's for resource targets, typically overridden by the portlet implementation.
+ *
+ * @see PortletRequestContext#encodeResourceURL(CharSequence)
* @param path
- * @return The encoded url
+ * the URL to encode
+ * @return the encoded url
*/
public CharSequence encodeResourceURL(CharSequence path)
{
@@ -109,8 +155,14 @@
}
/**
+ * Encodes URL's for shared resource targets, typically overridden by the portlet
+ * implementation.
+ *
+ * @see ISharedResourceRequestTarget
+ * @see PortletRequestContext#encodeSharedResourceURL(CharSequence)
* @param path
- * @return The encoded url
+ * the URL to encode
+ * @return the encoded url
*/
public CharSequence encodeSharedResourceURL(CharSequence path)
{
@@ -118,6 +170,9 @@
}
/**
+ * Used to override response objects, typically used by the portlet implementation.
+ *
+ * @see PortletRequestContext#getHeaderResponse()
* @return The IHeaderResponse
*/
public IHeaderResponse getHeaderResponse()
@@ -126,7 +181,7 @@
}
/**
- * @return boolean if this is a portlet request
+ * @return boolean true if this is a portlet request
*/
public boolean isPortletRequest()
{
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/Resource.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/Resource.java?rev=706750&r1=706749&r2=706750&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/Resource.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/Resource.java Tue Oct 21 13:12:44 2008
@@ -48,6 +48,7 @@
* ImageButton components in this example are like all other components in Wicket and cannot be
* shared.
*
+ * @see SharedResources
* @author Jonathan Locke
* @author Johan Compagner
* @author Gili Tzabari
@@ -148,7 +149,7 @@
* @param parameters
* Map of query parameters that parameterize this resource
*/
- public final void setParameters(final Map< ? , ? > parameters)
+ public final void setParameters(final Map<?, ?> parameters)
{
if (parameters == null)
{
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/SharedResources.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/SharedResources.java?rev=706750&r1=706749&r2=706750&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/SharedResources.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/SharedResources.java Tue Oct 21 13:12:44 2008
@@ -32,6 +32,13 @@
* Class which holds shared resources. Resources can be shared by name. An optional scope can be
* given to prevent naming conflicts and a locale and/or style can be given as well.
*
+ * <p>
+ * Unlike component hosted resources, shared resources have stable URLs, which makes them suitable
+ * for indexing by web crawlers and caching by web browsers. As they are also not synchronised on
+ * the {@link Session}, they can be loaded asynchronously, which is important with images and
+ * resources such as JavaScript and CSS.
+ *
+ * @see Resource
* @author Jonathan Locke
* @author Johan Compagner
* @author Gili Tzabari
@@ -42,8 +49,10 @@
private static final Logger log = LoggerFactory.getLogger(SharedResources.class);
/**
- * THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT CALL IT. Inserts _[locale] and
- * _[style] into path just before any extension that might exist.
+ * THIS METHOD IS NOT PART OF THE WICKET PUBLIC API. DO NOT CALL IT.
+ *
+ * <p>
+ * Inserts _[locale] and _[style] into path just before any extension that might exist.
*
* @param path
* The resource path
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/ContextParamWebApplicationFactory.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/ContextParamWebApplicationFactory.java?rev=706750&r1=706749&r2=706750&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/ContextParamWebApplicationFactory.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/ContextParamWebApplicationFactory.java Tue Oct 21 13:12:44 2008
@@ -31,7 +31,7 @@
*/
public static final String APP_CLASS_PARAM = "applicationClassName";
- /** @see IWebApplicationFactory#createApplication(WicketFilter) */
+ /* @see IWebApplicationFactory#createApplication(WicketFilter) */
public WebApplication createApplication(WicketFilter filter)
{
final String applicationClassName = filter.getFilterConfig().getInitParameter(
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java?rev=706750&r1=706749&r2=706750&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java Tue Oct 21 13:12:44 2008
@@ -25,6 +25,7 @@
import java.util.Properties;
import java.util.Set;
+import javax.portlet.Portlet;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
@@ -44,6 +45,8 @@
import org.apache.wicket.markup.parser.XmlPullParser;
import org.apache.wicket.markup.parser.XmlTag;
import org.apache.wicket.protocol.http.portlet.FilterRequestContext;
+import org.apache.wicket.protocol.http.portlet.PortletServletRequestWrapper;
+import org.apache.wicket.protocol.http.portlet.PortletServletResponseWrapper;
import org.apache.wicket.protocol.http.portlet.WicketFilterPortletContext;
import org.apache.wicket.protocol.http.request.WebRequestCodingStrategy;
import org.apache.wicket.session.ISessionStore;
@@ -56,10 +59,19 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-
/**
* Filter for initiating handling of Wicket requests.
*
+ * <p>
+ * For 1.3 and onward, what we do is instead of using a servlet, use a filter.
+ *
+ * <p>
+ * The advantage of a filter is that, unlike a servlet, it can choose not to process the request and
+ * let whatever is next in chain try. So when using a Wicket filter and a request comes in for
+ * foo.gif the filter can choose not to process it because it knows it is not a wicket-related
+ * request. Since the filter didn't process it, it falls on to the application server to try, and
+ * then it works."
+ *
* @see WicketServlet for documentation
*
* @author Jonathan Locke
@@ -139,13 +151,13 @@
*/
private static final String WICKET_PORTLET_PROPERTIES = "org/apache/wicket/protocol/http/portlet/WicketPortlet.properties";
- /*
+ /**
* Delegate for handling Portlet specific filtering. Not instantiated if not running in a
* portlet container context
*/
private WicketFilterPortletContext filterPortletContext;
- /*
+ /**
* Flag if this filter may only process request from within a Portlet context.
*/
private boolean portletOnlyFilter;
@@ -166,6 +178,36 @@
}
/**
+ * As per {@link javax.servlet.Filter#doFilter}, is called by the container each time a
+ * request/response pair is passed through the chain due to a client request for a resource at
+ * the end of the chain. The FilterChain passed in to this method allows the Filter to pass on
+ * the request and response to the next entity in the chain.
+ *
+ * <p>
+ * Delegates to {@link WicketFilter#doGet} for actual response rendering.
+ *
+ * <p>
+ * {@link WicketFilter#doFilter} goes through a series of steps of steps to process a request;
+ * <ol>
+ * <li>If running in a portlet context, sets up the {@link WicketFilterPortletContext}
+ * retrieving the portlet specific ({@link PortletServletRequestWrapper} and
+ * {@link PortletServletResponseWrapper}) wrapped request and response objects.
+ * <li>Otherwise retrieves standard {@link HttpServletRequest} and {@link HttpServletResponse}
+ * objects.
+ * <li>Passes on requests down the filter chain if configured as a portlet _only_ filter but not
+ * running in a portlet context. USE CASE IS WHAT?
+ * <li>Checks against registered ignore paths, and passes the request on down the chain if a
+ * match is found.
+ * <li>Pass the request to underling servlet style
+ * {@link WicketFilter#doGet(HttpServletRequest, HttpServletResponse)} to attempt actually
+ * rendering the response Wicket style.
+ * <li>Potentially respond with "not-modified" for resource type requests
+ * <li>Finally pass on the request if we didn't handle it
+ * </ol>
+ *
+ * @see WicketFilterPortletContext
+ * @see PortletServletRequestWrapper
+ * @see PortletServletResponseWrapper
* @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest,
* javax.servlet.ServletResponse, javax.servlet.FilterChain)
*/
@@ -180,8 +222,11 @@
{
FilterRequestContext filterRequestContext = new FilterRequestContext(
(HttpServletRequest)request, (HttpServletResponse)response);
+
+ // FIXME comment
inPortletContext = filterPortletContext.setupFilter(getFilterConfig(),
filterRequestContext, getFilterPath((HttpServletRequest)request));
+
httpServletRequest = filterRequestContext.getRequest();
httpServletResponse = filterRequestContext.getResponse();
}
@@ -191,7 +236,11 @@
httpServletResponse = (HttpServletResponse)response;
}
- if (portletOnlyFilter && !inPortletContext)
+ // If we are a filter which is only meant to process requests in a portlet context, and we
+ // are in fact not in a portlet context, stop processing now and pass to next filter in the
+ // chain.
+ boolean passToNextFilter = portletOnlyFilter && !inPortletContext;
+ if (passToNextFilter)
{
chain.doFilter(request, response);
return;
@@ -284,8 +333,15 @@
}
/**
- * Handles servlet page requests.
+ * Handles servlet page requests, delegating to the wicket {@link RequestCycle} system.
+ *
+ * <ol>
+ * <li>Checks for the an effective home page request and redirects appropriately.
+ * <li>Check for REDIRECT_TO_BUFFER case and redirect to a buffered response if one exists.
+ * <li>Otherwise begins the {@link RequestCycle} processing.
+ * </ol>
*
+ * @see RequestCycle
* @param servletRequest
* Servlet request object
* @param servletResponse
@@ -433,6 +489,13 @@
return true;
}
+ /**
+ * Ensures the {@link HttpServletRequest} has the correct character encoding set. Tries to
+ * intelligently handle the situation where the character encoding information is missing from
+ * the request.
+ *
+ * @param servletRequest
+ */
private void checkCharacterEncoding(final HttpServletRequest servletRequest)
{
// If the request does not provide information about the encoding of
@@ -482,7 +545,8 @@
}
/**
- * Returns a relative path from an HttpServletRequest Use this to resolve a Wicket request.
+ * Returns a relative path to the filter path and context root from an HttpServletRequest - use
+ * this to resolve a Wicket request.
*
* @param request
* @return Path requested, minus query string, context path, and filterPath. Relative, no
@@ -525,6 +589,22 @@
}
/**
+ * As per {@link javax.servlet.Filter#init(FilterConfig)}, is called by the web container to
+ * indicate to a filter that it is being placed into service.
+ *
+ * {@link WicketFilter#init(FilterConfig)} goes through a series of steps of steps to
+ * initialise;
+ * <ol>
+ * <li>Sets up ignore paths
+ * <li>Records class loaders
+ * <li>Finds the filter's path - {@link WicketFilter#filterPath}
+ * <li>Sets up the {@link IWebApplicationFactory} and {@link WebApplication} for this filter,
+ * including it's initialisation.
+ * <li>Initialise {@link WebApplication} request listeners.
+ * <li>Log start of Application
+ * <li>Detect if running in a {@link Portlet} context and if so intialise the
+ * {@link WicketFilterPortletContext}
+ * </ol>
*
* @see javax.servlet.Filter#init(javax.servlet.FilterConfig)
*/
@@ -615,10 +695,12 @@
portletOnlyFilter = Boolean.valueOf(filterConfig.getInitParameter(PORTLET_ONLY_FILTER))
.booleanValue();
+ // sets up Portlet context if this application is deployed as a portlet
if (isPortletContextAvailable(filterConfig))
{
filterPortletContext = newWicketFilterPortletContext();
}
+ // if WicketFilterPortletContext instantiation succeeded, initialise it
if (filterPortletContext != null)
{
filterPortletContext.initFilter(filterConfig, webApplication);
@@ -656,10 +738,23 @@
}
}
+ /**
+ * Tries to find if a PortletContext is available. Searches for the 'detect portlet context'
+ * flag in various places and if true, tries to load the {@link javax.portlet.PortletContext}.
+ *
+ * @param config
+ * the FilterConfig object
+ * @return true if {@link javax.portlet.PortletContext} was successfully loaded
+ * @throws ServletException
+ * on IO errors
+ */
protected boolean isPortletContextAvailable(FilterConfig config) throws ServletException
{
boolean detectPortletContext = false;
+
+ // search for portlet detection boolean in various places
String parameter = config.getInitParameter(DETECT_PORTLET_CONTEXT);
+ // search filter parameter
if (parameter != null)
{
detectPortletContext = Boolean.valueOf(parameter).booleanValue();
@@ -668,6 +763,7 @@
{
parameter = config.getServletContext().getInitParameter(
DETECT_PORTLET_CONTEXT_FULL_NAME);
+ // search web.xml context paramter
if (parameter != null)
{
detectPortletContext = Boolean.valueOf(parameter).booleanValue();
@@ -677,6 +773,7 @@
InputStream is = Thread.currentThread()
.getContextClassLoader()
.getResourceAsStream(WICKET_PORTLET_PROPERTIES);
+ // search wicket.properties
if (is != null)
{
try
@@ -697,6 +794,7 @@
}
if (detectPortletContext)
{
+ // load the portlet context
try
{
Class<?> portletClass = Class.forName("javax.portlet.PortletContext");
@@ -985,7 +1083,7 @@
}
/**
- * Gets the last modified time stamp for the given request.
+ * Gets the last modified time stamp for the given request if the request is for a resource.
*
* @param servletRequest
* @return The last modified time stamp
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/WicketServlet.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/WicketServlet.java?rev=706750&r1=706749&r2=706750&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/WicketServlet.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/WicketServlet.java Tue Oct 21 13:12:44 2008
@@ -36,6 +36,7 @@
*
* Please use {@link WicketFilter} if you require advanced chaining of resources.
*
+ * <p>
* Servlet class for all wicket applications. The specific application class to instantiate should
* be specified to the application server via an init-params argument named "applicationClassName"
* in the servlet declaration, which is typically in a <i>web.xml </i> file. The servlet declaration
@@ -56,7 +57,8 @@
* Note that the applicationClassName parameter you specify must be the fully qualified name of a
* class that extends WebApplication. If your class cannot be found, does not extend WebApplication
* or cannot be instantiated, a runtime exception of type WicketRuntimeException will be thrown.
- * </p> As an alternative, you can configure an application factory instead. This looks like:
+ * </p>
+ * As an alternative, you can configure an application factory instead. This looks like:
*
* <pre>
* <init-param>
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/EmbeddedPortletHeaderResponse.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/EmbeddedPortletHeaderResponse.java?rev=706750&r1=706749&r2=706750&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/EmbeddedPortletHeaderResponse.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/EmbeddedPortletHeaderResponse.java Tue Oct 21 13:12:44 2008
@@ -25,12 +25,15 @@
import org.apache.wicket.response.StringResponse;
/**
+ * Portlet behaviour override of the {@link HeaderResponse} implementation, responsible for writing
+ * header contributions from portlets in the body of the response, as opposed to the head.
+ *
* @author Ate Douma
*/
public class EmbeddedPortletHeaderResponse extends HeaderResponse
{
- private Response realResponse;
- private StringResponse bufferedResponse;
+ private final Response realResponse;
+ private final StringResponse bufferedResponse;
public EmbeddedPortletHeaderResponse(Response realResponse)
{
@@ -38,6 +41,7 @@
bufferedResponse = new StringResponse();
}
+ @Override
public void renderCSSReference(String url, String media)
{
if (!isClosed())
@@ -54,8 +58,7 @@
{
getResponse().write("elem.setAttribute(\"media\",\"" + media + "\");");
}
- getResponse()
- .write("document.getElementsByTagName(\"head\")[0].appendChild(elem);");
+ getResponse().write("document.getElementsByTagName(\"head\")[0].appendChild(elem);");
getResponse().println("</script>");
markRendered(token);
}
@@ -63,9 +66,10 @@
}
- /**
+ /*
* @see org.apache.wicket.markup.html.internal.HeaderResponse#close()
*/
+ @Override
public void close()
{
super.close();
@@ -101,16 +105,17 @@
if (output.length() > 0)
{
realResponse.write("<span id=\"" + RequestContext.get().getNamespace() +
- "_embedded_head\" style=\"display:none\">");
+ "_embedded_head\" style=\"display:none\">");
realResponse.write(output);
realResponse.write("</span>");
}
bufferedResponse.reset();
}
- /**
+ /*
* @see org.apache.wicket.markup.html.internal.HeaderResponse#getRealResponse()
*/
+ @Override
protected Response getRealResponse()
{
return bufferedResponse;
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/FilterRequestContext.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/FilterRequestContext.java?rev=706750&r1=706749&r2=706750&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/FilterRequestContext.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/FilterRequestContext.java Tue Oct 21 13:12:44 2008
@@ -19,6 +19,14 @@
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.apache.wicket.protocol.http.WicketFilter;
+
+/**
+ * Wraps the HttpServletRequest and HttpServletResponse objects for convenience during
+ * {@link WicketFilterPortletContext} and {@link WicketFilter}'s processing.
+ *
+ * @author Ate Douma
+ */
public final class FilterRequestContext
{
private HttpServletRequest request;
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletActionServletResponseWrapper.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletActionServletResponseWrapper.java?rev=706750&r1=706749&r2=706750&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletActionServletResponseWrapper.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletActionServletResponseWrapper.java Tue Oct 21 13:12:44 2008
@@ -25,75 +25,99 @@
import javax.servlet.http.HttpServletResponse;
/**
+ * <p>
+ * Portlet Action specific response wrapper.
+ *
+ * <p>
+ * Overrides many of the {@link PortletServletResponseWrapper} with no-op methods as they are not
+ * applicable in Action response situations because a response is not actually going to be sent to
+ * the client - the response actually sent to the client is wrapped in
+ * {@link PortletRenderServletResponseWrapper}.
+ *
+ * @see PortletServletResponseWrapper
* @author Ate Douma
*/
public class PortletActionServletResponseWrapper extends PortletServletResponseWrapper
{
public PortletActionServletResponseWrapper(HttpServletResponse response,
- WicketResponseState responseState)
+ WicketResponseState responseState)
{
super(response, responseState);
}
+ @Override
public void addCookie(Cookie cookie)
{
}
+ @Override
public void addDateHeader(String s, long l)
{
}
+ @Override
public void addHeader(String s, String s1)
{
}
+ @Override
public void addIntHeader(String s, int i)
{
}
+ @Override
public String encodeUrl(String s)
{
return s;
}
+ @Override
public String encodeURL(String s)
{
return s;
}
+ @Override
public void flushBuffer() throws IOException
{
}
+ @Override
public int getBufferSize()
{
return 0;
}
+ @Override
public ServletOutputStream getOutputStream() throws IOException
{
return null;
}
+ @Override
public PrintWriter getWriter() throws IOException
{
return null;
}
+ @Override
public boolean isCommitted()
{
return false;
}
+ @Override
public void reset()
{
}
+ @Override
public void resetBuffer()
{
}
+ @Override
public void setBufferSize(int i)
{
}
@@ -102,26 +126,32 @@
{
}
+ @Override
public void setContentLength(int i)
{
}
+ @Override
public void setContentType(String s)
{
}
+ @Override
public void setDateHeader(String s, long l)
{
}
+ @Override
public void setHeader(String s, String s1)
{
}
+ @Override
public void setIntHeader(String s, int i)
{
}
+ @Override
public void setLocale(Locale locale)
{
}
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletInvalidMarkupFilter.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletInvalidMarkupFilter.java?rev=706750&r1=706749&r2=706750&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletInvalidMarkupFilter.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletInvalidMarkupFilter.java Tue Oct 21 13:12:44 2008
@@ -48,6 +48,16 @@
return responseBuffer;
}
+ /**
+ * Removes entire html fragments from the response buffer (inclusive of fragment body).
+ *
+ * @param responseBuffer
+ * the buffer to delete from
+ * @param prefix
+ * the beginning string to delete
+ * @param postfix
+ * the end string to delete
+ */
private void deleteFragment(AppendingStringBuffer responseBuffer, String prefix, String postfix)
{
int startIndex, endIndex;
@@ -60,6 +70,14 @@
}
}
+ /**
+ * Finds and removes the opening and closing tag, if it exists, from the responseBuffer.
+ *
+ * @param responseBuffer
+ * the buffer to search
+ * @param tagName
+ * the tag to delete
+ */
private void deleteOpenTag(AppendingStringBuffer responseBuffer, String tagName)
{
int startIndex, endIndex;
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletRenderServletResponseWrapper.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletRenderServletResponseWrapper.java?rev=706750&r1=706749&r2=706750&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletRenderServletResponseWrapper.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletRenderServletResponseWrapper.java Tue Oct 21 13:12:44 2008
@@ -20,10 +20,19 @@
import javax.portlet.RenderResponse;
import javax.servlet.http.HttpServletResponse;
+import javax.servlet.http.HttpServletResponseWrapper;
import org.apache.wicket.RequestContext;
/**
+ * FIXME javadoc - can be more specific? Doesn't seem to do much except for sendRedirect()
+ *
+ * <p>
+ * Wraps the PortletServletResponseWrapper object with Render request specifics - mainly used to
+ * override the {@link PortletServletResponseWrapper} (see {@link HttpServletResponseWrapper}) when
+ * serving render responses.
+ *
+ * @see HttpServletResponseWrapper
* @author Ate Douma
*/
public class PortletRenderServletResponseWrapper extends PortletServletResponseWrapper
@@ -31,7 +40,7 @@
RenderResponse renderResponse;
public PortletRenderServletResponseWrapper(HttpServletResponse response,
- RenderResponse renderResponse, WicketResponseState responseState)
+ RenderResponse renderResponse, WicketResponseState responseState)
{
super(response, responseState);
this.renderResponse = renderResponse;
@@ -40,11 +49,18 @@
/**
* @see javax.servlet.ServletResponseWrapper#setContentType(java.lang.String)
*/
+ @Override
public void setContentType(String arg0)
{
renderResponse.setContentType(arg0);
}
+ /**
+ * FIXME javadoc - implementation requires explanation
+ *
+ * @see org.apache.wicket.protocol.http.portlet.PortletServletResponseWrapper#sendRedirect(java.lang.String)
+ */
+ @Override
public void sendRedirect(String redirectLocation) throws IOException
{
RequestContext rc = RequestContext.get();
@@ -58,7 +74,7 @@
else
{
String contextPath = ((PortletRequestContext)rc).getPortletRequest()
- .getContextPath();
+ .getContextPath();
if (redirectLocation.startsWith(contextPath + "/"))
{
redirectLocation = redirectLocation.substring(contextPath.length());
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletRequestContext.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletRequestContext.java?rev=706750&r1=706749&r2=706750&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletRequestContext.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletRequestContext.java Tue Oct 21 13:12:44 2008
@@ -38,6 +38,17 @@
import org.apache.wicket.protocol.http.servlet.ServletWebRequest;
/**
+ * FIXME javadoc
+ *
+ * <p>
+ * Porlet strategy for url rewriting, and providing access to the portlet namespace for markup Ids
+ * and isolated session state. Portlets need to have their URLs encoded with special portal
+ * information, namespace etc.
+ *
+ * <p>
+ * For url rewriting, only three methods are needed to support creating Portlet ActionURLs, Portlet
+ * RenderURLs and Resource/Ajax URLs.
+ *
* @author Ate Douma
*/
public class PortletRequestContext extends RequestContext
@@ -46,39 +57,59 @@
private final PortletConfig portletConfig;
private final PortletRequest portletRequest;
private final PortletResponse portletResponse;
- // needed for JSR-168 support which only allows PortletURLs to be created by RenderResponse,
- // with JSR-286 PortletResponse can do that too
+ /**
+ * Needed for JSR-168 support which only allows PortletURLs to be created by RenderResponse with
+ * JSR-286 PortletResponse can do that too.
+ */
private final RenderResponse renderResponse;
+ /**
+ * URL factory for JSR-168 support.
+ */
private final PortletResourceURLFactory resourceURLFactory;
private final IHeaderResponse headerResponse;
+ /**
+ * The porlet's window id.
+ */
private String portletWindowId;
- private String wicketUrlPortletParameter;
+ /**
+ * Parameter name by which to store the parameter name to store the original Wicket URL.
+ */
+ private final String wicketUrlPortletParameter;
+ /**
+ * Is this an Ajax request?
+ */
private final boolean ajax;
+ /**
+ * Is this an embedded request?
+ */
private final boolean embedded;
+ /**
+ * Is this a resource request?
+ */
private final boolean resourceRequest;
- private String[] lastEncodedUrl = new String[2];
+ /**
+ * Stores the last Wicket URL encoding as a key value pair.
+ *
+ * @see #saveLastEncodedUrl(String, String)
+ */
+ private final String[] lastEncodedUrl = new String[2];
public PortletRequestContext(WicketFilterPortletContext filterContext,
- ServletWebRequest request, WebResponse response)
+ ServletWebRequest request, WebResponse response)
{
this.filterContext = filterContext;
HttpServletRequest servletRequest = request.getHttpServletRequest();
- this.portletConfig = (PortletConfig)servletRequest.getAttribute("javax.portlet.config");
- this.portletRequest = (PortletRequest)servletRequest.getAttribute("javax.portlet.request");
- this.portletResponse = (PortletResponse)servletRequest
- .getAttribute("javax.portlet.response");
- this.renderResponse = (portletResponse instanceof RenderResponse)
- ? (RenderResponse)portletResponse
- : null;
- this.resourceURLFactory = (PortletResourceURLFactory)portletRequest
- .getAttribute(WicketPortlet.RESOURCE_URL_FACTORY_ATTR);
- this.wicketUrlPortletParameter = (String)portletRequest
- .getAttribute(WicketPortlet.WICKET_URL_PORTLET_PARAMETER_ATTR);
- this.ajax = request.isAjax();
- this.resourceRequest = "true".equals(servletRequest
- .getAttribute(WicketPortlet.PORTLET_RESOURCE_URL_ATTR));
- this.embedded = !(ajax || resourceRequest);
- this.headerResponse = embedded ? newPortletHeaderResponse(response) : null;
+ portletConfig = (PortletConfig)servletRequest.getAttribute("javax.portlet.config");
+ portletRequest = (PortletRequest)servletRequest.getAttribute("javax.portlet.request");
+ portletResponse = (PortletResponse)servletRequest.getAttribute("javax.portlet.response");
+ renderResponse = (portletResponse instanceof RenderResponse)
+ ? (RenderResponse)portletResponse : null;
+ resourceURLFactory = (PortletResourceURLFactory)portletRequest.getAttribute(WicketPortlet.RESOURCE_URL_FACTORY_ATTR);
+ wicketUrlPortletParameter = (String)portletRequest.getAttribute(WicketPortlet.WICKET_URL_PORTLET_PARAMETER_ATTR);
+ ajax = request.isAjax();
+ resourceRequest = "true".equals(servletRequest.getAttribute(WicketPortlet.PORTLET_RESOURCE_URL_ATTR));
+ embedded = !(ajax || resourceRequest);
+ headerResponse = embedded ? newPortletHeaderResponse(response) : null;
}
protected IHeaderResponse newPortletHeaderResponse(Response response)
@@ -86,6 +117,14 @@
return new EmbeddedPortletHeaderResponse(response);
}
+
+ /**
+ * Used to retrieve the path last encoded as a portlet URL, used for internal Wicket processing
+ * when internal methods require a target URL e.g.
+ * {@link org.apache.wicket.markup.html.form.Form#getJsForInterfaceUrl(CharSequence)}.
+ *
+ * @return the original Wicket URL
+ */
public String getLastEncodedPath()
{
if (lastEncodedUrl != null)
@@ -95,6 +134,12 @@
return null;
}
+ /**
+ * @see #getLastEncodedPath()
+ * @param url
+ * the portal encoded URL
+ * @return the original Wicket URL
+ */
public String getLastEncodedPath(String url)
{
if (url != null && lastEncodedUrl != null && url.equals(lastEncodedUrl[0]))
@@ -104,6 +149,17 @@
return null;
}
+ /**
+ * Saves the key/value pairs so the original Wicket URL can be retrieved later if needed by
+ * Wicket, keyed by the encoded portal URL.
+ *
+ * @see #getLastEncodedPath()
+ * @param url
+ * the portal encoded URL
+ * @param path
+ * the original Wicket URL
+ * @return
+ */
protected String saveLastEncodedUrl(String url, String path)
{
lastEncodedUrl[0] = url;
@@ -112,13 +168,37 @@
}
/**
+ * FIXME javadoc
+ *
+ * <p>
+ * Delegates to {@link #encodeActionURL(CharSequence, boolean)}, passing in forceRenderURL as
+ * false - FIXME why?
+ *
+ * @param path
+ * the URL to encode
* @see org.apache.wicket.RequestContext#encodeActionURL(java.lang.CharSequence)
+ * @see #encodeActionURL(CharSequence, boolean)
*/
+ @Override
public CharSequence encodeActionURL(CharSequence path)
{
return encodeActionURL(path, false);
}
+ /**
+ * FIXME javadoc
+ *
+ * <p>
+ * Encodes the given path into a portlet URL, saving the original URL against the
+ * {@link PortletURL} and in the class {@link #saveLastEncodedUrl(String, String)}.
+ *
+ * @see #saveLastEncodedUrl(String, String)
+ * @param path
+ * the path to encode
+ * @param forceRenderURL
+ * FIXME param
+ * @return
+ */
public CharSequence encodeActionURL(CharSequence path, boolean forceActionURL)
{
if ((!forceActionURL && resourceRequest) || RequestCycle.get().isUrlForNewWindowEncoding())
@@ -140,7 +220,9 @@
/**
* @see org.apache.wicket.RequestContext#encodeMarkupId(java.lang.String)
+ * @return the markupId prefixed with the portlet's namespace.
*/
+ @Override
public String encodeMarkupId(String markupId)
{
if (markupId != null)
@@ -151,13 +233,37 @@
}
/**
+ * FIXME javadoc
+ *
+ * <p>
+ * Delegates to {@link #encodeRenderURL(CharSequence, boolean)}, passing in forceRenderURL as
+ * false - FIXME why?
+ *
+ * @param path
+ * the URL to encode
* @see org.apache.wicket.RequestContext#encodeRenderURL(java.lang.CharSequence)
+ * @see #encodeActionURL(CharSequence, boolean)
*/
+ @Override
public CharSequence encodeRenderURL(CharSequence path)
{
return encodeRenderURL(path, false);
}
+ /**
+ * FIXME javadoc
+ *
+ * <p>
+ * Encodes the given path into a portlet URL, saving the original URL against the
+ * {@link PortletURL} and in the class {@link #saveLastEncodedUrl(String, String)}.
+ *
+ * @see #saveLastEncodedUrl(String, String)
+ * @param path
+ * the path to encode
+ * @param forceRenderURL
+ * FIXME param
+ * @return
+ */
public CharSequence encodeRenderURL(CharSequence path, boolean forceRenderURL)
{
if ((!forceRenderURL && resourceRequest) || RequestCycle.get().isUrlForNewWindowEncoding())
@@ -171,7 +277,7 @@
{
PortletURL url = renderResponse.createRenderURL();
url.setParameter(wicketUrlPortletParameter +
- portletRequest.getPortletMode().toString(), path.toString());
+ portletRequest.getPortletMode().toString(), path.toString());
path = saveLastEncodedUrl(url.toString(), path.toString());
}
}
@@ -179,8 +285,12 @@
}
/**
+ * Override to encode the path to the resource with the portal specific URL (e.g. adds portlet
+ * window id etc...) and includes the actual Wicket URL as a URL parameter.
+ *
* @see org.apache.wicket.RequestContext#encodeResourceURL(java.lang.CharSequence)
*/
+ @Override
public CharSequence encodeResourceURL(CharSequence path)
{
if (path != null)
@@ -192,13 +302,12 @@
{
HashMap parameters = new HashMap(2);
parameters.put(wicketUrlPortletParameter +
- portletRequest.getPortletMode().toString(), new String[] { path
- .toString() });
+ portletRequest.getPortletMode().toString(),
+ new String[] { path.toString() });
parameters.put(WicketPortlet.PORTLET_RESOURCE_URL_PARAMETER,
- new String[] { "true" });
+ new String[] { "true" });
path = saveLastEncodedUrl(resourceURLFactory.createResourceURL(portletConfig,
- (RenderRequest)portletRequest, renderResponse, parameters), path
- .toString());
+ (RenderRequest)portletRequest, renderResponse, parameters), path.toString());
}
catch (PortletException e)
{
@@ -210,8 +319,13 @@
}
/**
+ * Override to encode the path to the resource with the portal specific url (e.g. adds portlet
+ * window id etc...).
+ *
+ * @see WicketFilterPortletContext#encodeWindowIdInPath(String, CharSequence)
* @see org.apache.wicket.RequestContext#encodeSharedResourceURL(java.lang.CharSequence)
*/
+ @Override
public CharSequence encodeSharedResourceURL(CharSequence path)
{
if (path != null)
@@ -223,16 +337,27 @@
}
/**
+ * Override to return the special {@link EmbeddedPortletHeaderResponse}.
+ *
+ * @see EmbeddedPortletHeaderResponse
+ * @see #newPortletHeaderResponse(Response)
* @see org.apache.wicket.RequestContext#getHeaderResponse()
*/
+ @Override
public IHeaderResponse getHeaderResponse()
{
return headerResponse;
}
/**
+ * Should be prefixed or appended to elements, such as JavaScript variables or function names,
+ * to ensure they are unique in the context of the portal page.
+ *
+ * @see javax.portlet.PortletResponse#getNamespace
* @see org.apache.wicket.RequestContext#getNamespace()
+ * @return the portlet's namespace, typically the portlet window id.
*/
+ @Override
public CharSequence getNamespace()
{
return renderResponse != null ? renderResponse.getNamespace() : "";
@@ -241,48 +366,74 @@
/**
* @see org.apache.wicket.RequestContext#isPortletRequest()
*/
+ @Override
public boolean isPortletRequest()
{
return true;
}
+ /**
+ * @return true if this is an embedded request.
+ */
public boolean isEmbedded()
{
return embedded;
}
+ /**
+ * @param path
+ * the relative path
+ * @return the fully qualified path which begins with the servlet context.
+ */
protected String getQualifiedPath(CharSequence path)
{
- HttpServletRequest request = ((WebRequest)RequestCycle.get().getRequest())
- .getHttpServletRequest();
+ HttpServletRequest request = ((WebRequest)RequestCycle.get().getRequest()).getHttpServletRequest();
return request.getServletPath() + "/" + path;
}
+ /**
+ * @see PortletWindowUtils#getPortletWindowId(javax.portlet.PortletSession)
+ * @return the portlet window id as assigned by the portlet container.
+ */
protected String getPortletWindowId()
{
if (portletWindowId == null)
{
- portletWindowId = PortletWindowUtils.getPortletWindowId(portletRequest
- .getPortletSession());
+ portletWindowId = PortletWindowUtils.getPortletWindowId(portletRequest.getPortletSession());
}
return portletWindowId;
}
+ /**
+ * @see PortletConfig
+ * @return the portlet config
+ */
public PortletConfig getPortletConfig()
{
return portletConfig;
}
+ /**
+ * @see PortletRequest
+ * @return the portlet request
+ */
public PortletRequest getPortletRequest()
{
return portletRequest;
}
+ /**
+ * @see PortletResponse
+ * @return the portlet response
+ */
public PortletResponse getPortletResponse()
{
return portletResponse;
}
+ /**
+ * @return is the current request an Ajax request?
+ */
public boolean isAjax()
{
return ajax;
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletServletRequestWrapper.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletServletRequestWrapper.java?rev=706750&r1=706749&r2=706750&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletServletRequestWrapper.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletServletRequestWrapper.java Tue Oct 21 13:12:44 2008
@@ -22,120 +22,202 @@
import javax.servlet.http.HttpSession;
/**
+ * Wraps servlet request object with Portal specific functionality by overriding the
+ * {@link HttpServletRequestWrapper} retrieval of the context path, path info, request URI etc... to
+ * return the portal specific translations.
+ *
+ * FIXME javadoc
+ *
* @author Ate Douma
*/
public class PortletServletRequestWrapper extends HttpServletRequestWrapper
{
+ /**
+ * Context path.
+ */
private String contextPath;
- private String servletPath;
+ /**
+ * Servlet path.
+ */
+ private final String servletPath;
+ /**
+ * Path info - the url relative to the context and filter path.
+ */
private String pathInfo;
+ /**
+ * Request URI.
+ */
private String requestURI;
+ /**
+ * Query string.
+ */
private String queryString;
+ /**
+ * HTTP session.
+ */
private HttpSession session;
+ /**
+ * FIXME Remove! This should be removed - it no longer appears to be used?
+ */
private static String decodePathInfo(HttpServletRequest request, String filterPath)
{
String pathInfo = request.getRequestURI().substring(
- request.getContextPath().length() + filterPath.length());
+ request.getContextPath().length() + filterPath.length());
return pathInfo == null || pathInfo.length() < 2 ? null : pathInfo;
}
+ /**
+ * Converts from a filterPath (path with a trailing slash), to a servletPath (path with a
+ * leading slash).
+ *
+ * @param filterPath
+ * @return the filterPath prefixed with a leading slash and with the trailing slash removed
+ */
private static String makeServletPath(String filterPath)
{
return "/" + filterPath.substring(0, filterPath.length() - 1);
}
+ /**
+ * Package private constructor which is called from either of the two public constructors - sets
+ * up the various portlet specific versions of the context path, servlet path, request URI
+ * etc...
+ *
+ * @param context
+ * @param proxiedSession
+ * @param request
+ * @param filterPath
+ */
protected PortletServletRequestWrapper(ServletContext context, HttpSession proxiedSession,
- HttpServletRequest request, String filterPath)
+ HttpServletRequest request, String filterPath)
{
super(request);
- this.session = proxiedSession;
+ session = proxiedSession;
if (proxiedSession == null)
{
- this.session = request.getSession(false);
+ session = request.getSession(false);
}
- this.servletPath = makeServletPath(filterPath);
- if ((this.contextPath = (String)request.getAttribute("javax.servlet.include.context_path")) != null)
+ servletPath = makeServletPath(filterPath);
+ // retrieve the correct contextPath, requestURI and queryString
+ // if request is an include
+ if ((contextPath = (String)request.getAttribute("javax.servlet.include.context_path")) != null)
{
- this.requestURI = (String)request.getAttribute("javax.servlet.include.request_uri");
- this.queryString = (String)request.getAttribute("javax.servlet.include.query_string");
+ requestURI = (String)request.getAttribute("javax.servlet.include.request_uri");
+ queryString = (String)request.getAttribute("javax.servlet.include.query_string");
}
- else if ((this.contextPath = (String)request
- .getAttribute("javax.servlet.forward.context_path")) != null)
+ // else if request is a forward
+ else if ((contextPath = (String)request.getAttribute("javax.servlet.forward.context_path")) != null)
{
- this.requestURI = (String)request.getAttribute("javax.servlet.forward.request_uri");
- this.queryString = (String)request.getAttribute("javax.servlet.forward.query_string");
+ requestURI = (String)request.getAttribute("javax.servlet.forward.request_uri");
+ queryString = (String)request.getAttribute("javax.servlet.forward.query_string");
}
+ // else it is a normal request
else
{
- this.contextPath = request.getContextPath();
- this.requestURI = request.getRequestURI();
- this.queryString = request.getQueryString();
+ contextPath = request.getContextPath();
+ requestURI = request.getRequestURI();
+ queryString = request.getQueryString();
}
}
+ /**
+ * FIXME javadoc
+ *
+ * <p>
+ * Public constructor which internally builds the path info from request URI, instead of
+ * deriving it.
+ *
+ * @param context
+ * @param request
+ * @param proxiedSession
+ * @param filterPath
+ */
public PortletServletRequestWrapper(ServletContext context, HttpServletRequest request,
- HttpSession proxiedSession, String filterPath)
+ HttpSession proxiedSession, String filterPath)
{
this(context, proxiedSession, request, filterPath);
- String pathInfo = this.requestURI
- .substring(this.contextPath.length() + filterPath.length());
+ String pathInfo = requestURI.substring(contextPath.length() + filterPath.length());
this.pathInfo = pathInfo == null || pathInfo.length() < 2 ? null : pathInfo;
}
+ /**
+ * FIXME javadoc
+ *
+ * <p>
+ * Public constructor called when not running in a portlet environment, which is passed in the
+ * path info instead of deriving it. It overrides the generated request URI from the internal
+ * constructor.
+ *
+ * @param context
+ * @param request
+ * @param proxiedSession
+ * @param filterPath
+ * ???
+ * @param pathInfo
+ * ???
+ */
public PortletServletRequestWrapper(ServletContext context, HttpServletRequest request,
- HttpSession proxiedSession, String filterPath, String pathInfo)
+ HttpSession proxiedSession, String filterPath, String pathInfo)
{
this(context, proxiedSession, request, filterPath);
this.pathInfo = pathInfo;
- // override requestURI
- this.requestURI = this.contextPath + this.servletPath + (pathInfo != null ? pathInfo : "");
+ // override requestURI which is setup in the protected constructor
+ requestURI = contextPath + servletPath + (pathInfo != null ? pathInfo : "");
}
+ @Override
public String getContextPath()
{
return contextPath;
}
+ @Override
public String getServletPath()
{
return servletPath;
}
+ @Override
public String getPathInfo()
{
return pathInfo;
}
+ @Override
public String getRequestURI()
{
return requestURI;
}
+ @Override
public String getQueryString()
{
return queryString;
}
+ @Override
public HttpSession getSession()
{
return getSession(true);
}
+ @Override
public HttpSession getSession(boolean create)
{
return session != null ? session : super.getSession(create);
}
+ @Override
public Object getAttribute(String name)
{
// TODO: check if these can possibly be set/handled
// nullifying these for now to prevent Wicket
// ServletWebRequest.getRelativePathPrefixToWicketHandler() going the wrong route
if ("javax.servlet.error.request_uri".equals(name) ||
- "javax.servlet.forward.servlet_path".equals(name))
+ "javax.servlet.forward.servlet_path".equals(name))
{
return null;
}
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletServletResponseWrapper.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletServletResponseWrapper.java?rev=706750&r1=706749&r2=706750&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletServletResponseWrapper.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletServletResponseWrapper.java Tue Oct 21 13:12:44 2008
@@ -22,14 +22,18 @@
import javax.servlet.http.HttpServletResponseWrapper;
/**
+ * General class for all Portal responses, wrapping Servlet responses with Portal specific
+ * functionality.
+ *
+ * @see PortletMimeServletResponseWrapper
* @author Ate Douma
*/
public class PortletServletResponseWrapper extends HttpServletResponseWrapper
{
- private WicketResponseState responseState;
+ private final WicketResponseState responseState;
public PortletServletResponseWrapper(HttpServletResponse response,
- WicketResponseState responseState)
+ WicketResponseState responseState)
{
super(response);
this.responseState = responseState;
@@ -38,6 +42,7 @@
/**
* @see javax.servlet.http.HttpServletResponseWrapper#sendError(int, java.lang.String)
*/
+ @Override
public void sendError(int errorCode, String errorMessage) throws IOException
{
responseState.setErrorCode(errorCode);
@@ -47,6 +52,7 @@
/**
* @see javax.servlet.http.HttpServletResponseWrapper#sendError(int)
*/
+ @Override
public void sendError(int errorCode) throws IOException
{
responseState.setErrorCode(errorCode);
@@ -56,6 +62,7 @@
/**
* @see javax.servlet.http.HttpServletResponseWrapper#sendRedirect(java.lang.String)
*/
+ @Override
public void sendRedirect(String redirectLocation) throws IOException
{
responseState.setRedirectLocation(redirectLocation);
@@ -64,17 +71,20 @@
/**
* @see javax.servlet.http.HttpServletResponseWrapper#setStatus(int)
*/
+ @Override
public void setStatus(int statusCode)
{
responseState.setStatusCode(statusCode);
}
+ @Override
public String encodeRedirectUrl(String url)
{
String s = super.encodeRedirectUrl(url);
return s != null ? s : url;
}
+ @Override
public String encodeRedirectURL(String url)
{
String s = super.encodeRedirectURL(url);
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/WicketFilterPortletContext.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/WicketFilterPortletContext.java?rev=706750&r1=706749&r2=706750&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/WicketFilterPortletContext.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/WicketFilterPortletContext.java Tue Oct 21 13:12:44 2008
@@ -30,52 +30,104 @@
import org.apache.wicket.protocol.http.WebApplication;
import org.apache.wicket.protocol.http.WebRequest;
import org.apache.wicket.protocol.http.WebResponse;
+import org.apache.wicket.protocol.http.WicketFilter;
import org.apache.wicket.protocol.http.servlet.ServletWebRequest;
import org.apache.wicket.settings.IRequestCycleSettings;
/**
+ * Handles Portlet specific filtering requirements.
+ * <p/>
+ *
+ * The WicketFilterPortletContext first checks if it is a Portlet based request or a direct browser
+ * (servlet) request. If the request is a direct browser request it simply delegates the request to
+ * the {@link WicketFilter} and "normal" Wicket web application handling continues. This allows
+ * deploying the same Wicket application (with the same web.xml) as a normal web application too (as
+ * long as you don't use portlet specific features within your application).
+ * </p>
+ *
+ * If the request is dispatched from the WicketPortlet (easily determined from request attributes),
+ * the WicketPortletFilter wraps the servlet request and response objects with specialized portlet
+ * environment versions. Furthermore, the Servlet Session object will be wrapped to provide an
+ * isolated PORTLET_SCOPED session to Wicket to support multiple windows of the same portlet. And
+ * the RenderStrategy {@link IRequestCycleSettings#REDIRECT_TO_RENDER} will have to be enforced when
+ * invoked from portlet processAction, otherwise {@link IRequestCycleSettings#ONE_PASS_RENDER}.
+ * Thereafter, the {@link WicketFilterPortletContext} can let the standard {@link WicketFilter}
+ * handle the request as if it were a "normal" web based request.
+ * <p/>
+ *
+ * @see WicketFilter
* @author Ate Douma
*/
public class WicketFilterPortletContext
{
+ /**
+ * The unique, reserved string used to prefix the portlet's "window id" in the URL.
+ */
private static final String SERVLET_RESOURCE_URL_PORTLET_WINDOW_ID_PREFIX = "/ps:";
+ /**
+ * Overrides render strategy and adds the {@link PortletInvalidMarkupFilter} filter.
+ *
+ * @see PortletInvalidMarkupFilter
+ * @param webApplication
+ */
public void initFilter(FilterConfig filterConfig, WebApplication webApplication)
- throws ServletException
+ throws ServletException
{
+ // override render strategy to REDIRECT_TO_REDNER
webApplication.getRequestCycleSettings().setRenderStrategy(
- IRequestCycleSettings.REDIRECT_TO_RENDER);
+ IRequestCycleSettings.REDIRECT_TO_RENDER);
+ // Add response filter to remove extra HTML such as <body> etc as they are not appropriate
+ // for portlet environments
webApplication.getRequestCycleSettings()
- .addResponseFilter(new PortletInvalidMarkupFilter());
+ .addResponseFilter(new PortletInvalidMarkupFilter());
}
+ /**
+ * Sets up the filter to process a given request cycle. Potentially wraps the request and
+ * response objects with portlet specific wrappers.
+ *
+ * <p>
+ * Also sets up the session proxy using Apache Portals Bridge to ensure portlet session
+ * isolation. This is an option feature of Portal 2.0 spec so we just use portal bridges instead
+ * as it guarantees us support.
+ *
+ * @see org.apache.portals.bridges.util.ServletPortletSessionProxy
+ * @param config
+ * filter configuration
+ * @param filterRequestContext
+ * @param filterPath
+ * @return true if we are in a portlet environment
+ * @throws IOException
+ * @throws ServletException
+ */
public boolean setupFilter(FilterConfig config, FilterRequestContext filterRequestContext,
- String filterPath) throws IOException, ServletException
+ String filterPath) throws IOException, ServletException
{
boolean inPortletContext = false;
PortletConfig portletConfig = (PortletConfig)filterRequestContext.getRequest()
- .getAttribute("javax.portlet.config");
+ .getAttribute("javax.portlet.config");
if (portletConfig != null)
{
inPortletContext = true;
- WicketResponseState responseState = (WicketResponseState)filterRequestContext
- .getRequest().getAttribute(WicketPortlet.RESPONSE_STATE_ATTR);
- filterRequestContext.setRequest(new PortletServletRequestWrapper(config
- .getServletContext(), filterRequestContext.getRequest(),
- ServletPortletSessionProxy.createProxy(filterRequestContext.getRequest()),
- filterPath));
+ WicketResponseState responseState = (WicketResponseState)filterRequestContext.getRequest()
+ .getAttribute(WicketPortlet.RESPONSE_STATE_ATTR);
+ filterRequestContext.setRequest(new PortletServletRequestWrapper(
+ config.getServletContext(), filterRequestContext.getRequest(),
+ ServletPortletSessionProxy.createProxy(filterRequestContext.getRequest()),
+ filterPath));
if (WicketPortlet.ACTION_REQUEST.equals(filterRequestContext.getRequest().getAttribute(
- WicketPortlet.REQUEST_TYPE_ATTR)))
+ WicketPortlet.REQUEST_TYPE_ATTR)))
{
filterRequestContext.setResponse(new PortletActionServletResponseWrapper(
- filterRequestContext.getResponse(), responseState));
+ filterRequestContext.getResponse(), responseState));
}
else
{
- filterRequestContext
- .setResponse(new PortletRenderServletResponseWrapper(filterRequestContext
- .getResponse(), (RenderResponse)filterRequestContext.getRequest()
- .getAttribute("javax.portlet.response"), responseState));
+ filterRequestContext.setResponse(new PortletRenderServletResponseWrapper(
+ filterRequestContext.getResponse(),
+ (RenderResponse)filterRequestContext.getRequest().getAttribute(
+ "javax.portlet.response"), responseState));
}
}
else
@@ -83,20 +135,29 @@
ServletContext context = config.getServletContext();
HttpServletRequest request = filterRequestContext.getRequest();
String pathInfo = request.getRequestURI().substring(
- request.getContextPath().length() + filterPath.length());
+ request.getContextPath().length() + filterPath.length());
String portletWindowId = decodePortletWindowId(pathInfo);
if (portletWindowId != null)
{
HttpSession proxiedSession = ServletPortletSessionProxy.createProxy(request,
- portletWindowId);
+ portletWindowId);
pathInfo = stripWindowIdFromPathInfo(pathInfo);
filterRequestContext.setRequest(new PortletServletRequestWrapper(context, request,
- proxiedSession, filterPath, pathInfo));
+ proxiedSession, filterPath, pathInfo));
}
}
return inPortletContext;
}
+ /**
+ * Factory method which will delegate to
+ * {@link #newPortletRequestContext(ServletWebRequest, WebResponse)} to create the
+ * {@link PortletRequestContext} if the request is in a portlet context.
+ *
+ * @param request
+ * @param response
+ * @return true if running in a portlet context.
+ */
public boolean createPortletRequestContext(WebRequest request, WebResponse response)
{
if (request.getHttpServletRequest().getAttribute("javax.portlet.config") != null)
@@ -107,31 +168,59 @@
return false;
}
+ /**
+ * @see WicketFilterPortletContext#SERVLET_RESOURCE_URL_PORTLET_WINDOW_ID_PREFIX
+ * @return the unique, reserved string used to prefix the portlet's "window id" in the URL.
+ */
public String getServletResourceUrlPortletWindowIdPrefix()
{
return SERVLET_RESOURCE_URL_PORTLET_WINDOW_ID_PREFIX;
}
+ /**
+ * FIXME javadoc
+ *
+ * Try to extract the portlet's window id from the request url.
+ *
+ * @param pathInfo
+ * the url relative to the servlet context and filter path
+ * @return the window id, or null if it couldn't be decoded, with no leading forward slash
+ */
public String decodePortletWindowId(String pathInfo)
{
String portletWindowId = null;
+ // the path info should start with the window id prefix
if (pathInfo != null && pathInfo.startsWith(getServletResourceUrlPortletWindowIdPrefix()))
{
int nextPath = pathInfo.indexOf('/', 1);
if (nextPath > -1)
{
- portletWindowId = pathInfo.substring(getServletResourceUrlPortletWindowIdPrefix()
- .length(), nextPath);
+ portletWindowId = pathInfo.substring(
+ getServletResourceUrlPortletWindowIdPrefix().length(), nextPath);
}
else
{
- portletWindowId = pathInfo.substring(getServletResourceUrlPortletWindowIdPrefix()
- .length());
+ portletWindowId = pathInfo.substring(getServletResourceUrlPortletWindowIdPrefix().length());
}
}
+ else
+ // pathInfo was empty or didn't start with the window id prefix
+ {
+ // ignore - returns null
+ }
return portletWindowId;
}
+
+ /**
+ * FIXME javadoc
+ *
+ * <p>
+ * If the pathInfo contains the portlet window id namespace prefix, remove it.
+ *
+ * @param pathInfo
+ * @return
+ */
public String stripWindowIdFromPathInfo(String pathInfo)
{
if (pathInfo != null && pathInfo.startsWith(getServletResourceUrlPortletWindowIdPrefix()))
@@ -142,13 +231,28 @@
return pathInfo;
}
+ /**
+ * Encodes the given path portlet window id.
+ *
+ * @param windowId
+ * @param path
+ * @return
+ */
public String encodeWindowIdInPath(String windowId, CharSequence path)
{
return (getServletResourceUrlPortletWindowIdPrefix().substring(1) + windowId + "/" + path);
}
+ /**
+ * Factory method to create the {@link PortletRequestContext}.
+ *
+ * @see #createPortletRequestContext(WebRequest, WebResponse)
+ * @see PortletRequestContext
+ * @param request
+ * @param response
+ */
protected void newPortletRequestContext(ServletWebRequest request, WebResponse response)
{
new PortletRequestContext(this, request, response);
}
-}
+}
\ No newline at end of file
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/WicketPortlet.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/WicketPortlet.java?rev=706750&r1=706749&r2=706750&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/WicketPortlet.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/WicketPortlet.java Tue Oct 21 13:12:44 2008
@@ -27,6 +27,7 @@
import javax.portlet.GenericPortlet;
import javax.portlet.PortletConfig;
import javax.portlet.PortletException;
+import javax.portlet.PortletMode;
import javax.portlet.PortletRequest;
import javax.portlet.PortletRequestDispatcher;
import javax.portlet.PortletResponse;
@@ -40,34 +41,111 @@
import org.apache.portals.bridges.common.PortletResourceURLFactory;
import org.apache.portals.bridges.common.ServletContextProvider;
+import org.apache.wicket.Resource;
+import org.apache.wicket.protocol.http.WicketFilter;
/**
+ * Adapter between the Portlet world requests and the internal Wicket engine. I.e. simulates the
+ * web/servlet environment for Wicket, while it's actually running as a Portlet.
+ *
+ * <p>
+ * It receives a portlet request and dispatches to a a Wicket filter; wrapping the servlet context,
+ * request and response objects; intercepts response writing (especially urls and redirects) and
+ * rewrites and adapts the output to accommodate the portlet requirements.
+ *
+ * <p>
+ * The WicketPortlet is configured (using an initParameter) against a specific filter path, e.g.
+ * Wicket WebApplication. The WicketPortlet maintains a parameter for the current Wicket page url,
+ * based against the filter path (e.g. fully qualified to the context path). When a request (action,
+ * render or direct resource/ajax call) is received by the WicketPortlet, it dispatches it to Wicket
+ * as a servlet request using the provided Wicket page url parameter.
+ *
+ * @see WicketFilter
* @author Ate Douma
*/
public class WicketPortlet extends GenericPortlet
{
+ /**
+ * FIXME javadoc
+ *
+ * <p>
+ * The prefix for the parameter name for storing Wicket URLs.
+ */
public static final String WICKET_URL_PORTLET_PARAMETER = "_wu";
+
+ /**
+ * FIXME javadoc
+ *
+ * <p>
+ * The prefix for the parameter name for storing Wicket Resource URLs.
+ *
+ * @see Resource
+ */
public static final String PORTLET_RESOURCE_URL_PARAMETER = "_ru";
+
+ /**
+ * FIXME javadoc
+ *
+ * <p>
+ * The attribute name for storing if the request is a Resource request or not.
+ *
+ * @see Resource
+ */
public static final String PORTLET_RESOURCE_URL_ATTR = "_ru";
+
+ /**
+ * FIXME javadoc
+ */
public static final String WICKET_FILTER_PATH_PARAM = "wicketFilterPath";
+
+ /**
+ * FIXME javadoc
+ *
+ * <p>
+ * Parameter name to store the {@link ServletContextProvider}.
+ */
public static final String PARAM_SERVLET_CONTEXT_PROVIDER = "ServletContextProvider";
+
+ /**
+ * FIXME javadoc
+ *
+ * <p>
+ * Parameter name to store the {@link PortletResourceURLFactory}.
+ */
public static final String PARAM_PORTLET_RESOURCE_URL_FACTORY = "PortletResourceURLFactory";
+ /** Portal Action request */
public static final String ACTION_REQUEST = "ACTION";
- public static final String VIEW_REQUEST = "VIEW";
+ /** Portal Resource request */
public static final String RESOURCE_REQUEST = "RESOURCE";
+
+ /** Portal Custom request */
public static final String CUSTOM_REQUEST = "CUSTOM";
+ /** Portal View request - i.e. doView */
+ public static final String VIEW_REQUEST = "VIEW";
+ /** Portal Edit request - i.e. doEdit */
public static final String EDIT_REQUEST = "EDIT";
+ /** Portal Help request - i.e. doHelp */
public static final String HELP_REQUEST = "HELP";
+ /**
+ * Marker used as key to store the type of request as a request attribute - i.e. resource /
+ * action / event request etc .
+ */
public static final String REQUEST_TYPE_ATTR = WicketPortlet.class.getName() + ".REQUEST_TYPE";
+ /**
+ * FIXME javadoc
+ * <p>
+ * The parameter name to store the URL to the Wicket porlet.
+ */
public static final String WICKET_URL_PORTLET_PARAMETER_ATTR = WicketPortlet.class.getName() +
- ".WICKET_URL_PORTLET_PARAMETER";
+ ".WICKET_URL_PORTLET_PARAMETER";
public static final String CONFIG_PARAM_PREFIX = WicketPortlet.class.getName() + ".";
+ /** Marker used as key for the WicketResponseState object stored as a request attribute. */
public static final String RESPONSE_STATE_ATTR = WicketResponseState.class.getName();
- public static final String RESOURCE_URL_FACTORY_ATTR = PortletResourceURLFactory.class
- .getName();
+ public static final String RESOURCE_URL_FACTORY_ATTR = PortletResourceURLFactory.class.getName();
+ /** FIXME javadoc */
public static final String WICKET_PORTLET_PROPERTIES = WicketPortlet.class.getName().replace(
- '.', '/') +
- ".properties";
+ '.', '/') +
+ ".properties";
public static final String WICKET_FILTER_PATH = WicketPortlet.class.getName() + ".FILTERPATH";
public static final String WICKET_FILTER_QUERY = WicketPortlet.class.getName() + ".FILTERQUERY";
@@ -93,11 +171,16 @@
public static final String PARAM_VIEW_PAGE = "viewPage";
private ServletContextProvider servletContextProvider;
+ /**
+ * {@link PortletResourceURLFactory}, used to generate {@link Resource} URLs for Portal 168
+ * support.
+ */
private PortletResourceURLFactory resourceURLFactory;
private String wicketFilterPath;
private String wicketFilterQuery;
private final HashMap defaultPages = new HashMap();
+ @Override
public void init(PortletConfig config) throws PortletException
{
super.init(config);
@@ -106,21 +189,20 @@
if (contextProviderClassName == null)
{
contextProviderClassName = config.getPortletContext().getInitParameter(
- ServletContextProvider.class.getName());
+ ServletContextProvider.class.getName());
}
if (contextProviderClassName == null)
{
wicketPortletProperties = getWicketPortletProperties(wicketPortletProperties);
- contextProviderClassName = wicketPortletProperties
- .getProperty(ServletContextProvider.class.getName());
+ contextProviderClassName = wicketPortletProperties.getProperty(ServletContextProvider.class.getName());
}
if (contextProviderClassName == null)
{
throw new PortletException("Portlet " + config.getPortletName() +
- " is incorrectly configured. Init parameter " + PARAM_SERVLET_CONTEXT_PROVIDER +
- " not specified, nor as context parameter " +
- ServletContextProvider.class.getName() + " or as property in " +
- WICKET_PORTLET_PROPERTIES + " in the classpath.");
+ " is incorrectly configured. Init parameter " + PARAM_SERVLET_CONTEXT_PROVIDER +
+ " not specified, nor as context parameter " +
+ ServletContextProvider.class.getName() + " or as property in " +
+ WICKET_PORTLET_PROPERTIES + " in the classpath.");
}
try
{
@@ -140,22 +222,20 @@
if (resourceURLFactoryClassName == null)
{
resourceURLFactoryClassName = config.getPortletContext().getInitParameter(
- PortletResourceURLFactory.class.getName());
+ PortletResourceURLFactory.class.getName());
}
if (resourceURLFactoryClassName == null)
{
wicketPortletProperties = getWicketPortletProperties(wicketPortletProperties);
- resourceURLFactoryClassName = wicketPortletProperties
- .getProperty(PortletResourceURLFactory.class.getName());
+ resourceURLFactoryClassName = wicketPortletProperties.getProperty(PortletResourceURLFactory.class.getName());
}
if (resourceURLFactoryClassName == null)
{
throw new PortletException("Portlet " + config.getPortletName() +
- " is incorrectly configured. Init parameter " +
- PARAM_PORTLET_RESOURCE_URL_FACTORY +
- " not specified, nor as context parameter " +
- PortletResourceURLFactory.class.getName() + " or as property in " +
- WICKET_PORTLET_PROPERTIES + " in the classpath.");
+ " is incorrectly configured. Init parameter " + PARAM_PORTLET_RESOURCE_URL_FACTORY +
+ " not specified, nor as context parameter " +
+ PortletResourceURLFactory.class.getName() + " or as property in " +
+ WICKET_PORTLET_PROPERTIES + " in the classpath.");
}
try
{
@@ -183,6 +263,7 @@
validateDefaultPages(defaultPages, wicketFilterPath, wicketFilterQuery);
}
+ @Override
public void destroy()
{
resourceURLFactory = null;
@@ -231,6 +312,19 @@
}
}
+ /**
+ * FIXME javadoc
+ *
+ * <p>
+ * Corrects the incoming URL if the old home page style, or if it's missing the filter path
+ * prefix.
+ *
+ * @param url
+ * the URL to fix
+ * @param wicketFilterPath
+ * @param wicketFilterQuery
+ * @return the corrected URL
+ */
protected String fixWicketUrl(String url, String wicketFilterPath, String wicketFilterQuery)
{
if (url == null)
@@ -254,14 +348,30 @@
return url;
}
+ /**
+ * FIXME javadoc
+ *
+ * <p>
+ * Registers the default pages and their URLs for the different {@link PortletMode}s. Also
+ * corrects and slightly incorrect URLs (see {@link #fixWicketUrl(String, String, String)}).
+ *
+ * <p>
+ * If no specific page was specified for a given portlet mode (VIEW, EDIT etc) then the page for
+ * that mode is set to be the same page as that of the VIEW mode.
+ *
+ * @see PortletMode
+ * @see #fixWicketUrl(String, String, String)
+ * @param defaultPages
+ * @param wicketFilterPath
+ * @param wicketFilterQuery
+ */
protected void validateDefaultPages(Map defaultPages, String wicketFilterPath,
- String wicketFilterQuery)
+ String wicketFilterQuery)
{
String viewPage = fixWicketUrl((String)defaultPages.get(PARAM_VIEW_PAGE), wicketFilterPath,
- wicketFilterQuery);
- defaultPages.put(PARAM_VIEW_PAGE, viewPage.startsWith(wicketFilterPath)
- ? viewPage
- : wicketFilterPath);
+ wicketFilterQuery);
+ defaultPages.put(PARAM_VIEW_PAGE, viewPage.startsWith(wicketFilterPath) ? viewPage
+ : wicketFilterPath);
String defaultPage = (String)defaultPages.get(PARAM_ACTION_PAGE);
if (defaultPage == null)
@@ -272,8 +382,7 @@
{
defaultPage = fixWicketUrl(defaultPage, wicketFilterPath, wicketFilterQuery);
defaultPages.put(PARAM_ACTION_PAGE, defaultPage.startsWith(wicketFilterPath)
- ? defaultPage
- : viewPage);
+ ? defaultPage : viewPage);
}
defaultPage = (String)defaultPages.get(PARAM_CUSTOM_PAGE);
@@ -285,8 +394,7 @@
{
defaultPage = fixWicketUrl(defaultPage, wicketFilterPath, wicketFilterQuery);
defaultPages.put(PARAM_CUSTOM_PAGE, defaultPage.startsWith(wicketFilterPath)
- ? defaultPage
- : viewPage);
+ ? defaultPage : viewPage);
}
defaultPage = (String)defaultPages.get(PARAM_HELP_PAGE);
@@ -298,8 +406,7 @@
{
defaultPage = fixWicketUrl(defaultPage, wicketFilterPath, wicketFilterQuery);
defaultPages.put(PARAM_HELP_PAGE, defaultPage.startsWith(wicketFilterPath)
- ? defaultPage
- : viewPage);
+ ? defaultPage : viewPage);
}
defaultPage = (String)defaultPages.get(PARAM_EDIT_PAGE);
@@ -311,11 +418,22 @@
{
defaultPage = fixWicketUrl(defaultPage, wicketFilterPath, wicketFilterQuery);
defaultPages.put(PARAM_EDIT_PAGE, defaultPage.startsWith(wicketFilterPath)
- ? defaultPage
- : viewPage);
+ ? defaultPage : viewPage);
}
}
+ /**
+ * Loads the Wicket Portlet properties file off the class path.
+ *
+ * FIXME javadoc - check properties
+ *
+ * @param properties
+ * appends the portlet properties to
+ * @return Wicket portlet properties. Returns an empty or unchanged properties object if Wicket
+ * Portlet properties could not be found
+ * @throws PortletException
+ * if loading the properties fails
+ */
protected Properties getWicketPortletProperties(Properties properties) throws PortletException
{
if (properties == null)
@@ -323,7 +441,7 @@
properties = new Properties();
}
InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(
- WICKET_PORTLET_PROPERTIES);
+ WICKET_PORTLET_PROPERTIES);
if (is != null)
{
try
@@ -333,47 +451,70 @@
catch (IOException e)
{
throw new PortletException(
- "Failed to load WicketPortlet.properties from classpath", e);
+ "Failed to load WicketPortlet.properties from classpath", e);
}
}
return properties;
}
+ /**
+ * Gets the Context Provider ClassName Parameter from the config object.
+ *
+ * @param config
+ * @return Context Provider ClassName
+ */
protected String getContextProviderClassNameParameter(PortletConfig config)
{
return config.getInitParameter(PARAM_SERVLET_CONTEXT_PROVIDER);
}
+ /**
+ * Gets the portlet resource url factory class name from the config object.
+ *
+ * @param config
+ * @return portlet resource url factory class name
+ */
protected String getPortletResourceURLFactoryClassNameParameter(PortletConfig config)
{
return config.getInitParameter(PARAM_PORTLET_RESOURCE_URL_FACTORY);
}
+ /**
+ *
+ * @return servlet context provider
+ */
protected ServletContextProvider getServletContextProvider()
{
return servletContextProvider;
}
+ /**
+ *
+ * @param portlet
+ * @param request
+ * @param response
+ * @return
+ */
protected ServletContext getServletContext(GenericPortlet portlet, PortletRequest request,
- PortletResponse response)
+ PortletResponse response)
{
return getServletContextProvider().getServletContext(portlet);
}
protected HttpServletRequest getHttpServletRequest(GenericPortlet portlet,
- PortletRequest request, PortletResponse response)
+ PortletRequest request, PortletResponse response)
{
return getServletContextProvider().getHttpServletRequest(portlet, request);
}
protected HttpServletResponse getHttpServletResponse(GenericPortlet portlet,
- PortletRequest request, PortletResponse response)
+ PortletRequest request, PortletResponse response)
{
return getServletContextProvider().getHttpServletResponse(portlet, response);
}
protected String getWicketConfigParameter(PortletRequest request, String paramName,
- String defaultValue)
+ String defaultValue)
{
return defaultValue;
}
@@ -388,73 +529,95 @@
return wicketFilterPath;
}
+ /**
+ * Retrieves the Wicket URL from the request object, or if none exists returns the default URL.
+ *
+ * @see PortletRequestContext#getLastEncodedPath()
+ * @param request
+ * @param pageType
+ * @param defaultPage
+ * @return the Wicket URL from within the specified request
+ */
protected String getWicketURL(PortletRequest request, String pageType, String defaultPage)
{
String wicketURL = null;
if (request instanceof ActionRequest)
{
- wicketURL = request.getParameter((String)request
- .getAttribute(WicketPortlet.WICKET_URL_PORTLET_PARAMETER_ATTR));
+ wicketURL = request.getParameter((String)request.getAttribute(WicketPortlet.WICKET_URL_PORTLET_PARAMETER_ATTR));
}
else
{
- wicketURL = request.getParameter((String)request
- .getAttribute(WicketPortlet.WICKET_URL_PORTLET_PARAMETER_ATTR) +
- request.getPortletMode().toString());
+ wicketURL = request.getParameter((String)request.getAttribute(WicketPortlet.WICKET_URL_PORTLET_PARAMETER_ATTR) +
+ request.getPortletMode().toString());
}
if (wicketURL == null)
{
wicketURL = getWicketConfigParameter(request, CONFIG_PARAM_PREFIX + pageType,
- defaultPage);
+ defaultPage);
}
return wicketURL;
}
+ @Override
protected void doView(RenderRequest request, RenderResponse response) throws PortletException,
- IOException
+ IOException
{
processRequest(request, response, VIEW_REQUEST, PARAM_VIEW_PAGE);
}
+ @Override
protected void doEdit(RenderRequest request, RenderResponse response) throws PortletException,
- IOException
+ IOException
{
processRequest(request, response, EDIT_REQUEST, PARAM_EDIT_PAGE);
}
+ @Override
protected void doHelp(RenderRequest request, RenderResponse response) throws PortletException,
- IOException
+ IOException
{
processRequest(request, response, HELP_REQUEST, PARAM_HELP_PAGE);
}
protected void doCustom(RenderRequest request, RenderResponse response)
- throws PortletException, IOException
+ throws PortletException, IOException
{
processRequest(request, response, CUSTOM_REQUEST, PARAM_CUSTOM_PAGE);
}
+ @Override
public void processAction(ActionRequest request, ActionResponse response)
- throws PortletException, IOException
+ throws PortletException, IOException
{
processRequest(request, response, ACTION_REQUEST, PARAM_ACTION_PAGE);
}
+ /**
+ * Consumes and processes all portlet requests. All the doX methods delegate to this method,
+ * including processAction and serveResource.
+ *
+ * @param request
+ * @param response
+ * @param requestType
+ * @param pageType
+ * @throws PortletException
+ * @throws IOException
+ */
protected void processRequest(PortletRequest request, PortletResponse response,
- String requestType, String pageType) throws PortletException, IOException
+ String requestType, String pageType) throws PortletException, IOException
{
String wicketURL = null;
String wicketFilterPath = null;
String wicketFilterQuery = null;
request.setAttribute(WICKET_URL_PORTLET_PARAMETER_ATTR,
- getWicketUrlPortletParameter(request));
+ getWicketUrlPortletParameter(request));
wicketURL = getWicketURL(request, pageType, getDefaultPage(pageType));
wicketFilterPath = getWicketConfigParameter(request, WICKET_FILTER_PATH,
- this.wicketFilterPath);
+ this.wicketFilterPath);
wicketFilterQuery = getWicketConfigParameter(request, WICKET_FILTER_QUERY,
- this.wicketFilterQuery);
+ this.wicketFilterQuery);
boolean actionRequest = ACTION_REQUEST.equals(requestType);
@@ -499,7 +662,7 @@
{
rd.include(req, res);
processActionResponseState(wicketURL, wicketFilterPath, wicketFilterQuery,
- (ActionRequest)request, (ActionResponse)response, responseState);
+ (ActionRequest)request, (ActionResponse)response, responseState);
}
catch (ServletException e)
{
@@ -521,30 +684,28 @@
if (redirectLocation != null)
{
redirectLocation = fixWicketUrl(redirectLocation, wicketFilterPath,
- wicketFilterQuery);
+ wicketFilterQuery);
boolean validWicketUrl = redirectLocation.startsWith(wicketFilterPath);
if (portletResourceURL != null)
{
if (validWicketUrl)
{
HashMap parameters = new HashMap(2);
- parameters
- .put(
- (String)request
- .getAttribute(WicketPortlet.WICKET_URL_PORTLET_PARAMETER_ATTR) +
- request.getPortletMode().toString(),
- new String[] { redirectLocation });
+ parameters.put(
+ (String)request.getAttribute(WicketPortlet.WICKET_URL_PORTLET_PARAMETER_ATTR) +
+ request.getPortletMode().toString(),
+ new String[] { redirectLocation });
parameters.put(PORTLET_RESOURCE_URL_PARAMETER,
- new String[] { "true" });
+ new String[] { "true" });
redirectLocation = resourceURLFactory.createResourceURL(
- getPortletConfig(), (RenderRequest)request,
- (RenderResponse)response, parameters);
+ getPortletConfig(), (RenderRequest)request,
+ (RenderResponse)response, parameters);
}
getHttpServletResponse(this, request, response).sendRedirect(
- redirectLocation);
+ redirectLocation);
}
else if (validWicketUrl &&
- ((previousURL == null || previousURL != redirectLocation)))
+ ((previousURL == null || previousURL != redirectLocation)))
{
previousURL = wicketURL;
wicketURL = redirectLocation;
@@ -563,18 +724,33 @@
}
}
+ /**
+ * Handles redirects set from processing the action. Checks the response state after the action
+ * has been processed by Wicket for the presence of a redirect URL, and if present, portletifies
+ * the URL. If the URL is a redirect to within the scope of this portlet, leaves it to be
+ * handled in a subsequent render call, or if not, sends the redirect to the client.
+ *
+ * @param wicketURL
+ * @param wicketFilterPath
+ * @param wicketFilterQuery
+ * @param request
+ * @param response
+ * @param responseState
+ * @throws PortletException
+ * @throws IOException
+ */
protected void processActionResponseState(String wicketURL, String wicketFilterPath,
- String wicketFilterQuery, ActionRequest request, ActionResponse response,
- WicketResponseState responseState) throws PortletException, IOException
+ String wicketFilterQuery, ActionRequest request, ActionResponse response,
+ WicketResponseState responseState) throws PortletException, IOException
{
if (responseState.getRedirectLocation() != null)
{
wicketURL = fixWicketUrl(responseState.getRedirectLocation(), wicketFilterPath,
- wicketFilterQuery);
+ wicketFilterQuery);
if (wicketURL.startsWith(wicketFilterPath))
{
- response.setRenderParameter((String)request
- .getAttribute(WicketPortlet.WICKET_URL_PORTLET_PARAMETER_ATTR) +
+ response.setRenderParameter(
+ (String)request.getAttribute(WicketPortlet.WICKET_URL_PORTLET_PARAMETER_ATTR) +
request.getPortletMode().toString(), wicketURL);
}
else
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/WicketResponseState.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/WicketResponseState.java?rev=706750&r1=706749&r2=706750&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/WicketResponseState.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/WicketResponseState.java Tue Oct 21 13:12:44 2008
@@ -17,6 +17,8 @@
package org.apache.wicket.protocol.http.portlet;
/**
+ * Holds the current state of the response and the redirect location for Portlets.
+ *
* @author Ate Douma
*/
public class WicketResponseState
Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/request/target/resource/ISharedResourceRequestTarget.java
URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/request/target/resource/ISharedResourceRequestTarget.java?rev=706750&r1=706749&r2=706750&view=diff
==============================================================================
--- wicket/trunk/wicket/src/main/java/org/apache/wicket/request/target/resource/ISharedResourceRequestTarget.java (original)
+++ wicket/trunk/wicket/src/main/java/org/apache/wicket/request/target/resource/ISharedResourceRequestTarget.java Tue Oct 21 13:12:44 2008
@@ -17,11 +17,20 @@
package org.apache.wicket.request.target.resource;
import org.apache.wicket.IRequestTarget;
+import org.apache.wicket.ResourceReference;
+import org.apache.wicket.SharedResources;
import org.apache.wicket.request.RequestParameters;
/**
- * Target that denotes a shared {@link org.apache.wicket.Resource}.
+ * Target that denotes a shared {@link org.apache.wicket.Resource}, i.e a resource that doesn't need
+ * a host component.
*
+ * <p>
+ * Shared resources for an application are contained in the {@link SharedResources} class.
+ *
+ * @see SharedResources
+ * @see ResourceReference
+ * @see org.apache.wicket.Resource
* @author Eelco Hillenius
*/
public interface ISharedResourceRequestTarget extends IRequestTarget