use of org.apache.wicket.request.Url in project wicket by apache.
the class MountedMapper method mapHandler.
@Override
public Url mapHandler(IRequestHandler requestHandler) {
Url url = super.mapHandler(requestHandler);
if (url == null && requestHandler instanceof ListenerRequestHandler && getRecreateMountedPagesAfterExpiry()) {
ListenerRequestHandler handler = (ListenerRequestHandler) requestHandler;
IRequestablePage page = handler.getPage();
if (checkPageInstance(page)) {
Integer renderCount = null;
if (handler.includeRenderCount()) {
renderCount = page.getRenderCount();
}
String componentPath = handler.getComponentPath();
PageInfo pageInfo = getPageInfo(handler);
ComponentInfo componentInfo = new ComponentInfo(renderCount, componentPath, handler.getBehaviorIndex());
PageComponentInfo pageComponentInfo = new PageComponentInfo(pageInfo, componentInfo);
PageParameters parameters = newPageParameters();
parameters.mergeWith(page.getPageParameters());
UrlInfo urlInfo = new UrlInfo(pageComponentInfo, page.getClass(), parameters.mergeWith(handler.getPageParameters()));
url = buildUrl(urlInfo);
}
}
return url;
}
use of org.apache.wicket.request.Url 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;
}
use of org.apache.wicket.request.Url in project wicket by apache.
the class PageInstanceMapper method matches.
/**
* Matches when the request url starts with
* {@link org.apache.wicket.core.request.mapper.IMapperContext#getNamespace()}/{@link org.apache.wicket.core.request.mapper.IMapperContext#getPageIdentifier()}
* or when the base url starts with
* {@link org.apache.wicket.core.request.mapper.IMapperContext#getNamespace()}/{@link org.apache.wicket.core.request.mapper.IMapperContext#getPageIdentifier()}
* and the request url with {@link org.apache.wicket.core.request.mapper.IMapperContext#getPageIdentifier()}
*
* @param request
* the request to check
* @return {@code true} if the conditions match
*/
private boolean matches(final Request request) {
boolean matches = false;
Url url = request.getUrl();
Url baseUrl = request.getClientUrl();
String namespace = getContext().getNamespace();
String pageIdentifier = getContext().getPageIdentifier();
List<String> segments = url.getSegments();
if (isNotPageInstanceUrl(segments, pageIdentifier)) {
return false;
}
if (urlStartsWith(url, namespace, pageIdentifier)) {
matches = true;
} else if (urlStartsWith(baseUrl, namespace, pageIdentifier) && urlStartsWith(url, pageIdentifier)) {
matches = true;
} else if (urlStartsWith(baseUrl, pageIdentifier) && urlStartsWith(url, pageIdentifier)) {
matches = true;
}
return matches;
}
use of org.apache.wicket.request.Url in project wicket by apache.
the class PackageResourceReference method getResource.
/**
* @see org.apache.wicket.request.resource.ResourceReference#getResource()
*/
@Override
public PackageResource getResource() {
final String extension = getExtension();
final PackageResource resource;
RequestCycle requestCycle = RequestCycle.get();
UrlAttributes urlAttributes = null;
if (requestCycle != null) {
// resource attributes (locale, style, variation) might be encoded in the URL
final Url url = requestCycle.getRequest().getUrl();
urlAttributes = ResourceUtil.decodeResourceReferenceAttributes(url);
}
final String currentVariation = getCurrentVariation(urlAttributes);
final String currentStyle = getCurrentStyle(urlAttributes);
final Locale currentLocale = getCurrentLocale(urlAttributes);
final Class<?> scope = getScope();
final String name = getName();
if (CSS_EXTENSION.equals(extension)) {
resource = new CssPackageResource(scope, name, currentLocale, currentStyle, currentVariation);
} else if (JAVASCRIPT_EXTENSION.equals(extension)) {
resource = new JavaScriptPackageResource(scope, name, currentLocale, currentStyle, currentVariation);
} else {
resource = new PackageResource(scope, name, currentLocale, currentStyle, currentVariation);
}
resource.readBuffered(readBuffered);
removeCompressFlagIfUnnecessary(resource);
return resource;
}
use of org.apache.wicket.request.Url in project wicket by apache.
the class HttpsMapper method mapHandler.
/**
* Creates a url for the handler. Modifies it with the correct {@link Scheme} if necessary.
*
* @param handler
* @param request
* @return url
*/
final Url mapHandler(IRequestHandler handler, Request request) {
Url url = delegate.mapHandler(handler);
Scheme desired = getDesiredSchemeFor(handler);
if (Scheme.ANY.equals(desired)) {
return url;
}
Scheme current = getSchemeOf(request);
if (!desired.isCompatibleWith(current)) {
// the generated url does not have the correct scheme, set it (which in turn will cause
// the url to be rendered in its full representation)
url.setProtocol(desired.urlName());
url.setPort(desired.getPort(config));
}
return url;
}
Aggregations