The following document contains the results of PMD's CPD 4.2.2.
| File | Line | 
|---|---|
| com\octo\captcha\component\image\textpaster\glyphsdecorator\BaffleGlyphsDecorator.java | 102 | 
| com\octo\captcha\component\image\textpaster\textdecorator\BaffleTextDecorator.java | 100 | 
            double circleMaxSize = (double) bounds.getWidth() / 2;
            for (int i = 0; i < numberOfHolesPerGlyph.intValue(); i++) {
                double circleSize = circleMaxSize * (1 + myRandom.nextDouble()) / 2;
                double circlex = bounds.getMinX() + bounds.getWidth() * circleXRatio
                        * myRandom.nextDouble();
                double circley = bounds.getMinY() - bounds.getHeight() * circleYRatio
                        * myRandom.nextDouble();
                Ellipse2D circle = new Ellipse2D.Double(circlex, circley, circleSize, circleSize);
                g2.fill(circle);
            }
        }
        g2.setColor(oldColor);
        g2.setComposite(oldComp);
    }
}
 | |
| File | Line | 
|---|---|
| com\octo\captcha\sound\speller\SpellerSoundFactoryTest.java | 26 | 
| com\octo\captcha\sound\spellfind\SpellFindCaptchaFactoryTest.java | 28 | 
public class SpellFindCaptchaFactoryTest extends TestCase {
    public void testSpellerSoundFactory() throws Exception {
        try {
            new SpellerSoundFactory(null, null, null);
            fail("Test is not implemented");
        } catch (CaptchaException e) {
            assertNotNull(e.getMessage());
        }
        try {
            new SpellerSoundFactory(new RandomWordGenerator("a"), null, null);
            fail("Test is not implemented");
        } catch (CaptchaException e) {
            assertNotNull(e.getMessage());
        }
        try {
            new SpellerSoundFactory(null, new WordToSoundMock(), null);
            fail("Test is not implemented");
        } catch (CaptchaException e) {
            assertNotNull(e.getMessage());
        }
    }
    public void testGetSoundCaptcha() throws Exception {
 | |
| File | Line | 
|---|---|
| com\octo\captcha\sound\speller\SoundSpellerFactoryTest.java | 27 | 
| com\octo\captcha\sound\speller\SpellerSoundFactoryTest.java | 26 | 
public class SpellerSoundFactoryTest extends TestCase {
      public void testSpellerSoundFactory() throws Exception {
          try {
              new SpellerSoundFactory(null, null, null);
              fail("Test is not implemented");
          } catch (CaptchaException e) {
              assertNotNull(e.getMessage());
          }
          try {
              new SpellerSoundFactory(new RandomWordGenerator("a"), null, null);
              fail("Test is not implemented");
          } catch (CaptchaException e) {
              assertNotNull(e.getMessage());
          }
          try {
              new SpellerSoundFactory(null, new WordToSoundMock(), null);
              fail("Test is not implemented");
          } catch (CaptchaException e) {
              assertNotNull(e.getMessage());
          }
      }
 | |
| File | Line | 
|---|---|
| com\octo\captcha\component\image\color\RandomRangeColorGeneratorTest.java | 38 | 
| com\octo\captcha\component\image\color\RandomRangeColorGeneratorTest.java | 56 | 
        colorGenerator = new RandomRangeColorGenerator(redRange, greenRange, blueRange);
        // due to the random factor, test is repeated several times
        for (int i = 0; i < 100; i++) {
            Color color = colorGenerator.getNextColor();
            assertTrue(color.getRed() >= redRange[0] && color.getRed() <= redRange[1]);
            assertTrue(color.getGreen() >= greenRange[0] && color.getGreen() <= greenRange[1]);
            assertTrue(color.getBlue() >= blueRange[0] && color.getBlue() <= blueRange[1]);
 | |
| File | Line | 
|---|---|
| com\octo\captcha\sound\gimpy\GimpySoundFactory.java | 85 | 
| com\octo\captcha\sound\speller\SpellerSoundFactory.java | 94 | 
        SoundCaptcha soundCaptcha = new SpellerSound(getQuestion(locale), sound, word);
        return soundCaptcha;
    }
    protected String getQuestion(Locale locale) {
        return CaptchaQuestionHelper.getQuestion(locale, BUNDLE_QUESTION_KEY);
    }
    protected Integer getRandomLength() {
        Integer wordLength;
        int range = getWordToSound().getMaxAcceptedWordLength()
                - getWordToSound().getMinAcceptedWordLength();
        int randomRange = range != 0 ? myRandom.nextInt(range + 1) : 0;
        wordLength = new Integer(randomRange + getWordToSound().getMinAcceptedWordLength());
        return wordLength;
    }
}
 | |
| File | Line | 
|---|---|
| com\octo\captcha\module\web\image\ImageToJpegHelper.java | 62 | 
| com\octo\captcha\module\web\sound\SoundToWavHelper.java | 57 | 
            AudioSystem.write(stream, AudioFileFormat.Type.WAVE, wavOutputStream);
            //AudioSystem.(pAudioInputStream, AudioFileFormat.Type.WAVE, pFile);
        }
        catch (IllegalArgumentException e) {
            //    log a security warning and return a 404...
            if (log != null && log.isWarnEnabled()) {
                log.warn("There was a try from " + theRequest.getRemoteAddr()
                        + " to render an captcha with invalid ID :'" + id + "' or with a too long one");
                theResponse.sendError(HttpServletResponse.SC_NOT_FOUND);
                return;
            }
        }
        catch (CaptchaServiceException e) {
            // log and return a 404 instead of an image...
            if (log != null && log.isWarnEnabled()) {
                log.warn(
                        "Error trying to generate a captcha and " + "render its challenge as JPEG", e);
            }
            theResponse.sendError(HttpServletResponse.SC_NOT_FOUND);
            return;
        }
 | |
| File | Line | 
|---|---|
| com\octo\captcha\sound\gimpy\GimpySound.java | 24 | 
| com\octo\captcha\sound\spellfind\SpellFindCaptcha.java | 23 | 
      public SpellFindCaptcha(String thequestion,
                          AudioInputStream thechallenge, String theresponse) {
          super(thequestion, thechallenge);
          this.response = theresponse;
      }
      public Boolean validateResponse(Object theresponse) {
          if ((theresponse != null) && (theresponse instanceof String)) {
              return this.validateResponse((String) theresponse);
          } else {
              return Boolean.FALSE;
          }
      }
      public Boolean validateResponse(String theresponse) {
          return Boolean.valueOf(this.response.equalsIgnoreCase(theresponse));
      }
}
 | |
