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, MixedParamHybridUrlCodingStrategy

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  WeakReference<Class<? extends Page>> pageClassRef
          bookmarkable page class.
 
Constructor Summary
HybridUrlCodingStrategy(String mountPath, Class<? extends Page> pageClass)
          Construct.
HybridUrlCodingStrategy(String mountPath, Class<? extends Page> pageClass, boolean redirectOnBookmarkableRequest)
          Construct.
 
Method Summary
protected  String addPageInfo(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.
 CharSequence encode(IRequestTarget requestTarget)
          Gets the encoded url for the provided request target.
protected  HybridUrlCodingStrategy.PageInfoExtraction extractPageInfo(String url)
          Extracts the PageInfo string.
protected  String getBeginSeparator()
           
protected  String getEndSeparator()
           
static PageParameters getInitialPagePageParameters(Page page)
           
protected  IRequestTarget handleExpiredPage(String pageMapName, Class<? extends Page> 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(String path, boolean caseSensitive)
          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.
 String toString()
           
protected  String urlDecodePathComponent(String value)
          Returns a decoded value of the given value (taken from a URL path section)
protected  String urlEncodePathComponent(String string)
          Url encodes a string that is mean for a URL path (e.g., between slashes)
 
Methods inherited from class org.apache.wicket.request.target.coding.AbstractRequestTargetUrlCodingStrategy
appendParameters, appendPathParameter, decodeParameters, getMountPath, urlDecode, urlDecodeQueryComponent, urlEncode, urlEncodeQueryComponent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

pageClassRef

protected final WeakReference<Class<? extends Page>> 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(String mountPath,
                               Class<? extends Page> 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(String mountPath,
                               Class<? extends Page> pageClass)
Construct.

Parameters:
mountPath -
pageClass -
Method Detail

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:
initial page parameters

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:
true if redirect on bookmarkable request

alwaysRedirectWhenPageMapIsSpecified

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

Returns:
true if always redirect when page map is specified

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(String pageMapName,
                                           Class<? extends Page> 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

encode

public 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)

urlEncodePathComponent

protected String urlEncodePathComponent(String string)
Description copied from class: AbstractRequestTargetUrlCodingStrategy
Url encodes a string that is mean for a URL path (e.g., between slashes)

Overrides:
urlEncodePathComponent in class AbstractRequestTargetUrlCodingStrategy
Parameters:
string - string to be encoded
Returns:
encoded string

urlDecodePathComponent

protected String urlDecodePathComponent(String value)
Description copied from class: AbstractRequestTargetUrlCodingStrategy
Returns a decoded value of the given value (taken from a URL path section)

Overrides:
urlDecodePathComponent in class AbstractRequestTargetUrlCodingStrategy
Returns:
Decodes the value

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(String url)
Extracts the PageInfo string.

Parameters:
url -
Returns:
extract page info

getBeginSeparator

protected String getBeginSeparator()
Returns:
begin separator

getEndSeparator

protected String getEndSeparator()
Returns:
end separator

addPageInfo

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

Parameters:
url -
pageInfo -
Returns:
URL

matches

public boolean matches(String path,
                       boolean caseSensitive)
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
caseSensitive - whether the strategy should treat path argument with case sensitivity or not
Returns:
true if matches, false otherwise
See Also:
AbstractRequestTargetUrlCodingStrategy.matches(String, boolean)

toString

public String toString()
Overrides:
toString in class Object
See Also:
Object.toString()


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