Created
March 27, 2012 21:37
-
-
Save armhold/2220564 to your computer and use it in GitHub Desktop.
Wicket NoVersionHomePageMapper - don't show page version/id on home page
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class NoVersionHomePageMapper extends AbstractComponentMapper | |
{ | |
/** | |
* If this is the home page URL, return a bigger compatibility score than | |
* {@link org.apache.wicket.request.mapper.HomePageMapper#getCompatibilityScore(Request)} | |
* | |
* @see org.apache.wicket.request.mapper.HomePageMapper#getCompatibilityScore(org.apache.wicket.request.Request) | |
*/ | |
public int getCompatibilityScore(Request request) | |
{ | |
return isHomeUrl(request) ? 1 : 0; | |
} | |
@Override | |
public Url mapHandler(IRequestHandler requestHandler) | |
{ | |
if (requestHandler instanceof ListenerInterfaceRequestHandler) | |
{ | |
return null; | |
} | |
if (requestHandler instanceof IPageRequestHandler) | |
{ | |
IPageRequestHandler pageRequestHandler = (IPageRequestHandler)requestHandler; | |
if (pageRequestHandler.getPageClass().equals(Application.get().getHomePage())) | |
{ | |
return new Url(); | |
} | |
} | |
return null; | |
} | |
@Override | |
public IRequestHandler mapRequest(Request request) | |
{ | |
return null; | |
} | |
/** | |
* A home URL is considered a URL without any segments | |
* | |
* @param request | |
* @return <code>true</code> if the request is to the home page ("/") | |
*/ | |
private boolean isHomeUrl(Request request) | |
{ | |
return request.getUrl().getSegments().isEmpty(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment