1 | package clarin.cmdi.componentregistry.rss; |
---|
2 | |
---|
3 | import clarin.cmdi.componentregistry.DatesHelper; |
---|
4 | import clarin.cmdi.componentregistry.model.BaseDescription; |
---|
5 | import java.util.Comparator; |
---|
6 | import java.util.List; |
---|
7 | |
---|
8 | /** |
---|
9 | * |
---|
10 | * @author olhsha |
---|
11 | */ |
---|
12 | public class RssCreatorDescriptions<T extends BaseDescription> extends RssCreator<T> { |
---|
13 | |
---|
14 | /** |
---|
15 | * |
---|
16 | * @param isPrivate if "true" then profiles and components from the user's |
---|
17 | * workspace, otherwise -- public (uri-parameter) |
---|
18 | * @param baseURI where the database is located |
---|
19 | * @param descriptionType "profile" or "component" |
---|
20 | * @param limit number of items to be displayed (uri-parameter) |
---|
21 | * @param descriptions the list of comments from which the list of rss-items |
---|
22 | * for the channel will be created |
---|
23 | * @param comparator compare descriptions by dates |
---|
24 | */ |
---|
25 | public RssCreatorDescriptions(boolean isPrivate, String baseURI, String descriptionType, |
---|
26 | int limit, List<T> descriptions, Comparator<T> comparator) { |
---|
27 | super(isPrivate, baseURI, limit, descriptions); |
---|
28 | setChannelLink(baseURI + "/"); |
---|
29 | setChannelTitle((isPrivate ? "Private " : "Public ") + descriptionType); |
---|
30 | setChannelDescription(String.format("News feed for the %s", descriptionType)); |
---|
31 | setComparator(comparator); |
---|
32 | } |
---|
33 | |
---|
34 | /** |
---|
35 | * creator method, desc to rssItem, overrides the dummy method of the |
---|
36 | * RssCreatorClass |
---|
37 | * |
---|
38 | * @param desc |
---|
39 | * @return |
---|
40 | */ |
---|
41 | @Override |
---|
42 | protected RssItem fromArgToRssItem(T desc) { |
---|
43 | String href = getBaseURI() + "?item=" + desc.getId() + (isPrivate ? "&space=user" : ""); |
---|
44 | RssItem retval = new RssItem(); |
---|
45 | retval.setDescription(desc.getDescription()); |
---|
46 | retval.setGuid(makeGuid(href)); |
---|
47 | retval.setLink(href); |
---|
48 | retval.setPubDate(DatesHelper.getRFCDateTime(desc.getRegistrationDate())); |
---|
49 | retval.setTitle(makeDescriptionTitle(desc.getName(), desc.getCreatorName(), desc.getGroupName())); |
---|
50 | return retval; |
---|
51 | } |
---|
52 | |
---|
53 | protected String makeDescriptionTitle(String name, String creatorname, String group) { |
---|
54 | final String help = (group == null) ? "is unspecified" : group; |
---|
55 | return (name + " by user " + creatorname + ", group " + help); |
---|
56 | } |
---|
57 | } |
---|