Home

Rejuvenation of the news feed

Creating a news feed with Spring 3.0.0.M3

The next release of Spring comes with an AbstractRssFeedView. A good reason to rejuvenate Pebble's XmlView:

public abstract class XmlView extends JspView {
...
}

One reason why the JspView cannot be removed is the RSS news feed.

At the time of writing this Pebble instance is based on Spring version 2.5.x. I did't want to move completely forward to a milestone release. With some small changes to the AbstractRssFeedView and related classes the brand new RssView now serves the RSS news feed.

public class RssView extends AbstractRssFeedView {
    protected void buildFeedMetadata(Map model, Channel feed, HttpServletRequest request) {

        feed.setTitle(blog.getName());
        feed.setDescription(blog.getDescription());
        feed.setLink(blog.getUrl());
    }

...

    protected List buildFeedItems(Map model, HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        List items = new ArrayList();

        List blogEntries = (List) model.get(Constants.BLOG_ENTRIES);
        for (BlogEntry blogEntry : blogEntries) {
            Item item = new Item();
            item.setTitle(blogEntry.getTitle());
            item.setAuthor(blogEntry.getAuthor());
            item.setPubDate(blogEntry.getDate());
            item.setLink(blogEntry.getPermalink());

            Description description = new Description();
...
            items.add(item);
        }
        return items;
}

The FeedAction in modern Spring-mvc 2.5 style is the link between Model and View:

@Controller
public class FeedAction {

    @RequestMapping("/feed.action")
    public ModelAndView process(HttpServletRequest request, HttpServletResponse response) {

        ModelAndView mav = new ModelAndView("rssBlogEntriesView");
...
    }
...
}

With a little bit of glue written in XML...

<bean id="beanNameViewResolver" class="org.springframework.web.servlet.view.BeanNameViewResolver">
    <property name="order" value="1" />
</bean>

<bean id="rssBlogEntriesView" class="net.sourceforge.pebble.web.view.impl.RssView">
</bean>

the RSS news feed is up and running. ;-)




Add a comment