}
// Lookup or generate the feed
// Cache key is handle + locale
String cacheKey = (handle==null?"site":handle)+"."+locale.toString();
SyndicationFeed feed = null;
if (feedCache != null)
{
CacheFeed cFeed = feedCache.get(cacheKey);
if (cFeed != null) // cache hit, but...
{
// Is the feed current?
boolean cacheFeedCurrent = false;
if (cFeed.timeStamp + (cacheAge * HOUR_MSECS) < System.currentTimeMillis())
{
cacheFeedCurrent = true;
}
// Not current, but have any items changed since feed was created/last checked?
else if ( ! itemsChanged(context, dso, cFeed.timeStamp))
{
// no items have changed, re-stamp feed and use it
cFeed.timeStamp = System.currentTimeMillis();
cacheFeedCurrent = true;
}
if (cacheFeedCurrent)
{
feed = cFeed.access();
}
}
}
// either not caching, not found in cache, or feed in cache not current
if (feed == null)
{
feed = new SyndicationFeed(SyndicationFeed.UITYPE_JSPUI);
feed.populate(request, dso, getItems(context, dso), labelMap);
if (feedCache != null)
{
cache(cacheKey, new CacheFeed(feed));
}
}
// set the feed to the requested type & return it
try
{
feed.setType(feedType);
response.setContentType("text/xml; charset=UTF-8");
feed.output(response.getWriter());
}
catch( FeedException fex )
{
throw new IOException(fex.getMessage(), fex);
}