Search in sources :

Example 31 with IRequestablePage

use of org.apache.wicket.request.component.IRequestablePage in project wicket by apache.

the class PackageMapper method parseRequest.

@Override
protected UrlInfo parseRequest(Request request) {
    Url url = request.getUrl();
    if (urlStartsWithMountedSegments(url)) {
        // try to extract page and component information from URL
        PageComponentInfo info = getPageComponentInfo(url);
        final List<String> segments = url.getSegments();
        if (segments.size() <= mountSegments.length) {
            return null;
        }
        // load the page class
        String name = segments.get(mountSegments.length);
        if (Strings.isEmpty(name)) {
            return null;
        }
        String className = cleanClassName(name);
        if (isValidClassName(className) == false) {
            return null;
        }
        className = transformFromUrl(className);
        String fullyQualifiedClassName = packageName.getName() + '.' + className;
        Class<? extends IRequestablePage> pageClass = getPageClass(fullyQualifiedClassName);
        if (pageClass != null && Modifier.isAbstract(pageClass.getModifiers()) == false && IRequestablePage.class.isAssignableFrom(pageClass)) {
            // extract the PageParameters from URL if there are any
            Url urlWithoutPageSegment = new Url(url);
            urlWithoutPageSegment.getSegments().remove(mountSegments.length);
            Request requestWithoutPageSegment = request.cloneWithUrl(urlWithoutPageSegment);
            PageParameters pageParameters = extractPageParameters(requestWithoutPageSegment, urlWithoutPageSegment);
            return new UrlInfo(info, pageClass, pageParameters);
        }
    }
    return null;
}
Also used : IRequestablePage(org.apache.wicket.request.component.IRequestablePage) Request(org.apache.wicket.request.Request) PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) Url(org.apache.wicket.request.Url) PageComponentInfo(org.apache.wicket.request.mapper.info.PageComponentInfo)

Example 32 with IRequestablePage

use of org.apache.wicket.request.component.IRequestablePage in project wicket by apache.

the class PageInstanceMapper method mapHandler.

/**
 * @see org.apache.wicket.request.IRequestMapper#mapHandler(org.apache.wicket.request.IRequestHandler)
 */
@Override
public Url mapHandler(IRequestHandler requestHandler) {
    PageComponentInfo info = null;
    if (requestHandler instanceof RenderPageRequestHandler) {
        IRequestablePage page = ((RenderPageRequestHandler) requestHandler).getPage();
        PageInfo i = new PageInfo(page.getPageId());
        info = new PageComponentInfo(i, null);
    } else if (requestHandler instanceof ListenerRequestHandler) {
        ListenerRequestHandler handler = (ListenerRequestHandler) requestHandler;
        IRequestablePage page = handler.getPage();
        String componentPath = handler.getComponentPath();
        Integer renderCount = null;
        if (handler.includeRenderCount()) {
            renderCount = page.getRenderCount();
        }
        PageInfo pageInfo = new PageInfo(page.getPageId());
        ComponentInfo componentInfo = new ComponentInfo(renderCount, componentPath, handler.getBehaviorIndex());
        info = new PageComponentInfo(pageInfo, componentInfo);
    }
    if (info != null) {
        Url url = new Url();
        url.getSegments().add(getContext().getNamespace());
        url.getSegments().add(getContext().getPageIdentifier());
        encodePageComponentInfo(url, info);
        return url;
    } else {
        return null;
    }
}
Also used : PageInfo(org.apache.wicket.request.mapper.info.PageInfo) RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) IRequestablePage(org.apache.wicket.request.component.IRequestablePage) ListenerRequestHandler(org.apache.wicket.core.request.handler.ListenerRequestHandler) ComponentInfo(org.apache.wicket.request.mapper.info.ComponentInfo) PageComponentInfo(org.apache.wicket.request.mapper.info.PageComponentInfo) Url(org.apache.wicket.request.Url) PageComponentInfo(org.apache.wicket.request.mapper.info.PageComponentInfo)

Example 33 with IRequestablePage

use of org.apache.wicket.request.component.IRequestablePage in project wicket by apache.

the class AbstractBookmarkableMapper method getPageInfo.

protected final PageInfo getPageInfo(IPageRequestHandler handler) {
    Args.notNull(handler, "handler");
    Integer pageId = null;
    if (handler.isPageInstanceCreated()) {
        IRequestablePage page = handler.getPage();
        if (page.isPageStateless() == false) {
            pageId = page.getPageId();
        }
    }
    return new PageInfo(pageId);
}
Also used : PageInfo(org.apache.wicket.request.mapper.info.PageInfo) IRequestablePage(org.apache.wicket.request.component.IRequestablePage)

