//# 0 errors, 49 messages
//#
/*
    //#imagecaptchaconfirmationstrategy.java:1:1: class: net.sourceforge.pebble.confirmation.ImageCaptchaConfirmationStrategy
 * Copyright (c) 2003-2006, Simon Brown
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *   - Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *
 *   - Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in
 *     the documentation and/or other materials provided with the
 *     distribution.
 *
 *   - Neither the name of Pebble nor the names of its contributors may
 *     be used to endorse or promote products derived from this software
 *     without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
package net.sourceforge.pebble.confirmation;

import com.octo.captcha.service.CaptchaServiceException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import javax.servlet.http.HttpServletRequest;

/**
 * Image captcha comment confirmation strategy.
 *
 * @author    Simon Brown
 */
public class ImageCaptchaConfirmationStrategy extends AbstractConfirmationStrategy {
    //#imagecaptchaconfirmationstrategy.java:45: method: void net.sourceforge.pebble.confirmation.ImageCaptchaConfirmationStrategy.net.sourceforge.pebble.confirmation.ImageCaptchaConfirmationStrategy()
    //#input(void net.sourceforge.pebble.confirmation.ImageCaptchaConfirmationStrategy()): this
    //#imagecaptchaconfirmationstrategy.java:45: end of method: void net.sourceforge.pebble.confirmation.ImageCaptchaConfirmationStrategy.net.sourceforge.pebble.confirmation.ImageCaptchaConfirmationStrategy()

