Weblog localWeblog;
try {
localWeblog = WebloggerFactory.getWeblogger().getWeblogManager()
.getWeblogByHandle(weblogHandle);
if (localWeblog == null) {
throw new FetcherException("Local feed - "+feedURL+" no longer exists in weblogger");
}
} catch (WebloggerException ex) {
throw new FetcherException("Problem looking up local weblog - "+weblogHandle, ex);
}
// if weblog hasn't changed since last fetch then bail
if(lastModified != null && !localWeblog.getLastModified().after(lastModified)) {
log.debug("Skipping unmodified LOCAL weblog");
return null;
}
// build planet subscription from weblog
Subscription newSub = new Subscription();
newSub.setFeedURL(feedURL);
newSub.setSiteURL(WebloggerFactory.getWeblogger().getUrlStrategy().getWeblogURL(localWeblog, null, true));
newSub.setTitle(localWeblog.getName());
newSub.setAuthor(localWeblog.getName());
newSub.setLastUpdated(localWeblog.getLastModified());
// must have a last updated time
if(newSub.getLastUpdated() == null) {
newSub.setLastUpdated(new Date());
}
// lookup recent entries from weblog and add them to the subscription
try {
int entryCount = WebloggerRuntimeConfig.getIntProperty("site.newsfeeds.defaultEntries");
if (log.isDebugEnabled()) {
log.debug("Seeking up to " + entryCount + " entries from " + localWeblog.getHandle());
}
// grab recent entries for this weblog
WeblogEntryManager wmgr = WebloggerFactory.getWeblogger().getWeblogEntryManager();
List<WeblogEntry> entries = wmgr.getWeblogEntries(
localWeblog, // weblog
null, // user
null, // startDate
null, // endDate
null, // catName
null, // tags
WeblogEntry.PUBLISHED, // status
null, // text
null, // sortby (null means pubTime)
null, // sortOrder
null, // locale
0, // offset
entryCount); // range
log.debug("Found " + entries.size());
// Populate subscription object with new entries
PluginManager ppmgr = WebloggerFactory.getWeblogger().getPluginManager();
Map pagePlugins = ppmgr.getWeblogEntryPlugins(localWeblog);
for ( WeblogEntry rollerEntry : entries ) {
SubscriptionEntry entry = new SubscriptionEntry();
String content = "";
if (!StringUtils.isEmpty(rollerEntry.getText())) {
content = rollerEntry.getText();
} else {
content = rollerEntry.getSummary();
}
content = ppmgr.applyWeblogEntryPlugins(pagePlugins, rollerEntry, content);
entry.setAuthor(rollerEntry.getCreator().getScreenName());
entry.setTitle(rollerEntry.getTitle());
entry.setPubTime(rollerEntry.getPubTime());
entry.setText(content);
entry.setPermalink(rollerEntry.getPermalink());
entry.setCategoriesString(rollerEntry.getCategory().getPath());
newSub.addEntry(entry);
}
} catch (WebloggerException ex) {
throw new FetcherException("Error processing entries for local weblog - "+weblogHandle, ex);
}
// all done
return newSub;
}