use of org.apache.wicket.request.cycle.RequestCycle in project wicket by apache.
the class DefaultPageManagerContext method setRequestData.
/**
* @see org.apache.wicket.page.IPageManagerContext#setRequestData(Object)
*/
@Override
public void setRequestData(final Object data) {
RequestCycle requestCycle = RequestCycle.get();
if (requestCycle == null) {
throw new IllegalStateException("Not a request thread.");
}
requestCycle.setMetaData(requestCycleMetaDataKey, data);
}
use of org.apache.wicket.request.cycle.RequestCycle in project wicket by apache.
the class CssUrlReplacer method process.
/**
* Replaces the URLs of CSS resources with Wicket representatives.
*/
@Override
public String process(String input, Class<?> scope, String name) {
// filter out the excluded css files
for (String excludeName : excludes) {
if (name.endsWith(excludeName)) {
return input;
}
}
RequestCycle cycle = RequestCycle.get();
Url cssUrl = Url.parse(name);
Matcher matcher = URL_PATTERN.matcher(input);
StringBuffer output = new StringBuffer();
while (matcher.find()) {
Url imageCandidateUrl = Url.parse(matcher.group(1));
CharSequence processedUrl;
boolean embedded = false;
if (imageCandidateUrl.isFull()) {
processedUrl = imageCandidateUrl.toString(Url.StringMode.FULL);
} else if (imageCandidateUrl.isContextAbsolute()) {
processedUrl = imageCandidateUrl.toString();
} else if (imageCandidateUrl.isDataUrl()) {
embedded = true;
processedUrl = imageCandidateUrl.toString();
} else {
// relativize against the url for the containing CSS file
Url cssUrlCopy = new Url(cssUrl);
cssUrlCopy.resolveRelative(imageCandidateUrl);
// if the image should be processed as URL or base64 embedded
if (cssUrlCopy.getQueryString() != null && cssUrlCopy.getQueryString().contains(EMBED_BASE64)) {
embedded = true;
PackageResourceReference imageReference = new PackageResourceReference(scope, cssUrlCopy.toString().replace("?" + EMBED_BASE64, ""));
try {
processedUrl = ImageUtil.createBase64EncodedImage(imageReference, true);
} catch (Exception e) {
throw new WicketRuntimeException("Error while embedding an image into the css: " + imageReference, e);
}
} else {
PackageResourceReference imageReference = new PackageResourceReference(scope, cssUrlCopy.toString());
processedUrl = cycle.urlFor(imageReference, null);
}
}
// embedded data urls don't need single quotes, but regular urls do:
matcher.appendReplacement(output, embedded ? "url(" + processedUrl + ")" : "url('" + processedUrl + "')");
}
matcher.appendTail(output);
return output.toString();
}
use of org.apache.wicket.request.cycle.RequestCycle in project wicket by apache.
the class QueryStringWithVersionResourceCachingStrategy method undecorateUrl.
@Override
public void undecorateUrl(ResourceUrl url) {
final INamedParameters parameters = url.getParameters();
if (parameters != null) {
// store the version in the request cycle
StringValue versionValue = parameters.get(versionParameter);
RequestCycle requestCycle = RequestCycle.get();
if (versionValue.isEmpty() == false && requestCycle != null) {
requestCycle.setMetaData(URL_VERSION, versionValue.toString());
}
// undecorate
parameters.remove(versionParameter);
}
}
use of org.apache.wicket.request.cycle.RequestCycle in project wicket by apache.
the class AbstractAutoCompleteBehavior method respond.
@Override
protected void respond(final AjaxRequestTarget target) {
final RequestCycle requestCycle = RequestCycle.get();
final String val = requestCycle.getRequest().getRequestParameters().getParameterValue(settings.getParameterName()).toOptionalString();
onRequest(val, requestCycle);
}
use of org.apache.wicket.request.cycle.RequestCycle in project wicket by apache.
the class ComponentRenderer method renderPage.
/**
* Collects the html generated by rendering a page.
*
* @param page
* supplier of the page
* @return the html rendered by the panel
*/
public CharSequence renderPage(final Supplier<? extends Page> page) {
return inThreadContext(() -> {
Request request = newRequest();
BufferedWebResponse response = new BufferedWebResponse(null);
RequestCycle cycle = application.createRequestCycle(request, response);
ThreadContext.setRequestCycle(cycle);
page.get().renderPage();
return response.getText();
});
}
Aggregations