1 package net.sourceforge.blogentis.om;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 import java.util.ArrayList;
26 import java.util.List;
27
28 import net.sourceforge.blogentis.rss.RSSItem;
29 import net.sourceforge.blogentis.utils.AbsoluteLinkURL;
30 import net.sourceforge.blogentis.utils.DateUtils;
31 import net.sourceforge.blogentis.utils.LinkFactoryService;
32 import net.sourceforge.blogentis.utils.StringUtils;
33
34 import org.apache.commons.logging.Log;
35 import org.apache.commons.logging.LogFactory;
36 import org.apache.ecs.xml.XML;
37 import org.apache.torque.TorqueException;
38 import org.apache.torque.om.Persistent;
39
40 public class Comment
41 extends BaseComment
42 implements Persistent, RSSItem {
43 private static final Log log = LogFactory.getLog(Comment.class);
44
45 public List getItemDescription() {
46 List l = new ArrayList(4);
47 AbsoluteLinkURL link = LinkFactoryService.getLink();
48
49 if (getTitle() != null)
50 l.add(new XML("blogentis:title").addElement(getTitle()));
51 if (getEmail() != null)
52 l.add(new XML("blogentis:author").addElement(getEmail()));
53 if (getText() != null)
54 l.add(new XML("blogentis:description").addElement(StringUtils
55 .entityfyHTML(getText())));
56 l.add(new XML("blogentis:link").addElement(getRDFIdentifier()));
57 l.add(new XML("blogentis:pubDate")
58 .addElement(DateUtils.formatRFC822(getPostedTime())));
59 l.add(new XML("blogentis:pubDate-iso").addElement(DateUtils
60 .formatIso8601(getPostedTime())));
61 l.add(new XML("blogentis:guid").addElement(getRDFIdentifier())
62 .addAttribute("isPermaLink", "true"));
63 try {
64 l.add(new XML("blogentis:source").addElement(getPost().getTitle())
65 .addAttribute("url", link.permaLink(getPost()).toString()));
66
67 } catch (TorqueException e) {
68 log.warn("doConvert", e);
69 }
70 return l;
71 }
72
73 public String getRDFIdentifier() {
74 try {
75 return LinkFactoryService.getLink().permaLink(getPost()) + "#c"
76 + getCommentId();
77 } catch (TorqueException e) {
78 log.warn("getIdentifier", e);
79 return null;
80 }
81 }
82
83 public String getOriginatorName() {
84 if (getName() != null)
85 return getName();
86 if (getTitle() != null)
87 return getTitle();
88 if (getUrl() != null)
89 return getUrl();
90 if (getEmail() != null)
91 return getEmail();
92 return "Unknown";
93 }
94
95 public String getOriginatorTitle() {
96 if (getTitle() != null)
97 return getTitle();
98 if (getName() != null)
99 return getName();
100 if (getUrl() != null)
101 return getUrl();
102 if (getEmail() != null)
103 return getEmail();
104 return "Unknown";
105 }
106
107 public String getOriginatorLink() {
108 if (getUrl() != null)
109 return getUrl();
110 if (getEmail() != null)
111 return "mailto:" + getEmail();
112 return null;
113 }
114
115 public boolean isComment() {
116 return getTitle() == null && getName() != null && getText() != null;
117 }
118
119 public boolean isPingBack() {
120 return getTitle() == null && getName() == null && getText() == null;
121 }
122
123 public boolean isTrackBack() {
124 return getTitle() != null && getName() != null && getUrl() != null;
125 }
126 }