Implementation of HttpServletResponseWrapper that captures page data instead of
sending to the writer.
Should be used in filter-chains or when forwarding/including pages
using a RequestDispatcher.
Method from com.opensymphony.module.sitemesh.filter.PageResponseWrapper Detail: |
public void addHeader(String name,
String value) {
if (name.toLowerCase().equals("content-type")) { // ensure ContentType is always set through setContentType()
setContentType(value);
} else if (!parseablePage || !name.toLowerCase().equals("content-length")) {
super.addHeader(name, value);
}
}
Prevent content-length being set if page is parseable. |
public ServletOutputStream getOutputStream() {
return routableServletOutputStream;
}
|
public Page getPage() throws IOException {
if (aborted || !parseablePage) {
return null;
} else {
return buffer.parse();
}
}
|
public PrintWriter getWriter() {
return routablePrintWriter;
}
|
public boolean isUsingStream() {
return buffer != null && buffer.isUsingStream();
}
|
public void sendError(int sc) throws IOException {
aborted = true;
super.sendError(sc);
}
|
public void sendError(int sc,
String msg) throws IOException {
aborted = true;
super.sendError(sc, msg);
}
|
public void sendRedirect(String location) throws IOException {
aborted = true;
super.sendRedirect(location);
}
|
public void setContentLength(int contentLength) {
if (!parseablePage) super.setContentLength(contentLength);
}
Prevent content-length being set if page is parseable. |
public void setContentType(String type) {
super.setContentType(type);
if (type != null) {
// this is the content type + charset. eg: text/html;charset=UTF-8
int offset = type.lastIndexOf("charset=");
String encoding = null;
if (offset != -1)
encoding = extractContentTypeValue(type, offset + 8);
String contentType = extractContentTypeValue(type, 0);
if (factory.shouldParsePage(contentType)) {
activateSiteMesh(contentType, encoding);
}
}
}
|
public void setHeader(String name,
String value) {
if (name.toLowerCase().equals("content-type")) { // ensure ContentType is always set through setContentType()
setContentType(value);
} else if (!parseablePage || !name.toLowerCase().equals("content-length")) {
super.setHeader(name, value);
}
}
Prevent content-length being set if page is parseable. |
public void setStatus(int sc) {
if (!parseablePage || sc != HttpServletResponse.SC_NOT_MODIFIED) {
super.setStatus(sc);
}
}
Prevent 'not modified' (304) HTTP status from being sent if page is parseable
(so web-server/browser doesn't cache contents). |