You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by kn...@apache.org on 2008/11/16 23:04:29 UTC

svn commit: r718123 [5/10] - in /wicket/sandbox/knopp/experimental/wicket: ./ .settings/ src/main/java/org/apache/wicket/ src/main/java/org/apache/wicket/ajax/ src/main/java/org/apache/wicket/ajax/form/ src/main/java/org/apache/wicket/ajax/markup/html/...

Modified: wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/WebSession.java
URL: http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/WebSession.java?rev=718123&r1=718122&r2=718123&view=diff
==============================================================================
--- wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/WebSession.java (original)
+++ wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/WebSession.java Sun Nov 16 14:04:19 2008
@@ -16,6 +16,8 @@
  */
 package org.apache.wicket.protocol.http;
 
+import java.util.List;
+
 import org.apache.wicket.Application;
 import org.apache.wicket.Component;
 import org.apache.wicket.Request;
@@ -25,6 +27,8 @@
 import org.apache.wicket.feedback.IFeedbackMessageFilter;
 import org.apache.wicket.settings.IRequestCycleSettings;
 import org.apache.wicket.util.string.Strings;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
  * A session subclass for the HTTP protocol.
@@ -34,6 +38,9 @@
 public class WebSession extends Session
 {
 	private static final long serialVersionUID = 1L;
+
+	private static final Logger logger = LoggerFactory.getLogger(WebSession.class);
+
 	/**
 	 * Filter that returns all component scoped messages ({@link FeedbackMessage#getReporter()} !=
 	 * null).
@@ -71,6 +78,7 @@
 	 * @param request
 	 *            The current request
 	 */
+	@Deprecated
 	public WebSession(final Application application, Request request)
 	{
 		super(application, request);
@@ -86,6 +94,7 @@
 	 * @param request
 	 *            The current request
 	 */
+	@Deprecated
 	public WebSession(final WebApplication application, Request request)
 	{
 		super(application, request);
@@ -105,6 +114,7 @@
 	/**
 	 * @see org.apache.wicket.Session#isCurrentRequestValid(org.apache.wicket.RequestCycle)
 	 */
+	@Override
 	protected boolean isCurrentRequestValid(RequestCycle lockedRequestCycle)
 	{
 		WebRequest lockedRequest = (WebRequest)lockedRequestCycle.getRequest();
@@ -125,9 +135,10 @@
 		}
 
 		String lockedPageId = Strings.firstPathComponent(lockedRequest.getRequestParameters()
-				.getComponentPath(), Component.PATH_SEPARATOR);
+			.getComponentPath(), Component.PATH_SEPARATOR);
 		String currentPageId = Strings.firstPathComponent(currentRequestCycle.getRequest()
-				.getRequestParameters().getComponentPath(), Component.PATH_SEPARATOR);
+			.getRequestParameters()
+			.getComponentPath(), Component.PATH_SEPARATOR);
 
 		int lockedVersion = lockedRequest.getRequestParameters().getVersionNumber();
 		int currentVersion = currentRequest.getRequestParameters().getVersionNumber();
@@ -144,6 +155,7 @@
 	/**
 	 * @see org.apache.wicket.Session#cleanupFeedbackMessages()
 	 */
+	@Override
 	public void cleanupFeedbackMessages()
 	{
 		// remove all component feedback messages if we are either using one
@@ -152,8 +164,8 @@
 		// used, when we're doing the render request (isRedirect should return
 		// false in that case)
 		if (Application.get().getRequestCycleSettings().getRenderStrategy() != IRequestCycleSettings.REDIRECT_TO_RENDER ||
-				((WebRequest)RequestCycle.get().getRequest()).isAjax() ||
-				(!RequestCycle.get().isRedirect()))
+			((WebRequest)RequestCycle.get().getRequest()).isAjax() ||
+			(!RequestCycle.get().isRedirect()))
 		{
 			// If session scoped, rendered messages got indeed cleaned up, mark
 			// the session as dirty
@@ -162,6 +174,23 @@
 				dirty();
 			}
 
+			// see if any component related feedback messages were left unrendered and warn if in
+			// dev mode
+			if (Application.DEVELOPMENT.equals(getApplication().getConfigurationType()))
+			{
+				List<FeedbackMessage> messages = getFeedbackMessages().messages(
+					WebSession.MESSAGES_FOR_COMPONENTS);
+				for (FeedbackMessage message : messages)
+				{
+					if (!message.isRendered())
+					{
+						logger.warn(
+							"Component-targetted feedback message was left unrendered. This could be because you are missing a FeedbackPanel on the page.  Message: {}",
+							message);
+					}
+				}
+			}
+
 			// clean up all component related feedback messages
 			getFeedbackMessages().clear(WebSession.MESSAGES_FOR_COMPONENTS);
 		}

