You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2013/06/13 11:48:14 UTC
[02/11] git commit: condition refactor for unit test before
refactoring
condition refactor for unit test before refactoring
Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/3da1d656
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/3da1d656
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/3da1d656
Branch: refs/heads/master
Commit: 3da1d656cd4c85efe0919d1a32c33b300ef35490
Parents: f5af56b
Author: Michael Mosmann <mi...@mosmann.de>
Authored: Wed Sep 26 22:09:58 2012 +0200
Committer: Michael Mosmann <mi...@mosmann.de>
Committed: Wed Sep 26 22:09:58 2012 +0200
----------------------------------------------------------------------
.../request/handler/render/WebPageRenderer.java | 205 ++++++++++---------
1 file changed, 110 insertions(+), 95 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/wicket/blob/3da1d656/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 46ee1b4..66b1224 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
@@ -177,114 +177,129 @@ public class WebPageRenderer extends PageRenderer
// if there is saved response for this URL render it
bufferedResponse.writeTo((WebResponse)requestCycle.getResponse());
}
- else if (getRedirectPolicy() == RedirectPolicy.NEVER_REDIRECT ||
- (isOnePassRender() && isAjax == false && getRedirectPolicy() != RedirectPolicy.ALWAYS_REDIRECT) //
- ||
- (!isAjax //
- &&
- (targetUrl.equals(currentUrl) && !getPageProvider().isNewPageInstance() && !getPage().isPageStateless()) //
- || (targetUrl.equals(currentUrl) && isRedirectToRender()) //
- ) //
- || shouldPreserveClientUrl) //
- {
- // if the policy is never to redirect
- // or one pass render mode is on
- // or the targetUrl matches current url and the page is not stateless
- // or the targetUrl matches current url, page is stateless but it's redirect-to-render
- // or the request determines that the current url should be preserved
- // just render the page
- BufferedWebResponse response = renderPage(currentUrl, requestCycle);
- if (response != null)
- {
- response.writeTo((WebResponse)requestCycle.getResponse());
- }
- }
- else if (getRedirectPolicy() == RedirectPolicy.ALWAYS_REDIRECT //
- ||
- isRedirectToRender() //
- || (isAjax && targetUrl.equals(currentUrl)))
- {
- // if target URL is different
- // and render policy is always-redirect or it's redirect-to-render
- redirectTo(targetUrl, requestCycle);
- }
- else if (!targetUrl.equals(currentUrl) //
- &&
- (getPageProvider().isNewPageInstance() || (isSessionTemporary() && getPage().isPageStateless())))
- {
- // 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
-
- // alternatively if URLs are different and we have a page class and not an instance we
- // can redirect to the url which will instantiate the instance of us
-
- // 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)
- redirectTo(targetUrl, requestCycle);
- }
- else
- {
- if (isRedirectToBuffer() == 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'",
- Application.get().getRequestCycleSettings().getRenderStrategy(),
- isAjax, getRedirectPolicy(), currentUrl, targetUrl, getPageProvider().isNewPageInstance(),
- getPage().isPageStateless(), isSessionTemporary());
- logger.debug("Falling back to Redirect_To_Buffer render strategy because none of the conditions " +
- "matched. Details: " + details);
- }
-
- // redirect to buffer
- BufferedWebResponse response = renderPage(targetUrl, requestCycle);
+ else {
+ RedirectPolicy redirectPolicy = getRedirectPolicy();
- if (response == null)
- {
- return;
- }
+ boolean onePassRender = isOnePassRender();
+ boolean isRedirectToRender = isRedirectToRender();
- // check if the url hasn't changed after page has been rendered
- // (i.e. the stateless flag might have changed which could result in different page url)
- Url targetUrl2 = requestCycle.mapUrlFor(getRenderPageRequestHandler());
+ boolean targetEqualsCurrentUrl = targetUrl.equals(currentUrl);
+ boolean isNewPageInstance = getPageProvider().isNewPageInstance();
+ boolean isPageStateless = getPage().isPageStateless();
- if (targetUrl.getSegments().equals(targetUrl2.getSegments()) == false)
+ if (shouldRenderPageAndWriteResponse(isAjax, onePassRender, isRedirectToRender, redirectPolicy, shouldPreserveClientUrl, targetEqualsCurrentUrl, isNewPageInstance, isPageStateless)) //
{
- // the amount of segments is different - generated relative URLs will not work, we
- // need to rerender the page. This shouldn't happen, but in theory it can - with
- // RequestHandlerEncoders that produce different URLs with different amount of
- // segments for stateless and stateful pages
- response = renderPage(targetUrl2, requestCycle);
+ BufferedWebResponse response = renderPage(currentUrl, requestCycle);
+ if (response != null)
+ {
+ response.writeTo((WebResponse)requestCycle.getResponse());
+ }
}
-
- if (currentUrl.equals(targetUrl2))
+ else if (redirectPolicy == RedirectPolicy.ALWAYS_REDIRECT //
+ ||
+ isRedirectToRender //
+ || (isAjax && targetEqualsCurrentUrl))
{
- // no need to redirect when both urls are exactly the same
- response.writeTo((WebResponse)requestCycle.getResponse());
+ // if target URL is different
+ // and render policy is always-redirect or it's redirect-to-render
+ redirectTo(targetUrl, requestCycle);
}
- // if page is still stateless after render
- else if (getPage().isPageStateless() && !enableRedirectForStatelessPage())
+ else if (!targetEqualsCurrentUrl //
+ &&
+ (isNewPageInstance || (isSessionTemporary() && isPageStateless)))
{
- // we don't want the redirect to happen for stateless page
- // example:
- // when a normal mounted stateful page is hit at /mount/point
- // wicket renders the page to buffer and redirects to /mount/point?12
- // but for stateless page the redirect is not necessary
- // also for listener interface on stateful page we want to redirect
- // after the listener is invoked, but on stateless page the user
- // must ask for redirect explicitly
- response.writeTo((WebResponse)requestCycle.getResponse());
+ // 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
+
+ // alternatively if URLs are different and we have a page class and not an instance we
+ // can redirect to the url which will instantiate the instance of us
+
+ // 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)
+ redirectTo(targetUrl, requestCycle);
}
else
{
- storeBufferedResponse(targetUrl2, response);
+ if (isRedirectToBuffer() == 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'",
+ Application.get().getRequestCycleSettings().getRenderStrategy(),
+ isAjax, redirectPolicy, currentUrl, targetUrl, isNewPageInstance,
+ isPageStateless, isSessionTemporary());
+ logger.debug("Falling back to Redirect_To_Buffer render strategy because none of the conditions " +
+ "matched. Details: " + details);
+ }
+
+ // redirect to buffer
+ BufferedWebResponse response = renderPage(targetUrl, requestCycle);
+
+ if (response == null)
+ {
+ return;
+ }
- redirectTo(targetUrl2, requestCycle);
+ // check if the url hasn't changed after page has been rendered
+ // (i.e. the stateless flag might have changed which could result in different page url)
+ Url targetUrl2 = requestCycle.mapUrlFor(getRenderPageRequestHandler());
+
+ if (targetUrl.getSegments().equals(targetUrl2.getSegments()) == false)
+ {
+ // the amount of segments is different - generated relative URLs will not work, we
+ // need to rerender the page. This shouldn't happen, but in theory it can - with
+ // RequestHandlerEncoders that produce different URLs with different amount of
+ // segments for stateless and stateful pages
+ response = renderPage(targetUrl2, requestCycle);
+ }
+
+ if (currentUrl.equals(targetUrl2))
+ {
+ // no need to redirect when both urls are exactly the same
+ response.writeTo((WebResponse)requestCycle.getResponse());
+ }
+ // if page is still stateless after render
+ else if (isPageStateless && !enableRedirectForStatelessPage())
+ {
+ // we don't want the redirect to happen for stateless page
+ // example:
+ // when a normal mounted stateful page is hit at /mount/point
+ // wicket renders the page to buffer and redirects to /mount/point?12
+ // but for stateless page the redirect is not necessary
+ // also for listener interface on stateful page we want to redirect
+ // after the listener is invoked, but on stateless page the user
+ // must ask for redirect explicitly
+ response.writeTo((WebResponse)requestCycle.getResponse());
+ }
+ else
+ {
+ storeBufferedResponse(targetUrl2, response);
+
+ redirectTo(targetUrl2, requestCycle);
+ }
}
}
}
+
+ // if the policy is never to redirect
+ // or one pass render mode is on
+ // or the targetUrl matches current url and the page is not stateless
+ // or the targetUrl matches current url, page is stateless but it's redirect-to-render
+ // or the request determines that the current url should be preserved
+ // just render the page
+ protected static boolean shouldRenderPageAndWriteResponse(boolean ajax, boolean onePassRender, boolean redirectToRender, RedirectPolicy redirectPolicy, boolean shouldPreserveClientUrl, boolean targetEqualsCurrentUrl, boolean newPageInstance, boolean pageStateless) {
+ return redirectPolicy == RedirectPolicy.NEVER_REDIRECT ||
+ (onePassRender && ajax == false && redirectPolicy != RedirectPolicy.ALWAYS_REDIRECT) //
+ ||
+ (!ajax //
+ &&
+ (targetEqualsCurrentUrl && !newPageInstance && !pageStateless) //
+ || (targetEqualsCurrentUrl && redirectToRender) //
+ ) //
+ || shouldPreserveClientUrl;
+ }
}