org.apache.wicket.protocol.http.request
Class WebRequestCodingStrategy

java.lang.Object
  extended by org.apache.wicket.protocol.http.request.WebRequestCodingStrategy
All Implemented Interfaces:
IRequestCodingStrategy, IRequestTargetMounter, IRequestTargetMountsInfo
Direct Known Subclasses:
UrlCompressingWebCodingStrategy

public class WebRequestCodingStrategy
extends Object
implements IRequestCodingStrategy, IRequestTargetMountsInfo

Request parameters factory implementation that uses http request parameters and path info to construct the request parameters object.

Author:
Eelco Hillenius, Jonathan Locke

Nested Class Summary
static class WebRequestCodingStrategy.Settings
          Various settings used to configure this strategy
 
Field Summary
static String BEHAVIOR_ID_PARAMETER_NAME
          AJAX query parameter name
static String BOOKMARKABLE_PAGE_PARAMETER_NAME
          Parameter name used all over the place
static String DEFAULT_PAGEMAP_NAME
          Url name of the default pagemap When we encode the default pagemap name in a url we cannot always use null or "" because it breaks urls which are encoded with /param1/value1/ eg /product/14/wicket:pageMapName/ split on / will split into {product,14,wicket:pageMapName}
static String IGNORE_IF_NOT_ACTIVE_PARAMETER_NAME
          Parameter name that tells decode to ignore this request if the page+version encoded in the url is not on top of the stack.
static String INTERFACE_PARAMETER_NAME
          Name of interface target query parameter
static String NAME_SPACE
          Name of interface target query parameter
static String PAGEMAP
          Pagemap parameter constant
static String RESOURCES_PATH_PREFIX
          The URL path prefix expected for (so called) resources (not html pages).
 
Constructor Summary
WebRequestCodingStrategy()
          Construct.
WebRequestCodingStrategy(WebRequestCodingStrategy.Settings settings)
          Construct.
 
Method Summary
protected  void addBookmarkablePageParameters(Request request, RequestParameters parameters)
          Adds bookmarkable page related parameters (page alias and optionally page parameters).
 void addIgnoreMountPath(String path)
          Partly unmounts/ignores a path that normally would map to another mount path.
protected  void addInterfaceParameters(Request request, RequestParameters parameters)
          Adds page related parameters (path and pagemap and optionally version and interface).
static void addInterfaceParameters(String interfaceParameter, RequestParameters parameters)
          Analyzes the passed in interfaceParameter for the relevant parts and puts the parts as parameters in the provided request parameters object.
protected  void addResourceParameters(Request request, RequestParameters parameters)
          Adds (shared) resource related parameters (resource key).
 RequestParameters decode(Request request)
          Analyze the request and create a corresponding request parameters object for it.
static String decodePageMapName(String pageMapName)
          Undoes the effect of encodePageMapName(String)
protected  String doEncode(RequestCycle requestCycle, IRequestTarget requestTarget)
          In case you are using custom targets that are not part of the default target hierarchy, you need to override this method, which will be called after the defaults have been tried.
 CharSequence encode(CharSequence url)
          Returns the given url encoded.
protected  CharSequence encode(RequestCycle requestCycle, IBookmarkablePageRequestTarget requestTarget)
          Encode a page class target.
protected  CharSequence encode(RequestCycle requestCycle, IListenerInterfaceRequestTarget requestTarget)
          Encode a listener interface target.
protected  CharSequence encode(RequestCycle requestCycle, IPageRequestTarget requestTarget)
          Encode a page target.
 CharSequence encode(RequestCycle requestCycle, IRequestTarget requestTarget)
          Encode the given request target.
protected  CharSequence encode(RequestCycle requestCycle, ISharedResourceRequestTarget requestTarget)
          Encode a shared resource target.
protected  CharSequence encode(RequestCycle requestCycle, PageReferenceRequestTarget requestTarget)
          Encode a pageid request target.
static String encodePageMapName(String pageMapName)
          Makes page map name url safe.
protected  IRequestTargetUrlCodingStrategy getMountEncoder(IRequestTarget requestTarget)
          Gets the mount encoder for the given request target if any.
