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 | |
|
35 | |
|
36 | |
|
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | 0 | public class RssFeedGenerator |
44 | |
{ |
45 | 0 | private Logger log = LoggerFactory.getLogger( RssFeedGenerator.class ); |
46 | |
|
47 | |
|
48 | 0 | public static String DEFAULT_FEEDTYPE = "rss_2.0"; |
49 | |
|
50 | 0 | public static String DEFAULT_LANGUAGE = "en-us"; |
51 | |
|
52 | |
public SyndFeed generateFeed( String title, String description, List<RssFeedEntry> dataEntries ) |
53 | |
{ |
54 | 0 | if( dataEntries.size() == 0 ) |
55 | |
{ |
56 | 0 | log.debug( "No updates found, feed not generated." ); |
57 | 0 | return null; |
58 | |
} |
59 | |
|
60 | 0 | SyndFeed feed = new SyndFeedImpl(); |
61 | 0 | feed.setTitle( title ); |
62 | 0 | feed.setDescription( description ); |
63 | 0 | feed.setLanguage( DEFAULT_LANGUAGE ); |
64 | 0 | feed.setPublishedDate( dataEntries.get( dataEntries.size() - 1 ).getPublishedDate() ); |
65 | 0 | feed.setFeedType( DEFAULT_FEEDTYPE ); |
66 | 0 | feed.setEntries( getEntries( dataEntries ) ); |
67 | |
|
68 | 0 | log.debug( "Finished generating the feed \'" + title + "\'." ); |
69 | |
|
70 | 0 | return feed; |
71 | |
} |
72 | |
|
73 | |
private List<SyndEntry> getEntries( List<RssFeedEntry> dataEntries ) |
74 | |
{ |
75 | 0 | List<SyndEntry> entries = new ArrayList<SyndEntry>(); |
76 | |
|
77 | |
SyndEntry entry; |
78 | |
SyndContent description; |
79 | |
|
80 | 0 | for ( RssFeedEntry dataEntry : dataEntries ) |
81 | |
{ |
82 | 0 | entry = new SyndEntryImpl(); |
83 | 0 | entry.setTitle( dataEntry.getTitle() ); |
84 | 0 | entry.setPublishedDate( dataEntry.getPublishedDate() ); |
85 | |
|
86 | 0 | description = new SyndContentImpl(); |
87 | 0 | description.setType( "text/plain" ); |
88 | 0 | description.setValue( dataEntry.getDescription() ); |
89 | 0 | entry.setDescription( description ); |
90 | |
|
91 | 0 | entries.add( entry ); |
92 | |
} |
93 | |
|
94 | 0 | return entries; |
95 | |
} |
96 | |
} |