use of org.apache.wicket.request.Request 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.Request in project wicket by apache.
the class WebPage method dirty.
/**
* Prevents page from get dirty inside an AJAX request.
*/
@Override
public final void dirty(boolean isInitialization) {
Request request = getRequest();
if (isInitialization == false && request instanceof WebRequest && ((WebRequest) request).isAjax()) {
return;
}
super.dirty(isInitialization);
}
use of org.apache.wicket.request.Request in project wicket by apache.
the class BaseWicketTester method applyRequest.
/**
* Rebuilds {@link ServletWebRequest} used by wicket from the mock request used to build
* requests. Sometimes this method is useful when changes need to be checked without processing
* a request.
*/
public void applyRequest() {
Request req = newServletWebRequest();
requestCycle.setRequest(req);
if (useRequestUrlAsBase) {
requestCycle.getUrlRenderer().setBaseUrl(req.getUrl());
}
}
use of org.apache.wicket.request.Request 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.Request in project wicket by apache.
the class BookmarkableMapperTest method decode11.
/**
* 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#getBookmarkableIdentifier()}
*/
@Test
public void decode11() {
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.getBookmarkableIdentifier()).append('/').append("com.example.MyPage");
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 bookmarkable page!", handler);
IRequestablePage page = ((IPageRequestHandler) handler).getPage();
assertEquals(page.getClass().getName(), PAGE_CLASS_NAME);
}
Aggregations