use of org.apache.wicket.core.request.handler.BookmarkableListenerRequestHandler in project wicket by apache.
the class AbstractBookmarkableMapper method mapHandler.
@Override
public Url mapHandler(IRequestHandler requestHandler) {
// eliminate the need for IRequestHandlerDelegate
while (requestHandler instanceof IRequestHandlerDelegate) {
requestHandler = ((IRequestHandlerDelegate) requestHandler).getDelegateHandler();
}
if (requestHandler instanceof BookmarkablePageRequestHandler) {
// simple bookmarkable URL with no page instance information
BookmarkablePageRequestHandler handler = (BookmarkablePageRequestHandler) requestHandler;
if (!checkPageClass(handler.getPageClass())) {
return null;
}
PageInfo info = new PageInfo();
UrlInfo urlInfo = new UrlInfo(new PageComponentInfo(info, null), handler.getPageClass(), handler.getPageParameters());
return buildUrl(urlInfo);
} else if (requestHandler instanceof RenderPageRequestHandler) {
// possibly hybrid URL - bookmarkable URL with page instance information
// but only allowed if the page was created by bookmarkable URL
RenderPageRequestHandler handler = (RenderPageRequestHandler) requestHandler;
if (!checkPageClass(handler.getPageClass())) {
return null;
}
if (handler.getPageProvider().isNewPageInstance()) {
// no existing page instance available, don't bother creating new page instance
PageInfo info = new PageInfo();
UrlInfo urlInfo = new UrlInfo(new PageComponentInfo(info, null), handler.getPageClass(), handler.getPageParameters());
return buildUrl(urlInfo);
}
IRequestablePage page = handler.getPage();
if (checkPageInstance(page) && (!pageMustHaveBeenCreatedBookmarkable() || page.wasCreatedBookmarkable())) {
PageInfo info = getPageInfo(handler);
PageComponentInfo pageComponentInfo = new PageComponentInfo(info, null);
UrlInfo urlInfo = new UrlInfo(pageComponentInfo, page.getClass(), handler.getPageParameters());
return buildUrl(urlInfo);
} else {
return null;
}
} else if (requestHandler instanceof BookmarkableListenerRequestHandler) {
// request listener URL with page class information
BookmarkableListenerRequestHandler handler = (BookmarkableListenerRequestHandler) requestHandler;
Class<? extends IRequestablePage> pageClass = handler.getPageClass();
if (!checkPageClass(pageClass)) {
return null;
}
Integer renderCount = null;
if (handler.includeRenderCount()) {
renderCount = handler.getRenderCount();
}
PageInfo pageInfo = getPageInfo(handler);
ComponentInfo componentInfo = new ComponentInfo(renderCount, handler.getComponentPath(), handler.getBehaviorIndex());
PageParameters parameters = getRecreateMountedPagesAfterExpiry() ? new PageParameters(handler.getPage().getPageParameters()).mergeWith(handler.getPageParameters()) : handler.getPageParameters();
UrlInfo urlInfo = new UrlInfo(new PageComponentInfo(pageInfo, componentInfo), pageClass, parameters);
return buildUrl(urlInfo);
}
return null;
}
use of org.apache.wicket.core.request.handler.BookmarkableListenerRequestHandler in project wicket by apache.
the class BookmarkableMapperTest method encode7.
/**
*/
@Test
public void encode7() {
MockPage page = new MockPage(15);
page.getPageParameters().set(0, "i1");
page.getPageParameters().set(1, "i2");
page.getPageParameters().set("a", "b", INamedParameters.Type.QUERY_STRING);
page.getPageParameters().set("b", "c", INamedParameters.Type.QUERY_STRING);
// shouldn't make any difference for BookmarkableListenerRequestHandler,
// as this explicitly says the url must be bookmarkable
page.setCreatedBookmarkable(false);
IRequestableComponent c = page.get("foo:bar");
PageAndComponentProvider provider = new PageAndComponentProvider(page, c);
IRequestHandler handler = new BookmarkableListenerRequestHandler(provider, 4);
Url url = encoder.mapHandler(handler);
assertEquals("wicket/bookmarkable/" + PAGE_CLASS_NAME + "/i1/i2?15-0.4-foo-bar&a=b&b=c", url.toString());
}
use of org.apache.wicket.core.request.handler.BookmarkableListenerRequestHandler in project wicket by apache.
the class CryptoMapperTest method homePageForceEncryptionOfRequestListener.
/**
* Tests that we do not allow unencrypted URLs to IRequestListeners on the home page, like: ?0-0.ILinkListener-link
*/
@Test
public void homePageForceEncryptionOfRequestListener() {
PageAndComponentProvider provider = new PageAndComponentProvider(tester.getApplication().getHomePage(), "link");
IRequestHandler requestHandler = new BookmarkableListenerRequestHandler(provider);
Url plainUrl = mapper.getDelegateMapper().mapHandler(requestHandler);
assertTrue("Plain URL for home page has segments: " + plainUrl.toString(), plainUrl.getSegments().isEmpty());
assertNull(mapper.mapRequest(getRequest(plainUrl)));
}
use of org.apache.wicket.core.request.handler.BookmarkableListenerRequestHandler in project wicket by apache.
the class BaseWicketTester method executeListener.
/**
* Simulates processing URL that invokes an {@link IRequestListener} on a component.
*
* After the listener is invoked the page containing the component will be rendered
* (with an optional redirect - depending on {@link RenderStrategy}).
*
* @param component
* @param listener
*/
public void executeListener(final Component component) {
Args.notNull(component, "component");
// there are two ways to do this. RequestCycle could be forced to call the handler
// directly but constructing and parsing the URL increases the chance of triggering bugs
Page page = component.getPage();
PageAndComponentProvider pageAndComponentProvider = new PageAndComponentProvider(page, component);
IRequestHandler handler = null;
if (page.isPageStateless() || (page.isBookmarkable() && page.wasCreatedBookmarkable())) {
handler = new BookmarkableListenerRequestHandler(pageAndComponentProvider);
} else {
handler = new ListenerRequestHandler(pageAndComponentProvider);
}
Url url = urlFor(handler);
request.setUrl(url);
// Process the request
processRequest(request, null);
}
use of org.apache.wicket.core.request.handler.BookmarkableListenerRequestHandler in project wicket by apache.
the class BookmarkableMapperTest method encode6.
/**
*/
@Test
public void encode6() {
MockPage page = new MockPage(15);
page.getPageParameters().set(0, "i1");
page.getPageParameters().set(1, "i2");
page.getPageParameters().set("a", "b", INamedParameters.Type.QUERY_STRING);
page.getPageParameters().set("b", "c", INamedParameters.Type.QUERY_STRING);
// shouldn't make any difference for BookmarkableListenerRequestHandler,
// as this explicitly says the url must be bookmarkable
page.setCreatedBookmarkable(false);
IRequestableComponent c = page.get("foo:bar");
PageAndComponentProvider provider = new PageAndComponentProvider(page, c);
IRequestHandler handler = new BookmarkableListenerRequestHandler(provider);
Url url = encoder.mapHandler(handler);
assertEquals("wicket/bookmarkable/" + PAGE_CLASS_NAME + "/i1/i2?15-0.-foo-bar&a=b&b=c", url.toString());
}
Aggregations