Search in sources :

Example 6 with PageComponentInfo

use of org.apache.wicket.request.mapper.info.PageComponentInfo in project wicket by apache.

the class PageInstanceMapper method mapRequest.

/**
 * @see org.apache.wicket.request.IRequestMapper#mapRequest(org.apache.wicket.request.Request)
 */
@Override
public IRequestHandler mapRequest(Request request) {
    if (matches(request)) {
        Url url = request.getUrl();
        PageComponentInfo info = getPageComponentInfo(url);
        if (info != null && info.getPageInfo().getPageId() != null) {
            Integer renderCount = info.getComponentInfo() != null ? info.getComponentInfo().getRenderCount() : null;
            if (info.getComponentInfo() == null) {
                PageProvider provider = new PageProvider(info.getPageInfo().getPageId(), renderCount);
                provider.setPageSource(getContext());
                // render page
                return new RenderPageRequestHandler(provider);
            } else {
                ComponentInfo componentInfo = info.getComponentInfo();
                PageAndComponentProvider provider = new PageAndComponentProvider(info.getPageInfo().getPageId(), renderCount, componentInfo.getComponentPath());
                provider.setPageSource(getContext());
                return new ListenerRequestHandler(provider, componentInfo.getBehaviorId());
            }
        }
    }
    return null;
}
Also used : RenderPageRequestHandler(org.apache.wicket.core.request.handler.RenderPageRequestHandler) PageProvider(org.apache.wicket.core.request.handler.PageProvider) PageAndComponentProvider(org.apache.wicket.core.request.handler.PageAndComponentProvider) ComponentInfo(org.apache.wicket.request.mapper.info.ComponentInfo) PageComponentInfo(org.apache.wicket.request.mapper.info.PageComponentInfo) ListenerRequestHandler(org.apache.wicket.core.request.handler.ListenerRequestHandler) Url(org.apache.wicket.request.Url) PageComponentInfo(org.apache.wicket.request.mapper.info.PageComponentInfo)

Example 7 with PageComponentInfo

use of org.apache.wicket.request.mapper.info.PageComponentInfo 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 8 with PageComponentInfo

use of org.apache.wicket.request.mapper.info.PageComponentInfo 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 9 with PageComponentInfo

use of org.apache.wicket.request.mapper.info.PageComponentInfo in project wicket by apache.

the class AbstractBookmarkableMapper method mapRequest.

@Override
public IRequestHandler mapRequest(Request request) {
    UrlInfo urlInfo = parseRequest(request);
    if (urlInfo != null) {
        PageComponentInfo info = urlInfo.getPageComponentInfo();
        Class<? extends IRequestablePage> pageClass = urlInfo.getPageClass();
        PageParameters pageParameters = urlInfo.getPageParameters();
        if (info == null) {
            // then this is a simple bookmarkable URL
            return processBookmarkable(pageClass, pageParameters);
        } else if (info.getPageInfo().getPageId() != null && info.getComponentInfo() == null) {
            // instance
            return processHybrid(info.getPageInfo(), pageClass, pageParameters, null);
        } else if (info.getComponentInfo() != null) {
            // with both page instance and component this is a request listener URL
            return processListener(info, pageClass, pageParameters);
        } else if (info.getPageInfo().getPageId() == null) {
            return processBookmarkable(pageClass, pageParameters);
        }
    }
    return null;
}
Also used : PageParameters(org.apache.wicket.request.mapper.parameter.PageParameters) PageComponentInfo(org.apache.wicket.request.mapper.info.PageComponentInfo)

Aggregations

PageComponentInfo (org.apache.wicket.request.mapper.info.PageComponentInfo)9 Url (org.apache.wicket.request.Url)6 ListenerRequestHandler (org.apache.wicket.core.request.handler.ListenerRequestHandler)5 IRequestablePage (org.apache.wicket.request.component.IRequestablePage)5 ComponentInfo (org.apache.wicket.request.mapper.info.ComponentInfo)5 PageParameters (org.apache.wicket.request.mapper.parameter.PageParameters)5 PageInfo (org.apache.wicket.request.mapper.info.PageInfo)4 BookmarkableListenerRequestHandler (org.apache.wicket.core.request.handler.BookmarkableListenerRequestHandler)3 PageAndComponentProvider (org.apache.wicket.core.request.handler.PageAndComponentProvider)3 RenderPageRequestHandler (org.apache.wicket.core.request.handler.RenderPageRequestHandler)3 BookmarkablePageRequestHandler (org.apache.wicket.core.request.handler.BookmarkablePageRequestHandler)1 PageProvider (org.apache.wicket.core.request.handler.PageProvider)1 IRequestHandler (org.apache.wicket.request.IRequestHandler)1 IRequestHandlerDelegate (org.apache.wicket.request.IRequestHandlerDelegate)1 Request (org.apache.wicket.request.Request)1 Test (org.junit.Test)1