protected  String getRequestPath(Request request)
          Gets the request info path.
 IRequestTargetUrlCodingStrategy[] listMounts()
          List the mounts that are known to the implementing mounter.
 void mount(IRequestTargetUrlCodingStrategy encoder)
          Mounts a request target with the given path.
 CharSequence pathForTarget(IRequestTarget requestTarget)
          Gets the url that the provided request target conforms to.
 String rewriteStaticRelativeUrl(String string)
          Rewrites relative paths found in static markup attributes (src,href,background) of wicket pages.
 IRequestTarget targetForRequest(RequestParameters requestParameters)
          Gets the request target that conforms to the given request parameters.
 void unmount(String path)
          Unmounts a request target.
 IRequestTargetUrlCodingStrategy urlCodingStrategyForPath(String path)
          Gets the encoder that was mounted on the provided path if any.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NAME_SPACE

public static final String NAME_SPACE
Name of interface target query parameter

See Also:
Constant Field Values

INTERFACE_PARAMETER_NAME

public static final String INTERFACE_PARAMETER_NAME
Name of interface target query parameter

See Also:
Constant Field Values

BEHAVIOR_ID_PARAMETER_NAME

public static final String BEHAVIOR_ID_PARAMETER_NAME
AJAX query parameter name

See Also:
Constant Field Values

BOOKMARKABLE_PAGE_PARAMETER_NAME

public static final String BOOKMARKABLE_PAGE_PARAMETER_NAME
Parameter name used all over the place

See Also:
Constant Field Values

PAGEMAP

public static final String PAGEMAP
Pagemap parameter constant

See Also:
Constant Field Values

DEFAULT_PAGEMAP_NAME

public static final String DEFAULT_PAGEMAP_NAME
Url name of the default pagemap When we encode the default pagemap name in a url we cannot always use null or "" because it breaks urls which are encoded with /param1/value1/ eg /product/14/wicket:pageMapName/ split on / will split into {product,14,wicket:pageMapName}

See Also:
Constant Field Values

RESOURCES_PATH_PREFIX

public static final String RESOURCES_PATH_PREFIX
The URL path prefix expected for (so called) resources (not html pages).

See Also:
Constant Field Values

IGNORE_IF_NOT_ACTIVE_PARAMETER_NAME

public static final String IGNORE_IF_NOT_ACTIVE_PARAMETER_NAME
Parameter name that tells decode to ignore this request if the page+version encoded in the url is not on top of the stack. The value of this parameter is not important, it simply has to be present to enable the behavior

See Also:
Constant Field Values
Constructor Detail

WebRequestCodingStrategy

public WebRequestCodingStrategy()
Construct.


WebRequestCodingStrategy

public WebRequestCodingStrategy(WebRequestCodingStrategy.Settings settings)
Construct.

Parameters:
settings -
Method Detail

decode

public RequestParameters decode(Request request)
Description copied from interface: IRequestCodingStrategy
Analyze the request and create a corresponding request parameters object for it.

Specified by:
decode in interface IRequestCodingStrategy
Parameters:
request - the incoming request
Returns:
a request parameters object that corresponds to the request
See Also:
IRequestCodingStrategy.decode(org.apache.wicket.Request)

encode

public CharSequence encode(RequestCycle requestCycle,
                           IRequestTarget requestTarget)
Encode the given request target. If a mount is found, that mounted url will be returned. Otherwise, one of the delegation methods will be called. In case you are using custom targets that are not part of the default target hierarchy, you need to override doEncode(RequestCycle, IRequestTarget), which will be called after the defaults have been tried. When that doesn't provide a url either, an exception will be thrown saying that encoding could not be done.

Specified by:
encode in interface IRequestCodingStrategy
Parameters:
requestCycle - the current request cycle (for efficient access)
requestTarget - the request target
Returns:
the url to the provided target
See Also:
IRequestCodingStrategy.encode(org.apache.wicket.RequestCycle, org.apache.wicket.IRequestTarget)

encode

public CharSequence encode(CharSequence url)
Returns the given url encoded.

Parameters:
url - The URL to encode
Returns:
The encoded url

listMounts