  /** the log used by this class */
  private static final Log log = LogFactory.getLog(ImageCaptchaConfirmationStrategy.class);
    //#imagecaptchaconfirmationstrategy.java:48: method: net.sourceforge.pebble.confirmation.ImageCaptchaConfirmationStrategy.net.sourceforge.pebble.confirmation.ImageCaptchaConfirmationStrategy__static_init
    //#imagecaptchaconfirmationstrategy.java:48: Warning: method not available
    //#    -- call on Log org.apache.commons.logging.LogFactory:getLog(Class)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.confirmation.ImageCaptchaConfirmationStrategy
    //#    method: net.sourceforge.pebble.confirmation.ImageCaptchaConfirmationStrategy__static_init
    //#    unanalyzed callee: Log org.apache.commons.logging.LogFactory:getLog(Class)
    //#output(net.sourceforge.pebble.confirmation.ImageCaptchaConfirmationStrategy__static_init): __Descendant_Table[net/sourceforge/pebble/confirmation/ImageCaptchaConfirmationStrategy]
    //#output(net.sourceforge.pebble.confirmation.ImageCaptchaConfirmationStrategy__static_init): __Dispatch_Table.confirmationRequired(Lnet/sourceforge/pebble/domain/Blog;)Z
    //#output(net.sourceforge.pebble.confirmation.ImageCaptchaConfirmationStrategy__static_init): __Dispatch_Table.confirmationRequired(Lnet/sourceforge/pebble/domain/Comment;)Z
    //#output(net.sourceforge.pebble.confirmation.ImageCaptchaConfirmationStrategy__static_init): __Dispatch_Table.getUri()Ljava/lang/String;
    //#output(net.sourceforge.pebble.confirmation.ImageCaptchaConfirmationStrategy__static_init): __Dispatch_Table.isConfirmed(Ljavax/servlet/http/HttpServletRequest;)Z
    //#output(net.sourceforge.pebble.confirmation.ImageCaptchaConfirmationStrategy__static_init): __Dispatch_Table.setupConfirmation(Ljavax/servlet/http/HttpServletRequest;)V
    //#output(net.sourceforge.pebble.confirmation.ImageCaptchaConfirmationStrategy__static_init): log
    //#output(net.sourceforge.pebble.confirmation.ImageCaptchaConfirmationStrategy__static_init): net/sourceforge/pebble/api/confirmation/CommentConfirmationStrategy.__Descendant_Table[net/sourceforge/pebble/confirmation/ImageCaptchaConfirmationStrategy]
    //#output(net.sourceforge.pebble.confirmation.ImageCaptchaConfirmationStrategy__static_init): net/sourceforge/pebble/api/confirmation/ConfirmationStrategy.__Descendant_Table[net/sourceforge/pebble/confirmation/ImageCaptchaConfirmationStrategy]
    //#output(net.sourceforge.pebble.confirmation.ImageCaptchaConfirmationStrategy__static_init): net/sourceforge/pebble/api/confirmation/TrackBackConfirmationStrategy.__Descendant_Table[net/sourceforge/pebble/confirmation/ImageCaptchaConfirmationStrategy]
    //#output(net.sourceforge.pebble.confirmation.ImageCaptchaConfirmationStrategy__static_init): net/sourceforge/pebble/confirmation/AbstractConfirmationStrategy.__Descendant_Table[net/sourceforge/pebble/confirmation/ImageCaptchaConfirmationStrategy]
    //#post(net.sourceforge.pebble.confirmation.ImageCaptchaConfirmationStrategy__static_init): __Descendant_Table[net/sourceforge/pebble/confirmation/ImageCaptchaConfirmationStrategy] == &__Dispatch_Table
    //#post(net.sourceforge.pebble.confirmation.ImageCaptchaConfirmationStrategy__static_init): net/sourceforge/pebble/api/confirmation/CommentConfirmationStrategy.__Descendant_Table[net/sourceforge/pebble/confirmation/ImageCaptchaConfirmationStrategy] == &__Dispatch_Table
    //#post(net.sourceforge.pebble.confirmation.ImageCaptchaConfirmationStrategy__static_init): net/sourceforge/pebble/api/confirmation/ConfirmationStrategy.__Descendant_Table[net/sourceforge/pebble/confirmation/ImageCaptchaConfirmationStrategy] == &__Dispatch_Table
    //#post(net.sourceforge.pebble.confirmation.ImageCaptchaConfirmationStrategy__static_init): net/sourceforge/pebble/api/confirmation/TrackBackConfirmationStrategy.__Descendant_Table[net/sourceforge/pebble/confirmation/ImageCaptchaConfirmationStrategy] == &__Dispatch_Table
    //#post(net.sourceforge.pebble.confirmation.ImageCaptchaConfirmationStrategy__static_init): net/sourceforge/pebble/confirmation/AbstractConfirmationStrategy.__Descendant_Table[net/sourceforge/pebble/confirmation/ImageCaptchaConfirmationStrategy] == &__Dispatch_Table
    //#post(net.sourceforge.pebble.confirmation.ImageCaptchaConfirmationStrategy__static_init): __Dispatch_Table.confirmationRequired(Lnet/sourceforge/pebble/domain/Blog;)Z == &net/sourceforge/pebble/confirmation/AbstractConfirmationStrategy.confirmationRequired
    //#post(net.sourceforge.pebble.confirmation.ImageCaptchaConfirmationStrategy__static_init): __Dispatch_Table.confirmationRequired(Lnet/sourceforge/pebble/domain/Comment;)Z == &net/sourceforge/pebble/confirmation/AbstractConfirmationStrategy.confirmationRequired
    //#post(net.sourceforge.pebble.confirmation.ImageCaptchaConfirmationStrategy__static_init): __Dispatch_Table.getUri()Ljava/lang/String; == &getUri
    //#post(net.sourceforge.pebble.confirmation.ImageCaptchaConfirmationStrategy__static_init): __Dispatch_Table.isConfirmed(Ljavax/servlet/http/HttpServletRequest;)Z == &isConfirmed
    //#post(net.sourceforge.pebble.confirmation.ImageCaptchaConfirmationStrategy__static_init): __Dispatch_Table.setupConfirmation(Ljavax/servlet/http/HttpServletRequest;)V == &setupConfirmation
    //#post(net.sourceforge.pebble.confirmation.ImageCaptchaConfirmationStrategy__static_init): init'ed(log)
    //#imagecaptchaconfirmationstrategy.java:48: end of method: net.sourceforge.pebble.confirmation.ImageCaptchaConfirmationStrategy.net.sourceforge.pebble.confirmation.ImageCaptchaConfirmationStrategy__static_init

