//# 0 errors, 35 messages
//#
package net.sourceforge.pebble.web.action;
    //#confirmcommentaction.java:1:1: class: net.sourceforge.pebble.web.action.ConfirmCommentAction

import net.sourceforge.pebble.Constants;
import net.sourceforge.pebble.api.confirmation.CommentConfirmationStrategy;
import net.sourceforge.pebble.api.decorator.ContentDecoratorContext;
import net.sourceforge.pebble.domain.*;
import net.sourceforge.pebble.web.view.NotFoundView;
import net.sourceforge.pebble.web.view.View;
import net.sourceforge.pebble.web.view.impl.CommentConfirmationView;
import net.sourceforge.pebble.web.view.impl.ConfirmCommentView;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Confirms a comment.
 *
 * @author    Simon Brown
 */
public class ConfirmCommentAction extends AbstractCommentAction {
    //#confirmcommentaction.java:23: method: void net.sourceforge.pebble.web.action.ConfirmCommentAction.net.sourceforge.pebble.web.action.ConfirmCommentAction()
    //#input(void net.sourceforge.pebble.web.action.ConfirmCommentAction()): this
    //#unanalyzed(void net.sourceforge.pebble.web.action.ConfirmCommentAction()): Effects-of-calling:net.sourceforge.pebble.web.action.Action
    //#confirmcommentaction.java:23: end of method: void net.sourceforge.pebble.web.action.ConfirmCommentAction.net.sourceforge.pebble.web.action.ConfirmCommentAction()

  /** the log used by this class */
  private static Log log = LogFactory.getLog(ConfirmCommentAction.class);
    //#confirmcommentaction.java:26: method: net.sourceforge.pebble.web.action.ConfirmCommentAction.net.sourceforge.pebble.web.action.ConfirmCommentAction__static_init
    //#confirmcommentaction.java:26: Warning: method not available
    //#    -- call on Log org.apache.commons.logging.LogFactory:getLog(Class)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.web.action.ConfirmCommentAction
    //#    method: net.sourceforge.pebble.web.action.ConfirmCommentAction__static_init
    //#    unanalyzed callee: Log org.apache.commons.logging.LogFactory:getLog(Class)
    //#output(net.sourceforge.pebble.web.action.ConfirmCommentAction__static_init): __Descendant_Table[net/sourceforge/pebble/web/action/ConfirmCommentAction]
    //#output(net.sourceforge.pebble.web.action.ConfirmCommentAction__static_init): __Dispatch_Table.createBlankComment(Lnet/sourceforge/pebble/domain/Blog;Lnet/sourceforge/pebble/domain/BlogEntry;Ljavax/servlet/http/HttpServletRequest;)Lnet/sourceforge/pebble/domain/Comment;
    //#output(net.sourceforge.pebble.web.action.ConfirmCommentAction__static_init): __Dispatch_Table.createComment(Ljavax/servlet/http/HttpServletRequest;Lnet/sourceforge/pebble/domain/BlogEntry;)Lnet/sourceforge/pebble/domain/Comment;
    //#output(net.sourceforge.pebble.web.action.ConfirmCommentAction__static_init): __Dispatch_Table.encode(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String;
    //#output(net.sourceforge.pebble.web.action.ConfirmCommentAction__static_init): __Dispatch_Table.getLocalizedString(Ljava/lang/String;)Ljava/lang/String;
    //#output(net.sourceforge.pebble.web.action.ConfirmCommentAction__static_init): __Dispatch_Table.getModel()Lnet/sourceforge/pebble/web/model/Model;
    //#output(net.sourceforge.pebble.web.action.ConfirmCommentAction__static_init): __Dispatch_Table.process(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)Lnet/sourceforge/pebble/web/view/View;
    //#output(net.sourceforge.pebble.web.action.ConfirmCommentAction__static_init): __Dispatch_Table.saveComment(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;Lnet/sourceforge/pebble/domain/BlogEntry;Lnet/sourceforge/pebble/domain/Comment;)V
    //#output(net.sourceforge.pebble.web.action.ConfirmCommentAction__static_init): __Dispatch_Table.setModel(Lnet/sourceforge/pebble/web/model/Model;)V
    //#output(net.sourceforge.pebble.web.action.ConfirmCommentAction__static_init): __Dispatch_Table.validateComment(Lnet/sourceforge/pebble/domain/Comment;)Lnet/sourceforge/pebble/web/validation/ValidationContext;
    //#output(net.sourceforge.pebble.web.action.ConfirmCommentAction__static_init): log
    //#output(net.sourceforge.pebble.web.action.ConfirmCommentAction__static_init): net/sourceforge/pebble/web/action/AbstractCommentAction.__Descendant_Table[net/sourceforge/pebble/web/action/ConfirmCommentAction]
    //#output(net.sourceforge.pebble.web.action.ConfirmCommentAction__static_init): net/sourceforge/pebble/web/action/Action.__Descendant_Table[net/sourceforge/pebble/web/action/ConfirmCommentAction]
    //#post(net.sourceforge.pebble.web.action.ConfirmCommentAction__static_init): __Descendant_Table[net/sourceforge/pebble/web/action/ConfirmCommentAction] == &__Dispatch_Table
    //#post(net.sourceforge.pebble.web.action.ConfirmCommentAction__static_init): net/sourceforge/pebble/web/action/AbstractCommentAction.__Descendant_Table[net/sourceforge/pebble/web/action/ConfirmCommentAction] == &__Dispatch_Table
    //#post(net.sourceforge.pebble.web.action.ConfirmCommentAction__static_init): net/sourceforge/pebble/web/action/Action.__Descendant_Table[net/sourceforge/pebble/web/action/ConfirmCommentAction] == &__Dispatch_Table
    //#post(net.sourceforge.pebble.web.action.ConfirmCommentAction__static_init): __Dispatch_Table.createBlankComment(Lnet/sourceforge/pebble/domain/Blog;Lnet/sourceforge/pebble/domain/BlogEntry;Ljavax/servlet/http/HttpServletRequest;)Lnet/sourceforge/pebble/domain/Comment; == &net/sourceforge/pebble/web/action/AbstractCommentAction.createBlankComment
    //#post(net.sourceforge.pebble.web.action.ConfirmCommentAction__static_init): __Dispatch_Table.createComment(Ljavax/servlet/http/HttpServletRequest;Lnet/sourceforge/pebble/domain/BlogEntry;)Lnet/sourceforge/pebble/domain/Comment; == &net/sourceforge/pebble/web/action/AbstractCommentAction.createComment
    //#post(net.sourceforge.pebble.web.action.ConfirmCommentAction__static_init): __Dispatch_Table.encode(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String; == &net/sourceforge/pebble/web/action/AbstractCommentAction.encode
    //#post(net.sourceforge.pebble.web.action.ConfirmCommentAction__static_init): __Dispatch_Table.getLocalizedString(Ljava/lang/String;)Ljava/lang/String; == &net/sourceforge/pebble/web/action/Action.getLocalizedString
    //#post(net.sourceforge.pebble.web.action.ConfirmCommentAction__static_init): __Dispatch_Table.getModel()Lnet/sourceforge/pebble/web/model/Model; == &net/sourceforge/pebble/web/action/Action.getModel
    //#post(net.sourceforge.pebble.web.action.ConfirmCommentAction__static_init): __Dispatch_Table.process(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;)Lnet/sourceforge/pebble/web/view/View; == &process
    //#post(net.sourceforge.pebble.web.action.ConfirmCommentAction__static_init): __Dispatch_Table.saveComment(Ljavax/servlet/http/HttpServletRequest;Ljavax/servlet/http/HttpServletResponse;Lnet/sourceforge/pebble/domain/BlogEntry;Lnet/sourceforge/pebble/domain/Comment;)V == &net/sourceforge/pebble/web/action/AbstractCommentAction.saveComment
    //#post(net.sourceforge.pebble.web.action.ConfirmCommentAction__static_init): __Dispatch_Table.setModel(Lnet/sourceforge/pebble/web/model/Model;)V == &net/sourceforge/pebble/web/action/Action.setModel
    //#post(net.sourceforge.pebble.web.action.ConfirmCommentAction__static_init): __Dispatch_Table.validateComment(Lnet/sourceforge/pebble/domain/Comment;)Lnet/sourceforge/pebble/web/validation/ValidationContext; == &net/sourceforge/pebble/web/action/AbstractCommentAction.validateComment
    //#post(net.sourceforge.pebble.web.action.ConfirmCommentAction__static_init): init'ed(log)
    //#confirmcommentaction.java:26: end of method: net.sourceforge.pebble.web.action.ConfirmCommentAction.net.sourceforge.pebble.web.action.ConfirmCommentAction__static_init

