File Source: abstractconfirmationstrategy.java
/*
P/P * Method: net.sourceforge.pebble.confirmation.AbstractConfirmationStrategy__static_init
*/
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 import net.sourceforge.pebble.PluginProperties;
16 import net.sourceforge.pebble.api.event.comment.CommentEvent;
17 import net.sourceforge.pebble.api.event.comment.CommentListener;
18 import net.sourceforge.pebble.api.confirmation.CommentConfirmationStrategy;
19 import net.sourceforge.pebble.api.confirmation.TrackBackConfirmationStrategy;
20 import net.sourceforge.pebble.domain.Blog;
21 import net.sourceforge.pebble.domain.Comment;
22 import net.sourceforge.pebble.event.response.ContentSpamListener;
23 import net.sourceforge.pebble.event.response.IpAddressListener;
24 import net.sourceforge.pebble.event.response.LinkSpamListener;
25 import net.sourceforge.pebble.event.response.SpamScoreListener;
26 import net.sourceforge.pebble.util.SecurityUtils;
27
28 /**
29 * Starting point for ConfirmationStrategy implementations.
30 *
31 * @author Simon Brown
32 */
/*
P/P * Method: void net.sourceforge.pebble.confirmation.AbstractConfirmationStrategy()
*/
33 public abstract class AbstractConfirmationStrategy implements CommentConfirmationStrategy, TrackBackConfirmationStrategy {
34
35 /** the name of the required override property */
36 public static final String REQUIRED_KEY = "CommentConfirmationStrategy.required";
37
38 /**
39 * Called to determine whether confirmation is required. This default
40 * implementation returns false if the user is authenticated. Otherwise,
41 * it runs the default set of comment listeners to determine
42 * whether the comment is spam. If so, true is returned.
43 *
44 * @param comment the Comment being confirmed
45 * @return true if the comment should be confirmed, false otherwise
46 */
47 public boolean confirmationRequired(Comment comment) {
/*
P/P * Method: bool confirmationRequired(Comment)
*
* Preconditions:
* comment != null
*
* Postconditions:
* init'ed(return_value)
*
* Test Vectors:
* java.lang.String:equalsIgnoreCase(...)@68: {1}, {0}
* net.sourceforge.pebble.util.SecurityUtils:isUserAuthorisedForBlog(...)@52: {0}, {1}
*
* Preconditions:
* comment.blogEntry != null
* comment.blogEntry.blog.pluginProperties != null
* comment.blogEntry.blog != null
* (soft) comment.state != null
* (soft) init'ed(comment.state.name)
*
* Presumptions:
* net.sourceforge.pebble.domain.State__static_init.new State(State__static_init#1).name@66 != null
*
* Test Vectors:
* net.sourceforge.pebble.PluginProperties:getProperty(...)@49: Addr_Set{null}, Inverse{null}
*/
48 PluginProperties props = comment.getBlogEntry().getBlog().getPluginProperties();
49 String required = props.getProperty(REQUIRED_KEY);
50
51 Blog blog = comment.getBlogEntry().getBlog();
52 if (SecurityUtils.isUserAuthorisedForBlog(blog)) {
53 return false;
54 } else {
55 // run a subset of the default comment listeners to figure out whether
56 // the comment is spam
57 CommentListener listener1 = new IpAddressListener();
58 CommentListener listener2 = new LinkSpamListener();
59 CommentListener listener3 = new ContentSpamListener();
60 CommentListener listener4 = new SpamScoreListener();
61 CommentEvent event = new CommentEvent(comment, CommentEvent.COMMENT_ADDED);
62
63 listener1.commentAdded(event);
64 listener2.commentAdded(event);
65 listener3.commentAdded(event);
66 listener4.commentAdded(event);
67
68 return (required != null && required.equalsIgnoreCase("true")) || !comment.isApproved();
69 }
70 }
71
72 /**
73 * Called to determine whether confirmation is required.
74 *
75 * @param blog the owning Blog
76 * @return true if the confirmation is required, false otherwise
77 */
78 public boolean confirmationRequired(Blog blog) {
/*
P/P * Method: bool confirmationRequired(Blog)
*
* Postconditions:
* init'ed(return_value)
*/
79 return !SecurityUtils.isUserAuthorisedForBlog(blog);
80 }
81
82 }
SofCheck Inspector Build Version : 2.22510
| abstractconfirmationstrategy.java |
2010-Jul-14 00:27:22 |
| abstractconfirmationstrategy.class |
2010-Jul-19 20:23:40 |