Clover Coverage Report - Pebble 2.5-SNAPSHOT
Coverage timestamp: Sat Jun 12 2010 09:39:29 EST
../../../../img/srcFileCovDistChart9.png 23% of files have more coverage
16   70   3   8
2   37   0,19   2
2     1,5  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  AbstractConfirmationStrategy       Line # 21 16 0% 3 2 90% 0.9
 
  (8)
 
1    package net.sourceforge.pebble.confirmation;
2   
3    import net.sourceforge.pebble.PluginProperties;
4    import net.sourceforge.pebble.api.event.comment.CommentEvent;
5    import net.sourceforge.pebble.api.event.comment.CommentListener;
6    import net.sourceforge.pebble.api.confirmation.CommentConfirmationStrategy;
7    import net.sourceforge.pebble.api.confirmation.TrackBackConfirmationStrategy;
8    import net.sourceforge.pebble.domain.Blog;
9    import net.sourceforge.pebble.domain.Comment;
10    import net.sourceforge.pebble.event.response.ContentSpamListener;
11    import net.sourceforge.pebble.event.response.IpAddressListener;
12    import net.sourceforge.pebble.event.response.LinkSpamListener;
13    import net.sourceforge.pebble.event.response.SpamScoreListener;
14    import net.sourceforge.pebble.util.SecurityUtils;
15   
16    /**
17    * Starting point for ConfirmationStrategy implementations.
18    *
19    * @author Simon Brown
20    */
 
21    public abstract class AbstractConfirmationStrategy implements CommentConfirmationStrategy, TrackBackConfirmationStrategy {
22   
23    /** the name of the required override property */
24    public static final String REQUIRED_KEY = "CommentConfirmationStrategy.required";
25   
26    /**
27    * Called to determine whether confirmation is required. This default
28    * implementation returns false if the user is authenticated. Otherwise,
29    * it runs the default set of comment listeners to determine
30    * whether the comment is spam. If so, true is returned.
31    *
32    * @param comment the Comment being confirmed
33    * @return true if the comment should be confirmed, false otherwise
34    */
 
35  8 toggle public boolean confirmationRequired(Comment comment) {
36  8 PluginProperties props = comment.getBlogEntry().getBlog().getPluginProperties();
37  8 String required = props.getProperty(REQUIRED_KEY);
38   
39  8 Blog blog = comment.getBlogEntry().getBlog();
40  8 if (SecurityUtils.isUserAuthorisedForBlog(blog)) {
41  6 return false;
42    } else {
43    // run a subset of the default comment listeners to figure out whether
44    // the comment is spam
45  2 CommentListener listener1 = new IpAddressListener();
46  2 CommentListener listener2 = new LinkSpamListener();
47  2 CommentListener listener3 = new ContentSpamListener();
48  2 CommentListener listener4 = new SpamScoreListener();
49  2 CommentEvent event = new CommentEvent(comment, CommentEvent.COMMENT_ADDED);
50   
51  2 listener1.commentAdded(event);
52  2 listener2.commentAdded(event);
53  2 listener3.commentAdded(event);
54  2 listener4.commentAdded(event);
55   
56  2 return (required != null && required.equalsIgnoreCase("true")) || !comment.isApproved();
57    }
58    }
59   
60    /**
61    * Called to determine whether confirmation is required.
62    *
63    * @param blog the owning Blog
64    * @return true if the confirmation is required, false otherwise
65    */
 
66  0 toggle public boolean confirmationRequired(Blog blog) {
67  0 return !SecurityUtils.isUserAuthorisedForBlog(blog);
68    }
69   
70    }