| File | Line | 
|---|---|
| com\octo\captcha\sound\gimpy\GimpySoundFactory.java | 85 | 
| com\octo\captcha\sound\spellfind\SpellFindCaptchaFactory.java | 115 | 
        SoundCaptcha soundCaptcha = new SpellerSound(getQuestion(locale), sound, response.toString());
        return soundCaptcha;
    }
    protected String getQuestion(Locale locale) {
        return CaptchaQuestionHelper.getQuestion(locale, BUNDLE_QUESTION_KEY);
    }
    protected Integer getRandomLength() {
        /*Integer wordLength;
        int range = maxWords-minWords;
        int randomRange = range != 0 ? myRandom.nextInt(range + 1) : 0;
        return randomRange + minWords;*/
        Integer wordLength;
        int range = getWordToSound().getMaxAcceptedWordLength()
                - getWordToSound().getMinAcceptedWordLength();
        int randomRange = range != 0 ? myRandom.nextInt(range + 1) : 0;
        wordLength = new Integer(randomRange + getWordToSound().getMinAcceptedWordLength());
        return wordLength;
    }
    /*
private class WordAndPosition{
public WordAndPosition(String word, int position) {
    this.word = word;
    this.position = position;
}
String word;
int position;
}
    */
}
 | |
| File | Line | 
|---|---|
| com\octo\captcha\service\RunableAbstractManageableCaptchaServiceTest.java | 254 | 
| com\octo\captcha\service\RunableAbstractManageableCaptchaServiceTest.java | 288 | 
                    getMService().getNumberOfCorrectResponses());
        }
        for (int i = 0; i < CAPTCHA_STORE_LOAD_BEFORE_GARBAGE_COLLECTION; i++) {
            String id = String.valueOf(i);
            service.generateAndStoreCaptcha(Locale.getDefault(), id);
            try {
                service.validateResponseForID("unknown", "false");
                fail("should have thrown an exception");
            } catch (CaptchaServiceException e) {
            	assertNotNull(e.getMessage());
            }
            assertEquals("should not have been incremented", CAPTCHA_STORE_LOAD_BEFORE_GARBAGE_COLLECTION,
                    getMService().getNumberOfCorrectResponses());
 | |
| File | Line | 
|---|---|
| com\octo\captcha\component\image\textpaster\textdecorator\BaffleTextDecorator.java | 85 | 
| com\octo\captcha\component\image\textpaster\textdecorator\LineTextDecorator.java | 75 | 
        this(numberOfLinesPerGlyph, linesColorGenerator);
        this.alphaCompositeType = alphaCompositeType != null ? alphaCompositeType.intValue() : this.alphaCompositeType;
    }
    public void decorateAttributedString(Graphics2D g2,  MutableAttributedString mutableAttributedString) {
        Color oldColor = g2.getColor();
        Composite oldComp = g2.getComposite();
        g2.setComposite(AlphaComposite.getInstance(alphaCompositeType));
        for (int j = 0; j < mutableAttributedString.length(); j++) {
            g2.setColor(linesColorGenerator.getNextColor());
 | |
| File | Line | 
|---|---|
| com\octo\captcha\component\image\textpaster\DecoratedRandomTextPaster.java | 53 | 
| com\octo\captcha\component\image\textpaster\VisitedAndDecoratedTextPaster.java | 47 | 
    }
    /**
     * Pastes the attributed string on the backround image and return the final image. Implementation must take into
     * account the fact that the text must be readable by human and non by programs
     *
     * @return the final image
     *
     * @throws com.octo.captcha.CaptchaException
     *          if any exception accurs during paste routine.
     */
    public BufferedImage pasteText(BufferedImage background, AttributedString attributedWord)
            throws CaptchaException {
        BufferedImage out = copyBackground(background);
        Graphics2D g2 = pasteBackgroundAndSetTextColor(out, background);
        g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
                RenderingHints.VALUE_FRACTIONALMETRICS_ON);
        g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
        g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        // convert string into a series of glyphs we can work with
        MutableAttributedString mas = new MutableAttributedString(g2,
                      attributedWord, kerning);
 | |
| File | Line | 
|---|---|
| com\octo\captcha\service\image\AbstractManageableImageCaptchaService.java | 73 | 
| com\octo\captcha\service\multitype\GenericManageableCaptchaService.java | 149 | 
        if (ImageCaptcha.class.isAssignableFrom(captchaClass)) {
            BufferedImage challenge = (BufferedImage) captcha.getChallenge();
            BufferedImage clone = new BufferedImage(challenge.getWidth(), challenge.getHeight(), challenge.getType());
            clone.getGraphics().drawImage(challenge, 0, 0, clone.getWidth(), clone.getHeight(), null);
            clone.getGraphics().dispose();
            return clone;
        } else if (SoundCaptcha.class.isAssignableFrom(captchaClass)) {
 | |
| File | Line | 
|---|---|
| com\octo\captcha\engine\image\ImageCaptchaEngine.java | 73 | 
| com\octo\captcha\engine\sound\SoundCaptchaEngine.java | 63 | 
        return getNextSoundCaptcha(locale);
    }
    /**
     * @return captcha factories used by this engine
     */
    public CaptchaFactory[] getFactories() {
        return (CaptchaFactory[]) this.factories.toArray(new CaptchaFactory[factories.size()]);
    }
    /**
     * @param factories new captcha factories for this engine
     */
    public void setFactories(CaptchaFactory[] factories) throws CaptchaEngineException {
        checkNotNullOrEmpty(factories);
        ArrayList tempFactories = new ArrayList();
        for (int i = 0; i < factories.length; i++) {
            if (!SoundCaptchaFactory.class.isAssignableFrom(factories[i].getClass())) {
 | |
| File | Line | 
|---|---|
| com\octo\captcha\service\image\AbstractManageableImageCaptchaService.java | 27 | 
| com\octo\captcha\service\multitype\GenericManageableCaptchaService.java | 48 | 
    										CaptchaEngine captchaEngine,
								            int minGuarantedStorageDelayInSeconds,
								            int maxCaptchaStoreSize,
								            int captchaStoreLoadBeforeGarbageCollection) {
    	super(captchaStore, captchaEngine, minGuarantedStorageDelayInSeconds,
    			maxCaptchaStoreSize, captchaStoreLoadBeforeGarbageCollection);
    }
    
    /**
     * Method to retrive the image challenge corresponding to the given ticket.
     *
     * @param ID the ticket
     *
     * @return the challenge
     *
     * @throws com.octo.captcha.service.CaptchaServiceException
     *          if the ticket is invalid
     */
    public BufferedImage getImageChallengeForID(String ID) throws CaptchaServiceException {
        return (BufferedImage) this.getChallengeForID(ID);
    }
    /**
     * Method to retrive the image challenge corresponding to the given ticket.
     *
     * @param ID the ticket
     *
     * @return the challenge
     *
     * @throws com.octo.captcha.service.CaptchaServiceException
     *          if the ticket is invalid
     */
    public BufferedImage getImageChallengeForID(String ID, Locale locale) throws CaptchaServiceException {
        return (BufferedImage) this.getChallengeForID(ID, locale);
    }
 | |
| File | Line | 
|---|---|
| com\octo\captcha\engine\image\gimpy\HotmailEngine.java | 77 | 
| com\octo\captcha\engine\image\gimpy\HotmailEngine2008.java | 68 | 
                        new TranslateAllToRandomPointVisitor(20,20)
                }
                );
        
        BackgroundGenerator back = new UniColorBackgroundGenerator(
                218, 48, new Color(238, 238,238));
        FontGenerator shearedFont = new RandomFontGenerator(30,
                35,
                new Font[]{
                        new Font("Caslon",Font.BOLD, 30)
                }
        ,false);
        SwimFilter swim= new SwimFilter();
        swim.setScale(30);
        swim.setAmount(10);
 | |
| File | Line | 
|---|---|
| com\octo\captcha\component\image\color\RandomRangeColorGeneratorTest.java | 69 | 
| com\octo\captcha\component\image\color\RandomRangeColorGeneratorTest.java | 82 | 
        int[] redRange = new int[]{-12, 42};
        int[] greenRange = new int[]{57, 62};
        int[] blueRange = new int[]{10, 12};
        try {
            colorGenerator = new RandomRangeColorGenerator(redRange, greenRange, blueRange);
            fail();
        } catch (CaptchaException e) {
        	assertNotNull(e.getMessage());
        }
    }
    public void testClosedRange() {
 | |
| File | Line | 
|---|---|
| com\octo\captcha\component\word\wordgenerator\DictionaryWordGeneratorTest.java | 47 | 
| com\octo\captcha\component\word\wordgenerator\DictionaryWordGeneratorTest.java | 64 | 
            String test = this.dictionaryWordGenerator.getWord(length, Locale.US);
            assertNotNull(test);
            assertTrue(test.length() > 0);
            assertEquals(length.intValue(), test.length());
        }
        try {
            this.dictionaryWordGenerator.getWord(UNKNOWN_LENGTH);
            fail("Should throw a CaptchaException");
        } catch (CaptchaException e) {
            assertNotNull(e.getMessage());
        }
    }
 | |
