com.octo.captcha.service
Class AbstractCaptchaService

java.lang.Object
  extended by com.octo.captcha.service.AbstractCaptchaService
All Implemented Interfaces:
CaptchaService
Direct Known Subclasses:
AbstractManageableCaptchaService

public abstract class AbstractCaptchaService
extends java.lang.Object
implements CaptchaService

This is a base class for CaptchaService implementations. It implements the lyfe cycle stuff. It uses : a CaptchaStore to store captcha during the life cycle, and a CaptchaEngine to build captchas. All concrete implementation (that uses a specific capthcaStore and captchaEngine) should provide a default non argument constructor (by subclassing this class, and calling the constructor of the abstract class)


Field Summary
protected  CaptchaEngine engine
           
protected  Log logger
           
protected  CaptchaStore store
           
 
Constructor Summary
protected AbstractCaptchaService(CaptchaStore captchaStore, CaptchaEngine captchaEngine)
           
 
Method Summary
protected  Captcha generateAndStoreCaptcha(java.util.Locale locale, java.lang.String ID)
           
protected abstract  java.lang.Object getChallengeClone(Captcha captcha)
          This method must be implemented by sublcasses and : Retrieve the challenge from the captcha Make and return a clone of the challenge Return the clone It has be design in order to let the service dispose the challenge of the captcha after rendering.
 java.lang.Object getChallengeForID(java.lang.String ID)
          Method to retrive the challenge corresponding to the given ticket from the store.
 java.lang.Object getChallengeForID(java.lang.String ID, java.util.Locale locale)
          Method to retrive the challenge corresponding to the given ticket.
 java.lang.String getQuestionForID(java.lang.String ID)
          Method to retrive the question corresponding to the given ticket from the store.
 java.lang.String getQuestionForID(java.lang.String ID, java.util.Locale locale)
          Method to retrive the question corresponding to the given ticket.
 java.lang.Boolean validateResponseForID(java.lang.String ID, java.lang.Object response)
          Method to validate a response to the challenge corresponding to the given ticket and remove the coresponding captcha from the store.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

store

protected CaptchaStore store

engine

protected CaptchaEngine engine

logger

protected Log logger
Constructor Detail

AbstractCaptchaService

protected AbstractCaptchaService(CaptchaStore captchaStore,
                                 CaptchaEngine captchaEngine)
Method Detail

getChallengeForID

public java.lang.Object getChallengeForID(java.lang.String ID)
                                   throws CaptchaServiceException
Method to retrive the challenge corresponding to the given ticket from the store.

Specified by:
getChallengeForID in interface CaptchaService
Parameters:
ID - the ticket provided by the buildCaptchaAndGetID method
Returns:
the challenge
Throws:
CaptchaServiceException - if the ticket is invalid

getChallengeForID

public java.lang.Object getChallengeForID(java.lang.String ID,
                                          java.util.Locale locale)
                                   throws CaptchaServiceException
Method to retrive the challenge corresponding to the given ticket.

Specified by:
getChallengeForID in interface CaptchaService
Parameters:
ID - ticket
locale - the desired localized capthca
Returns:
the localized challenge
Throws:
CaptchaServiceException - if the ticket is invalid

getQuestionForID

public java.lang.String getQuestionForID(java.lang.String ID,
                                         java.util.Locale locale)
                                  throws CaptchaServiceException
Method to retrive the question corresponding to the given ticket.

Specified by:
getQuestionForID in interface CaptchaService
Parameters:
ID - ticket
locale - the desired localized capthca
Returns:
the localized question
Throws:
CaptchaServiceException - if the ticket is invalid

getQuestionForID

public java.lang.String getQuestionForID(java.lang.String ID)
                                  throws CaptchaServiceException
Method to retrive the question corresponding to the given ticket from the store.

Specified by:
getQuestionForID in interface CaptchaService
Parameters:
ID - the ticket provided by the buildCaptchaAndGetID method
Returns:
the question
Throws:
CaptchaServiceException - if the ticket is invalid

validateResponseForID

public java.lang.Boolean validateResponseForID(java.lang.String ID,
                                               java.lang.Object response)
                                        throws CaptchaServiceException
Method to validate a response to the challenge corresponding to the given ticket and remove the coresponding captcha from the store.

Specified by:
validateResponseForID in interface CaptchaService
Parameters:
ID - the ticket provided by the buildCaptchaAndGetID method
Returns:
true if the response is correct, false otherwise.
Throws:
CaptchaServiceException - if the ticket is invalid

generateAndStoreCaptcha

protected Captcha generateAndStoreCaptcha(java.util.Locale locale,
                                          java.lang.String ID)

getChallengeClone

protected abstract java.lang.Object getChallengeClone(Captcha captcha)
This method must be implemented by sublcasses and : Retrieve the challenge from the captcha Make and return a clone of the challenge Return the clone It has be design in order to let the service dispose the challenge of the captcha after rendering. It should be implemented for all captcha type (@see ImageCaptchaService implementations for exemple)

Returns:
a Challenge Clone


Copyright 2003-2009 JCaptcha. All Rights Reserved.