private static final Logger logger = Logger.getLogger(RssOutput.class);
public String getDocs(ResponsePojo rp) {
// Create the feed using Rome
SyndFeed feed = new SyndFeedImpl(); // create the feed
String feedType = "rss_2.0";
// Setup a list of feeds
@SuppressWarnings("unchecked")
List<BasicDBObject> docs = (List<BasicDBObject>) rp.getData();
PropertiesManager props = new PropertiesManager();
// Set the title of the feed
feed.setTitle( "Infinit.e Knowledge Discovery RSS Feed" );
feed.setDescription( "Infinit.e Search Results RSS Feed" );
feed.setLanguage( "en-us" );
feed.setPublishedDate( new Date( System.currentTimeMillis() ) );
feed.setFeedType( feedType ); // set the type of your feed
String urlRoot = props.getUrlRoot();
if (null != urlRoot) {
feed.setLink(urlRoot.replace("/api/", ""));
}
else { // feed.link needs to be specified, otherwise RSS feed will fail:
feed.setLink("http://www.ikanow.com/#SET_YOUR_URL_ROOT");
}
// Establish the list to contain the feeds
List<SyndEntry> entries = new ArrayList<SyndEntry>();
// loop through the result set
for ( BasicDBObject fdbo : docs)
{
SyndEntry entry = new SyndEntryImpl(); // create a feed entry
String title = fdbo.getString(DocumentPojo.title_);
if ( title != null ) {
entry.setTitle( title );
}
Date pubDate = (Date) fdbo.get(DocumentPojo.publishedDate_);
if ( pubDate != null )
entry.setPublishedDate( pubDate );
String url = fdbo.getString(DocumentPojo.displayUrl_);
if (null == url) {
url = fdbo.getString(DocumentPojo.url_);
if ((null != url) && !url.startsWith("http")) {
url = null;
}
}//TESTED
else if (!url.startsWith("http:") && !url.startsWith("https:")) {
if (null != urlRoot) {
Object sourceKeyObj = fdbo.get(DocumentPojo.sourceKey_);
String sourceKey = null;
try {
if (sourceKeyObj instanceof String) {
sourceKey = (String) sourceKey;
}//(should never happen)
else if (sourceKeyObj instanceof Collection) {
@SuppressWarnings("rawtypes")
Collection sourceKeyCollection = ((Collection)sourceKeyObj);
sourceKey = (String) sourceKeyCollection.iterator().next();
}//TESTED
else if (sourceKeyObj instanceof String[]) {
sourceKey = ((String[])sourceKeyObj)[0];
}//(should never happen)
if (url.startsWith("/")) {
url = urlRoot + "knowledge/document/file/get/" + sourceKey + url;
}
else {
url = urlRoot + "knowledge/document/file/get/" + sourceKey + "/" + url;
}
}
catch (Exception e) {} // carry on...
}//TESTED
else {
url = null;
}
}//TESTED
if ((null == url) && (null != urlRoot)) {
url = urlRoot + "knowledge/document/get/" + fdbo.getObjectId(DocumentPojo._id_).toString() + "?returnRawData=false";
}//TESTED
if (null != url) {
entry.setLink( url );
}
String description = fdbo.getString(DocumentPojo.description_);
if ( description != null ) {
// Create the content for the entry
SyndContent content = new SyndContentImpl(); // create the content of your entry
content.setType( "text/plain" );
content.setValue( description );
entry.setDescription( content );
}
entries.add( entry );
}//(end loop over entries)
feed.setEntries( entries ); // you can add multiple entries in your feed
SyndFeedOutput output = new SyndFeedOutput();
String rss = null;
try {