use of org.apache.wicket.response.StringResponse in project wicket by apache.
the class HtmlHeaderContainer method onComponentTagBody.
/**
* First render the body of the component. And if it is the header component of a Page (compared
* to a Panel or Border), then get the header sections from all component in the hierarchy and
* render them as well.
*/
@Override
public final void onComponentTagBody(MarkupStream markupStream, ComponentTag openTag) {
// We are able to automatically add <head> to the page if it is
// missing. But we only want to add it, if we have content to be
// written to its body. Thus we first write the output into a
// StringResponse and if not empty, we copy it to the original
// web response.
// Temporarily replace the web response with a String response
final Response webResponse = getResponse();
try {
// Create a (string) response for all headers contributed by any component on the Page.
final StringResponse response = new StringResponse();
getRequestCycle().setResponse(response);
IHeaderResponse headerResponse = getHeaderResponse();
if (!response.equals(headerResponse.getResponse())) {
getRequestCycle().setResponse(headerResponse.getResponse());
}
// Render the header sections of all components on the page
AbstractHeaderRenderStrategy.get().renderHeader(this, new HeaderStreamState(markupStream, openTag), getPage());
// Close the header response before rendering the header container itself
// See https://issues.apache.org/jira/browse/WICKET-3728
headerResponse.close();
// Cleanup extraneous CR and LF from the response
CharSequence output = getCleanResponse(response);
// Automatically add <head> if necessary
if (output.length() > 0) {
if (renderOpenAndCloseTags()) {
webResponse.write("<head>");
}
webResponse.write(output);
if (renderOpenAndCloseTags()) {
webResponse.write("</head>");
}
}
} finally {
// Restore the original response
getRequestCycle().setResponse(webResponse);
}
}
use of org.apache.wicket.response.StringResponse in project wicket by apache.
the class HtmlHeaderContainer method renderHeaderTagBody.
/**
* Renders the content of the <head> section of the page, including <wicket:head>
* sections in subclasses of the page. For every child-component, the content is rendered to a
* string and passed to {@link IHeaderResponse}.
*
* @param headerStreamState
*/
public void renderHeaderTagBody(HeaderStreamState headerStreamState) {
if (headerStreamState == null)
return;
final Response oldResponse = getRequestCycle().getResponse();
try {
// Create a separate (string) response for the header container itself
final StringResponse bodyResponse = new StringResponse();
getRequestCycle().setResponse(bodyResponse);
// render the header section directly associated with the markup
super.onComponentTagBody(headerStreamState.getMarkupStream(), headerStreamState.getOpenTag());
CharSequence bodyOutput = getCleanResponse(bodyResponse);
if (bodyOutput.length() > 0) {
getHeaderResponse().render(new PageHeaderItem(bodyOutput));
}
} finally {
getRequestCycle().setResponse(oldResponse);
}
}
use of org.apache.wicket.response.StringResponse in project wicket by apache.
the class ResponseBufferZone method execute.
public CharSequence execute() {
final int originalStreamPos = stream.getCurrentIndex();
final Response original = cycle.getResponse();
final StringResponse buffer = new StringResponse();
cycle.setResponse(buffer);
try {
executeInsideBufferedZone();
return buffer.getBuffer();
} finally {
cycle.setResponse(original);
stream.setCurrentIndex(originalStreamPos);
}
}
use of org.apache.wicket.response.StringResponse in project wicket by apache.
the class AjaxRequestHandler method respond.
/**
* @see org.apache.wicket.core.request.handler.IPageRequestHandler#respond(org.apache.wicket.request.IRequestCycle)
*/
@Override
public final void respond(final IRequestCycle requestCycle) {
final RequestCycle rc = (RequestCycle) requestCycle;
final WebResponse response = (WebResponse) requestCycle.getResponse();
if (shouldRedirectToPage(requestCycle)) {
// the page itself has been added to the request target, we simply issue a redirect
// back to the page
IRequestHandler handler = new RenderPageRequestHandler(new PageProvider(page));
final String url = rc.urlFor(handler).toString();
response.sendRedirect(url);
return;
}
respondersFrozen = true;
for (ITargetRespondListener listener : respondListeners) {
listener.onTargetRespond(this);
}
final Application app = page.getApplication();
page.send(app, Broadcast.BREADTH, this);
// Determine encoding
final String encoding = app.getRequestCycleSettings().getResponseRequestEncoding();
// Set content type based on markup type for page
update.setContentType(response, encoding);
// Make sure it is not cached by a client
response.disableCaching();
final StringResponse bodyResponse = new StringResponse();
update.writeTo(bodyResponse, encoding);
CharSequence filteredResponse = invokeResponseFilters(bodyResponse);
response.write(filteredResponse);
}
use of org.apache.wicket.response.StringResponse in project wicket by apache.
the class JavaScriptUtilsTest method writeJavaScriptUrlAsync.
/**
* https://issues.apache.org/jira/browse/WICKET-5715
*/
@Test
public void writeJavaScriptUrlAsync() {
StringResponse response = new StringResponse();
String url = "some/url;jsessionid=1234?p1=v1&p2=v2";
String id = "some&bad%id";
boolean defer = true;
boolean async = true;
String charset = "some&bad%%charset";
JavaScriptUtils.writeJavaScriptUrl(response, url, id, defer, charset, async);
assertEquals("<script type=\"text/javascript\" id=\"some&bad%id\" defer=\"defer\" async=\"async\" charset=\"some&bad%%charset\" src=\"some/url;jsessionid=1234?p1=v1&p2=v2\"></script>\n", response.toString());
}
Aggregations