org.apache.wicket.request.target.coding
Class HybridUrlCodingStrategy

java.lang.Object
  extended by org.apache.wicket.request.target.coding.AbstractRequestTargetUrlCodingStrategy
      extended by org.apache.wicket.request.target.coding.HybridUrlCodingStrategy
All Implemented Interfaces:
IMountableRequestTargetUrlCodingStrategy, IRequestTargetUrlCodingStrategy
Direct Known Subclasses:
IndexedHybridUrlCodingStrategy

public class HybridUrlCodingStrategy
extends AbstractRequestTargetUrlCodingStrategy

An URL coding strategy that encodes the mount point, page parameters and page instance information into the URL. The benefits compared to mounting page with BookmarkablePageRequestTargetUrlCodingStrategy are that the mount point is preserved even after invoking listener interfaces (thus you don't lose bookmarkability after clicking links) and that for ajax only pages the state is preserved on refresh.

The url with HybridUrlCodingStrategy looks like /mount/path/param1/value1.3. or /mount/path/param1/value1.3.2 where 3 is page Id and 2 is version number.

Also to preserve state on refresh with ajax-only pages the HybridUrlCodingStrategy does an immediate redirect after hitting bookmarkable URL, e.g. it immediately redirects from /mount/path to /mount/path.3 where 3 is the next page id. This preserves the page instance on subsequent page refresh.

Author:
Matej Knopp

Nested Class Summary
static class HybridUrlCodingStrategy.HybridBookmarkablePageRequestTarget
          BookmarkablePage request target that does a redirect after bookmarkable page was rendered (only if the bookmarkable page is stateful though)
protected static class HybridUrlCodingStrategy.PageInfo
          Possible string representation of PageInfo: pageId pageId.version pageMap (only if pageMap starts with a letter) .pageMap pageMap.pageId.version pageMap.pageId (only if pageMap name starts with a letter)
protected static class HybridUrlCodingStrategy.PageInfoExtraction
          Class that encapsulates HybridUrlCodingStrategy.PageInfo instance and the URL part prior the PageInfo part
 
Field Summary
static org.apache.wicket.request.target.coding.HybridUrlCodingStrategy.PageParametersMetaDataKey PAGE_PARAMETERS_META_DATA_KEY
          Meta data key to store PageParameters in page instance.
protected  java.lang.ref.WeakReference pageClassRef
          bookmarkable page class.
 
Constructor Summary
HybridUrlCodingStrategy(java.lang.String mountPath, java.lang.Class pageClass)
          Construct.
HybridUrlCodingStrategy(java.lang.String mountPath, java.lang.Class pageClass, boolean redirectOnBookmarkableRequest)
          Construct.
 
Method Summary
protected  java.lang.String addPageInfo(java.lang.String url, HybridUrlCodingStrategy.PageInfo pageInfo)
          Encodes the PageInfo part to the URL
protected  boolean alwaysRedirectWhenPageMapIsSpecified()
          Returns whether to redirect when there is pageMap specified in bookmarkable URL
 IRequestTarget decode(RequestParameters requestParameters)
          Gets the decoded request target.
 java.lang.CharSequence encode(IRequestTarget requestTarget)
          Gets the encoded url for the provided request target.
protected  HybridUrlCodingStrategy.PageInfoExtraction extractPageInfo(java.lang.String url)
          Extracts the PageInfo string.
protected  java.lang.String getBeginSeparator()
           
protected  java.lang.String getEndSeparator()
           
static PageParameters getInitialPagePageParameters(Page page)
           
protected  IRequestTarget handleExpiredPage(java.lang.String pageMapName, java.lang.Class pageClass, int trailingSlashesCount, boolean redirect)
          Handles the case where a non-bookmarkable url with a hybrid base refers to a page that is no longer in session.
protected  boolean isRedirectOnBookmarkableRequest()
          Returns whether after hitting bookmarkable url the request should be redirected to a hybrid URL.
 boolean matches(IRequestTarget requestTarget)
          Gets whether this mounter is applicable for the provided request target.
 boolean matches(java.lang.String path)
          Does given path match this mount? We match /mount/point or /mount/point/with/extra/path, but not /mount/pointXXX.
static void setInitialPageParameters(Page page, PageParameters pageParameters)
          Sets the initial page parameters for page instance.
 java.lang.String toString()
           
 
Methods inherited from class org.apache.wicket.request.target.coding.AbstractRequestTargetUrlCodingStrategy
appendParameters, decodeParameters, getMountPath, urlDecode, urlDecodePathComponent, urlDecodeQueryComponent, urlEncode, urlEncodePathComponent, urlEncodeQueryComponent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

pageClassRef

protected final java.lang.ref.WeakReference pageClassRef
bookmarkable page class.


PAGE_PARAMETERS_META_DATA_KEY

public static final org.apache.wicket.request.target.coding.HybridUrlCodingStrategy.PageParametersMetaDataKey PAGE_PARAMETERS_META_DATA_KEY
Meta data key to store PageParameters in page instance. This is used to save the PageParameters that were used to create the page instance so that later they can be used when generating page URL

Constructor Detail

HybridUrlCodingStrategy

public HybridUrlCodingStrategy(java.lang.String mountPath,
                               java.lang.Class pageClass,
                               boolean redirectOnBookmarkableRequest)
Construct.

Parameters:
mountPath -
pageClass -
redirectOnBookmarkableRequest - whether after hitting the page with URL in bookmarkable form it should be redirected to hybrid URL - needed for ajax to work properly after page refresh

HybridUrlCodingStrategy

public HybridUrlCodingStrategy(java.lang.String mountPath,
                               java.lang.Class pageClass)
Construct.

Parameters:
mountPath -
pageClass -
Method Detail

isRedirectOnBookmarkableRequest

protected boolean isRedirectOnBookmarkableRequest()
Returns whether after hitting bookmarkable url the request should be redirected to a hybrid URL. This is recommended for pages with Ajax.

Returns:

alwaysRedirectWhenPageMapIsSpecified

protected boolean alwaysRedirectWhenPageMapIsSpecified()
Returns whether to redirect when there is pageMap specified in bookmarkable URL

Returns:

decode

public IRequestTarget decode(RequestParameters requestParameters)
Description copied from interface: IRequestTargetUrlCodingStrategy
Gets the decoded request target.

Parameters:
requestParameters - the request parameters
Returns:
the decoded request target
See Also:
IRequestTargetUrlCodingStrategy.decode(org.apache.wicket.request.RequestParameters)

handleExpiredPage

protected IRequestTarget handleExpiredPage(java.lang.String pageMapName,
                                           java.lang.Class pageClass,
                                           int trailingSlashesCount,
                                           boolean redirect)
Handles the case where a non-bookmarkable url with a hybrid base refers to a page that is no longer in session. eg /context/hybrid-mount.0.23?wicket:interface=.... The default behavior is to throw a PageExpiredException. This method can be overwritten to, for example, return the user to a new instance of the bookmarkable page that was mounted using hybrid strategy - this, however, should only be used in cases where the page expects no page parameters because they are no longer available.

Parameters:
pageMapName - page map name this page is mounted in
pageClass - class of mounted page
trailingSlashesCount - count of trailing slsahes in the url
redirect - whether or not a redirect should be issued
Returns:
request target used to handle this situation

setInitialPageParameters

public static void setInitialPageParameters(Page page,
                                            PageParameters pageParameters)
Sets the initial page parameters for page instance. Use this only if you know what you are doing.

Parameters:
page -
pageParameters -

getInitialPagePageParameters

public static PageParameters getInitialPagePageParameters(Page page)
Parameters:
page -
Returns:

encode

public java.lang.CharSequence encode(IRequestTarget requestTarget)
Description copied from interface: IRequestTargetUrlCodingStrategy
Gets the encoded url for the provided request target. Typically, the result will be prepended with a protocol specific prefix. In a servlet environment, the prefix typically is the context-path + servlet path, eg mywebapp/myservletname.

Parameters:
requestTarget - the request target to encode
Returns:
the encoded url
See Also:
IRequestTargetUrlCodingStrategy.encode(org.apache.wicket.IRequestTarget)

matches

public boolean matches(IRequestTarget requestTarget)
Description copied from interface: IRequestTargetUrlCodingStrategy
Gets whether this mounter is applicable for the provided request target.

Parameters:
requestTarget - the request target
Returns:
whether this mounter is applicable for the provided request target
See Also:
IRequestTargetUrlCodingStrategy.matches(org.apache.wicket.IRequestTarget)

extractPageInfo

protected HybridUrlCodingStrategy.PageInfoExtraction extractPageInfo(java.lang.String url)
Extracts the PageInfo string.

Parameters:
url -
Returns:

getBeginSeparator

protected java.lang.String getBeginSeparator()

getEndSeparator

protected java.lang.String getEndSeparator()

addPageInfo

protected java.lang.String addPageInfo(java.lang.String url,
                                       HybridUrlCodingStrategy.PageInfo pageInfo)
Encodes the PageInfo part to the URL

Parameters:
url -
pageInfo -
Returns:

matches

public boolean matches(java.lang.String path)
Description copied from class: AbstractRequestTargetUrlCodingStrategy
Does given path match this mount? We match /mount/point or /mount/point/with/extra/path, but not /mount/pointXXX.

Specified by:
matches in interface IRequestTargetUrlCodingStrategy
Overrides:
matches in class AbstractRequestTargetUrlCodingStrategy
Returns:
true if matches, false otherwise
See Also:
AbstractRequestTargetUrlCodingStrategy.matches(java.lang.String)

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object


Copyright © 2004-2010 Apache Software Foundation. All Rights Reserved.