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