1) Reintroduced PHPPerspectiveFactory (was lost with refactoring).
[phpeclipse.git] / net.sourceforge.phpeclipse.ui / src / net / sourceforge / phpdt / internal / ui / text / spelling / engine / PersistentSpellDictionary.java
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 net.sourceforge.phpdt.ui.text.spelling.engine.AbstractSpellDictionary#acceptsWords()
40          */
41         public boolean acceptsWords() {
42                 return true;
43         }
44
45         /*
46          * @see net.sourceforge.phpdt.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(),
56                                                 true);
57                                 writer.write(word);
58                                 writer.write("\n"); //$NON-NLS-1$
59                                 writer.close();
60
61                         } catch (IOException exception) {
62                                 // Do nothing
63                         }
64                 }
65         }
66
67         /*
68          * @see net.sourceforge.phpdt.internal.ui.text.spelling.engine.AbstractSpellDictionary#getURL()
69          */
70         protected final URL getURL() {
71                 return fLocation;
72         }
73 }