1 package net.sourceforge.blogentis.plugins.impl;
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.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 }