| File | Line | 
|---|---|
| com\octo\captcha\engine\image\gimpy\HotmailEngine.java | 52 | 
| com\octo\captcha\engine\image\gimpy\HotmailEngine2008.java | 51 | 
public class HotmailEngine2008 extends ListImageCaptchaEngine {
    /**
     * this method should be implemented as folow : <ul> <li>First construct all the factories you want to initialize
     * the gimpy with</li> <li>then call the this.addFactoriy method for each factory</li> </ul>
     */
    protected void buildInitialFactories() {
        //word generator
        com.octo.captcha.component.word.wordgenerator.WordGenerator dictionnaryWords =
                new RandomWordGenerator("ABCDEGHJKLMNRSTUWXY235689");
        //wordtoimage components
        TextPaster randomPaster = new GlyphsPaster(8, 8,
                new SingleColorGenerator(new Color(0, 0, 80))
                ,new GlyphsVisitors[]{
                        new OverlapGlyphsUsingShapeVisitor(3),
 | |
| File | Line | 
|---|---|
| com\octo\captcha\engine\image\gimpy\BaffleListGimpyEngine.java | 41 | 
| com\octo\captcha\engine\image\gimpy\GmailEngine.java | 49 | 
public class GmailEngine extends ListImageCaptchaEngine {
    /**
     * this method should be implemented as folow : <ul> <li>First construct all the factories you want to initialize
     * the gimpy with</li> <li>then call the this.addFactoriy method for each factory</li> </ul>
     */
    protected void buildInitialFactories() {
        //word generator
        com.octo.captcha.component.word.wordgenerator.WordGenerator dictionnaryWords = //new ConstantWordGenerator("gefefi");
                new com.octo.captcha.component.word.wordgenerator.ComposeDictionaryWordGenerator(
                        new com.octo.captcha.component.word.FileDictionary(
                                "toddlist"));
        //wordtoimage components
        TextPaster randomPaster = new GlyphsPaster(7, 7,
 | |
| File | Line | 
|---|---|
| com\octo\captcha\engine\image\fisheye\SimpleFishEyeEngine.java | 44 | 
| com\octo\captcha\engine\image\gimpy\DeformedBaffleListGimpyEngine.java | 56 | 
        com.jhlabs.image.RippleFilter rippleBack = new com.jhlabs.image.RippleFilter();
        com.jhlabs.image.RippleFilter ripple = new com.jhlabs.image.RippleFilter();
        com.jhlabs.image.TwirlFilter twirl = new com.jhlabs.image.TwirlFilter();
        com.jhlabs.image.WaterFilter water = new com.jhlabs.image.WaterFilter();
 | |
| File | Line | 
|---|---|
| com\octo\captcha\engine\image\ImageCaptchaEngine.java | 93 | 
| com\octo\captcha\engine\sound\SoundCaptchaEngine.java | 82 | 
                throw new CaptchaEngineException("This factory is not an sound captcha factory " + factories[i].getClass());
            }
            tempFactories.add(factories[i]);
        }
        this.factories = tempFactories;
    }
  protected void checkNotNullOrEmpty(CaptchaFactory[] factories) {
        if (factories == null || factories.length == 0) {
            throw new CaptchaEngineException("impossible to set null or empty factories");
        }
    }
 | |
| File | Line | 
|---|---|
| com\octo\captcha\sound\gimpy\GimpySoundFactory.java | 57 | 
| com\octo\captcha\sound\speller\SpellerSoundFactory.java | 67 | 
    }
    public WordToSound getWordToSound() {
        return this.word2Sound;
    }
    public WordGenerator getWordGenerator() {
        return this.wordGenerator;
    }
    /**
     * @return a Sound Captcha
     */
    public SoundCaptcha getSoundCaptcha() {
        String word = this.wordGenerator.getWord(getRandomLength(), Locale.getDefault());
        AudioInputStream sound = this.word2Sound.getSound(wordDecorator.decorateWord(word));
 | |
| File | Line | 
|---|---|
| com\octo\captcha\component\image\textpaster\DecoratedRandomTextPaster.java | 65 | 
| com\octo\captcha\component\image\textpaster\RandomTextPaster.java | 65 | 
                                   final AttributedString attributedString) {
        BufferedImage out = copyBackground(background);
        Graphics2D g2 = pasteBackgroundAndSetTextColor(out, background);
        g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS,
                RenderingHints.VALUE_FRACTIONALMETRICS_ON);
        g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
        g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        // this doesn't do anything in JDK 1.4, but maybe it will in JDK 1.5
        // attributedString.addAttribute(TextAttribute.WIDTH, TextAttribute.WIDTH_EXTENDED);
        // convert string into a series of glyphs we can work with
        MutableAttributedString newAttrString = new MutableAttributedString(g2,
 | |
| File | Line | 
|---|---|
| com\octo\captcha\component\image\wordtoimage\ComposedWordToImageTest.java | 43 | 
| com\octo\captcha\component\image\wordtoimage\DeformedComposedWordToImageTest.java | 46 | 
    private Integer minAcceptedWordLength = new Integer(1);
    private Integer maxAcceptedWordLength = new Integer(10);
    private Integer imageHeight = new Integer(100);
    private Integer imageWidth = new Integer(100);
    private Integer minFontSize = new Integer(10);
    private Integer maxFontSize = new Integer(10);
 | |
| File | Line | 
|---|---|
| com\octo\captcha\service\AbstractCaptchaService.java | 71 | 
| com\octo\captcha\service\AbstractCaptchaService.java | 106 | 
        if (!this.store.hasCaptcha(ID)) {
            //if not generate it
            captcha = generateAndStoreCaptcha(locale, ID);
        } else {
            captcha = this.store.getCaptcha(ID);
            if (captcha == null) {
                captcha = generateAndStoreCaptcha(locale, ID);
            }else if (locale != null) {
 | |
| File | Line | 
|---|---|
| com\octo\captcha\component\image\textpaster\glyphsvisitor\OverlapGlyphsUsingShapeVisitor.java | 79 | 
| com\octo\captcha\component\image\textpaster\glyphsvisitor\OverlapGlyphsVisitor.java | 22 | 
            double tx =gv.getBoundsX(i-1)+gv.getBoundsWidth(i-1)-gv.getBoundsX(i)
                    -Math.abs(gv.getRSB(i-1))
                    -Math.abs(gv.getLSB(i))
 | |