use of org.apache.wicket.request.Response in project wicket by apache.
the class LocaleAwarePageParametersTest method newApplication.
@Override
protected WebApplication newApplication() {
return new MockApplication() {
@Override
protected void init() {
super.init();
mountPage("unaware", LocaleUnawarePageParametersPage.class);
mount(new MountedMapper("aware", LocaleAwarePageParametersPage.class) {
@Override
protected Locale resolveLocale() {
return resolveUserLocale();
}
});
}
@Override
public Session newSession(Request request, Response response) {
final Session session = super.newSession(request, response);
session.setLocale(Locale.GERMANY);
return session;
}
};
}
use of org.apache.wicket.request.Response in project wicket by apache.
the class AjaxIndicatorAppender method afterRender.
@Override
public void afterRender(final Component component) {
super.afterRender(component);
final Response r = component.getResponse();
r.write("<span style=\"display:none;\" class=\"");
r.write(getSpanClass());
r.write("\" ");
r.write("id=\"");
r.write(getMarkupId());
r.write("\">");
r.write("<img src=\"");
r.write(getIndicatorUrl());
r.write("\" alt=\"\"/></span>");
}
use of org.apache.wicket.request.Response in project wicket by apache.
the class ComponentRenderer method renderComponent.
/**
* Collects the Html generated by rendering a component.
* <p>
* Important notes:
* <ul>
* <li>this method is meant to render fresh component instances that are disposed after the html
* has been generate. To avoid unwanted side effects do not use it with components that are from
* an existing hierarchy.</li>
* <li>does <strong>not</strong> support rendering
* {@link org.apache.wicket.markup.html.panel.Fragment} instances</li>
* <li>must be called on a thread bound to an application's {@link ThreadContext}!</li>
* </ul>
*
* @param component
* the component to render.
* @return the html rendered by the component
*
* @see ThreadContext
*/
public static CharSequence renderComponent(final Component component) {
RequestCycle requestCycle = RequestCycle.get();
final Response originalResponse = requestCycle.getResponse();
BufferedWebResponse tempResponse = new BufferedWebResponse(null);
MarkupContainer oldParent = component.getParent();
if (oldParent != null && LOGGER.isWarnEnabled()) {
LOGGER.warn("Component '{}' with a parent '{}' is passed for standalone rendering. " + "It is recommended to render only orphan components because they are not cleaned up/detached" + " after the rendering.", component, oldParent);
}
try {
requestCycle.setResponse(tempResponse);
// add the component to a dummy page just for the rendering
RenderPage page = new RenderPage(component);
page.internalInitialize();
component.beforeRender();
component.renderPart();
} finally {
if (oldParent != null) {
// re-add the child to its old parent
oldParent.add(component);
}
requestCycle.setResponse(originalResponse);
}
return tempResponse.getText();
}
use of org.apache.wicket.request.Response in project wicket by apache.
the class AbstractResource method configureCache.
/**
* Configure the web response header for client cache control.
*
* @param data
* resource data
* @param attributes
* request attributes
*/
protected void configureCache(final ResourceResponse data, final Attributes attributes) {
Response response = attributes.getResponse();
if (response instanceof WebResponse) {
Duration duration = data.getCacheDuration();
WebResponse webResponse = (WebResponse) response;
if (duration.compareTo(Duration.NONE) > 0) {
webResponse.enableCaching(duration, data.getCacheScope());
} else {
webResponse.disableCaching();
}
}
}
use of org.apache.wicket.request.Response in project wicket by apache.
the class AbstractResource method setResponseHeaders.
/**
* Sets the response header of resource response to the response received from the attributes
*
* @param resourceResponse
* the resource response to get the header fields from
* @param attributes
* the attributes to get the response from to which the header information are going
* to be applied
*/
protected void setResponseHeaders(final ResourceResponse resourceResponse, final Attributes attributes) {
Response response = attributes.getResponse();
if (response instanceof WebResponse) {
WebResponse webResponse = (WebResponse) response;
// 1. Last Modified
Time lastModified = resourceResponse.getLastModified();
if (lastModified != null) {
webResponse.setLastModifiedTime(lastModified);
}
// 2. Caching
configureCache(resourceResponse, attributes);
if (resourceResponse.getErrorCode() != null) {
webResponse.sendError(resourceResponse.getErrorCode(), resourceResponse.getErrorMessage());
return;
}
if (resourceResponse.getStatusCode() != null) {
webResponse.setStatus(resourceResponse.getStatusCode());
}
if (!resourceResponse.dataNeedsToBeWritten(attributes)) {
webResponse.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
return;
}
// 3. Content Disposition
String fileName = resourceResponse.getFileName();
ContentDisposition disposition = resourceResponse.getContentDisposition();
if (ContentDisposition.ATTACHMENT == disposition) {
webResponse.setAttachmentHeader(fileName);
} else if (ContentDisposition.INLINE == disposition) {
webResponse.setInlineHeader(fileName);
}
// 4. Mime Type (+ encoding)
String mimeType = resourceResponse.getContentType();
if (mimeType != null) {
final String encoding = resourceResponse.getTextEncoding();
if (encoding == null) {
webResponse.setContentType(mimeType);
} else {
webResponse.setContentType(mimeType + "; charset=" + encoding);
}
}
// 5. Accept Range
ContentRangeType acceptRange = resourceResponse.getAcceptRange();
if (acceptRange != null) {
webResponse.setAcceptRange(acceptRange.getTypeName());
}
long contentLength = resourceResponse.getContentLength();
boolean contentRangeApplied = false;
// 6. Content Range
// for more information take a look here:
// http://stackoverflow.com/questions/8293687/sample-http-range-request-session
// if the content range header has been set directly
// to the resource response use it otherwise calculate it
String contentRange = resourceResponse.getContentRange();
if (contentRange != null) {
webResponse.setContentRange(contentRange);
} else {
// moment
if (contentLength != -1 && ContentRangeType.BYTES.equals(acceptRange)) {
contentRangeApplied = setResponseContentRangeHeaderFields(webResponse, attributes, contentLength);
}
}
// 7. Content Length
if (contentLength != -1 && !contentRangeApplied) {
webResponse.setContentLength(contentLength);
}
// add custom headers and values
final HttpHeaderCollection headers = resourceResponse.getHeaders();
for (String name : headers.getHeaderNames()) {
checkHeaderAccess(name);
for (String value : headers.getHeaderValues(name)) {
webResponse.addHeader(name, value);
}
}
}
}
Aggregations