use of org.apache.wicket.request.IRequestMapper in project wicket by apache.
the class Application method getRootRequestMapperAsCompound.
/**
* Converts the root mapper to a {@link ICompoundRequestMapper} if necessary and returns the
* converted instance.
*
* @return compound instance of the root mapper
*/
public final ICompoundRequestMapper getRootRequestMapperAsCompound() {
IRequestMapper root = getRootRequestMapper();
if (!(root instanceof ICompoundRequestMapper)) {
root = new SystemMapper(this).add(root);
setRootRequestMapper(root);
}
return (ICompoundRequestMapper) root;
}
use of org.apache.wicket.request.IRequestMapper in project wicket by apache.
the class RequestCycleUrlForTest method before.
@Before
public void before() {
Request request = mock(Request.class);
Url baseUrl = Url.parse("");
when(request.getClientUrl()).thenReturn(baseUrl);
Response response = new StringResponse() {
@Override
public String encodeURL(CharSequence url) {
return url + JSESSIONID;
}
};
IRequestMapper mapper = mock(IRequestMapper.class);
Url bookmarkablePageUrl = Url.parse(BOOKMARKABLE_PAGE_URL);
when(mapper.mapHandler(argThat(new ExactClassMatcher<BookmarkablePageRequestHandler>(BookmarkablePageRequestHandler.class)))).thenReturn(bookmarkablePageUrl);
Url resourceUrl = Url.parse(RESOURCE_URL);
when(mapper.mapHandler(argThat(new ExactClassMatcher<ResourceRequestHandler>(ResourceRequestHandler.class)))).thenReturn(resourceUrl);
Url resourceReferenceUrl = Url.parse(RES_REF_URL);
when(mapper.mapHandler(argThat(new ExactClassMatcher<ResourceReferenceRequestHandler>(ResourceReferenceRequestHandler.class)))).thenReturn(resourceReferenceUrl);
IExceptionMapper exceptionMapper = mock(IExceptionMapper.class);
RequestCycleContext context = new RequestCycleContext(request, response, mapper, exceptionMapper);
requestCycle = new RequestCycle(context);
requestCycle.getUrlRenderer().setBaseUrl(baseUrl);
}
use of org.apache.wicket.request.IRequestMapper in project webanno by webanno.
the class WicketApplicationBase method initDefaultPageMounts.
protected void initDefaultPageMounts() {
mountPage("/login.html", getSignInPageClass());
mountPage("/welcome.html", getHomePage());
// Mount the other pages via @MountPath annotation on the page classes
AnnotatedMountList mounts = new AnnotatedMountScanner().scanPackage("de.tudarmstadt.ukp");
for (IRequestMapper mapper : mounts) {
if (mapper instanceof HomePageMapper) {
System.out.println(mapper);
}
}
mounts.mount(this);
}
use of org.apache.wicket.request.IRequestMapper in project wicket by apache.
the class WebApplication method unmount.
/**
* Unregisters all {@link IRequestMapper}s which would match on a this path.
* <p>
* Useful in OSGi environments where a bundle may want to update the mount point.
* </p>
*
* @param path
* the path to unmount
*/
public void unmount(String path) {
Args.notNull(path, "path");
if (path.charAt(0) == '/') {
path = path.substring(1);
}
IRequestMapper mapper = getRootRequestMapper();
while (mapper instanceof IRequestMapperDelegate) {
mapper = ((IRequestMapperDelegate) mapper).getDelegateMapper();
}
/*
* Only attempt to unmount if root request mapper is either a compound, or wraps a compound to avoid leaving the
* application with no mappers installed.
*/
if (mapper instanceof ICompoundRequestMapper) {
final Url url = Url.parse(path);
Request request = new Request() {
@Override
public Url getUrl() {
return url;
}
@Override
public Url getClientUrl() {
return url;
}
@Override
public Locale getLocale() {
return null;
}
@Override
public Charset getCharset() {
return null;
}
@Override
public Object getContainerRequest() {
return null;
}
};
unmountFromCompound((ICompoundRequestMapper) mapper, request);
}
}
use of org.apache.wicket.request.IRequestMapper in project wicket by apache.
the class CompoundRequestMapper method mapRequest.
/**
* Searches the registered {@link IRequestMapper}s to find one that can map the {@link Request}.
* Each registered {@link IRequestMapper} is asked to provide its compatibility score. Then the
* mappers are asked to map the request in order depending on the provided compatibility
* score.
* <p>
* The mapper with highest compatibility score which can map the request is returned.
*
* @param request
* @return RequestHandler for the request or <code>null</code> if no mapper for the request is
* found.
*/
@Override
public IRequestHandler mapRequest(final Request request) {
List<MapperWithScore> list = new ArrayList<>(mappers.size());
for (IRequestMapper mapper : this) {
int score = mapper.getCompatibilityScore(request);
list.add(new MapperWithScore(mapper, score));
}
Collections.sort(list);
if (LOG.isDebugEnabled()) {
logMappers(list, request.getUrl().toString());
}
for (MapperWithScore mapperWithScore : list) {
IRequestMapper mapper = mapperWithScore.getMapper();
IRequestHandler handler = mapper.mapRequest(request);
if (handler != null) {
return handler;
}
}
return null;
}
Aggregations