org.apache.cocoon.reading
Class CaptchaReader

java.lang.Object
  extended byorg.apache.cocoon.util.AbstractLogEnabled
      extended byorg.apache.cocoon.reading.AbstractReader
          extended byorg.apache.cocoon.reading.CaptchaReader
All Implemented Interfaces:
Poolable, org.apache.cocoon.reading.Reader, Recyclable, org.apache.cocoon.sitemap.SitemapModelComponent, org.apache.cocoon.sitemap.SitemapOutputComponent

public class CaptchaReader
extends org.apache.cocoon.reading.AbstractReader

The CaptchaReader is a simple tool generating JPEG images for the text supplied as its source in a way so that it's hard to parse automatically.

CAPTCHA means quite literally Completely Automated Public Turing Test to Tell Computers and Humans Apart and one of the best resources on this can be found at the Carnegie Mellon School of Computer Science CAPTCHA project..

This reader creates very simple CAPTCHAs from within a Cocoon pipeline, enabling quick and safe end-user presence identificat. As an example, look at the following pipeline snippet:

 <map:match pattern="*">
   <map:read type="captcha" src="{1}"/>
 </map:match>
 

The example will produce an image containing the text in {1} "warped" or "bent" in a way similar to the Adobe® Photoshop® "Wave" filter plugin.

Few pipeline parameters control the operation of the CaptchaReader (this component is not configurable):

Note that when the foreground parameter is not specified, the color used to write the text will be randomly chosen in a way that it contrasts well with the background color to avoid problems of illegible text.

Both the foreground and background parameters accept strings in the format specified by Color.decode(String) (for example fff, or 0099CC) or one of the field names of the Color class (for example BLACK or cyan ...).

The scale parameter controls how much the specified size should be scaled while processing the interim images: the bigger the scaling factor, the better the image quality, but also the memory used while generating the final image will be bigger. In other words, use with care.

The amount parameter is interpreted as a floating point number and must be greater than zero. This controls how much text should be warped, and normally a value of 1 produce quite-good warping. Increasing (or decreasing) this value will produce more (ore less) warping.

Remember that in no way the CaptchaReader claims to be able to generate "unbreakable" text (that will be impossible), and improvements to the algorithm are welcome.

Version:
$Id: CaptchaReader.html 1304280 2012-03-23 11:18:01Z ilgrosso $

Field Summary
 
Fields inherited from class org.apache.cocoon.reading.AbstractReader
objectModel, out, parameters, resolver, source
 
Fields inherited from interface org.apache.cocoon.reading.Reader
ROLE
 
Constructor Summary
CaptchaReader()
           
 
Method Summary
 void generate()
          Create an image containing the text specified as this reader source warped to avoid automatic interpretation.
 String getMimeType()
          The content type of the generated content: image/jpeg.
 
Methods inherited from class org.apache.cocoon.reading.AbstractReader
getLastModified, recycle, setOutputStream, setup, shouldSetContentLength
 
Methods inherited from class org.apache.cocoon.util.AbstractLogEnabled
getLogger, setLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CaptchaReader

public CaptchaReader()
Method Detail

getMimeType

public String getMimeType()

The content type of the generated content: image/jpeg.

Returns:
Always image/jpeg.

generate

public void generate()
              throws IOException

Create an image containing the text specified as this reader source warped to avoid automatic interpretation.

Throws:
IOException - if an I/O error occurred generating the image.


Copyright 1999-2008 The Apache Software Foundation. All Rights Reserved.