Clover Coverage Report - Pebble 2.5-SNAPSHOT
Coverage timestamp: Sat Jun 12 2010 09:39:29 EST
../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
11   45   6   11
10   27   0,55   1
1     6  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  HideUnapprovedResponsesDecorator       Line # 17 11 0% 6 0 100% 1.0
 
  (22)
 
1    package net.sourceforge.pebble.decorator;
2   
3    import net.sourceforge.pebble.domain.BlogEntry;
4    import net.sourceforge.pebble.domain.Comment;
5    import net.sourceforge.pebble.domain.TrackBack;
6    import net.sourceforge.pebble.util.SecurityUtils;
7    import net.sourceforge.pebble.api.decorator.ContentDecoratorContext;
8   
9    import java.util.List;
10   
11    /**
12    * Hides unapproved responses (comments and TrackBacks) if the current user is
13    * not a blog contributor.
14    *
15    * @author Simon Brown
16    */
 
17    public class HideUnapprovedResponsesDecorator extends ContentDecoratorSupport {
18   
19    /**
20    * Decorates the specified blog entry.
21    *
22    * @param context the context in which the decoration is running
23    * @param blogEntry the blog entry to be decorated
24    */
 
25  22 toggle public void decorate(ContentDecoratorContext context, BlogEntry blogEntry) {
26  22 if (!SecurityUtils.isUserAuthorisedForBlogAsBlogContributor(blogEntry.getBlog())) {
27  14 List comments = blogEntry.getComments();
28  28 for (int i = comments.size()-1; i >= 0; i--) {
29  14 Comment comment = (Comment)comments.get(i);
30  14 if (!comment.isApproved()) {
31  8 blogEntry.removeComment(comment.getId());
32    }
33    }
34   
35  14 List trackBacks = blogEntry.getTrackBacks();
36  20 for (int i = trackBacks.size()-1; i >= 0; i--) {
37  6 TrackBack trackBack = (TrackBack)trackBacks.get(i);
38  6 if (!trackBack.isApproved()) {
39  4 blogEntry.removeTrackBack(trackBack.getId());
40    }
41    }
42    }
43    }
44   
45    }