View Javadoc

1   package net.sourceforge.blogentis.plugins.impl;
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: CommentExtensionPointImpl.java,v 1.1 2004/10/22 17:34:14 tassos Exp $
23  //
24  
25  import java.util.ArrayList;
26  import java.util.Iterator;
27  import java.util.List;
28  
29  import org.apache.commons.lang.StringUtils;
30  
31  import net.sourceforge.blogentis.om.Blog;
32  import net.sourceforge.blogentis.om.Comment;
33  import net.sourceforge.blogentis.plugins.AbstractBlogExtensionPoint;
34  import net.sourceforge.blogentis.plugins.IPlugin;
35  import net.sourceforge.blogentis.plugins.base.ICommentExtension;
36  import net.sourceforge.blogentis.plugins.base.ICommentExtensionPoint;
37  import net.sourceforge.blogentis.turbine.BlogRunData;
38  
39  /***
40   * Private implementation of the comment extension point.
41   * 
42   * @author abas
43   */
44  public class CommentExtensionPointImpl
45          extends AbstractBlogExtensionPoint
46          implements ICommentExtensionPoint {
47      public CommentExtensionPointImpl(IPlugin plugin, Blog blog) {
48          super(plugin, blog);
49      }
50  
51      public String getName() {
52          return "Comment Operations Extension Point";
53      }
54  
55      public Class getExtensionClass() {
56          return ICommentExtension.class;
57      }
58  
59      public boolean commentCreated(BlogRunData data, Comment comment) {
60          boolean status = true;
61          for(Iterator i = extensions.iterator(); i.hasNext();) {
62              ICommentExtension ice = (ICommentExtension)i.next();
63              status = status & ice.commentCreated(data, comment);
64          }
65          return status;
66      }
67  
68      public void commentRemoved(BlogRunData data, Comment comment) {
69          for(Iterator i = extensions.iterator(); i.hasNext();) {
70              ICommentExtension ice = (ICommentExtension)i.next();
71              ice.commentRemoved(data, comment);
72          }
73      }
74  
75      public List commentActions(BlogRunData data, Comment c) {
76          List results = new ArrayList();
77          for(Iterator i = extensions.iterator(); i.hasNext();) {
78              ICommentExtension ice = (ICommentExtension)i.next();
79              List tmp = ice.commentActions(data, c);
80              if (tmp != null)
81                  results.addAll(tmp);
82          }
83          return results;
84      }
85  
86      public String getNewCommentMessage(BlogRunData data) {
87          StringBuffer sb = new StringBuffer();
88          for(Iterator i = extensions.iterator(); i.hasNext();) {
89              ICommentExtension ice = (ICommentExtension)i.next();
90              String message = ice.getNewCommentMessage(data);
91              if (!StringUtils.isEmpty(message)) {
92                  sb.append(message);
93                  if (i.hasNext())
94                      sb.append(' ');
95              }
96          }
97          return sb.toString();
98      }
99  }