File Source: confirmcommentaction.java

         /* 
    P/P   *  Method: net.sourceforge.pebble.web.action.ConfirmCommentAction__static_init
          * 
          *  Postconditions:
          *    init'ed(log)
          */
     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  
         /* 
    P/P   *  Method: void net.sourceforge.pebble.web.action.ConfirmCommentAction()
          */
    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    public View process(HttpServletRequest request, HttpServletResponse response) throws ServletException {
    36      Blog blog = (Blog)getModel().get(Constants.BLOG_KEY);
    37      BlogEntry blogEntry = null;
    38      Comment comment = null;
    39  
    40      comment = (Comment)request.getSession().getAttribute(Constants.COMMENT_KEY);
    41      String entry = comment.getBlogEntry().getId();
    42  
    43      BlogService service = new BlogService();
    44      try {
    45        blogEntry = service.getBlogEntry(blog, entry);
    46      } catch (BlogServiceException e) {
    47        throw new ServletException(e);
    48      }
    49      if (blogEntry == null) {
    50        // just send back a 404 - this is probably somebody looking for a way
    51        // to send comment spam ;-)
    52        return new NotFoundView();
    53      } else if (!blogEntry.isCommentsEnabled()) {
    54        return new CommentConfirmationView();
    55      }
    56  
    57      ContentDecoratorContext decoratorContext = new ContentDecoratorContext();
    58      decoratorContext.setView(ContentDecoratorContext.DETAIL_VIEW);
    59      decoratorContext.setMedia(ContentDecoratorContext.HTML_PAGE);
    60  
    61      Comment decoratedComment = (Comment)comment.clone();
    62      blog.getContentDecoratorChain().decorate(decoratorContext, decoratedComment);
    63      getModel().put("decoratedComment", decoratedComment);
    64      getModel().put("undecoratedComment", comment);
    65      getModel().put(Constants.BLOG_ENTRY_KEY, blogEntry);
    66      getModel().put(Constants.COMMENT_KEY, comment);
    67  
    68      CommentConfirmationStrategy strategy = blog.getCommentConfirmationStrategy();
    69  
    70      Comment clonedComment = (Comment)comment.clone();
    71  
    72      if (strategy.isConfirmed(request)) {
    73        try {
    74          saveComment(request, response, blogEntry, comment);
    75          request.getSession().removeAttribute(Constants.COMMENT_KEY);
    76          return new CommentConfirmationView();
    77        } catch (BlogServiceException be) {
    78          log.error(be.getMessage(), be);
    79          throw new ServletException(be);
    80        }
    81      } else {
    82        // try again!
    83        strategy.setupConfirmation(request);
    84        return new ConfirmCommentView();
    85      }
    86    }
    87  
    88  }








SofCheck Inspector Build Version : 2.22510
confirmcommentaction.java 2010-Jun-25 19:40:34
confirmcommentaction.class 2010-Jul-19 20:23:38