  /**
   * Called before showing the confirmation page.
   *
   * @param request the HttpServletRequest used in the confirmation
   */
  public void setupConfirmation(HttpServletRequest request) {
  }
    //#imagecaptchaconfirmationstrategy.java:56: method: void net.sourceforge.pebble.confirmation.ImageCaptchaConfirmationStrategy.setupConfirmation(HttpServletRequest)
    //#imagecaptchaconfirmationstrategy.java:56: end of method: void net.sourceforge.pebble.confirmation.ImageCaptchaConfirmationStrategy.setupConfirmation(HttpServletRequest)

  /**
   * Gets the URI of the confirmation page.
   *
   * @return a URI, relative to the web application root.
   */
  public String getUri() {
    return "/WEB-INF/jsp/confirmation/imageCaptcha.jsp";
    //#imagecaptchaconfirmationstrategy.java:64: method: String net.sourceforge.pebble.confirmation.ImageCaptchaConfirmationStrategy.getUri()
    //#output(String getUri()): return_value
    //#post(String getUri()): return_value == &".WEB-INF.jsp.confirmation.imageCaptcha.jsp"
    //#imagecaptchaconfirmationstrategy.java:64: end of method: String net.sourceforge.pebble.confirmation.ImageCaptchaConfirmationStrategy.getUri()
  }

  /**
   * Called to determine whether confirmation was successful.
   *
   * @param request   the HttpServletRequest used in the confirmation
   * @return  true if the confirmation was successful, false otherwise
   */
  public boolean isConfirmed(HttpServletRequest request) {
    String captchaId = request.getSession().getId();
    //#imagecaptchaconfirmationstrategy.java:74: method: bool net.sourceforge.pebble.confirmation.ImageCaptchaConfirmationStrategy.isConfirmed(HttpServletRequest)
    //#input(bool isConfirmed(HttpServletRequest)): log
    //#input(bool isConfirmed(HttpServletRequest)): net/sourceforge/pebble/confirmation/CaptchaService.instance
    //#input(bool isConfirmed(HttpServletRequest)): request
    //#output(bool isConfirmed(HttpServletRequest)): return_value
    //#pre[1] (bool isConfirmed(HttpServletRequest)): request != null
    //#presumption(bool isConfirmed(HttpServletRequest)): com.octo.captcha.service.image.ImageCaptchaService:validateResponseForID(...)@77 != null
    //#presumption(bool isConfirmed(HttpServletRequest)): javax.servlet.http.HttpServletRequest:getSession(...)@74 != null
    //#presumption(bool isConfirmed(HttpServletRequest)): org.apache.commons.logging.LogFactory:getLog(...)@48 != null
    //#post(bool isConfirmed(HttpServletRequest)): init'ed(return_value)
    String response = request.getParameter("j_captcha_response");
    try {
      return CaptchaService.getInstance().validateResponseForID(captchaId, response);
    //#imagecaptchaconfirmationstrategy.java:77: Warning: method not available
    //#    -- call on Boolean com.octo.captcha.service.image.ImageCaptchaService:validateResponseForID(String, Object)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.confirmation.ImageCaptchaConfirmationStrategy
    //#    method: bool isConfirmed(HttpServletRequest)
    //#    unanalyzed callee: Boolean com.octo.captcha.service.image.ImageCaptchaService:validateResponseForID(String, Object)
    } catch (CaptchaServiceException e) {
      ImageCaptchaConfirmationStrategy.log.error("Exception encountered", e);
    //#imagecaptchaconfirmationstrategy.java:79: Warning: method not available
    //#    -- call on void org.apache.commons.logging.Log:error(Object, Throwable)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.confirmation.ImageCaptchaConfirmationStrategy
    //#    method: bool isConfirmed(HttpServletRequest)
    //#    unanalyzed callee: void org.apache.commons.logging.Log:error(Object, Throwable)
    }

    return false;
    //#imagecaptchaconfirmationstrategy.java:82: end of method: bool net.sourceforge.pebble.confirmation.ImageCaptchaConfirmationStrategy.isConfirmed(HttpServletRequest)
  }

}
    //#imagecaptchaconfirmationstrategy.java:: end of class: net.sourceforge.pebble.confirmation.ImageCaptchaConfirmationStrategy
