Tallefer / kaptcha

Automatically exported from code.google.com/p/kaptcha
Other
0 stars 0 forks source link

Refactor original code from simplecaptcha #5

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Jon, attached is a patch of the refactored simplecaptcha code.
I've made sure that it builds fine, but I haven't verified it with
retroweaver its jar doesn't seem to exist in the trunk.

Change notes:
- Added lots of unit tests. I've made sure that they all pass, I used
Eclipse to run the tests. Image related tests writes the image files to
_eclipse directory.
- Reformatted the source code based on cinchblog's formatting style.
- Removed unnecessary inheritance (DefaultTextCreator extended by
FiveLetterFirstNameTextCreator & ChineseTextProducer) and interface (Engine).
- Introduced Configurable interface for classes that can be configured via
the properties file. This allows classes which don't use anything from the
properties (like FiveLetterFirstNameTextCreator & ChineseTextProducer) to
ignore the properties altogether.
- Moved all configuration properties handling to ConfigManager and
ConfigHelper, this used to be scattered across the Helper ThingFactory and
some model classes. ConfigManager is responsible for specifying the
property names and default values. ConfigHelper is responsible for the
actual value parsing.
- Introduced ConfigException when there's an invalid configuration values.
I think it's better to alert the client code a.s.a.p in such event, rather
than quietly returns the default values for any error.
- Changed Producer's createImage to really create the BufferedImage and not
muck around with OutputStream. I moved the JPEG file creation to
KaptchaServlet instead.

I kept the original package & class names even though some of them are
inconsistent (e.g. TextProducer - DefaultTextCreator). This is to avoid any
change to client properties configuration.

A short guide when client code wants to have specific implementations:
- implement the relevant interface (TextProducer, NoiseProducer, etc)
- implement Configurable interface, if additional configuration values are
needed. Properties are available from configManager.getProperties()
- specify the full class name in the properties / web.xml params.

I didn't change SimpleKaptcha since it doesn't use the model classes. I
also didn't clean up KaptchaServlet code just in case latchkey already
started making some changes there (noticed the new response headers on
r34). I'd probably suggest creating PNG file instead of JPEG for file size
reason.

Be careful with ChineseTextProducer class. I was having problem with
keeping the file encoding at might have lost the Chinese characters on
Eclipse when I checked out from svn. If this patch got in, please make sure
that the Chinese characters are kept.

Original issue reported on code.google.com by cliffano on 3 Jan 2008 at 1:41

Attachments:

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
fixed and then modified.

Original comment by latch...@gmail.com on 14 Feb 2008 at 5:52