19.11Feed Views

BothAbstractAtomFeedViewandAbstractRssFeedViewinherit from the base classAbstractFeedViewand are used to provide Atom and RSS Feed views respectfully. They are based on java.net’sROMEproject and are located in the packageorg.springframework.web.servlet.view.feed.

AbstractAtomFeedViewrequires you to implement thebuildFeedEntries()method and optionally override thebuildFeedMetadata()method (the default implementation is empty), as shown below.

public class SampleContentAtomView extends AbstractAtomFeedView {

    @Override
    protected void buildFeedMetadata(Map<String, Object> model,
            Feed feed, HttpServletRequest request) {
        // implementation omitted
    }

    @Override
    protected List<Entry> buildFeedEntries(Map<String, Object> model,
            HttpServletRequest request, HttpServletResponse response) throws Exception {
        // implementation omitted
    }

}

Similar requirements apply for implementingAbstractRssFeedView, as shown below.

public class SampleContentAtomView extends AbstractRssFeedView {

    @Override
    protected void buildFeedMetadata(Map<String, Object> model,
            Channel feed, HttpServletRequest request) {
        // implementation omitted
    }

    @Override
    protected List<Item> buildFeedItems(Map<String, Object> model,
            HttpServletRequest request, HttpServletResponse response) throws Exception {
        // implementation omitted
    }

}

ThebuildFeedItems()andbuildFeedEntires()methods pass in the HTTP request in case you need to access the Locale. The HTTP response is passed in only for the setting of cookies or other HTTP headers. The feed will automatically be written to the response object after the method returns.

For an example of creating an Atom view please refer to Alef Arendsen’s Spring Team Blogentry.

results matching ""

    No results matching ""