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

Last change on this file since 1443 was 1244, checked in by davidb, 5 years ago

After change to have resources-public and resources-private, some changes needed to support running Expeditee for a single user; other main change is to allow FrameDirs to specify relative directory paths, to help with when Expeditee is run on the cloud -- similar work still needs to occurr for ImageDir and AudioDir; some other minor changes also made.

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.getAbsoluteDirs()) {
49 fullPath = FrameIO.getFrameFullPathName(possiblePath, frameName);
50 if (fullPath != null)
51 break;
52 }
53 } else {
54 fullPath = FrameIO.getFrameFullPathName(path, frameName);
55 }
56 // If the frame was not located return null
57 if (fullPath == null)
58 return null;
59 Collection<String> results = new LinkedList<String>();
60 // Open the file and search the text items
61 try {
62 BufferedReader reader = new BufferedReader(new FileReader(fullPath));
63 String next;
64 while (reader.ready() && ((next = reader.readLine()) != null)) {
65 if (next.startsWith("T")) {
66 String toSearch = next.substring(2);
67 spellChecker.setText(toSearch);
68 String misspelled = spellChecker.getMisspelledWord();
69 if (misspelled != null && misspelled.length() > 0) {
70 results.add(toSearch);
71 }
72 }
73 }
74 } catch (FileNotFoundException e) {
75 e.printStackTrace();
76 return null;
77 } catch (IOException e) {
78 e.printStackTrace();
79 }
80 return results;
81 }
82
83 public static String checkSpelling(String word) {
84 try {
85 return JSpellChecker.getInstance().getSuggestions(word);
86 } catch (FileNotFoundException e) {
87 MessageBay.errorMessage("Could not find dictionary: "
88 + e.getMessage());
89 } catch (IOException e) {
90 e.printStackTrace();
91 }
92 return null;
93 }
94
95 public static String spellCheck(String word) {
96 return checkSpelling(word);
97 }
98}
Note: See TracBrowser for help on using the repository browser.