This project has retired. For details please refer to its
Attic page.
RssFeedGenerator xref
1 package org.apache.archiva.rss;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.ArrayList;
23 import java.util.List;
24
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
27
28 import com.sun.syndication.feed.synd.SyndContent;
29 import com.sun.syndication.feed.synd.SyndContentImpl;
30 import com.sun.syndication.feed.synd.SyndEntry;
31 import com.sun.syndication.feed.synd.SyndEntryImpl;
32 import com.sun.syndication.feed.synd.SyndFeed;
33 import com.sun.syndication.feed.synd.SyndFeedImpl;
34 import org.springframework.context.annotation.Scope;
35 import org.springframework.stereotype.Service;
36
37
38
39
40
41 @Service("rssFeedGenerator#default")
42 @Scope("prototype")
43 public class RssFeedGenerator
44 {
45 private Logger log = LoggerFactory.getLogger( RssFeedGenerator.class );
46
47
48 public static String DEFAULT_FEEDTYPE = "rss_2.0";
49
50 public static String DEFAULT_LANGUAGE = "en-us";
51
52 public SyndFeed generateFeed( String title, String description, List<RssFeedEntry> dataEntries )
53 {
54 if( dataEntries.size() == 0 )
55 {
56 log.debug( "No updates found, feed not generated." );
57 return null;
58 }
59
60 SyndFeed feed = new SyndFeedImpl();
61 feed.setTitle( title );
62 feed.setDescription( description );
63 feed.setLanguage( DEFAULT_LANGUAGE );
64 feed.setPublishedDate( dataEntries.get( dataEntries.size() - 1 ).getPublishedDate() );
65 feed.setFeedType( DEFAULT_FEEDTYPE );
66 feed.setEntries( getEntries( dataEntries ) );
67
68 log.debug( "Finished generating the feed \'{}\'.", title );
69
70 return feed;
71 }
72
73 private List<SyndEntry> getEntries( List<RssFeedEntry> dataEntries )
74 {
75 List<SyndEntry> entries = new ArrayList<>();
76
77 SyndEntry entry;
78 SyndContent description;
79
80 for ( RssFeedEntry dataEntry : dataEntries )
81 {
82 entry = new SyndEntryImpl();
83 entry.setTitle( dataEntry.getTitle() );
84 entry.setPublishedDate( dataEntry.getPublishedDate() );
85
86 description = new SyndContentImpl();
87 description.setType( "text/plain" );
88 description.setValue( dataEntry.getDescription() );
89 entry.setDescription( description );
90
91 entries.add( entry );
92 }
93
94 return entries;
95 }
96 }