com.wallstreetwise.app.jspell.domain.net
Class JSpellDictionaryServlet

java.lang.Object
  extended by com.wallstreetwise.app.jspell.domain.JSpellDictionary
      extended by com.wallstreetwise.app.jspell.domain.net.JSpellDictionaryServlet
All Implemented Interfaces:
JSpellDictionaryAccessor

public class JSpellDictionaryServlet
extends JSpellDictionary

JSpellDictionary subclass which is designed to communicate with a JSpellServlet being hosted on a web server. See JSpellServlet documentation for help in configuring a JSpellServlet to run on your web server.


Field Summary
 
Fields inherited from class com.wallstreetwise.app.jspell.domain.JSpellDictionary
batchCount, batchSize, currentError, dictionaryReady, errorCache, errors, forceUpperCase, ignoreDoubleWords, ignoreFirstCaps, ignoreIrregularCaps, ignoreUpper, ignoreWords, ignoreWordsWithNumbers, learnWords, maxSuggestions, nextWord, suggestions, validWords
 
Constructor Summary
JSpellDictionaryServlet()
          Construct a JSpellDictionaryServlet.
 
Method Summary
protected  void checkResponse(java.lang.StringBuffer sb)
          Performs the actual connection to the JSpell Servlet.
 boolean checkWord(JSpellWordBundle word)
          Places a word in a batch to be checked by the JSpell Servlet.
 void close()
          Closes the network connection to the dictionary server.
 java.lang.String getLanguage()
          Get the language of the JSpell Servlet.
 java.util.Vector getLanguages()
          Connects to the JSpell Servlet and retrieves the languages available in the JSpell Servlet.
 JSpellErrorInfo getNextError()
          First check if there are words to be validated against the server that didn't make it in the last batch.
protected  void getResults()
          Get results from the server.
 java.lang.String getURL()
          Get the URL of the JSpell Servlet.
protected  void learnResponse(java.lang.StringBuffer sb)
          Make a connection to the JSpell Servlet and persist the word contained in the StringBuffer.
 void learnWord(java.lang.String word)
          Add a word to the internal valid words collection and call learnResponse to update the word in the JSpell Servlet.
 void open()
          Opens access to a dictionary.
protected  void sendBatch()
          Sends words to the server.
 void setBatchSize(int batchSize)
          Set the number of words to validate in one call to the JSpell Servlet.
 void setFollowRedirects(boolean useRedirect)
          Sets whether HTTP redirects (requests with response code 3xx) of the internal HttpURLConnection should be automatically followed by this class.
 void setLanguage(java.lang.String language)
          Set the language of the JSpell Servlet.
 void setURL(java.lang.String urlName)
          Sets the URL of the JSpell Servlet.
 
Methods inherited from class com.wallstreetwise.app.jspell.domain.JSpellDictionary
addFrequentWords, adjustErrorPositions, checkCaps, checkCaps, getBatchSize, getCurrentError, getDictionaryReady, getForceUpperCase, getIgnoreDoubleWords, getIgnoreFirstCaps, getIgnoreIrregularCaps, getIgnoreUpper, getIgnoreWordsWithNumbers, getLearnWords, ignoreWord, init, learnWordManual, resetAll, resetErrors, setDictionaryReady, setForceUpperCase, setIgnoreDoubleWords, setIgnoreFirstCaps, setIgnoreIrregularCaps, setIgnoreUpper, setIgnoreWordsWithNumbers, setLearnWords, setMaxSuggestions
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JSpellDictionaryServlet

public JSpellDictionaryServlet()
Construct a JSpellDictionaryServlet. Batch size is automatically set to 100 which is usually optimal for many network configurations. The open method must still be called on this object before spell checking can occur.

Method Detail

open

public final void open()
Description copied from interface: JSpellDictionaryAccessor
Opens access to a dictionary.


setFollowRedirects

public final void setFollowRedirects(boolean useRedirect)
Sets whether HTTP redirects (requests with response code 3xx) of the internal HttpURLConnection should be automatically followed by this class. True by default. Applets cannot change this variable. If there is a security manager, this method first calls the security manager's checkSetFactory method to ensure the operation is allowed. This could result in a SecurityException.

