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: PostViewExtensionPointImpl.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 net.sourceforge.blogentis.om.Blog;
30  import net.sourceforge.blogentis.om.Post;
31  import net.sourceforge.blogentis.plugins.AbstractBlogExtensionPoint;
32  import net.sourceforge.blogentis.plugins.IPlugin;
33  import net.sourceforge.blogentis.plugins.base.IPostViewExtension;
34  import net.sourceforge.blogentis.plugins.base.IPostViewExtensionPoint;
35  import net.sourceforge.blogentis.turbine.BlogRunData;
36  
37  /***
38   * @author abas
39   */
40  public class PostViewExtensionPointImpl
41          extends AbstractBlogExtensionPoint
42          implements IPostViewExtensionPoint {
43  
44      /***
45       * @param plugin
46       * @param blog
47       */
48      public PostViewExtensionPointImpl(IPlugin plugin, Blog blog) {
49          super(plugin, blog);
50      }
51  
52      public String getName() {
53          return "View Post Extension Point";
54      }
55  
56      public Class getExtensionClass() {
57          return IPostViewExtension.class;
58      }
59  
60      /***
61       * Invoke the extensions to prepare this post for viewing.
62       * 
63       * @param data
64       *            the RunData of the current request.
65       * @param post
66       *            the post to be prepared.
67       * @return the actual post that will be viewed.
68       */
69      public Post doPostViewExtensions(BlogRunData data, Post post) {
70          for(Iterator i = extensions.iterator(); i.hasNext();) {
71              IPostViewExtension ipv = (IPostViewExtension)i.next();
72              post = ipv.prepareForView(data, post);
73          }
74          return post;
75      }
76  
77      /***
78       * Apply doPostViewExtensions to a whole List of Posts.
79       * 
80       * @param data
81       *            the RunData of the current request
82       * @param posts
83       *            a List of Posts to which the doPostViewExtensions() should be
84       *            applied.
85       * @return a new List containing the results of the invocations in the same
86       *         order as the original list.
87       */
88      public List doPostViewExtensions(BlogRunData data, List posts) {
89          ArrayList l = new ArrayList(posts.size());
90          for(Iterator i = posts.iterator(); i.hasNext();) {
91              Post p = (Post)i.next();
92              l.add(doPostViewExtensions(data, p));
93          }
94          return l;
95      }
96  }