View Javadoc

1   package com.octo.captcha.component.word.wordgenerator;
2   
3   import com.octo.captcha.CaptchaException;
4   
5   import java.util.Locale;
6   
7   /***
8    * @author mag
9    * @Date 7 mars 2008
10   */
11  public class ConstantWordGenerator implements WordGenerator{
12      String constantString;
13  
14      public ConstantWordGenerator(String constantString) {
15          this.constantString = constantString;
16          if(constantString==null||constantString.isEmpty())throw new CaptchaException("ConstantWordGenerator must be built with a non empty string");
17      }
18  
19      public String getWord(Integer length) {
20          StringBuilder toCut= new StringBuilder(constantString);
21          while(toCut.length()<length){
22              toCut.append(constantString);
23          }
24          return toCut.substring(0,length);
25      }
26  
27      public String getWord(Integer length, Locale locale) {
28          return getWord(length);
29      }
30  }