} else {
cacheKey = weblogFeedCache.generateKey(feedRequest);
}
// cached content checking
CachedContent cachedContent = null;
if(isSiteWide) {
cachedContent = (CachedContent) siteWideCache.get(cacheKey);
} else {
cachedContent = (CachedContent) weblogFeedCache.get(cacheKey, lastModified);
}
if(cachedContent != null) {
log.debug("HIT "+cacheKey);
response.setContentLength(cachedContent.getContent().length);
response.getOutputStream().write(cachedContent.getContent());
return;
} else {
log.debug("MISS "+cacheKey);
}
// looks like we need to render content
HashMap model = new HashMap();
String pageId = null;
try {
// determine what template to render with
if (RollerRuntimeConfig.isSiteWideWeblog(weblog.getHandle())) {
pageId = "templates/feeds/site-"+feedRequest.getType()+"-"+feedRequest.getFormat()+".vm";
} else {
pageId = "templates/feeds/weblog-"+feedRequest.getType()+"-"+feedRequest.getFormat()+".vm";
}
// populate the rendering model
Map initData = new HashMap();
initData.put("request", request);
initData.put("weblogRequest", feedRequest);
// Load models for feeds
String feedModels = RollerConfig.getProperty("rendering.feedModels");
ModelLoader.loadModels(feedModels, model, initData, true);
// Load special models for site-wide blog
if(RollerRuntimeConfig.isSiteWideWeblog(weblog.getHandle())) {
String siteModels = RollerConfig.getProperty("rendering.siteModels");
ModelLoader.loadModels(siteModels, model, initData, true);
}
// TODO: re-enable custom models once feeds are customizable
// Load weblog custom models
//ModelLoader.loadCustomModels(weblog, model, initData);
} catch (RollerException ex) {
log.error("ERROR loading model for page", ex);
if(!response.isCommitted()) response.reset();
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return;
}
// lookup Renderer we are going to use
Renderer renderer = null;
try {
log.debug("Looking up renderer");
Template template = new StaticTemplate(pageId, null, "velocity");
renderer = RendererManager.getRenderer(template);
} catch(Exception e) {
// nobody wants to render my content :(
// TODO: this log message has been disabled because it fills up
// the logs with useless errors due to the fact that the way these
// template ids are formed comes directly from the request and it
// often gets bunk data causing invalid template ids.
// at some point we should have better validation on the input so
// that we can quickly dispatch invalid feed requests and only
// get this far if we expect the template to be found
//log.error("Couldn't find renderer for page "+pageId, e);
if(!response.isCommitted()) response.reset();
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
// render content. use default size of about 24K for a standard page
CachedContent rendererOutput = new CachedContent(24567);
try {
log.debug("Doing rendering");
renderer.render(model, rendererOutput.getCachedWriter());
// flush rendered output and close
rendererOutput.flush();
rendererOutput.close();
} catch(Exception e) {
// bummer, error during rendering
log.error("Error during rendering for page "+pageId, e);
if(!response.isCommitted()) response.reset();
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}
// post rendering process
// flush rendered content to response
log.debug("Flushing response output");
response.setContentLength(rendererOutput.getContent().length);
response.getOutputStream().write(rendererOutput.getContent());
// cache rendered content. only cache if user is not logged in?
log.debug("PUT "+cacheKey);
if(isSiteWide) {
siteWideCache.put(cacheKey, rendererOutput);