Class CaptchaReader

  extended by org.apache.avalon.framework.logger.AbstractLogEnabled
      extended by org.apache.cocoon.reading.AbstractReader
          extended by org.apache.cocoon.reading.CaptchaReader
All Implemented Interfaces:
Poolable, Recyclable, Component, LogEnabled, Reader, SitemapModelComponent, SitemapOutputComponent

public class CaptchaReader
extends 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}"/>

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.

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
Constructor Summary
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.avalon.framework.logger.AbstractLogEnabled
enableLogging, getLogger, setupLogger, setupLogger, setupLogger
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail


public CaptchaReader()
Method Detail


public String getMimeType()

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

Specified by:
getMimeType in interface SitemapOutputComponent
getMimeType in class AbstractReader
Always image/jpeg.
See Also:
AbstractProcessingPipeline.setMimeTypeForSerializer(org.apache.cocoon.environment.Environment), AbstractProcessingPipeline.setMimeTypeForReader(org.apache.cocoon.environment.Environment)


public void generate()
              throws IOException

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

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

Copyright © 1999-2010 The Apache Software Foundation. All Rights Reserved.