Updated Branches:
  refs/heads/master 29b9422ad -> 4ab506431

formatted

Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/1c8dc6f7
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/1c8dc6f7
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/1c8dc6f7

Branch: refs/heads/master
Commit: 1c8dc6f77027a3b3bcc68e24b427daa7effd2aa2
Parents: 29b9422
Author: svenmeier <s...@meiers.net>
Authored: Thu Aug 8 11:43:23 2013 +0200
Committer: svenmeier <s...@meiers.net>
Committed: Thu Aug 8 11:43:23 2013 +0200

----------------------------------------------------------------------
 .../request/handler/render/WebPageRenderer.java | 135 +++++++++----------
 1 file changed, 62 insertions(+), 73 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/1c8dc6f7/wicket-core/src/main/java/org/apache/wicket/request/handler/render/WebPageRenderer.java
----------------------------------------------------------------------
diff --git 
a/wicket-core/src/main/java/org/apache/wicket/request/handler/render/WebPageRenderer.java
 
b/wicket-core/src/main/java/org/apache/wicket/request/handler/render/WebPageRenderer.java
index c3899ec..ad39922 100644
--- 
a/wicket-core/src/main/java/org/apache/wicket/request/handler/render/WebPageRenderer.java
+++ 
b/wicket-core/src/main/java/org/apache/wicket/request/handler/render/WebPageRenderer.java
@@ -107,7 +107,7 @@ public class WebPageRenderer extends PageRenderer
                }
 
                // keep the original response
-               final WebResponse originalResponse = (WebResponse) 
requestCycle.getResponse();
+               final WebResponse originalResponse = 
(WebResponse)requestCycle.getResponse();
 
                // buffered web response for page
                BufferedWebResponse response = new 
BufferedWebResponse(originalResponse);
@@ -123,10 +123,11 @@ public class WebPageRenderer extends PageRenderer
                        if (scheduled == null && 
requestCycle.getRequestHandlerScheduledAfterCurrent() != null)
                        {
                                // This is a special case.
-                               // During page render another request handler 
got scheduled and will want to overwrite
-                               // the response, so we need to let it.
-                               // Just preserve the meta data headers
-                               originalResponse.reset(); // clear the initial 
actions because they are already copied into the new response's actions
+                               // During page render another request handler 
got scheduled and will want to
+                               // overwrite the response, so we need to let it.
+                               // Just preserve the meta data headers. Clear 
the initial actions because they are
+                               // already copied into the new response's 
actions
+                               originalResponse.reset();
                                response.writeMetaData(originalResponse);
                                return null;
                        }
@@ -191,15 +192,18 @@ public class WebPageRenderer extends PageRenderer
 
                boolean isAjax = isAjax(requestCycle);
 
