// set last-modified date
ModDateHeaderUtil.setLastModifiedHeader(response, lastModified.getTime());
// cached content checking
String cacheKey = PlanetCache.CACHE_ID + ":" + this.generateKey(planetRequest);
CachedContent entry = (CachedContent) planetCache.get(cacheKey);
if (entry != null) {
response.setContentLength(entry.getContent().length);
response.getOutputStream().write(entry.getContent());
return;
}
// looks like we need to render content
@SuppressWarnings("unchecked")
HashMap<String, Object> model = new HashMap();
try {
// populate the rendering model
if (request.getParameter("group") != null) {
Planet planetObject = planet.getPlanet("default");
model.put("group", planet.getGroup(planetObject, request.getParameter("group")));
}
model.put("planet", planet);
model.put("date", new Date());
model.put("utils", new UtilitiesModel());
model.put("siteName", PlanetRuntimeConfig.getProperty("site.name"));
model.put("siteDescription", PlanetRuntimeConfig.getProperty("site.description"));
model.put("lastModified", lastModified);
if (StringUtils.isNotEmpty(PlanetRuntimeConfig.getProperty("site.absoluteurl"))) {
model.put("absoluteSite", PlanetRuntimeConfig.getProperty("site.absoluteurl"));
} else {
model.put("absoluteSite", WebloggerRuntimeConfig.getAbsoluteContextURL());
}
model.put("feedStyle", new Boolean(WebloggerRuntimeConfig.getBooleanProperty("site.newsfeeds.styledFeeds")));
int numEntries = WebloggerRuntimeConfig.getIntProperty("site.newsfeeds.defaultEntries");
int entryCount = numEntries;
String sCount = request.getParameter("count");
if (sCount != null) {
try {
entryCount = Integer.parseInt(sCount);
} catch (NumberFormatException e) {
log.warn("Improperly formatted count parameter");
}
if (entryCount > numEntries) {
entryCount = numEntries;
}
if (entryCount < 0) {
entryCount = 0;
}
}
model.put("entryCount", new Integer(entryCount));
} catch (Exception ex) {
log.error("Error loading model objects 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("templates/planet/planetrss.vm", "velocity");
renderer = RendererManager.getRenderer(template);
} catch (Exception e) {
// nobody wants to render my content :(
log.error("Couldn't find renderer for planet rss", 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 planet rss", 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.
this.planetCache.put(cacheKey, rendererOutput);
log.debug("Exiting");