View Javadoc

1   package net.sourceforge.blogentis.om;
2   
3   //-----------------------------------------------------------------------
4   //Blogentis - a blog publishing platform.
5   //Copyright (C) 2004 Tassos Bassoukos <abassouk@gmail.com>
6   //
7   //This library is free software; you can redistribute it and/or
8   //modify it under the terms of the GNU Lesser General Public
9   //License as published by the Free Software Foundation; either
10  //version 2.1 of the License, or (at your option) any later version.
11  //
12  //This library is distributed in the hope that it will be useful,
13  //but WITHOUT ANY WARRANTY; without even the implied warranty of
14  //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  //Lesser General Public License for more details.
16  //
17  //You should have received a copy of the GNU Lesser General Public
18  //License along with this library; if not, write to the Free Software
19  //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  //-----------------------------------------------------------------------
21  //
22  //$Id: Comment.java,v 1.1 2004/10/22 17:34:06 tassos Exp $
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 }