| 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 |
|
|
| 20 |
|
|
| 21 |
|
@author |
| 22 |
|
|
|
|
|
| 0% |
Uncovered Elements: 40 (40) |
Complexity: 6 |
Complexity Density: 0,18 |
|
| 23 |
|
public class ConfirmCommentAction extends AbstractCommentAction { |
| 24 |
|
|
| 25 |
|
|
| 26 |
|
private static Log log = LogFactory.getLog(ConfirmCommentAction.class); |
| 27 |
|
|
| 28 |
|
|
| 29 |
|
|
| 30 |
|
|
| 31 |
|
@param |
| 32 |
|
@param |
| 33 |
|
@return |
| 34 |
|
|
|
|
|
| 0% |
Uncovered Elements: 39 (39) |
Complexity: 6 |
Complexity Density: 0,18 |
|
| 35 |
0
|
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 |
|
|
| 51 |
|
|
| 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 |
|
|
| 83 |
0
|
strategy.setupConfirmation(request); |
| 84 |
0
|
return new ConfirmCommentView(); |
| 85 |
|
} |
| 86 |
|
} |
| 87 |
|
|
| 88 |
|
} |