  /**
   * Peforms the processing associated with this action.
   *
   * @param request  the HttpServletRequest instance
   * @param response the HttpServletResponse instance
   * @return the name of the next view
   */
  public View process(HttpServletRequest request, HttpServletResponse response) throws ServletException {
    Blog blog = (Blog)getModel().get(Constants.BLOG_KEY);
    BlogEntry blogEntry = null;
    Comment comment = null;

    comment = (Comment)request.getSession().getAttribute(Constants.COMMENT_KEY);
    String entry = comment.getBlogEntry().getId();

    BlogService service = new BlogService();
    try {
      blogEntry = service.getBlogEntry(blog, entry);
    } catch (BlogServiceException e) {
      throw new ServletException(e);
    }
    if (blogEntry == null) {
      // just send back a 404 - this is probably somebody looking for a way
      // to send comment spam ;-)
      return new NotFoundView();
    } else if (!blogEntry.isCommentsEnabled()) {
      return new CommentConfirmationView();
    }

    ContentDecoratorContext decoratorContext = new ContentDecoratorContext();
    decoratorContext.setView(ContentDecoratorContext.DETAIL_VIEW);
    decoratorContext.setMedia(ContentDecoratorContext.HTML_PAGE);

    Comment decoratedComment = (Comment)comment.clone();
    blog.getContentDecoratorChain().decorate(decoratorContext, decoratedComment);
    getModel().put("decoratedComment", decoratedComment);
    getModel().put("undecoratedComment", comment);
    getModel().put(Constants.BLOG_ENTRY_KEY, blogEntry);
    getModel().put(Constants.COMMENT_KEY, comment);

    CommentConfirmationStrategy strategy = blog.getCommentConfirmationStrategy();

    Comment clonedComment = (Comment)comment.clone();

    if (strategy.isConfirmed(request)) {
      try {
        saveComment(request, response, blogEntry, comment);
        request.getSession().removeAttribute(Constants.COMMENT_KEY);
        return new CommentConfirmationView();
      } catch (BlogServiceException be) {
        log.error(be.getMessage(), be);
        throw new ServletException(be);
      }
    } else {
      // try again!
      strategy.setupConfirmation(request);
      return new ConfirmCommentView();
    }
  }

}    //#confirmcommentaction.java:: end of class: net.sourceforge.pebble.web.action.ConfirmCommentAction
