View Javadoc

1   /*
2    * JCaptcha, the open source java framework for captcha definition and integration
3    * Copyright (c)  2007 jcaptcha.net. All Rights Reserved.
4    * See the LICENSE.txt file distributed with this package.
5    */
6   
7   package com.octo.captcha.text;
8   
9   import com.octo.captcha.Captcha;
10  
11  /***
12   * A text captcha is a captcha with a Text challenge... This class is abstract. 
13   */
14  public abstract class TextCaptcha implements Captcha {
15  
16      private Boolean hasChallengeBeenCalled = Boolean.FALSE;
17      protected String question;
18      protected String challenge;
19  
20      protected TextCaptcha(String question, String challenge) {
21          this.challenge = challenge;
22          this.question = question;
23      }
24  
25      /***
26       * Accessor captcha question.
27       *
28       * @return the question
29       */
30      public String getQuestion() {
31          return question;
32      }
33  
34      /***
35       * Accerssor for the questionned challenge.
36       *
37       * @return the challenge (may be an image for image captcha...
38       */
39      public Object getChallenge() {
40          return getTextChallenge();
41      }
42  
43      /***
44       * Accerssor for the questionned challenge in text format.
45       *
46       * @return the challenge
47       */
48      public String getTextChallenge() {
49          hasChallengeBeenCalled = Boolean.TRUE;
50          return challenge;
51      }
52  
53  
54      /***
55       * Dispose the challenge, once this method is call the getChallenge method will return null.<br> It has been added
56       * for technical reasons : a captcha is always used in a two step fashion<br> First submit the challenge, and then
57       * wait until the response arrives.<br> It had been asked to have a method to dispose the challenge that is no
58       * longer used after being dipslayed. So here it is!
59       */
60      public void disposeChallenge() {
61          this.challenge = null;
62  
63      }
64  
65      /***
66       * This method should return true if the getChalenge method has been called (has been added in order to properly
67       * manage the captcha state.
68       *
69       * @return true if getChallenge has been called false otherwise.
70       */
71      public Boolean hasGetChalengeBeenCalled() {
72          return hasChallengeBeenCalled;
73      }
74  }