Example 34 with IRequestablePage

use of org.apache.wicket.request.component.IRequestablePage in project wicket by apache.

the class BookmarkableMapperTest method decode12.

/**
 * WICKET-5071
 *
 * Decodes a request to
 * {@link org.apache.wicket.core.request.mapper.IMapperContext#getBookmarkableIdentifier()}
 * /com.example.MyPage when the current base url is
 * {@link org.apache.wicket.core.request.mapper.IMapperContext#getNamespace()} /
 * {@link org.apache.wicket.core.request.mapper.IMapperContext#getPageIdentifier()}
 */
@Test
public void decode12() {
    final Url url = Url.parse(context.getBookmarkableIdentifier() + "/" + PAGE_CLASS_NAME);
    Request request = new Request() {

        @Override
        public Url getUrl() {
            return url;
        }

        @Override
        public Locale getLocale() {
            return null;
        }

        @Override
        public Charset getCharset() {
            return Charset.forName("UTF-8");
        }

        @Override
        public Url getClientUrl() {
            StringBuilder url = new StringBuilder();
            url.append(context.getNamespace()).append('/').append(context.getPageIdentifier()).append("?3");
            return Url.parse(url.toString());
        }

        @Override
        public Object getContainerRequest() {
            return null;
        }
    };
    IRequestHandler handler = encoder.mapRequest(request);
    assertNotNull("A handler should be resolved for relative url to a page instance url!", handler);
    IRequestablePage page = ((IPageRequestHandler) handler).getPage();
    assertEquals(page.getClass().getName(), PAGE_CLASS_NAME);
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) Request(org.apache.wicket.request.Request) IRequestablePage(org.apache.wicket.request.component.IRequestablePage) IPageRequestHandler(org.apache.wicket.core.request.handler.IPageRequestHandler) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Example 35 with IRequestablePage

use of org.apache.wicket.request.component.IRequestablePage in project wicket by apache.

the class BookmarkableMapperTest method decode1.

/**
 */
@Test
public void decode1() {
    Url url = Url.parse("wicket/bookmarkable/" + PAGE_CLASS_NAME);
    IRequestHandler handler = encoder.mapRequest(getRequest(url));
    assertThat(handler, instanceOf(RenderPageRequestHandler.class));
    IRequestablePage page = ((RenderPageRequestHandler) handler).getPage();
    assertEquals(PAGE_CLASS_NAME, page.getClass().getName());
    assertEquals(0, page.getPageParameters().getIndexedCount());
    assertTrue(page.getPageParameters().getNamedKeys().isEmpty());
}
Also used : IRequestHandler(org.apache.wicket.request.IRequestHandler) RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) IRequestablePage(org.apache.wicket.request.component.IRequestablePage) Url(org.apache.wicket.request.Url) Test(org.junit.Test)

Aggregations

IRequestablePage (org.apache.wicket.request.component.IRequestablePage)59 Url (org.apache.wicket.request.Url)50 IRequestHandler (org.apache.wicket.request.IRequestHandler)47 Test (org.junit.Test)46 RenderPageRequestHandler (org.apache.wicket.core.request.handler.RenderPageRequestHandler)31 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)18 ListenerRequestHandler (org.apache.wicket.core.request.handler.ListenerRequestHandler)15 BookmarkableListenerRequestHandler (org.apache.wicket.core.request.handler.BookmarkableListenerRequestHandler)14 IPageRequestHandler (org.apache.wicket.core.request.handler.IPageRequestHandler)6 Request (org.apache.wicket.request.Request)6 PageComponentInfo (org.apache.wicket.request.mapper.info.PageComponentInfo)5 PageProvider (org.apache.wicket.core.request.handler.PageProvider)4 PageInfo (org.apache.wicket.request.mapper.info.PageInfo)4 IPageProvider (org.apache.wicket.core.request.handler.IPageProvider)3 ComponentInfo (org.apache.wicket.request.mapper.info.ComponentInfo)3 Page (org.apache.wicket.Page)2 AccessControlException (java.security.AccessControlException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 ForbiddenException (javax.ws.rs.ForbiddenException)1 Login (org.apache.syncope.client.console.pages.Login)1