Source Code Cross Referenced for Captcha.java in  » Forum » JForum-2.1.8 » net » jforum » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Forum » JForum 2.1.8 » net.jforum.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (c) JForum Team
003:         * All rights reserved.
004:         * 
005:         * Redistribution and use in source and binary forms, 
006:         * with or without modification, are permitted provided 
007:         * that the following conditions are met:
008:         * 
009:         * 1) Redistributions of source code must retain the above 
010:         * copyright notice, this list of conditions and the 
011:         * following  disclaimer.
012:         * 2)  Redistributions in binary form must reproduce the 
013:         * above copyright notice, this list of conditions and 
014:         * the following disclaimer in the documentation and/or 
015:         * other materials provided with the distribution.
016:         * 3) Neither the name of "Rafael Steil" nor 
017:         * the names of its contributors may be used to endorse 
018:         * or promote products derived from this software without 
019:         * specific prior written permission.
020:         * 
021:         * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT 
022:         * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
023:         * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 
024:         * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
025:         * MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
026:         * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 
027:         * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 
028:         * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
029:         * EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
030:         * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
031:         * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
032:         * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
033:         * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 
034:         * IN CONTRACT, STRICT LIABILITY, OR TORT 
035:         * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
036:         * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
037:         * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
038:         * 
039:         * This file creation date: Nov 13, 2004 / 17:17:09
040:         * The JForum Project
041:         * http://www.jforum.net
042:         */
043:
044:        package net.jforum.util;
045:
046:        import java.awt.Color;
047:        import java.awt.image.BufferedImage;
048:        import java.io.IOException;
049:        import java.io.OutputStream;
050:        import java.util.ArrayList;
051:        import java.util.Iterator;
052:        import java.util.List;
053:
054:        import javax.imageio.ImageIO;
055:
056:        import net.jforum.JForumExecutionContext;
057:        import net.jforum.SessionFacade;
058:        import net.jforum.util.preferences.ConfigKeys;
059:        import net.jforum.util.preferences.SystemGlobals;
060:
061:        import org.apache.log4j.Logger;
062:
063:        import com.octo.captcha.component.image.backgroundgenerator.BackgroundGenerator;
064:        import com.octo.captcha.component.image.backgroundgenerator.GradientBackgroundGenerator;
065:        import com.octo.captcha.component.image.fontgenerator.FontGenerator;
066:        import com.octo.captcha.component.image.fontgenerator.TwistedAndShearedRandomFontGenerator;
067:        import com.octo.captcha.component.image.textpaster.RandomTextPaster;
068:        import com.octo.captcha.component.image.textpaster.TextPaster;
069:        import com.octo.captcha.component.image.wordtoimage.ComposedWordToImage;
070:        import com.octo.captcha.component.image.wordtoimage.WordToImage;
071:        import com.octo.captcha.component.wordgenerator.RandomWordGenerator;
072:        import com.octo.captcha.component.wordgenerator.WordGenerator;
073:        import com.octo.captcha.engine.image.ListImageCaptchaEngine;
074:        import com.octo.captcha.image.ImageCaptchaFactory;
075:        import com.octo.captcha.image.gimpy.GimpyFactory;
076:
077:        /**
078:         * @author James Yong
079:         * @version $Id: Captcha.java,v 1.13 2007/08/06 15:38:01 rafaelsteil Exp $
080:         */
081:        public class Captcha extends ListImageCaptchaEngine {
082:            private static final Logger logger = Logger
083:                    .getLogger(Captcha.class);
084:
085:            private static Captcha classInstance = new Captcha();
086:            private List backgroundGeneratorList;
087:            private List textPasterList;
088:            private List fontGeneratorList;
089:
090:            private static String charsInUse;
091:
092:            private void initializeChars() {
093:                if (SystemGlobals.getBoolValue(ConfigKeys.CAPTCHA_IGNORE_CASE)) {
094:                    charsInUse = "123456789abcdefghijlmnopkrstuvxzyk@#%^";
095:                } else {
096:                    charsInUse = "123456789ABCDEFGHJLKMNPRSTWXYZabcdefghijlmnopkrstuvxzyk@#%^";
097:                }
098:            }
099:
100:            /**
101:             * Gets the singleton
102:             * 
103:             * @return Instance of Captcha class
104:             */
105:            public static Captcha getInstance() {
106:                return classInstance;
107:            }
108:
109:            protected void buildInitialFactories() {
110:                this .initializeChars();
111:
112:                this .backgroundGeneratorList = new ArrayList();
113:                this .textPasterList = new ArrayList();
114:                this .fontGeneratorList = new ArrayList();
115:
116:                int width = SystemGlobals.getIntValue(ConfigKeys.CAPTCHA_WIDTH);
117:                int height = SystemGlobals
118:                        .getIntValue(ConfigKeys.CAPTCHA_HEIGHT);
119:                int minWords = SystemGlobals
120:                        .getIntValue(ConfigKeys.CAPTCHA_MIN_WORDS);
121:                int maxWords = SystemGlobals
122:                        .getIntValue(ConfigKeys.CAPTCHA_MAX_WORDS);
123:                int minFontSize = SystemGlobals
124:                        .getIntValue(ConfigKeys.CAPTCHA_MIN_FONT_SIZE);
125:                int maxFontSize = SystemGlobals
126:                        .getIntValue(ConfigKeys.CAPTCHA_MAX_FONT_SIZE);
127:
128:                this .backgroundGeneratorList
129:                        .add(new GradientBackgroundGenerator(
130:                                new Integer(width), new Integer(height),
131:                                Color.PINK, Color.LIGHT_GRAY));
132:                this .backgroundGeneratorList
133:                        .add(new GradientBackgroundGenerator(
134:                                new Integer(width), new Integer(height),
135:                                Color.WHITE, Color.RED));
136:                this .backgroundGeneratorList
137:                        .add(new GradientBackgroundGenerator(
138:                                new Integer(width), new Integer(height),
139:                                Color.ORANGE, Color.LIGHT_GRAY));
140:                this .backgroundGeneratorList
141:                        .add(new GradientBackgroundGenerator(
142:                                new Integer(width), new Integer(height),
143:                                Color.CYAN, Color.LIGHT_GRAY));
144:                //this.backgroundGeneratorList.add(new FunkyBackgroundGenerator(new Integer(250), new Integer(50)));
145:
146:                this .textPasterList.add(new RandomTextPaster(new Integer(
147:                        minWords), new Integer(maxWords), Color.DARK_GRAY));
148:                this .textPasterList.add(new RandomTextPaster(new Integer(
149:                        minWords), new Integer(maxWords), Color.BLUE));
150:                this .textPasterList.add(new RandomTextPaster(new Integer(
151:                        minWords), new Integer(maxWords), Color.GREEN));
152:                this .textPasterList.add(new RandomTextPaster(new Integer(
153:                        minWords), new Integer(maxWords), Color.MAGENTA));
154:                this .textPasterList.add(new RandomTextPaster(new Integer(
155:                        minWords), new Integer(maxWords), Color.BLACK));
156:                this .textPasterList.add(new RandomTextPaster(new Integer(
157:                        minWords), new Integer(maxWords), Color.WHITE));
158:
159:                this .fontGeneratorList
160:                        .add(new TwistedAndShearedRandomFontGenerator(
161:                                new Integer(minFontSize), new Integer(
162:                                        maxFontSize)));
163:
164:                // Create a random word generator
165:                WordGenerator words = new RandomWordGenerator(charsInUse);
166:
167:                for (Iterator fontIter = this .fontGeneratorList.iterator(); fontIter
168:                        .hasNext();) {
169:                    FontGenerator fontGeny = (FontGenerator) fontIter.next();
170:
171:                    for (Iterator backIter = this .backgroundGeneratorList
172:                            .iterator(); backIter.hasNext();) {
173:                        BackgroundGenerator bkgdGeny = (BackgroundGenerator) backIter
174:                                .next();
175:
176:                        for (Iterator textIter = this .textPasterList.iterator(); textIter
177:                                .hasNext();) {
178:                            TextPaster textPaster = (TextPaster) textIter
179:                                    .next();
180:
181:                            WordToImage word2image = new ComposedWordToImage(
182:                                    fontGeny, bkgdGeny, textPaster);
183:
184:                            // Creates a ImageCaptcha Factory
185:                            ImageCaptchaFactory factory = new GimpyFactory(
186:                                    words, word2image);
187:
188:                            // Add a factory to the gimpy list (A Gimpy is a ImagCaptcha)
189:                            addFactory(factory);
190:                        }
191:                    }
192:                }
193:            }
194:
195:            public void writeCaptchaImage() {
196:                BufferedImage image = SessionFacade.getUserSession()
197:                        .getCaptchaImage();
198:
199:                if (image == null) {
200:                    return;
201:                }
202:
203:                OutputStream outputStream = null;
204:
205:                try {
206:                    outputStream = JForumExecutionContext.getResponse()
207:                            .getOutputStream();
208:                    ImageIO.write(image, "jpg", outputStream);
209:                } catch (IOException ex) {
210:                    logger.error(ex);
211:                } finally {
212:                    if (outputStream != null) {
213:                        try {
214:                            outputStream.close();
215:                        } catch (IOException ex) {
216:                        }
217:                    }
218:                }
219:            }
220:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.