Search in sources :

Example 1 with BookmarkableListenerRequestHandler

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;
}
Also used : PageInfo(org.apache.wicket.request.mapper.info.PageInfo) RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) BookmarkablePageRequestHandler(org.apache.wicket.core.request.handler.BookmarkablePageRequestHandler) BookmarkableListenerRequestHandler(org.apache.wicket.core.request.handler.BookmarkableListenerRequestHandler) IRequestablePage(org.apache.wicket.request.component.IRequestablePage) ComponentInfo(org.apache.wicket.request.mapper.info.ComponentInfo) PageComponentInfo(org.apache.wicket.request.mapper.info.PageComponentInfo) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) IRequestHandlerDelegate(org.apache.wicket.request.IRequestHandlerDelegate) PageComponentInfo(org.apache.wicket.request.mapper.info.PageComponentInfo)

Example 2 with BookmarkableListenerRequestHandler

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());
}
Also used : IRequestableComponent(org.apache.wicket.request.component.IRequestableComponent) IRequestHandler(org.apache.wicket.request.IRequestHandler) BookmarkableListenerRequestHandler(org.apache.wicket.core.request.handler.BookmarkableListenerRequestHandler) PageAndComponentProvider(org.apache.wicket.core.request.handler.PageAndComponentProvider) MockPage(org.apache.wicket.MockPage) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Example 3 with BookmarkableListenerRequestHandler

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)));
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) BookmarkableListenerRequestHandler(org.apache.wicket.core.request.handler.BookmarkableListenerRequestHandler) PageAndComponentProvider(org.apache.wicket.core.request.handler.PageAndComponentProvider) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Example 4 with BookmarkableListenerRequestHandler

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);
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) BookmarkableListenerRequestHandler(org.apache.wicket.core.request.handler.BookmarkableListenerRequestHandler) PageAndComponentProvider(org.apache.wicket.core.request.handler.PageAndComponentProvider) WebPage(org.apache.wicket.markup.html.WebPage) Page(org.apache.wicket.Page) ListenerRequestHandler(org.apache.wicket.core.request.handler.ListenerRequestHandler) BookmarkableListenerRequestHandler(org.apache.wicket.core.request.handler.BookmarkableListenerRequestHandler) Url(org.apache.wicket.request.Url)

Example 5 with BookmarkableListenerRequestHandler

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());
}
Also used : IRequestableComponent(org.apache.wicket.request.component.IRequestableComponent) IRequestHandler(org.apache.wicket.request.IRequestHandler) BookmarkableListenerRequestHandler(org.apache.wicket.core.request.handler.BookmarkableListenerRequestHandler) PageAndComponentProvider(org.apache.wicket.core.request.handler.PageAndComponentProvider) MockPage(org.apache.wicket.MockPage) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Aggregations

BookmarkableListenerRequestHandler (org.apache.wicket.core.request.handler.BookmarkableListenerRequestHandler)13 PageAndComponentProvider (org.apache.wicket.core.request.handler.PageAndComponentProvider)12 IRequestHandler (org.apache.wicket.request.IRequestHandler)11 Url (org.apache.wicket.request.Url)11 Test (org.junit.Test)10 MockPage (org.apache.wicket.MockPage)8 IRequestableComponent (org.apache.wicket.request.component.IRequestableComponent)8 ListenerRequestHandler (org.apache.wicket.core.request.handler.ListenerRequestHandler)4 IRequestablePage (org.apache.wicket.request.component.IRequestablePage)2 Page (org.apache.wicket.Page)1 BookmarkablePageRequestHandler (org.apache.wicket.core.request.handler.BookmarkablePageRequestHandler)1 RenderPageRequestHandler (org.apache.wicket.core.request.handler.RenderPageRequestHandler)1 WebPage (org.apache.wicket.markup.html.WebPage)1 IRequestHandlerDelegate (org.apache.wicket.request.IRequestHandlerDelegate)1 ComponentInfo (org.apache.wicket.request.mapper.info.ComponentInfo)1 PageComponentInfo (org.apache.wicket.request.mapper.info.PageComponentInfo)1 PageInfo (org.apache.wicket.request.mapper.info.PageInfo)1 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)1