source: trunk/src/org/expeditee/actions/Spelling.java@ 919

Last change on this file since 919 was 919, checked in by jts21, 10 years ago

Added license headers to all files, added full GPL3 license file, moved license header generator script to dev/bin/scripts

File size: 3.0 KB
Line 
1/**
2 * Spelling.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
19package org.expeditee.actions;
20
21import java.io.BufferedReader;
22import java.io.FileNotFoundException;
23import java.io.FileReader;
24import java.io.IOException;
25import java.util.Collection;
26import java.util.LinkedList;
27
28import org.expeditee.agents.wordprocessing.JSpellChecker;
29import org.expeditee.gui.FrameIO;
30import org.expeditee.gui.MessageBay;
31import org.expeditee.settings.folders.FolderSettings;
32
33public class Spelling {
34 public static Collection<String> spellCheckFrame(String frameName,
35 String path) {
36 String fullPath = null;
37 JSpellChecker spellChecker = null;
38 try {
39 spellChecker = JSpellChecker.getInstance();
40 } catch (FileNotFoundException e1) {
41 e1.printStackTrace();
42 return null;
43 } catch (IOException e1) {
44 e1.printStackTrace();
45 return null;
46 }
47 if (path == null) {
48 for (String possiblePath : FolderSettings.FrameDirs.get()) {
49 fullPath = FrameIO
50 .getFrameFullPathName(possiblePath, frameName);
51 if (fullPath != null)
52 break;
53 }
54 } else {
55 fullPath = FrameIO.getFrameFullPathName(path, frameName);
56 }
57 // If the frame was not located return null
58 if (fullPath == null)
59 return null;
60 Collection<String> results = new LinkedList<String>();
61 // Open the file and search the text items
62 try {
63 BufferedReader reader = new BufferedReader(new FileReader(fullPath));
64 String next;
65 while (reader.ready() && ((next = reader.readLine()) != null)) {
66 if (next.startsWith("T")) {
67 String toSearch = next.substring(2);
68 spellChecker.setText(toSearch);
69 String misspelled = spellChecker.getMisspelledWord();
70 if (misspelled != null && misspelled.length() > 0) {
71 results.add(toSearch);
72 }
73 }
74 }
75 } catch (FileNotFoundException e) {
76 e.printStackTrace();
77 return null;
78 } catch (IOException e) {
79 e.printStackTrace();
80 }
81 return results;
82 }
83
84 public static String checkSpelling(String word) {
85 try {
86 return JSpellChecker.getInstance().getSuggestions(word);
87 } catch (FileNotFoundException e) {
88 MessageBay.errorMessage("Could not find dictionary: "
89 + e.getMessage());
90 } catch (IOException e) {
91 e.printStackTrace();
92 }
93 return null;
94 }
95
96 public static String spellCheck(String word) {
97 return checkSpelling(word);
98 }
99}
Note: See TracBrowser for help on using the repository browser.