com.dotmarketing.util
Class DotSpellChecker

java.lang.Object
  extended by com.dotmarketing.util.DotSpellChecker

public class DotSpellChecker
extends java.lang.Object

Class used via AJAX to spell checks fields in the dotCMS This class internally uses the Jazzy library and method to perform the spellchecking

Author:
David

Nested Class Summary
 class DotSpellChecker.DotWordFinder
          Class internally used to match the words to spell check
 class DotSpellChecker.MisspelledWord
          This class represent a misspelled word in the process of spelling check.
 
Constructor Summary
DotSpellChecker()
          DotSpellCheck constructor This method will try to initialize the dictionaries if they weren't initilized before.
 
Method Summary
 void addToDictionary(java.lang.String newWord)
          Adds a word to the current dictionary.
 boolean changeDictionary(java.lang.String newDict)
          This method changes the current dictionrary used to do the spell checking
 java.lang.String getCurrentDictionary()
          Returns the current dictionary used by the class
 java.lang.String[] getDictionaries()
          Returns the list of possible dictionaries found in the system
 DotSpellChecker.MisspelledWord getNextMisspelledWord()
          Returns the next misspelled word found and the posible corrections.
 DotSpellChecker.MisspelledWord getSuggestions(java.lang.String nextWord)
          This method allows you to find suggestions for a single word without starting the whole spelling process over a text.
static void initializeDicts(boolean force, boolean sync)
          This method is used at the server startup to initialize the dictionaries, the dictionaries initilization process is a very time consuming task, that's why this process uses a separate thread to initialize the dictionaries on background.
 java.lang.String replaceWord(java.lang.String newWord)
          Replace the current mispelled word by the given word.
 void startSpellChecking(java.lang.String text)
          Triggers the spelling check of the given text
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DotSpellChecker

public DotSpellChecker()
                throws java.io.FileNotFoundException,
                       java.io.IOException
DotSpellCheck constructor This method will try to initialize the dictionaries if they weren't initilized before.

Throws:
java.io.IOException - If the process found an error reading the dictionaries
java.io.FileNotFoundException - If the dictionaries are not found
Method Detail

initializeDicts

public static void initializeDicts(boolean force,
                                   boolean sync)
This method is used at the server startup to initialize the dictionaries, the dictionaries initilization process is a very time consuming task, that's why this process uses a separate thread to initialize the dictionaries on background. This process tries to read Config.getStringProperty("MASTER_DICTS_DIR") to find the base dictionaries directory inside the WEB-INF folder of the web application.

Parameters:
force - true If you want to force a reinitialization even if the dictionaries were already loaded before.
sync - true If you want to wait until the initialization finishes

getCurrentDictionary

public java.lang.String getCurrentDictionary()
Returns the current dictionary used by the class

Returns:
The current dictionary

changeDictionary

public boolean changeDictionary(java.lang.String newDict)
                         throws java.io.FileNotFoundException,
                                java.io.IOException
This method changes the current dictionrary used to do the spell checking

Parameters:
newDict - The new dictionary to set
Returns:
true If the new dictionary exists and was set correctly.
Throws:
java.io.FileNotFoundException - If the dictionary file wasn't found
java.io.IOException - If the process wasn't able to read the new dictionary.

startSpellChecking

public void startSpellChecking(java.lang.String text)
Triggers the spelling check of the given text

Parameters:
text - The text to check.

getNextMisspelledWord

public DotSpellChecker.MisspelledWord getNextMisspelledWord()
Returns the next misspelled word found and the posible corrections.

Returns:
The next misspelled word class (which includes the corrections) or null if no more errors were found.

replaceWord

public java.lang.String replaceWord(java.lang.String newWord)
Replace the current mispelled word by the given word.

Parameters:
newWord - The correction to set.
Returns:

addToDictionary

public void addToDictionary(java.lang.String newWord)
Adds a word to the current dictionary.

Parameters:
newWord - The new word to be added to the dictionary.

getSuggestions

public DotSpellChecker.MisspelledWord getSuggestions(java.lang.String nextWord)
This method allows you to find suggestions for a single word without starting the whole spelling process over a text.

Parameters:
nextWord - Word to find spelling suggestions
Returns:
A misspelledWord class containing the suggestions or null if no suggestions were found.

getDictionaries

public java.lang.String[] getDictionaries()
Returns the list of possible dictionaries found in the system

Returns:
The list of loaded dictionaries.


Copyright © 2006 Dotmarketing, Inc. All Rights Reserved.