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;
}
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;
}
}
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);
}
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);
}
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());
}
Aggregations