fe555f33a079ac3a9fd4da088d22cef722be61b6
[phpeclipse.git] /
1 /*******************************************************************************
2  * Copyright (c) 2000, 2003 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11
12 package net.sourceforge.phpdt.internal.ui.text.spelling.engine;
13
14 import java.io.FileWriter;
15 import java.io.IOException;
16 import java.net.URL;
17
18 /**
19  * Persistent modifiable word-list based dictionary.
20  * 
21  * @since 3.0
22  */
23 public class PersistentSpellDictionary extends AbstractSpellDictionary {
24
25         /** The word list location */
26         private final URL fLocation;
27
28         /**
29          * Creates a new persistent spell dictionary.
30          * 
31          * @param url
32          *                   The URL of the word list for this dictionary
33          */
34         public PersistentSpellDictionary(final URL url) {
35                 fLocation= url;
36         }
37         
38         /*
39          * @see org.eclipse.jdt.ui.text.spelling.engine.AbstractSpellDictionary#acceptsWords()
40          */
41         public boolean acceptsWords() {
42                 return true;
43         }
44
45         /*
46          * @see org.eclipse.jdt.internal.ui.text.spelling.engine.ISpellDictionary#addWord(java.lang.String)
47          */
48         public void addWord(final String word) {
49
50                 if (!isCorrect(word)) {
51
52                         hashWord(word);
53                         try {
54
55                                 final FileWriter writer= new FileWriter(fLocation.getPath(), true);
56                                 writer.write(word);
57                                 writer.write("\n"); //$NON-NLS-1$
58                                 writer.close();
59
60                         } catch (IOException exception) {
61                                 // Do nothing
62                         }
63                 }
64         }
65
66         /*
67          * @see org.eclipse.jdt.internal.ui.text.spelling.engine.AbstractSpellDictionary#getURL()
68          */
69         protected final URL getURL() {
70                 return fLocation;
71         }
72 }