1
2
3
4
5
6
7 package com.octo.captcha.service.sound;
8
9 import com.octo.captcha.Captcha;
10 import com.octo.captcha.service.AbstractManageableCaptchaService;
11 import com.octo.captcha.service.CaptchaServiceException;
12 import com.octo.captcha.service.captchastore.CaptchaStore;
13
14 import javax.sound.sampled.AudioInputStream;
15 import java.util.Locale;
16
17 /***
18 * Base implementation of the SoundCaptchaService.
19 *
20 * @author <a href="mailto:mag@jcaptcha.net">Marc-Antoine Garrigue</a>
21 * @version 1.0
22 */
23 public abstract class AbstractManageableSoundCaptchaService extends AbstractManageableCaptchaService
24 implements SoundCaptchaService {
25
26 protected AbstractManageableSoundCaptchaService(CaptchaStore captchaStore,
27 com.octo.captcha.engine.CaptchaEngine captchaEngine,
28 int minGuarantedStorageDelayInSeconds,
29 int maxCaptchaStoreSize,
30 int captchaStoreLoadBeforeGarbageCollection) {
31 super(captchaStore, captchaEngine,
32 minGuarantedStorageDelayInSeconds, maxCaptchaStoreSize,
33 captchaStoreLoadBeforeGarbageCollection);
34 }
35
36
37 /***
38 * Method to retrive the image challenge corresponding to the given ticket.
39 *
40 * @param ID the ticket
41 *
42 * @return the challenge
43 *
44 * @throws com.octo.captcha.service.CaptchaServiceException
45 * if the ticket is invalid
46 */
47 public AudioInputStream getSoundChallengeForID(String ID) throws CaptchaServiceException {
48 return (AudioInputStream) this.getChallengeForID(ID);
49 }
50
51
52 /***
53 * Method to retrive the image challenge corresponding to the given ticket.
54 *
55 * @param ID the ticket
56 *
57 * @return the challenge
58 *
59 * @throws com.octo.captcha.service.CaptchaServiceException
60 * if the ticket is invalid
61 */
62 public AudioInputStream getSoundChallengeForID(String ID, Locale locale) throws CaptchaServiceException {
63 return (AudioInputStream) this.getChallengeForID(ID, locale);
64 }
65
66 /***
67 * This method must be implemented by sublcasses and : Retrieve the challenge from the captcha Make and return a
68 * clone of the challenge Return the clone It has be design in order to let the service dipose the challenge of the
69 * captcha after rendering. It should be implemented for all captcha type (@see ImageCaptchaService implementations
70 * for exemple)
71 *
72 * @return a Challenge Clone
73 */
74 protected Object getChallengeClone(Captcha captcha) {
75 AudioInputStream challenge = (AudioInputStream) captcha.getChallenge();
76 AudioInputStream clone = new AudioInputStream(challenge, challenge.getFormat(), challenge.getFrameLength());
77 return clone;
78 }
79 }