Modified: wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java
URL: http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java?rev=718123&r1=718122&r2=718123&view=diff
==============================================================================
--- wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java (original)
+++ wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/WicketFilter.java Sun Nov 16 14:04:19 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;
@@ -51,14 +54,24 @@
 import org.apache.wicket.util.resource.IResourceStream;
 import org.apache.wicket.util.resource.ResourceStreamNotFoundException;
 import org.apache.wicket.util.string.Strings;
+import org.apache.wicket.util.time.Duration;
 import org.apache.wicket.util.time.Time;
 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
@@ -138,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;
@@ -165,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)
 	 */
@@ -179,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();
 		}
@@ -190,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;
@@ -257,6 +307,8 @@
 					else
 					{
 						httpServletResponse.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
+						httpServletResponse.setDateHeader("Expires", System.currentTimeMillis() +
+							Duration.hours(1).getMilliseconds());
 					}
 				}
 			}
@@ -281,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
@@ -320,42 +379,7 @@
 				Thread.currentThread().setContextClassLoader(newClassLoader);
 			}
 
-			// If the request does not provide information about the encoding of
-			// its body (which includes POST parameters), than assume the
-			// default encoding as defined by the wicket application. Bear in
-			// mind that the encoding of the request usually is equal to the
-			// previous response.
-			// However it is a known bug of IE that it does not provide this
-			// information. Please see the wiki for more details and why all
-			// other browser deliberately copied that bug.
-			if (servletRequest.getCharacterEncoding() == null)
-			{
-				try
-				{
-					// It this request is a wicket-ajax request, we need decode the
-					// request always by UTF-8, because the request data is encoded by
-					// encodeUrlComponent() JavaScript function, which always encode data
-					// by UTF-8.
-					String wicketAjaxHeader = servletRequest.getHeader("wicket-ajax");
-					if (wicketAjaxHeader != null && wicketAjaxHeader.equals("true"))
-					{
-						servletRequest.setCharacterEncoding("UTF-8");
-					}
-					else
-					{
-						// The encoding defined by the wicket settings is used to
-						// encode the responses. Thus, it is reasonable to assume
-						// the request has the same encoding. This is especially
-						// important for forms and form parameters.
-						servletRequest.setCharacterEncoding(webApplication.getRequestCycleSettings()
-							.getResponseRequestEncoding());
-					}
-				}
-				catch (UnsupportedEncodingException ex)
-				{
-					throw new WicketRuntimeException(ex.getMessage());
-				}
-			}
+			checkCharacterEncoding(servletRequest);
 
 			// Create a new webrequest
 			final WebRequest request = webApplication.newWebRequest(servletRequest);
