1 | /**
|
---|
2 | * SpellcheckTree.java
|
---|
3 | * Copyright (C) 2010 New Zealand Digital Library, http://expeditee.org
|
---|
4 | *
|
---|
5 | * This program is free software: you can redistribute it and/or modify
|
---|
6 | * it under the terms of the GNU General Public License as published by
|
---|
7 | * the Free Software Foundation, either version 3 of the License, or
|
---|
8 | * (at your option) any later version.
|
---|
9 | *
|
---|
10 | * This program is distributed in the hope that it will be useful,
|
---|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
13 | * GNU General Public License for more details.
|
---|
14 | *
|
---|
15 | * You should have received a copy of the GNU General Public License
|
---|
16 | * along with this program. If not, see <http://www.gnu.org/licenses/>.
|
---|
17 | */
|
---|
18 |
|
---|
19 | package org.expeditee.agents;
|
---|
20 |
|
---|
21 | import java.io.FileNotFoundException;
|
---|
22 | import java.io.IOException;
|
---|
23 |
|
---|
24 | import org.expeditee.agents.wordprocessing.JSpellChecker;
|
---|
25 |
|
---|
26 | public class SpellcheckTree extends SearchTree {
|
---|
27 |
|
---|
28 | private JSpellChecker _spellChecker = null;
|
---|
29 |
|
---|
30 | public SpellcheckTree() {
|
---|
31 | super(null);
|
---|
32 |
|
---|
33 | try {
|
---|
34 | _spellChecker = JSpellChecker.getInstance();
|
---|
35 | } catch (FileNotFoundException e) {
|
---|
36 | e.printStackTrace();
|
---|
37 | } catch (IOException e) {
|
---|
38 | e.printStackTrace();
|
---|
39 | }
|
---|
40 | // TODO better handle errors
|
---|
41 | }
|
---|
42 |
|
---|
43 | @Override
|
---|
44 | protected String getResultSurrogate(String toSearch) {
|
---|
45 | if (_spellChecker == null)
|
---|
46 | return null;
|
---|
47 | _spellChecker.setText(toSearch);
|
---|
48 | _spellChecker.check();
|
---|
49 |
|
---|
50 | String badSpelling = _spellChecker.getMisspelledWord();
|
---|
51 | String result = badSpelling;
|
---|
52 | // while (badSpelling != null) {
|
---|
53 | // _spellChecker.ignoreWord(true);
|
---|
54 | // _spellChecker.check();
|
---|
55 | // badSpelling = _spellChecker.getMisspelledWord();
|
---|
56 | // if (badSpelling != null)
|
---|
57 | // result += "," + badSpelling;
|
---|
58 | // }
|
---|
59 |
|
---|
60 | if (badSpelling == null || badSpelling.length() <= 1)
|
---|
61 | return null;
|
---|
62 |
|
---|
63 | return "[" + result + "] " + toSearch;
|
---|
64 | }
|
---|
65 |
|
---|
66 | @Override
|
---|
67 | protected String getResultsTitleSuffix() {
|
---|
68 | return "";
|
---|
69 | }
|
---|
70 | }
|
---|