Parameters:
useRedirect - true or false

setURL

public final void setURL(java.lang.String urlName)
Sets the URL of the JSpell Servlet. If running this code within an applet then the hostname and port of this URL must match the codebase of the applet.

Parameters:
urlName - a String.

getURL

public final java.lang.String getURL()
Get the URL of the JSpell Servlet.

Returns:
a String.

setLanguage

public final void setLanguage(java.lang.String language)
Set the language of the JSpell Servlet.

Parameters:
language - a String.

getLanguage

public final java.lang.String getLanguage()
Get the language of the JSpell Servlet.

Returns:
a String.

setBatchSize

public final void setBatchSize(int batchSize)
Set the number of words to validate in one call to the JSpell Servlet.

Specified by:
setBatchSize in interface JSpellDictionaryAccessor
Overrides:
setBatchSize in class JSpellDictionary
Parameters:
batchSize - an int.

close

public final void close()
Closes the network connection to the dictionary server. Should not be necessary for a Java Servlet, however, there is an implementation bug with the JSDK servletrunner which may cause a "java.net.SocketException: Connection reset by peer" error message if this call is not made on the JSpellDictionaryServlet instance after spell checking is complete.


checkWord

public final boolean checkWord(JSpellWordBundle word)
                        throws java.lang.Exception
Places a word in a batch to be checked by the JSpell Servlet. When the batchSize is reached the words are sent and errors are retrieved from the servlet.

Specified by:
checkWord in interface JSpellDictionaryAccessor
Overrides:
checkWord in class JSpellDictionary
Parameters:
word - a String.
Returns:
true or false.
Throws:
java.lang.Exception - an Exception object.

getNextError

public final JSpellErrorInfo getNextError()
                                   throws java.lang.Exception
First check if there are words to be validated against the server that didn't make it in the last batch. Then return any errors by calling the super classes getNextError method.

Specified by:
getNextError in interface JSpellDictionaryAccessor
Overrides:
getNextError in class JSpellDictionary
Returns:
true or false.
Throws:
java.lang.Exception - an Exception object.

sendBatch

protected final void sendBatch()
                        throws java.io.IOException
Sends words to the server. Usually called when the number of words to validate reaches batchSize, however, it may also be called when performing getNextError if there are words left over from processing.

Throws:
java.io.IOException - an Exception object.

getResults

protected final void getResults()
                         throws java.io.IOException
Get results from the server. Results are read up until the server indicates that there are no remaining errors. Errors are placed in errors Vector to be returned by getNextError().

Throws:
java.io.IOException - an Exception object.

checkResponse

protected final void checkResponse(java.lang.StringBuffer sb)
                            throws java.io.IOException
Performs the actual connection to the JSpell Servlet.

Parameters:
sb - a StringBuffer.
Throws:
java.io.IOException - an Exception object.

getLanguages

public final java.util.Vector getLanguages()
                                    throws java.io.IOException
Connects to the JSpell Servlet and retrieves the languages available in the JSpell Servlet. The languages are returned in a descriptive format such as "English (US)" and/or "French (FR)".

Returns:
a Vector.
Throws:
java.io.IOException - an Exception object.

learnResponse

protected final void learnResponse(java.lang.StringBuffer sb)
                            throws java.io.IOException
Make a connection to the JSpell Servlet and persist the word contained in the StringBuffer.

Parameters:
sb - a StringBuffer.
Throws:
java.io.IOException - an Exception object.

learnWord

public final void learnWord(java.lang.String word)
Add a word to the internal valid words collection and call learnResponse to update the word in the JSpell Servlet.

Specified by:
learnWord in interface JSpellDictionaryAccessor
Overrides:
learnWord in class JSpellDictionary
Parameters:
word - a String.


JSpell SDK 2004 Spell Checker for the Java (tm) Platform
Copyright © 1996-2005 The Solution Cafe Inc, All Rights Reserved - http://www.thesolutioncafe.com