Question

I am using Rome to combine several feeds into one. It's largely based on this example on the Rome site.

I'm creating a RSS 2.0 feed, which I save as a (W3C) Document then pass to a stylesheet to convert to HTML.

One of my requirements is to display the source (link to and name of originating site) for each entry (as they can come from a variety of sources).

According to the RSS spec there is a optional source attribute per item. And Rome appears to support this with a setSource method on the SyndEntry interface. However, setting this to the SyndFeed of the original feed doesn't appear to set this attribute.

The document I output doesn't contain a source element in the item.

Any clues on what I might be doing wrong or suggestions on alternative methods for doing what I want to do?

Thanks in advance, Darren.

Was it helpful?

Solution 2

I have found a workaround for this for now.

As I only really need to give a name as attribution I am overriding the author field as follows.

SyndEntry entry = // fetched from SyndFeed
Module dcModule = entry.getModule(DCModule.URI);
String title = // My overridden title
if (dcModule != null && title != null) {
    ((DCModule)dcModule).setCreator(title);
}

The reason I use this code instead of SyndEntry.setAuthor is that calling that only sets the author if it's null, we need to always set it to our value.

I then reference this as dc:creator in my XSL stylesheet.

OTHER TIPS

I know it's a bit late for the response but maybe someone will use this later. I have done it with rome 1.0.

You can defined your own Converter and Generator.

My need was an RSS 2.0 feed with source field in items. So for both converter and generator I extend the implementation of RSS 2.0 by ROME.

First we need a converter. It's the one who will filling the source

/**
 * This is a convertor for RSS 2.0 setting source on output items
 */
public class ConverterForRSS20WithSource extends ConverterForRSS20 {

    /**
     * Default Constructor
     */
    public ConverterForRSS20WithSource() {
        this("rss_2.0_withSource");
    }

    /**
     * Constructor with type
     * @param type
     */
    protected ConverterForRSS20WithSource(String type) {
        super(type);
    }

    /** 
     * @see com.sun.syndication.feed.synd.impl.ConverterForRSS094#createRSSItem(com.sun.syndication.feed.synd.SyndEntry)
     */
    @Override
    protected Item createRSSItem(SyndEntry sEntry) {
        Item item = super.createRSSItem(sEntry);
        if(sEntry.getSource() != null 
                && StringUtils.isNotBlank(sEntry.getSource().getUri())) {
            Source s = new Source();
            s.setUrl(sEntry.getSource().getUri());
            s.setValue(sEntry.getSource().getTitle());
            item.setSource(s);
        }

        return item;
    }
}

Then we need a Generator. It's has nothing special to do. It just had to be

/**
 *  Rss 2.0 Generator with source field
 */
public class RSS020GeneratorWithSource extends RSS20Generator {

    /**
     * 
     */
    public RSS020GeneratorWithSource() {
        super("rss_2.0_withSource","2.0");
    }

}

We need to do one last things, declare our classes to rome. For that simply put a rome.properties at the root of your resources. Don't forget to add the dublin core to your rss.items... In that file just put

Converter.classes=my.package.ConverterForRSS20WithSource

WireFeedGenerator.classes=my.package.RSS020GeneratorWithSource

# Parsers for RSS 2.0 with source item modules
#
rss_2.0_withSource.item.ModuleParser.classes=com.sun.syndication.io.impl.DCModuleParser

# Generators for RSS_2.0 entry modules
#
rss_2.0_withSource.item.ModuleGenerator.classes=com.sun.syndication.io.impl.DCModuleGenerator

And that's all.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top