From 7f06639be2adad527969478b56e36909a6e2ef19 Mon Sep 17 00:00:00 2001 From: Mark Pollack Date: Mon, 13 Apr 2009 22:11:15 +0000 Subject: [PATCH] Add REST feed view docs, included edits from Thomas R. --- spring-framework-reference/src/rest.xml | 93 ++++++++++++++++++- .../src/spring-framework-reference.xml | 6 +- 2 files changed, 95 insertions(+), 4 deletions(-) diff --git a/spring-framework-reference/src/rest.xml b/spring-framework-reference/src/rest.xml index 6285985c7e..956ec7c92a 100644 --- a/spring-framework-reference/src/rest.xml +++ b/spring-framework-reference/src/rest.xml @@ -261,7 +261,7 @@ public class RelativePathUriTemplateController { bean is a class that inherits from AbstractAtomFeedView which returns an Atom RSS feed. For more information on creating an Atom Feed representation see - the section 'Atom Views'. + the section 'Atom Views'. In this configuration, if a request is made with a .html extension the view resolver will look for a view that matches the text/html media @@ -309,7 +309,94 @@ public class ContentController {
Views - blah + Several views were added to Spring 3 to help support creating + RESTful services. They are: + + + + AbstractAtomFeedView - return an Atom + feed + + + + AbstractRssFeedView - returns a RSS + feed + + + + MarshallingView - returns an XML + representation using Spring's Objecct/XML mapping (OXM) + functionality + + + + Available separately is the JacksonJsonView + included as part of the Spring JavaScript project. + +
+ Feed Views + + Both AbstractAtomFeedView and + AbstractRssFeedView inherit from the base class + AbstractFeedView<T> and are used to + provide Atom and RSS Feed views respectfully. They are based on + java.net's ROME project + and located in the package org.springframework.web.servlet.view.feed. + The AbstractAtomFeedView requires you to + implement the buildFeedEntries method and + optionally override the buildFeedMetadata + 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 implementing + AbstractRssFeedView, 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 + } + +} + + The buildFeedItems and + buildFeedEntires pass in the HTTP request in + case you need to access the Locale. The HTTP response in 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 implementation of creating a Atom view please + refer to Alef Arendsen's SpringSource TeamBlog entry. +
+ +
+ XML Marshalling View + + The MarhsallingView +
@@ -443,7 +530,7 @@ public String deletePet(@PathVariable int ownerId, @PathVariable int petId) {
-
+
MarshallingHttpMessageConverter diff --git a/spring-framework-reference/src/spring-framework-reference.xml b/spring-framework-reference/src/spring-framework-reference.xml index d6adfa63bd..9632577c02 100644 --- a/spring-framework-reference/src/spring-framework-reference.xml +++ b/spring-framework-reference/src/spring-framework-reference.xml @@ -19,8 +19,8 @@ + - @@ -289,6 +289,9 @@ + + + @@ -299,6 +302,7 @@ &mvc; &view; + &rest; &web-integration; &rest; &portlet;