response instanceof HttpServletResponse)
{
HttpServletRequest http_request = (HttpServletRequest)request;
HttpServletResponse http_response = (HttpServletResponse)response;
Renderer renderer = null;
String uri = http_request.getRequestURI();
String extension = FileUtils.getExtension(uri);
if (extension != null &&
extension.endsWith("s"))
{
renderer = XhtmlRendererFactory.getRenderer(extension.substring(0, extension.length()-1));
}
if (renderer != null)
{
SourceRequestWrapper request_wrapper = new SourceRequestWrapper(http_request);
CharResponseWrapper response_wrapper = new CharResponseWrapper(http_response);
chain.doFilter(request_wrapper, response_wrapper);
OutputStream out = response.getOutputStream();
try
{
if (HttpServletResponse.SC_OK == response_wrapper.getStatus())
{
InputStream is = new ByteArrayInputStream(response_wrapper.getWrappedOutputStream().toByteArray());
ByteArrayOutputStream os = new ByteArrayOutputStream();
String encoding = request.getCharacterEncoding();
if (null == encoding)
{
encoding = "UTF-8";
}
renderer.highlight(http_request.getServletPath().substring(1), is, os, encoding, false);
String highlighted = os.toString("ISO-8859-1");
response.setContentType("text/html");
response.setContentLength(highlighted.length());