public IRequestTargetUrlCodingStrategy[] listMounts()
Description copied from interface: IRequestTargetMountsInfo
List the mounts that are known to the implementing mounter.

Specified by:
listMounts in interface IRequestTargetMountsInfo
Returns:
the mounts that are known to the implementing mounter
See Also:
IRequestTargetMountsInfo.listMounts()

urlCodingStrategyForPath

public IRequestTargetUrlCodingStrategy urlCodingStrategyForPath(String path)
Description copied from interface: IRequestTargetMounter
Gets the encoder that was mounted on the provided path if any.

Specified by:
urlCodingStrategyForPath in interface IRequestTargetMounter
Parameters:
path - the path
Returns:
The encoder/decoder that was mounted on the provided path, if any
See Also:
IRequestTargetMounter.urlCodingStrategyForPath(java.lang.String)

mount

public void mount(IRequestTargetUrlCodingStrategy encoder)
Description copied from interface: IRequestTargetMounter
Mounts a request target with the given path.

Specified by:
mount in interface IRequestTargetMounter
Parameters:
encoder - The strategy to use for encoding and decoding urls
See Also:
IRequestTargetMounter.mount(org.apache.wicket.request.target.coding.IRequestTargetUrlCodingStrategy)

addIgnoreMountPath

public void addIgnoreMountPath(String path)
Description copied from interface: IRequestTargetMounter
Partly unmounts/ignores a path that normally would map to another mount path. Like mount("/mypage", MyPage.class); and then "/mypage/arealdir" should be ignored. This can be done by calling unMount("/mypage/arealdir");

Specified by:
addIgnoreMountPath in interface IRequestTargetMounter
Parameters:
path - the path that should be ignored.
See Also:
IRequestTargetMounter.addIgnoreMountPath(String)

pathForTarget

public CharSequence pathForTarget(IRequestTarget requestTarget)
Description copied from interface: IRequestTargetMounter
Gets the url that the provided request target conforms to.

Specified by:
pathForTarget in interface IRequestTargetMounter
Parameters:
requestTarget - the request target
Returns:
The url that the provided request target conforms to
See Also:
IRequestTargetMounter.pathForTarget(org.apache.wicket.IRequestTarget)

targetForRequest

public IRequestTarget targetForRequest(RequestParameters requestParameters)
Description copied from interface: IRequestTargetMounter
Gets the request target that conforms to the given request parameters.

Specified by:
targetForRequest in interface IRequestTargetMounter
Parameters:
requestParameters - the request parameters
Returns:
the request target or null if nothing was mounted with the given request parameters
See Also:
IRequestTargetMounter.targetForRequest(org.apache.wicket.request.RequestParameters)

unmount

public void unmount(String path)
Description copied from interface: IRequestTargetMounter
Unmounts a request target.

Specified by:
unmount in interface IRequestTargetMounter
Parameters:
path - the path to unmount
See Also:
IRequestTargetMounter.unmount(java.lang.String)

addBookmarkablePageParameters

protected void addBookmarkablePageParameters(Request request,
                                             RequestParameters parameters)
Adds bookmarkable page related parameters (page alias and optionally page parameters). Any bookmarkable page alias mount will override this method; hence if a mount is found, this method will not be called. If you override this method to behave differently then encode(RequestCycle, IBookmarkablePageRequestTarget) should also be overridden to be in sync with that behavior.

Parameters:
request - the incoming request
parameters - the parameters object to set the found values on

addInterfaceParameters

protected void addInterfaceParameters(Request request,
                                      RequestParameters parameters)
Adds page related parameters (path and pagemap and optionally version and interface). If you override this method to behave different then also encode(RequestCycle, IListenerInterfaceRequestTarget) should be overridden to be in sync with that behavior.

Parameters:
request - the incoming request
parameters - the parameters object to set the found values on

addInterfaceParameters

public static void addInterfaceParameters(String interfaceParameter,
                                          RequestParameters parameters)
Analyzes the passed in interfaceParameter for the relevant parts and puts the parts as parameters in the provided request parameters object.

Parameters:
interfaceParameter - The format of the interfaceParameter is: page-map-name:path:version:interface:behaviourId:urlDepth
parameters - parameters object to set the found parts in

