Jive Forums API (5.5.20.2-oracle) Developer Javadocs

com.jivesoftware.util
Class SpellSession

java.lang.Object
  extended by com.jivesoftware.util.SpellSession
All Implemented Interfaces:
java.io.Serializable

public final class SpellSession
extends java.lang.Object
implements java.io.Serializable

A spelling session is used to iteratively fix all spelling mistakes. The next() method performs an iteration, and then the other methods of the class can be called to correct any errors that are found. Iterations should be performed until the OK result is returned.

New SpellSession objects should be created with the SpellChecker.createSession(String) method. This class is Serializable so that it can be put into an HTTPSession. Note that some app-servers require you to re-add the value to the session every time changes to the object are made.

See Also:
SpellChecker, Serialized Form

Field Summary
static int DOUBLED_WORD
          The current word was repeated (doubled).
static int MISSPELLED_WORD
          The current word appears to be misspelled.
static int OK
          There were no errors; ie spell checking is done.
 
Constructor Summary
protected SpellSession(com.wintertree.ssce.SpellingSession session, com.wintertree.ssce.WordParser wordParser, MemLexicon memLexicon, java.lang.String language)
           
 
Method Summary
 void delete()
          Deletes the word returned by getWord().
 java.lang.String getHighlightedText()
          Returns the text being spell checked in its current state, but with all remaining spelling errors highlighted.
 java.lang.String[] getSuggestions()
          Returns an array of alternate spelling suggestions for the misspelled word at the current cursor.
 java.lang.String[] getSuggestions(java.lang.String word)
          Returns an array of alternate spelling suggestions for the provided word word or null if the word is not misspelt.
 java.lang.String getText()
          Returns the text being spell checked in its current state.
 java.lang.String getWord()
          Returns the word at the current cursor.
 void ignore()
          Ignores the spelling mistake found for the word at the current cursor.
 void ignoreAll()
          Ignores the spelling mistake found for the word at the current cursor and all future occurrences of the mistake.
protected  void ignoreAll(java.util.List ignoreWords)
          Ignores the spelling mistake found for the given word and all future occurrences of the mistake.
 int next()
          Runs the next iteration of spell checking and returns the result.
 void replace(java.lang.String newWord)
          Replaces the word returned by getWord() with a new word.
 void replaceAll(java.lang.String newWord)
          Replaces all occurences of the word returned by getWord() in the text with a new word.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DOUBLED_WORD

public static final int DOUBLED_WORD
The current word was repeated (doubled).

See Also:
Constant Field Values

MISSPELLED_WORD

public static final int MISSPELLED_WORD
The current word appears to be misspelled.

See Also:
Constant Field Values

OK

public static final int OK
There were no errors; ie spell checking is done.

See Also:
Constant Field Values
Constructor Detail

SpellSession

protected SpellSession(com.wintertree.ssce.SpellingSession session,
                       com.wintertree.ssce.WordParser wordParser,
                       MemLexicon memLexicon,
                       java.lang.String language)
Method Detail

getText

public java.lang.String getText()
Returns the text being spell checked in its current state.

Returns:
the text being spell checked.

getHighlightedText

public java.lang.String getHighlightedText()
Returns the text being spell checked in its current state, but with all remaining spelling errors highlighted. The first error is enclosed with the tag <spellfirst> </spellfirst>, and all other errors have the tag <spell> </spell>.

Returns:
the text being spell checked with errors highlighted.

next

public int next()
Runs the next iteration of spell checking and returns the result. Each iteration checks words until an error is encountered. If no errors are encountered, SpellSession.OK is returned. Otherwise, each error should be handled by calling the various methods of this class such as replace(), ignore(), etc. After the error is handles, the next iteration can be performed. A code snippet demonstrating the logic flow is as follows:
 int result;
 while ((result = session.next()) != SpellSession.OK) {
     // Decide on action to take. For example, we might want to
     // delete a doubled word or ignore all further occurences of a
     // misspelled word.
 }
 
Of course, if using the SpellSession in a server-side Java application, a while loop won't be applicable.

Returns:
the result of running the next spell checking iteration.

getWord

public java.lang.String getWord()
Returns the word at the current cursor. The cursor is set by the next() method, which advances the cursor until the next error is found. For example, for the text "This is a teste of spell checking." -- after calling the next() method once, we'd advance to the word "teste" before returning the result code SpellSession.MISSPELLED_WORD. Calling this method would then return "teste".

Warning: after the next() method return a result code of SpellSession.OK, the cursor will be at the end of the text so calling this method will result in an error.

Returns:
the word at the current cursor.

replace

public void replace(java.lang.String newWord)
Replaces the word returned by getWord() with a new word.

Parameters:
newWord - a new word to replace the word at the current cursor.

replaceAll

public void replaceAll(java.lang.String newWord)
Replaces all occurences of the word returned by getWord() in the text with a new word.

Parameters:
newWord - a new word to replace all occurences of the word at the current cursor.

ignore

public void ignore()
Ignores the spelling mistake found for the word at the current cursor.


ignoreAll

public void ignoreAll()
Ignores the spelling mistake found for the word at the current cursor and all future occurrences of the mistake.


ignoreAll

protected void ignoreAll(java.util.List ignoreWords)
Ignores the spelling mistake found for the given word and all future occurrences of the mistake. This method does not iterate to the next error, rather it is designed to be used immediately after a spellsession is created


delete

public void delete()
Deletes the word returned by getWord(). This is useful for fixing doubled word errors, such as the second "the" in the sentence: "This is the the best forum software".


getSuggestions

public java.lang.String[] getSuggestions()
Returns an array of alternate spelling suggestions for the misspelled word at the current cursor. No more than five suggestions will be returned.

Returns:
an array of alternate spelling suggestions for the misspelled word at the current cursor.

getSuggestions

public java.lang.String[] getSuggestions(java.lang.String word)
Returns an array of alternate spelling suggestions for the provided word word or null if the word is not misspelt. No more than five suggestions will be returned.


Jive Forums Project Page

Copyright © 1999-2006 Jive Software.