{
HttpServletRequest httpRequest = (HttpServletRequest)request;
final String uri = URLDecoder.decode(httpRequest.getRequestURI(), "UTF-8");
final HttpServletResponse httpResponse = (HttpServletResponse)response;
ExoContainer portalContainer = getContainer();
final SkinService skinService = (SkinService) portalContainer.getComponentInstanceOfType(SkinService.class);
long ifModifiedSince = httpRequest.getDateHeader(IF_MODIFIED_SINCE);
//
if (uri.endsWith(".css"))
{
// Check if cached resource has not been modifed, return 304 code
long cssLastModified = skinService.getLastModified(uri);
if (isNotModified(ifModifiedSince, cssLastModified)) {
httpResponse.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
return;
}
response.setContentType("text/css; charset=UTF-8");
final OutputStream out = response.getOutputStream();
final BinaryOutput output = new BinaryOutput()
{
public Charset getCharset()
{
return UTF_8;
}
public void write(byte b) throws IOException
{
out.write(b);
}
public void write(byte[] bytes) throws IOException
{
out.write(bytes);
}
public void write(byte[] bytes, int off, int len) throws IOException
{
out.write(bytes, off, len);
}
};
ResourceRenderer renderer = new ResourceRenderer()
{
public BinaryOutput getOutput() throws IOException
{
return output;
}
public void setExpiration(long seconds)
{
if (seconds > 0)
{
httpResponse.addHeader("Cache-Control", "max-age=" + seconds + ",s-maxage=" + seconds);
}
else
{
httpResponse.setHeader("Cache-Control", "no-cache");
}
long lastModified = skinService.getLastModified(uri);
processIfModified(lastModified, httpResponse);
}
};
//
try
{
skinService.renderCSS(renderer, uri);
if (log.isDebugEnabled())
{
log.debug("Use a merged CSS: " + uri);
}
}