addResourceParameters

protected void addResourceParameters(Request request,
                                     RequestParameters parameters)
Adds (shared) resource related parameters (resource key). Any shared resource key mount will override this method; hence if a mount is found, this method will not be called. If you override this method to behave different then also encode(RequestCycle, ISharedResourceRequestTarget) should be overridden to be in sync with that behavior.

Parameters:
request - the incoming request
parameters - the parameters object to set the found values on

doEncode

protected String doEncode(RequestCycle requestCycle,
                          IRequestTarget requestTarget)
In case you are using custom targets that are not part of the default target hierarchy, you need to override this method, which will be called after the defaults have been tried. When this doesn't provide a url either (returns null), null will be returned by the encode method.

Parameters:
requestCycle - the current request cycle (for efficient access)
requestTarget - the request target
Returns:
the url to the provided target, as a relative path from the filter root.

encode

protected CharSequence encode(RequestCycle requestCycle,
                              IBookmarkablePageRequestTarget requestTarget)
Encode a page class target. If you override this method to behave different then also addBookmarkablePageParameters(Request, RequestParameters) should be overridden to be in sync with that behavior.

Parameters:
requestCycle - the current request cycle
requestTarget - the target to encode
Returns:
the encoded url

encode

protected CharSequence encode(RequestCycle requestCycle,
                              ISharedResourceRequestTarget requestTarget)
Encode a shared resource target. If you override this method to behave different then also addResourceParameters(Request, RequestParameters) should be overridden to be in sync with that behavior.

Parameters:
requestCycle - the current request cycle
requestTarget - the target to encode
Returns:
the encoded url

encode

protected CharSequence encode(RequestCycle requestCycle,
                              PageReferenceRequestTarget requestTarget)
Encode a pageid request target.

Parameters:
requestCycle - the current request cycle
requestTarget - the target to encode
Returns:
the encoded url

encode

protected CharSequence encode(RequestCycle requestCycle,
                              IListenerInterfaceRequestTarget requestTarget)
Encode a listener interface target. If you override this method to behave different then also addInterfaceParameters(Request, RequestParameters) should be overridden to be in sync with that behavior.

Parameters:
requestCycle - the current request cycle
requestTarget - the target to encode
Returns:
the encoded url

encode

protected CharSequence encode(RequestCycle requestCycle,
                              IPageRequestTarget requestTarget)
Encode a page target.

Parameters:
requestCycle - the current request cycle
requestTarget - the target to encode
Returns:
the encoded url

getMountEncoder

protected IRequestTargetUrlCodingStrategy getMountEncoder(IRequestTarget requestTarget)
Gets the mount encoder for the given request target if any.

Parameters:
requestTarget - the request target to match
Returns:
the mount encoder if any

getRequestPath

protected String getRequestPath(Request request)
Gets the request info path. This is an overridable method in order to provide users with a means to implement e.g. a path encryption scheme. This method by default returns Request.getPath().

Parameters:
request - the request
Returns:
the path info object, possibly processed

encodePageMapName

public static final String encodePageMapName(String pageMapName)
Makes page map name url safe. Since the default page map name in wicket is null and null does not encode well into urls this method will substitute null for a known token. If the pageMapName passed in is not null it is returned without modification.

Parameters:
pageMapName - page map name
Returns:
encoded pagemap name

decodePageMapName

public static String decodePageMapName(String pageMapName)
Undoes the effect of encodePageMapName(String)

Parameters:
pageMapName - page map name
Returns:
decoded page map name

rewriteStaticRelativeUrl

public String rewriteStaticRelativeUrl(String string)
Rewrites relative paths found in static markup attributes (src,href,background) of wicket pages. Since we do not know the url depth at which the page will be rendered the implementations should usually simply append a prefix, eg ../../, to make the path context-relative. If the url is not relative it is returned intact. Implementations can be as simple as delegating to UrlUtils.rewriteToContextRelative(String, Request)

Specified by:
rewriteStaticRelativeUrl in interface IRequestCodingStrategy
Returns:
rewritten path
See Also:
Request.getRelativePathPrefixToContextRoot(), UrlUtils.rewriteToContextRelative(String, Request)


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