1 | |
package org.apache.archiva.rss.processor; |
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.Date; |
24 | |
import java.util.List; |
25 | |
import java.util.Map; |
26 | |
|
27 | |
import org.apache.archiva.rss.RssFeedEntry; |
28 | |
import org.apache.maven.archiva.database.ArchivaDatabaseException; |
29 | |
import org.apache.maven.archiva.model.ArchivaArtifact; |
30 | |
|
31 | |
import com.sun.syndication.feed.synd.SyndFeed; |
32 | |
|
33 | |
|
34 | |
|
35 | |
|
36 | 0 | public abstract class AbstractArtifactsRssFeedProcessor |
37 | |
implements RssFeedProcessor |
38 | |
{ |
39 | |
public abstract SyndFeed process( Map<String, String> reqParams ) throws ArchivaDatabaseException; |
40 | |
|
41 | |
protected List<RssFeedEntry> processData( List<ArchivaArtifact> artifacts, boolean isRepoLevel ) |
42 | |
{ |
43 | 0 | long tmp = 0; |
44 | 0 | RssFeedEntry entry = null; |
45 | 0 | List<RssFeedEntry> entries = new ArrayList<RssFeedEntry>(); |
46 | 0 | String description = ""; |
47 | 0 | int idx = 0; |
48 | 0 | for ( ArchivaArtifact artifact : artifacts ) |
49 | |
{ |
50 | 0 | long whenGathered = artifact.getModel().getWhenGathered().getTime(); |
51 | |
|
52 | 0 | if ( tmp != whenGathered ) |
53 | |
{ |
54 | 0 | if ( entry != null ) |
55 | |
{ |
56 | 0 | entry.setDescription( description ); |
57 | 0 | entries.add( entry ); |
58 | 0 | entry = null; |
59 | |
} |
60 | |
|
61 | 0 | if ( !isRepoLevel ) |
62 | |
{ |
63 | 0 | entry = |
64 | |
new RssFeedEntry( getTitle() + "\'" + artifact.getGroupId() + ":" + artifact.getArtifactId() + |
65 | |
"\'" + " as of " + new Date( whenGathered ) ); |
66 | 0 | entry.setPublishedDate( artifact.getModel().getWhenGathered() ); |
67 | 0 | description = getDescription() + "\'" + artifact.getGroupId() + ":" + artifact.getArtifactId() + |
68 | |
"\'" + ": \n" + artifact.toString() + " | "; |
69 | |
} |
70 | |
else |
71 | |
{ |
72 | 0 | String repoId = artifact.getModel().getRepositoryId(); |
73 | 0 | entry = new RssFeedEntry( getTitle() + "\'" + repoId + "\'" + " as of " + new Date( whenGathered ) ); |
74 | 0 | entry.setPublishedDate( artifact.getModel().getWhenGathered() ); |
75 | 0 | description = getDescription() + "\'" + repoId + "\'" + ": \n" + artifact.toString() + " | "; |
76 | 0 | } |
77 | |
} |
78 | |
else |
79 | |
{ |
80 | 0 | description = description + artifact.toString() + " | "; |
81 | |
} |
82 | |
|
83 | 0 | if ( idx == ( artifacts.size() - 1 ) ) |
84 | |
{ |
85 | 0 | entry.setDescription( description ); |
86 | 0 | entries.add( entry ); |
87 | |
} |
88 | |
|
89 | 0 | tmp = whenGathered; |
90 | 0 | idx++; |
91 | 0 | } |
92 | |
|
93 | 0 | return entries; |
94 | |
} |
95 | |
|
96 | |
protected abstract String getTitle(); |
97 | |
|
98 | |
protected abstract String getDescription(); |
99 | |
|
100 | |
} |