1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.module.rssaggregator.templates.components;
35
36 import info.magnolia.rendering.model.RenderingModel;
37 import info.magnolia.rendering.template.TemplateDefinition;
38 import info.magnolia.templating.functions.TemplatingFunctions;
39
40 import java.util.ArrayList;
41 import java.util.Collection;
42 import java.util.List;
43
44 import javax.jcr.Node;
45 import javax.jcr.RepositoryException;
46
47 import org.apache.commons.lang.StringUtils;
48
49
50
51
52
53
54
55 public class FeedSubscriptionsModel<RD extends TemplateDefinition> extends AbstractFeedModel<TemplateDefinition> {
56
57 public FeedSubscriptionsModel(Node content, TemplateDefinition definition, RenderingModel<?> parent, TemplatingFunctions templatingFunctions) {
58 super(content, definition, parent, templatingFunctions);
59 }
60
61
62
63
64
65
66 @SuppressWarnings("unused")
67 public Collection<Node> getItems() throws RepositoryException {
68
69 Collection<Node> authorsList = super.getPlanetItems("statistics/authors", "and t.author IS NOT NULL", "order by t.author asc", false);
70
71
72 List<Node> results = new ArrayList<Node>();
73 for (Node author : authorsList) {
74 if (author.hasProperty("feedLink")) {
75 boolean feedFound = false;
76 for (Node extAuthor : results) {
77 if (StringUtils.equalsIgnoreCase(extAuthor.getProperty("feedLink").getString(), author.getProperty("feedLink").getString())) {
78 log.debug("Duplicate feed for feed list found: " + extAuthor.getProperty("feedLink").getString());
79 feedFound = true;
80 }
81 }
82 if (!feedFound) {
83
84 String title = super.getFeedTitle(author.getProperty("feedLink").getString());
85
86 if (StringUtils.isNotBlank(title)) {
87 author.getProperty("author").setValue(title);
88 }
89 results.add(author);
90 }
91 }
92 }
93 return results;
94 }
95
96 }