Clover Coverage Report - Pebble 2.5-SNAPSHOT
Coverage timestamp: Sat Jun 12 2010 09:39:29 EST
../../../../../img/srcFileCovDistChart0.png 48% of files have more coverage
33   88   6   33
6   58   0,18   1
1     6  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  ConfirmCommentAction       Line # 23 33 0% 6 40 0% 0.0
 
No Tests
 
1    package net.sourceforge.pebble.web.action;
2   
3    import net.sourceforge.pebble.Constants;
4    import net.sourceforge.pebble.api.confirmation.CommentConfirmationStrategy;
5    import net.sourceforge.pebble.api.decorator.ContentDecoratorContext;
6    import net.sourceforge.pebble.domain.*;
7    import net.sourceforge.pebble.web.view.NotFoundView;
8    import net.sourceforge.pebble.web.view.View;
9    import net.sourceforge.pebble.web.view.impl.CommentConfirmationView;
10    import net.sourceforge.pebble.web.view.impl.ConfirmCommentView;
11    import org.apache.commons.logging.Log;
12    import org.apache.commons.logging.LogFactory;
13   
14    import javax.servlet.ServletException;
15    import javax.servlet.http.HttpServletRequest;
16    import javax.servlet.http.HttpServletResponse;
17   
18    /**
19    * Confirms a comment.
20    *
21    * @author Simon Brown
22    */
 
23    public class ConfirmCommentAction extends AbstractCommentAction {
24   
25    /** the log used by this class */
26    private static Log log = LogFactory.getLog(ConfirmCommentAction.class);
27   
28    /**
29    * Peforms the processing associated with this action.
30    *
31    * @param request the HttpServletRequest instance
32    * @param response the HttpServletResponse instance
33    * @return the name of the next view
34    */
 
35  0 toggle public View process(HttpServletRequest request, HttpServletResponse response) throws ServletException {
36  0 Blog blog = (Blog)getModel().get(Constants.BLOG_KEY);
37  0 BlogEntry blogEntry = null;
38  0 Comment comment = null;
39   
40  0 comment = (Comment)request.getSession().getAttribute(Constants.COMMENT_KEY);
41  0 String entry = comment.getBlogEntry().getId();
42   
43  0 BlogService service = new BlogService();
44  0 try {
45  0 blogEntry = service.getBlogEntry(blog, entry);
46    } catch (BlogServiceException e) {
47  0 throw new ServletException(e);
48    }
49  0 if (blogEntry == null) {
50    // just send back a 404 - this is probably somebody looking for a way
51    // to send comment spam ;-)
52  0 return new NotFoundView();
53  0 } else if (!blogEntry.isCommentsEnabled()) {
54  0 return new CommentConfirmationView();
55    }
56   
57  0 ContentDecoratorContext decoratorContext = new ContentDecoratorContext();
58  0 decoratorContext.setView(ContentDecoratorContext.DETAIL_VIEW);
59  0 decoratorContext.setMedia(ContentDecoratorContext.HTML_PAGE);
60   
61  0 Comment decoratedComment = (Comment)comment.clone();
62  0 blog.getContentDecoratorChain().decorate(decoratorContext, decoratedComment);
63  0 getModel().put("decoratedComment", decoratedComment);
64  0 getModel().put("undecoratedComment", comment);
65  0 getModel().put(Constants.BLOG_ENTRY_KEY, blogEntry);
66  0 getModel().put(Constants.COMMENT_KEY, comment);
67   
68  0 CommentConfirmationStrategy strategy = blog.getCommentConfirmationStrategy();
69   
70  0 Comment clonedComment = (Comment)comment.clone();
71   
72  0 if (strategy.isConfirmed(request)) {
73  0 try {
74  0 saveComment(request, response, blogEntry, comment);
75  0 request.getSession().removeAttribute(Constants.COMMENT_KEY);
76  0 return new CommentConfirmationView();
77    } catch (BlogServiceException be) {
78  0 log.error(be.getMessage(), be);
79  0 throw new ServletException(be);
80    }
81    } else {
82    // try again!
83  0 strategy.setupConfirmation(request);
84  0 return new ConfirmCommentView();
85    }
86    }
87   
88    }