Source Code Cross Referenced for Validator.java in  » Mail-Clients » columba-1.4 » org » columba » mail » spellcheck » cswilly » 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 » Mail Clients » columba 1.4 » org.columba.mail.spellcheck.cswilly 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Revision: 1.1 $
003:         * $Date: 2006/06/10 13:32:32 $
004:         * $Author: fdietz $
005:         *
006:         * Copyright (C) 2001 C. Scott Willy
007:         *
008:         * This program is free software; you can redistribute it and/or
009:         * modify it under the terms of the GNU General Public License
010:         * as published by the Free Software Foundation; either version 2
011:         * of the License, or any later version.
012:         *
013:         * This program is distributed in the hope that it will be useful,
014:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
015:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
016:         * GNU General Public License for more details.
017:         *
018:         * You should have received a copy of the GNU General Public License
019:         * along with this program; if not, write to the Free Software
020:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
021:         */
022:        package org.columba.mail.spellcheck.cswilly;
023:
024:        //import java.io.*;
025:        import java.util.HashMap;
026:        import java.util.HashSet;
027:        import java.util.List;
028:
029:        /**
030:         * A validator of a spell check results
031:         *<p>
032:         * After a spell check engine runs, its results must be validated (normally by
033:         * a user). The {@link Validator} class provides this service.
034:         */
035:        public class Validator {
036:            private final HashMap _changeAllMap = new HashMap();
037:            private final HashSet _ignoreAllSet = new HashSet();
038:
039:            /**
040:             * Validate a line of words that have the <code>results</code> of a spell
041:             * check.
042:             *<p>
043:             * @param line String with a line of words that are to be corrected
044:             * @param results List of {@link Result} of a spell check
045:             * @return new line with all corrected words validated
046:             */
047:            public String validate(String line, List results) {
048:                String checkedLine = line;
049:
050:                for (int ii = results.size() - 1; ii >= 0; ii--) {
051:                    Result result = (Result) results.get(ii);
052:
053:                    if (result.getType() != Result.OK) {
054:                        String replacementWord;
055:
056:                        if (_changeAllMap.containsKey(result.getOriginalWord())) {
057:                            replacementWord = (String) _changeAllMap.get(result
058:                                    .getOriginalWord());
059:                        } else if (_ignoreAllSet.contains(result
060:                                .getOriginalWord())) {
061:                            replacementWord = result.getOriginalWord();
062:                        } else {
063:                            replacementWord = validate(result);
064:
065:                            if (replacementWord == null) {
066:                                checkedLine = null;
067:
068:                                break;
069:                            }
070:                        }
071:
072:                        if (replacementWord != null) {
073:                            checkedLine = replaceWord(checkedLine, result
074:                                    .getOriginalWord(), result.getOffset(),
075:                                    replacementWord);
076:                        }
077:                    }
078:                }
079:
080:                return checkedLine;
081:            }
082:
083:            /**
084:             * Validates a single correction
085:             *<p>
086:             *
087:             *<p>
088:             * @param result A {@link Result} of spell checking one word
089:             * @return validated correction (this is the replacement word). <i>null</i>
090:             *         is returned if the operation is cancelled. The replacement word
091:             *         maybe the same or different from the original word in
092:             *         <code>result</code>.
093:             */
094:            public String validate(Result result) {
095:                String replacementWord = null;
096:
097:                ValidationDialog validationDialog;
098:                validationDialog = new ValidationDialog(result
099:                        .getOriginalWord(), result.getSuggestions());
100:                validationDialog.setVisible(true);
101:
102:                ValidationDialog.UserAction userAction = validationDialog
103:                        .getUserAction();
104:
105:                if (userAction == ValidationDialog.CANCEL) {
106:                    replacementWord = null;
107:                } else if (userAction == ValidationDialog.CHANGE_ALL) {
108:                    if (_changeAllMap.containsKey(result.getOriginalWord())) {
109:                        System.err
110:                                .println("Validator error: Change  all twice same word: "
111:                                        + result.getOriginalWord());
112:                    }
113:
114:                    _changeAllMap.put(result.getOriginalWord(),
115:                            validationDialog.getSelectedWord());
116:                    replacementWord = validationDialog.getSelectedWord();
117:                } else if (userAction == ValidationDialog.CHANGE) {
118:                    replacementWord = validationDialog.getSelectedWord();
119:                } else if (userAction == ValidationDialog.IGNORE_ALL) {
120:                    if (_ignoreAllSet.contains(result.getOriginalWord())) {
121:                        System.err
122:                                .println("Validator error: Ignore all twice same word: "
123:                                        + result.getOriginalWord());
124:                    }
125:
126:                    _ignoreAllSet.add(result.getOriginalWord());
127:                    replacementWord = result.getOriginalWord();
128:                } else if (userAction == ValidationDialog.IGNORE) {
129:                    replacementWord = result.getOriginalWord();
130:                }
131:
132:                return replacementWord;
133:            }
134:
135:            /**
136:             * Helper method to replace the original word with the correction in the line
137:             */
138:            protected String replaceWord(String originalLine,
139:                    String originalWord, int originalIndex,
140:                    String replacementWord) {
141:                String leftText = originalLine.substring(0, originalIndex - 1);
142:                String rightText = originalLine
143:                        .substring((originalIndex + originalWord.length()) - 1);
144:
145:                StringBuffer buf = new StringBuffer();
146:                buf.append(leftText);
147:                buf.append(replacementWord);
148:                buf.append(rightText);
149:
150:                return buf.toString();
151:            }
152:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.