source: ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/rss/RssCreatorDescriptions.java @ 4098

Last change on this file since 4098 was 4098, checked in by George.Georgovassilis@mpi.nl, 10 years ago

#360, #431, #432: JPA and unified component entities

File size: 2.2 KB
Line 
1package clarin.cmdi.componentregistry.rss;
2
3import clarin.cmdi.componentregistry.DatesHelper;
4import clarin.cmdi.componentregistry.model.BaseDescription;
5import java.util.Comparator;
6import java.util.List;
7
8/**
9 *
10 * @author olhsha
11 */
12public class RssCreatorDescriptions<T extends BaseDescription> extends RssCreator<T> {
13
14    /**
15     *
16     * @param userspace 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 userspace, String baseURI, String descriptionType,
26            int limit, List<T> descriptions, Comparator<T> comparator) {
27        super(userspace, baseURI, limit, descriptions);
28        setChannelLink(baseURI + "/");
29        setChannelTitle((userspace ? "Your workspace " : "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() + (userspace ? "&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}
Note: See TracBrowser for help on using the repository browser.