mirror of
https://github.com/spring-projects/spring-framework.git
synced 2026-09-17 16:39:29 +00:00
Prior to this commit, Spring Framework would ship several abstract `*View` implementations for rendering PDF, RSS or XLS documents using well-known libraries. More recently, supporting libraries evolved a lot with new versions and forks. Spring Framework is not in a position to efficiently support all variants within the project. This commit deprecates the relevant classes. Instead, libraries can reuse existing code and ship optional support for Spring directly. Often, updating imports and library usage is enough. As an alternative, applications can decide to perform rendering direclty in web handlers. Closes gh-35451
108 lines
3.2 KiB
Plaintext
108 lines
3.2 KiB
Plaintext
[[mvc-view-feeds]]
|
|
= RSS and Atom
|
|
|
|
WARNING: As of Spring Framework 7.0, view classes in the `org.springframework.web.servlet.view.feed`
|
|
package are deprecated. Instead, libraries can adapt this existing code to provide support with their own `*View` types.
|
|
As an alternative, applications can perform direct rendering in web handlers.
|
|
|
|
Both `AbstractAtomFeedView` and `AbstractRssFeedView` inherit from the
|
|
`AbstractFeedView` base class and are used to provide Atom and RSS Feed views, respectively. They
|
|
are based on https://rometools.github.io/rome/[ROME] project and are located in the
|
|
package `org.springframework.web.servlet.view.feed`.
|
|
|
|
`AbstractAtomFeedView` requires you to implement the `buildFeedEntries()` method and
|
|
optionally override the `buildFeedMetadata()` method (the default implementation is
|
|
empty). The following example shows how to do so:
|
|
|
|
[tabs]
|
|
======
|
|
Java::
|
|
+
|
|
[source,java,indent=0,subs="verbatim,quotes"]
|
|
----
|
|
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
|
|
}
|
|
}
|
|
----
|
|
|
|
Kotlin::
|
|
+
|
|
[source,kotlin,indent=0,subs="verbatim,quotes"]
|
|
----
|
|
class SampleContentAtomView : AbstractAtomFeedView() {
|
|
|
|
override fun buildFeedMetadata(model: Map<String, Any>,
|
|
feed: Feed, request: HttpServletRequest) {
|
|
// implementation omitted
|
|
}
|
|
|
|
override fun buildFeedEntries(model: Map<String, Any>,
|
|
request: HttpServletRequest, response: HttpServletResponse): List<Entry> {
|
|
// implementation omitted
|
|
}
|
|
}
|
|
----
|
|
======
|
|
|
|
Similar requirements apply for implementing `AbstractRssFeedView`, as the following example shows:
|
|
|
|
[tabs]
|
|
======
|
|
Java::
|
|
+
|
|
[source,java,indent=0,subs="verbatim,quotes"]
|
|
----
|
|
public class SampleContentRssView 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
|
|
}
|
|
}
|
|
----
|
|
|
|
Kotlin::
|
|
+
|
|
[source,kotlin,indent=0,subs="verbatim,quotes"]
|
|
----
|
|
class SampleContentRssView : AbstractRssFeedView() {
|
|
|
|
override fun buildFeedMetadata(model: Map<String, Any>,
|
|
feed: Channel, request: HttpServletRequest) {
|
|
// implementation omitted
|
|
}
|
|
|
|
override fun buildFeedItems(model: Map<String, Any>,
|
|
request: HttpServletRequest, response: HttpServletResponse): List<Item> {
|
|
// implementation omitted
|
|
}
|
|
}
|
|
----
|
|
======
|
|
|
|
The `buildFeedItems()` and `buildFeedEntries()` 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 is automatically written to the response
|
|
object after the method returns.
|
|
|
|
For an example of creating an Atom view, see Alef Arendsen's Spring Team Blog
|
|
{spring-site-blog}/2009/03/16/adding-an-atom-view-to-an-application-using-spring-s-rest-support[entry].
|