001 /*
002 * Apache License
003 * Version 2.0, January 2004
004 * http://www.apache.org/licenses/
005 *
006 * Copyright 2008 by chenillekit.org
007 *
008 * Licensed under the Apache License, Version 2.0 (the "License");
009 * you may not use this file except in compliance with the License.
010 * You may obtain a copy of the License at
011 *
012 * http://www.apache.org/licenses/LICENSE-2.0
013 */
014
015 package org.chenillekit.image.services.impl;
016
017 import java.awt.image.BufferedImage;
018 import java.util.Properties;
019
020 import com.google.code.kaptcha.impl.DefaultKaptcha;
021 import com.google.code.kaptcha.util.Config;
022 import org.chenillekit.image.services.CaptchaProducer;
023
024 /**
025 * implements the <a href="http://code.google.com/p/kaptcha">Kaptcha</a> library.
026 *
027 * @version $Id: KaptchaProducerImpl.java 594 2009-12-05 15:17:26Z mlusetti $
028 */
029 public class KaptchaProducerImpl implements CaptchaProducer
030 {
031 private DefaultKaptcha producer;
032
033 public KaptchaProducerImpl(Properties kaptchaConfig)
034 {
035 producer = new DefaultKaptcha();
036
037 if (kaptchaConfig == null)
038 kaptchaConfig = new Properties();
039
040 producer.setConfig(new Config(kaptchaConfig));
041 }
042
043 /**
044 * create the captch from given string.
045 */
046 public BufferedImage createImage(String captchaString)
047 {
048 return producer.createImage(captchaString);
049 }
050
051 /**
052 * create a random String.
053 */
054 public String createText()
055 {
056 return producer.createText();
057 }
058 }