use of org.apache.wicket.request.http.WebResponse in project wicket by apache.
the class AbstractTransformerBehavior method afterRender.
@Override
public void afterRender(final Component component) {
final RequestCycle requestCycle = RequestCycle.get();
try {
BufferedWebResponse tempResponse = (BufferedWebResponse) requestCycle.getResponse();
if (component instanceof Page && originalResponse instanceof WebResponse) {
tempResponse.writeMetaData((WebResponse) originalResponse);
}
// Transform the data
CharSequence output = transform(component, tempResponse.getText());
originalResponse.write(output);
} catch (Exception ex) {
throw new WicketRuntimeException("Error while transforming the output of component: " + component, ex);
} finally {
// Restore the original response object
requestCycle.setResponse(originalResponse);
}
}
use of org.apache.wicket.request.http.WebResponse in project wicket by apache.
the class AbstractTransformerBehavior method beforeRender.
@Override
public void beforeRender(Component component) {
super.beforeRender(component);
final RequestCycle requestCycle = RequestCycle.get();
// Temporarily replace the web response with a String response
originalResponse = requestCycle.getResponse();
WebResponse origResponse = (WebResponse) ((originalResponse instanceof WebResponse) ? originalResponse : null);
BufferedWebResponse tempResponse = newResponse(origResponse);
// temporarily set StringResponse to collect the transformed output
requestCycle.setResponse(tempResponse);
}
use of org.apache.wicket.request.http.WebResponse in project wicket by apache.
the class AjaxDownloadBehavior method initiate.
/**
* Call this method to initiate the download.
*
* @param target
* the initiating Ajax target
*/
public void initiate(AjaxRequestTarget target) {
if (getComponent() == null) {
throw new WicketRuntimeException("not bound to a component");
}
((WebResponse) RequestCycle.get().getResponse()).clearCookie(cookie(getName()));
CharSequence url;
if (resourceBehavior == null) {
if (resourceReference.canBeRegistered()) {
getComponent().getApplication().getResourceReferenceRegistry().registerResourceReference(resourceReference);
}
PageParameters parameters = new PageParameters();
if (resourceParameters != null) {
parameters.mergeWith(resourceParameters);
}
parameters.set(RESOURCE_PARAMETER_NAME, getName());
url = getComponent().getRequestCycle().urlFor(new ResourceReferenceRequestHandler(resourceReference, parameters));
} else {
url = resourceBehavior.getUrl();
}
JSONObject settings = new JSONObject();
settings.put("attributes", new JSONFunction(renderAjaxAttributes(getComponent())));
settings.put("name", getName());
settings.put("downloadUrl", url);
settings.put("method", getLocation().name().toLowerCase(Locale.ENGLISH));
target.appendJavaScript(String.format("Wicket.AjaxDownload.initiate(%s);", settings));
onBeforeDownload(target);
}
use of org.apache.wicket.request.http.WebResponse in project wicket by apache.
the class AutoCompleteBehavior method onRequest.
@Override
protected final void onRequest(final String val, final RequestCycle requestCycle) {
IRequestHandler target = new IRequestHandler() {
@Override
public void respond(final IRequestCycle requestCycle) {
WebResponse r = (WebResponse) requestCycle.getResponse();
// Determine encoding
final String encoding = Application.get().getRequestCycleSettings().getResponseRequestEncoding();
r.setContentType("text/xml; charset=" + encoding);
r.disableCaching();
Iterator<T> comps = getChoices(val);
int count = 0;
renderer.renderHeader(r);
while (comps.hasNext()) {
final T comp = comps.next();
renderer.render(comp, r, val);
count += 1;
}
renderer.renderFooter(r, count);
}
};
requestCycle.scheduleRequestHandlerAfterCurrent(target);
}
use of org.apache.wicket.request.http.WebResponse in project wicket by apache.
the class WebApplication method renderXmlDecl.
/**
* The rules if and when to insert an xml decl in the response are a bit tricky. Hence, we allow
* the user to replace the default implementation per page and per application.
* <p>
* Default implementation: the page mime type must be "application/xhtml+xml" and request
* HTTP_ACCEPT header must include "application/xhtml+xml" to automatically include the xml
* decl. Please see <a href=
* "https://developer.mozilla.org/en/Writing_JavaScript_for_XHTML#Finally:_Content_Negotiation"
* >Writing JavaScript for XHTML</a> for details.
* <p>
* Please note that xml decls in Wicket's markup are only used for reading the markup. The
* markup's xml decl will always be removed and never be used to configure the response.
*
* @param page
* The page currently being rendered
* @param insert
* If false, than the rules are applied. If true, it'll always be written. In order
* to never insert it, than subclass renderXmlDecl() with an empty implementation.
*/
public void renderXmlDecl(final WebPage page, boolean insert) {
if (insert || MarkupType.XML_MIME.equalsIgnoreCase(page.getMarkupType().getMimeType())) {
final RequestCycle cycle = RequestCycle.get();
if (insert == false) {
WebRequest request = (WebRequest) cycle.getRequest();
String accept = request.getHeader("Accept");
insert = ((accept == null) || (accept.indexOf(MarkupType.XML_MIME) != -1));
}
if (insert) {
WebResponse response = (WebResponse) cycle.getResponse();
response.write("<?xml version='1.0'");
String encoding = getRequestCycleSettings().getResponseRequestEncoding();
if (Strings.isEmpty(encoding) == false) {
response.write(" encoding='");
response.write(encoding);
response.write("'");
}
response.write(" ?>");
}
}
}
Aggregations