Class AbstractBookmarkableMapper
- java.lang.Object
-
- org.apache.wicket.request.mapper.AbstractMapper
-
- org.apache.wicket.core.request.mapper.AbstractComponentMapper
-
- org.apache.wicket.core.request.mapper.AbstractBookmarkableMapper
-
- All Implemented Interfaces:
IRequestMapper
- Direct Known Subclasses:
BookmarkableMapper
,MountedMapper
,PackageMapper
,ResourceMapper
public abstract class AbstractBookmarkableMapper extends AbstractComponentMapper
Abstract encoder for Bookmarkable, Hybrid and BookmarkableListener URLs.- Author:
- Matej Knopp
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
AbstractBookmarkableMapper.MountPathSegment
protected static class
AbstractBookmarkableMapper.UrlInfo
Represents information stored in URL.
-
Field Summary
Fields Modifier and Type Field Description protected String[]
mountSegments
protected IPageParametersEncoder
pageParametersEncoder
protected List<AbstractBookmarkableMapper.MountPathSegment>
pathSegments
-
Constructor Summary
Constructors Constructor Description AbstractBookmarkableMapper()
Construct.AbstractBookmarkableMapper(String mountPath, IPageParametersEncoder pageParametersEncoder)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract Url
buildUrl(AbstractBookmarkableMapper.UrlInfo info)
Builds URL for the givenAbstractBookmarkableMapper.UrlInfo
instance.protected boolean
checkPageClass(Class<? extends IRequestablePage> pageClass)
protected boolean
checkPageInstance(IRequestablePage page)
protected PageParameters
extractPageParameters(Request request, Url url)
Extracts the PageParameters from URL if there are anyint
getCompatibilityScore(Request request)
Returns the score representing how compatible this request mapper is to processing the given request.protected int[]
getMatchedSegmentSizes(Url url)
protected PageInfo
getPageInfo(IPageRequestHandler handler)
protected List<AbstractBookmarkableMapper.MountPathSegment>
getPathSegments(String[] segments)
protected boolean
isCaseSensitiveMatch()
protected boolean
isFixedSegment(String segment)
Url
mapHandler(IRequestHandler requestHandler)
IRequestHandler
mapRequest(Request request)
protected PageParameters
newPageParameters()
protected abstract boolean
pageMustHaveBeenCreatedBookmarkable()
Indicates whether hybridRenderPageRequestHandler
URL for page will be generated only if page has been created with bookmarkable URL.protected abstract AbstractBookmarkableMapper.UrlInfo
parseRequest(Request request)
Parse the given request to anAbstractBookmarkableMapper.UrlInfo
instance.protected IRequestHandler
processBookmarkable(Class<? extends IRequestablePage> pageClass, PageParameters pageParameters)
Creates aIRequestHandler
that processes a bookmarkable request.protected IRequestHandler
processHybrid(PageInfo pageInfo, Class<? extends IRequestablePage> pageClass, PageParameters pageParameters, Integer renderCount)
Creates aIRequestHandler
that processes a hybrid request.protected IRequestHandler
processListener(PageComponentInfo pageComponentInfo, Class<? extends IRequestablePage> pageClass, PageParameters pageParameters)
Creates aIRequestHandler
that notifies anIRequestListener
.protected Locale
resolveUserLocale()
OverrideAbstractMapper.resolveLocale()
to return the result of this method if you want to use the user's session or request locale for parsing numbers from the page parametersprotected boolean
segmentsMatch(String mountedSegment, String urlSegment)
Decides whether a segment from the mounted path matches with a segment from the requested url.AbstractBookmarkableMapper
setCaseSensitiveMatch(boolean isCaseSensitive)
Sets whether the matching of mounted segments against request's url ones should be case sensitive or not.protected boolean
setPlaceholders(PageParameters parameters, Url url)
Replaces mandatory and optional parameters with their values.protected boolean
urlStartsWithMountedSegments(Url url)
-
Methods inherited from class org.apache.wicket.core.request.mapper.AbstractComponentMapper
cleanClassName, encodePageComponentInfo, getContext, getPageClass, getPageComponentInfo, removeMetaParameter
-
Methods inherited from class org.apache.wicket.request.mapper.AbstractMapper
encodePageParameters, extractPageParameters, getMountSegments, getOptionalPlaceholder, getPlaceholder, getPlaceholder, resolveLocale, safeSegmentGetter, urlStartsWith
-
-
-
-
Field Detail
-
pathSegments
protected final List<AbstractBookmarkableMapper.MountPathSegment> pathSegments
-
mountSegments
protected final String[] mountSegments
-
pageParametersEncoder
protected final IPageParametersEncoder pageParametersEncoder
-
-
Constructor Detail
-
AbstractBookmarkableMapper
public AbstractBookmarkableMapper()
Construct.
-
AbstractBookmarkableMapper
public AbstractBookmarkableMapper(String mountPath, IPageParametersEncoder pageParametersEncoder)
-
-
Method Detail
-
parseRequest
protected abstract AbstractBookmarkableMapper.UrlInfo parseRequest(Request request)
Parse the given request to anAbstractBookmarkableMapper.UrlInfo
instance.- Parameters:
request
-- Returns:
- UrlInfo instance or
null
if this encoder can not handle the request
-
buildUrl
protected abstract Url buildUrl(AbstractBookmarkableMapper.UrlInfo info)
Builds URL for the givenAbstractBookmarkableMapper.UrlInfo
instance. The URL this method produces must be parseable by theparseRequest(Request)
method.- Parameters:
info
-- Returns:
- Url result URL
-
pageMustHaveBeenCreatedBookmarkable
protected abstract boolean pageMustHaveBeenCreatedBookmarkable()
Indicates whether hybridRenderPageRequestHandler
URL for page will be generated only if page has been created with bookmarkable URL.For generic bookmarkable encoders this method should return
true
. For explicit (mounted) encoders this method should returnfalse
- Returns:
true
if hybrid URL requires page created bookmarkable,false
otherwise.
-
getCompatibilityScore
public int getCompatibilityScore(Request request)
Description copied from interface:IRequestMapper
Returns the score representing how compatible this request mapper is to processing the given request. When a request comes in all mappers are scored and are tried in order from highest score to lowest.A good criteria for calculating the score is the number of matched url segments. For example when there are two mappers for a mounted page, one mapped to
/foo
another to/foo/bar
and the incoming request URL is /foo/bar/baz, the mapping to/foo/bar
should probably handle the request first as it has matching segments count of 2 while the first one has only matching segments count of 1.Note that the method can return value greater then zero even if the mapper does not recognize the request.
- Returns:
- the compatibility score, e.g. count of matching segments
-
processBookmarkable
protected IRequestHandler processBookmarkable(Class<? extends IRequestablePage> pageClass, PageParameters pageParameters)
Creates aIRequestHandler
that processes a bookmarkable request.- Parameters:
pageClass
-pageParameters
-- Returns:
- a
IRequestHandler
capable of processing the bookmarkable request.
-
processHybrid
protected IRequestHandler processHybrid(PageInfo pageInfo, Class<? extends IRequestablePage> pageClass, PageParameters pageParameters, Integer renderCount)
Creates aIRequestHandler
that processes a hybrid request. When the page identified bypageInfo
was not available, the request should be treated as a bookmarkable request.- Parameters:
pageInfo
-pageClass
-pageParameters
-renderCount
-- Returns:
- a
IRequestHandler
capable of processing the hybrid request.
-
processListener
protected IRequestHandler processListener(PageComponentInfo pageComponentInfo, Class<? extends IRequestablePage> pageClass, PageParameters pageParameters)
Creates aIRequestHandler
that notifies anIRequestListener
.- Parameters:
pageComponentInfo
-pageClass
-pageParameters
-- Returns:
- a
IRequestHandler
that notifies anIRequestListener
.
-
mapRequest
public IRequestHandler mapRequest(Request request)
Description copied from interface:IRequestMapper
- Parameters:
request
- provides access to request data (i.e. Url and Parameters)- Returns:
- RequestHandler instance or
null
-
checkPageInstance
protected boolean checkPageInstance(IRequestablePage page)
-
checkPageClass
protected boolean checkPageClass(Class<? extends IRequestablePage> pageClass)
-
mapHandler
public Url mapHandler(IRequestHandler requestHandler)
Description copied from interface:IRequestMapper
- Returns:
- Url instance or
null
.
-
getPageInfo
protected final PageInfo getPageInfo(IPageRequestHandler handler)
-
newPageParameters
protected PageParameters newPageParameters()
- Returns:
- a new instance of
PageParameters
that will be passed to the page/resource
-
resolveUserLocale
protected Locale resolveUserLocale()
OverrideAbstractMapper.resolveLocale()
to return the result of this method if you want to use the user's session or request locale for parsing numbers from the page parameters- Returns:
- the Session or Request's locale to use for parsing any numbers in the request parameters
-
getPathSegments
protected List<AbstractBookmarkableMapper.MountPathSegment> getPathSegments(String[] segments)
-
isFixedSegment
protected boolean isFixedSegment(String segment)
-
extractPageParameters
protected PageParameters extractPageParameters(Request request, Url url)
Extracts the PageParameters from URL if there are any
-
getMatchedSegmentSizes
protected int[] getMatchedSegmentSizes(Url url)
-
segmentsMatch
protected boolean segmentsMatch(String mountedSegment, String urlSegment)
Decides whether a segment from the mounted path matches with a segment from the requested url. A custom implementation of this class may use more complex logic to handle spelling errors- Parameters:
mountedSegment
- the segment from the mounted pathurlSegment
- the segment from the request url- Returns:
true
if the segments match
-
isCaseSensitiveMatch
protected boolean isCaseSensitiveMatch()
- Returns:
- whether the matching of mounted segments against request's url ones should be case sensitive or not
-
setCaseSensitiveMatch
public AbstractBookmarkableMapper setCaseSensitiveMatch(boolean isCaseSensitive)
Sets whether the matching of mounted segments against request's url ones should be case sensitive or not.- Parameters:
isCaseSensitive
- a flag indicating whether the matching of mounted segments against request's url ones should be case sensitive or not- Returns:
- this instance, for chaining
-
setPlaceholders
protected boolean setPlaceholders(PageParameters parameters, Url url)
Replaces mandatory and optional parameters with their values. If a mandatory parameter is not provided then the method returnsfalse
indicating that there is a problem. Optional parameters with missing values are just dropped.- Parameters:
parameters
- The parameters with the valuesurl
- The url with the placeholders- Returns:
true
if all mandatory parameters are properly substituted,false
- otherwise
-
urlStartsWithMountedSegments
protected boolean urlStartsWithMountedSegments(Url url)
-
-