-               boolean shouldPreserveClientUrl = 
((WebRequest)requestCycle.getRequest()).shouldPreserveClientUrl();
+               boolean shouldPreserveClientUrl = 
((WebRequest)requestCycle.getRequest())
+                       .shouldPreserveClientUrl();
 
                if (bufferedResponse != null)
                {
-                       logger.warn("The Buffered response should be handled by 
BufferedResponseRequestHandler");
+                       logger
+                               .warn("The Buffered response should be handled 
by BufferedResponseRequestHandler");
                        // if there is saved response for this URL render it
                        
bufferedResponse.writeTo((WebResponse)requestCycle.getResponse());
                }
-               else {
+               else
+               {
                        RedirectPolicy redirectPolicy = getRedirectPolicy();
 
                        boolean onePassRender = isOnePassRender();
@@ -210,7 +214,9 @@ public class WebPageRenderer extends PageRenderer
                        boolean isNewPageInstance = 
getPageProvider().isNewPageInstance();
                        boolean isPageStateless = getPage().isPageStateless();
 
-                       if (shouldRenderPageAndWriteResponse(isAjax, 
onePassRender, isRedirectToRender, redirectPolicy, shouldPreserveClientUrl, 
targetEqualsCurrentUrl, isNewPageInstance, isPageStateless)) //
+                       if (shouldRenderPageAndWriteResponse(isAjax, 
onePassRender, isRedirectToRender,
+                               redirectPolicy, shouldPreserveClientUrl, 
targetEqualsCurrentUrl, isNewPageInstance,
+                               isPageStateless)) //
                        {
                                BufferedWebResponse response = 
renderPage(currentUrl, requestCycle);
                                if (response != null)
@@ -218,30 +224,36 @@ public class WebPageRenderer extends PageRenderer
                                        
response.writeTo((WebResponse)requestCycle.getResponse());
                                }
                        }
-                       else {
+                       else
+                       {
                                boolean sessionTemporary = isSessionTemporary();
-                               if (shouldRedirectToTargetUrl(isAjax, 
redirectPolicy, isRedirectToRender, targetEqualsCurrentUrl, isNewPageInstance, 
isPageStateless, sessionTemporary))
+                               if (shouldRedirectToTargetUrl(isAjax, 
redirectPolicy, isRedirectToRender,
+                                       targetEqualsCurrentUrl, 
isNewPageInstance, isPageStateless, sessionTemporary))
                                {
                                        redirectTo(targetUrl, requestCycle);
 
-                                       // note: if we had session here we 
would render the page to buffer and then redirect to
-                                       // URL generated *after* page has been 
rendered (the statelessness may change during
-                                       // render). this would save one 
redirect because now we have to render to URL generated
-                                       // *before* page is rendered, render 
the page, get URL after render and if the URL is
-                                       // different (meaning page is not 
stateless), save the buffer and redirect again (which
-                                       // is pretty much what the next step 
does)
+                                       // note: if we had session here we 
would render the page to buffer and then
+                                       // redirect to URL generated *after* 
page has been rendered (the statelessness
+                                       // may change during render). this 
would save one redirect because now we have
+                                       // to render to URL generated *before* 
page is rendered, render the page, get
+                                       // URL after render and if the URL is 
different (meaning page is not stateless),
+                                       // save the buffer and redirect again 
(which is pretty much what the next step
+                                       // does)
                                }
                                else
                                {
                                        if (redirectToBuffer == false && 
logger.isDebugEnabled())
                                        {
-                                               String details = 
String.format("redirect strategy: '%s', isAjax: '%s', redirect policy: '%s', " +
-                                                               "current url: 
'%s', target url: '%s', is new: '%s', is stateless: '%s', is temporary: '%s'",
+                                               String details = String
+                                                       .format(
+                                                               "redirect 
strategy: '%s', isAjax: '%s', redirect policy: '%s', "
+                                                                       + 
"current url: '%s', target url: '%s', is new: '%s', is stateless: '%s', is 
temporary: '%s'",
                                                                
Application.get().getRequestCycleSettings().getRenderStrategy(),
                                                                isAjax, 
redirectPolicy, currentUrl, targetUrl, isNewPageInstance,
-                                                                               
isPageStateless, sessionTemporary);
-                                               logger.debug("Falling back to 
Redirect_To_Buffer render strategy because none of the conditions " +
-                                                               "matched. 
Details: " + details);
+                                                               
isPageStateless, sessionTemporary);
+                                               logger
+                                                       .debug("Falling back to 
Redirect_To_Buffer render strategy because none of the conditions "
+                                                               + "matched. 
Details: " + details);
                                        }
 
                                        // force creation of possible stateful 
page to get the final target url
@@ -286,30 +298,17 @@ public class WebPageRenderer extends PageRenderer
                }
        }
 
-       // if
-       //              render policy is always-redirect
-       //      or
-       //              it's redirect-to-render
-       //      or
-       //              its ajax and the targetUrl matches current url
-       //      or
-       //              targetUrl DONT matches current url and
-       //                              is new page instance
-       //                      or
-       //                              session is temporary and page is 
stateless
-       // just redirect
-
-       protected boolean shouldRedirectToTargetUrl(boolean ajax, 
RedirectPolicy redirectPolicy, boolean redirectToRender, boolean 
targetEqualsCurrentUrl, boolean newPageInstance, boolean pageStateless,boolean 
sessionTemporary) {
+       /**
+        * Should the client be redirected to target url.
+        */
+       protected boolean shouldRedirectToTargetUrl(boolean ajax, 
RedirectPolicy redirectPolicy,
+               boolean redirectToRender, boolean targetEqualsCurrentUrl, 
boolean newPageInstance,
+               boolean pageStateless, boolean sessionTemporary)
+       {
                return alwaysRedirect(redirectPolicy) //
-                                               ||
-                                               redirectToRender //
-                                               ||
-                                               (ajax && targetEqualsCurrentUrl)
-                                               ||
-                                               (!targetEqualsCurrentUrl //
-                                                       &&
-                                                       (newPageInstance || 
(sessionTemporary && pageStateless))
-                                               );
+                       || redirectToRender //
+                       || (ajax && targetEqualsCurrentUrl) || 
(!targetEqualsCurrentUrl //
+                       && (newPageInstance || (sessionTemporary && 
pageStateless)));
                // if target URL is different and session is temporary and page 
is stateless
                // this is special case when page is stateless but there is no 
session so we can't
                // render it to buffer
@@ -318,46 +317,36 @@ public class WebPageRenderer extends PageRenderer
                // can redirect to the url which will instantiate the instance 
of us
        }
 
-       // if
-       //              the policy is never to redirect
-       //      or
-       //              its NOT ajax and
-       //                              one pass render mode is on and NOT 
forced to redirect
-       //                      or
-       //                              the targetUrl matches current url and 
page is NOT stateless and NOT a new instance
-       //      or
-       //              the targetUrl matches current url and it's 
redirect-to-render
-       //      or
-       //      the request determines that the current url should be preserved
-       //      just render the page
-       protected boolean shouldRenderPageAndWriteResponse(boolean ajax, 
boolean onePassRender, boolean redirectToRender, RedirectPolicy redirectPolicy, 
boolean shouldPreserveClientUrl, boolean targetEqualsCurrentUrl, boolean 
newPageInstance, boolean pageStateless) {
+       /**
+        * Should the page be rendered immediately.
+        */
+       protected boolean shouldRenderPageAndWriteResponse(boolean ajax, 
boolean onePassRender,
+               boolean redirectToRender, RedirectPolicy redirectPolicy, 
boolean shouldPreserveClientUrl,
+               boolean targetEqualsCurrentUrl, boolean newPageInstance, 
boolean pageStateless)
+       {
                return neverRedirect(redirectPolicy)
-                       ||
-                       (!ajax &&
-                               (
-                                       (onePassRender && 
notForcedRedirect(redirectPolicy))
-                                       ||
-                                       (targetEqualsCurrentUrl && 
notNewAndNotStatelessPage(newPageInstance, pageStateless)))
-                               )
-                       ||
-                       (targetEqualsCurrentUrl && redirectToRender)
-                       ||
-                       shouldPreserveClientUrl;
+                       || (!ajax && ((onePassRender && 
notForcedRedirect(redirectPolicy)) || (targetEqualsCurrentUrl && 
notNewAndNotStatelessPage(
+                               newPageInstance, pageStateless)))) || 
(targetEqualsCurrentUrl && redirectToRender)
+                       || shouldPreserveClientUrl;
        }
 
-       private static boolean notNewAndNotStatelessPage(boolean 
newPageInstance, boolean pageStateless) {
+       private static boolean notNewAndNotStatelessPage(boolean 
newPageInstance, boolean pageStateless)
+       {
                return !newPageInstance && !pageStateless;
        }
 
-       private static boolean neverRedirect(RedirectPolicy redirectPolicy) {
+       private static boolean neverRedirect(RedirectPolicy redirectPolicy)
+       {
                return redirectPolicy == RedirectPolicy.NEVER_REDIRECT;
        }
 
-       private static boolean alwaysRedirect(RedirectPolicy redirectPolicy) {
+       private static boolean alwaysRedirect(RedirectPolicy redirectPolicy)
+       {
                return redirectPolicy == RedirectPolicy.ALWAYS_REDIRECT;
        }
 
-       private static boolean notForcedRedirect(RedirectPolicy redirectPolicy) 
{
+       private static boolean notForcedRedirect(RedirectPolicy redirectPolicy)
+       {
                return !alwaysRedirect(redirectPolicy);
        }
 

Reply via email to