@@ -466,6 +490,53 @@
 	}
 
 	/**
+	 * 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
+		// its body (which includes POST parameters), than assume the
+		// default encoding as defined by the wicket application. Bear in
+		// mind that the encoding of the request usually is equal to the
+		// previous response.
+		// However it is a known bug of IE that it does not provide this
+		// information. Please see the wiki for more details and why all
+		// other browser deliberately copied that bug.
+		if (servletRequest.getCharacterEncoding() == null)
+		{
+			try
+			{
+				// It this request is a wicket-ajax request, we need decode the
+				// request always by UTF-8, because the request data is encoded by
+				// encodeUrlComponent() JavaScript function, which always encode data
+				// by UTF-8.
+				String wicketAjaxHeader = servletRequest.getHeader("wicket-ajax");
+				if (wicketAjaxHeader != null && wicketAjaxHeader.equals("true"))
+				{
+					servletRequest.setCharacterEncoding("UTF-8");
+				}
+				else
+				{
+					// The encoding defined by the wicket settings is used to
+					// encode the responses. Thus, it is reasonable to assume
+					// the request has the same encoding. This is especially
+					// important for forms and form parameters.
+					servletRequest.setCharacterEncoding(webApplication.getRequestCycleSettings()
+						.getResponseRequestEncoding());
+				}
+			}
+			catch (UnsupportedEncodingException ex)
+			{
+				throw new WicketRuntimeException(ex.getMessage());
+			}
+		}
+	}
+
+	/**
 	 * @return The filter config of this WicketFilter
 	 */
 	public FilterConfig getFilterConfig()
@@ -474,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
@@ -517,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)
 	 */
@@ -607,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);
@@ -648,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();
@@ -660,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();
@@ -669,6 +773,7 @@
 				InputStream is = Thread.currentThread()
 					.getContextClassLoader()
 					.getResourceAsStream(WICKET_PORTLET_PROPERTIES);
+				// search wicket.properties
 				if (is != null)
 				{
 					try
@@ -689,6 +794,7 @@
 		}
 		if (detectPortletContext)
 		{
+			// load the portlet context
 			try
 			{
 				Class<?> portletClass = Class.forName("javax.portlet.PortletContext");
@@ -977,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
@@ -1009,6 +1115,8 @@
 				// If resource found and it is cacheable
 				if ((resource != null) && resource.isCacheable())
 				{
+					// first check the char encoding for getting the parameters
+					checkCharacterEncoding(servletRequest);
 
 					final WebRequest request = webApplication.newWebRequest(servletRequest);
 					// make the session available.

Modified: wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/WicketServlet.java
URL: http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/WicketServlet.java?rev=718123&r1=718122&r2=718123&view=diff
==============================================================================
--- wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/WicketServlet.java (original)
+++ wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/WicketServlet.java Sun Nov 16 14:04:19 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>
  * &lt;init-param&gt;

Modified: wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/pagestore/AbstractPageStore.java
URL: http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/pagestore/AbstractPageStore.java?rev=718123&r1=718122&r2=718123&view=diff
==============================================================================
--- wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/pagestore/AbstractPageStore.java (original)
+++ wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/pagestore/AbstractPageStore.java Sun Nov 16 14:04:19 2008
@@ -176,7 +176,6 @@
 	 *            page to be serialized
 	 * @return list of {@link SerializedPage}s
 	 */
-	@SuppressWarnings("unchecked")
 	protected List<SerializedPage> serializePage(Page page)
 	{
 		final List<SerializedPage> result = new ArrayList<SerializedPage>();
@@ -218,7 +217,6 @@
 	 *            kept
 	 * @return page instance
 	 */
-	@SuppressWarnings("unchecked")
 	protected Page deserializePage(byte[] data, int versionNumber)
 	{
 		boolean set = Page.serializer.get() == null;
@@ -319,8 +317,8 @@
 			stream.defaultWriteObject();
 		}
 
-		public void deserializePage(int id, String pageMapName, Page page,
-			ObjectInputStream stream) throws IOException, ClassNotFoundException
+		public void deserializePage(int id, String pageMapName, Page page, ObjectInputStream stream)
+			throws IOException, ClassNotFoundException
 		{
 			// get the page instance registry
 			IntHashMap<Page> pages = SecondLevelCacheSessionStore.getUsedPages(pageMapName);

Modified: wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/pagestore/DiskPageStore.java
URL: http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/pagestore/DiskPageStore.java?rev=718123&r1=718122&r2=718123&view=diff
==============================================================================
--- wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/pagestore/DiskPageStore.java (original)
+++ wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/pagestore/DiskPageStore.java Sun Nov 16 14:04:19 2008
@@ -385,6 +385,7 @@
 
 		sessionId = sessionId.replace('*', '_');
 		sessionId = sessionId.replace('/', '_');
+		sessionId = sessionId.replace(':', '_');
 
 		File sessionFolder = new File(storeFolder, sessionId);
 		if (create && sessionFolder.exists() == false)
@@ -705,7 +706,6 @@
 
 			if (data != null)
 			{
-				@SuppressWarnings("unchecked")
 				final Page ret = deserializePage(data, versionNumber);
 				return ret;
 			}
@@ -835,9 +835,12 @@
 			else
 			{
 				List<SerializedPage> pages = getPagesToSaveList(sessionId);
-				synchronized (pages)
+				if (pages != null)
 				{
-					flushPagesToSaveList(sessionId, pages);
+					synchronized (pages)
+					{
+						pages.clear();						
+					}
 					entry.unbind();
 				}
 				pagesToSaveAll.remove(sessionId);

Modified: wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/pagestore/FileChannelPool.java
URL: http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/pagestore/FileChannelPool.java?rev=718123&r1=718122&r2=718123&view=diff
==============================================================================
--- wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/pagestore/FileChannelPool.java (original)
+++ wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/pagestore/FileChannelPool.java Sun Nov 16 14:04:19 2008
@@ -83,7 +83,7 @@
 	 * @param createIfDoesNotExist
 	 *            in case the file does not exist this parameter determines if the file should be
 	 *            created
-	 * @return
+	 * @return file channel or null
 	 */
 	private FileChannel newFileChannel(String fileName, boolean createIfDoesNotExist)
 	{
@@ -159,7 +159,7 @@
 	 * 
 	 * @param fileName
 	 * @param createIfDoesNotExist
-	 * @return
+	 * @return file channel
 	 */
 	public synchronized FileChannel getFileChannel(String fileName, boolean createIfDoesNotExist)
 	{

Modified: wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/pagestore/PageWindowManager.java
URL: http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/pagestore/PageWindowManager.java?rev=718123&r1=718122&r2=718123&view=diff
==============================================================================
--- wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/pagestore/PageWindowManager.java (original)
+++ wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/pagestore/PageWindowManager.java Sun Nov 16 14:04:19 2008
@@ -179,7 +179,7 @@
 	 * @param pageId
 	 * @param versionNumber
 	 * @param ajaxVersionNumber
-	 * @return
+	 * @return window index
 	 */
 	private int getWindowIndex(int pageId, int versionNumber, int ajaxVersionNumber)
 	{
@@ -205,7 +205,7 @@
 	 * Increments the {@link #indexPointer}. If the maximum file size has been reached, the
 	 * {@link #indexPointer} is set to 0.
 	 * 
-	 * @return
+	 * @return new index pointer
 	 */
 	private int incrementIndexPointer()
 	{
@@ -225,7 +225,7 @@
 	 * previous page offset and adding the previous page size to it.
 	 * 
 	 * @param index
-	 * @return
+	 * @return window file offset
 	 */
 	private int getWindowFileOffset(int index)
 	{
@@ -346,7 +346,7 @@
 	 * 
 	 * @param index
 	 * @param size
-	 * @return
+	 * @return page window
 	 */
 	private PageWindowInternal allocatePageWindow(int index, int size)
 	{
@@ -445,7 +445,7 @@
 	 * @param versionNumber
 	 * @param ajaxVersionNumber
 	 * @param size
-	 * @return
+	 * @return page window
 	 */
 	public PageWindow createPageWindow(int pageId, int versionNumber, int ajaxVersionNumber,
 		int size)
@@ -560,7 +560,7 @@
 	 * Returns last n saved page windows.
 	 * 
 	 * @param count
-	 * @return
+	 * @return list of page windows
 	 */
 	public synchronized List<PageWindow> getLastPageWindows(int count)
 	{
@@ -608,7 +608,7 @@
 	/**
 	 * Returns the size of all saved pages
 	 * 
-	 * @return
+	 * @return total size
 	 */
 	public int getTotalSize()
 	{

Modified: wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/pagestore/SerializedPagesCache.java
URL: http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/pagestore/SerializedPagesCache.java?rev=718123&r1=718122&r2=718123&view=diff
==============================================================================
--- wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/pagestore/SerializedPagesCache.java (original)
+++ wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/pagestore/SerializedPagesCache.java Sun Nov 16 14:04:19 2008
@@ -128,7 +128,7 @@
 	/**
 	 * Store the serialized page in cache
 	 * 
-	 * @return
+	 * @return serialized page
 	 * @param sessionId
 	 * @param page
 	 * @param pagesList

Modified: wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/pagestore/SimpleSynchronousFilePageStore.java
URL: http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/pagestore/SimpleSynchronousFilePageStore.java?rev=718123&r1=718122&r2=718123&view=diff
==============================================================================
--- wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/pagestore/SimpleSynchronousFilePageStore.java (original)
+++ wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/pagestore/SimpleSynchronousFilePageStore.java Sun Nov 16 14:04:19 2008
@@ -100,7 +100,7 @@
 	 * @param pageId
 	 * @param versionNumber
 	 * @param ajaxVersionNumber
-	 * @return
+	 * @return page file
 	 */
 	private File getPageFile(File sessionDir, String pageMapName, int pageId, int versionNumber,
 		int ajaxVersionNumber)

Modified: wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/EmbeddedPortletHeaderResponse.java
URL: http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/EmbeddedPortletHeaderResponse.java?rev=718123&r1=718122&r2=718123&view=diff
==============================================================================
--- wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/EmbeddedPortletHeaderResponse.java (original)
+++ wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/EmbeddedPortletHeaderResponse.java Sun Nov 16 14:04:19 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/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/FilterRequestContext.java
URL: http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/FilterRequestContext.java?rev=718123&r1=718122&r2=718123&view=diff
==============================================================================
--- wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/FilterRequestContext.java (original)
+++ wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/FilterRequestContext.java Sun Nov 16 14:04:19 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/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletActionServletResponseWrapper.java
URL: http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletActionServletResponseWrapper.java?rev=718123&r1=718122&r2=718123&view=diff
==============================================================================
--- wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletActionServletResponseWrapper.java (original)
+++ wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletActionServletResponseWrapper.java Sun Nov 16 14:04:19 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/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletInvalidMarkupFilter.java
URL: http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletInvalidMarkupFilter.java?rev=718123&r1=718122&r2=718123&view=diff
==============================================================================
--- wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletInvalidMarkupFilter.java (original)
+++ wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletInvalidMarkupFilter.java Sun Nov 16 14:04:19 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/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletRenderServletResponseWrapper.java
URL: http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletRenderServletResponseWrapper.java?rev=718123&r1=718122&r2=718123&view=diff
==============================================================================
--- wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletRenderServletResponseWrapper.java (original)
+++ wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletRenderServletResponseWrapper.java Sun Nov 16 14:04:19 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/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletRequestContext.java
URL: http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletRequestContext.java?rev=718123&r1=718122&r2=718123&view=diff
==============================================================================
--- wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletRequestContext.java (original)
+++ wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletRequestContext.java Sun Nov 16 14:04:19 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/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletServletRequestWrapper.java
URL: http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletServletRequestWrapper.java?rev=718123&r1=718122&r2=718123&view=diff
==============================================================================
--- wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletServletRequestWrapper.java (original)
+++ wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletServletRequestWrapper.java Sun Nov 16 14:04:19 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/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletServletResponseWrapper.java
URL: http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletServletResponseWrapper.java?rev=718123&r1=718122&r2=718123&view=diff
==============================================================================
--- wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletServletResponseWrapper.java (original)
+++ wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/PortletServletResponseWrapper.java Sun Nov 16 14:04:19 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/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/WicketFilterPortletContext.java
URL: http://svn.apache.org/viewvc/wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/WicketFilterPortletContext.java?rev=718123&r1=718122&r2=718123&view=diff
==============================================================================
--- wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/WicketFilterPortletContext.java (original)
+++ wicket/sandbox/knopp/experimental/wicket/src/main/java/org/apache/wicket/protocol/http/portlet/WicketFilterPortletContext.java Sun Nov 16 14:04:19 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