com.jspell.domain.net
Class JSpellDictionaryServlet

java.lang.Object
  extended by com.jspell.domain.JSpellDictionary
      extended by com.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.jspell.domain.JSpellDictionary
batchCount, batchSize, defaultCountry, defaultLanguage, defaultVersion, errors, language, learnWords, maxSuggestions, suggestions
 
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.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 postResponse(java.lang.StringBuffer data)
           
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 setURL(java.lang.String urlName)
          Sets the URL of the JSpell Servlet.
 
Methods inherited from class com.jspell.domain.JSpellDictionary
adjustErrorPositions, checkCaps, checkCaps, getBatchSize, getCurrentError, getDictionaryCountry, getDictionaryLanguage, getDictionaryReady, getDictionaryVersion, getForceUpperCase, getIgnoreDoubleWords, getIgnoreFirstCaps, getIgnoreIrregularCaps, getIgnoreUpper, getIgnoreWordsWithNumbers, getLanguage, getLearnWords, ignoreWord, init, isValidWord, learnWordManual, resetAll, resetErrors, setDictionaryReady, setForceUpperCase, setIgnoreDoubleWords, setIgnoreFirstCaps, setIgnoreIrregularCaps, setIgnoreUpper, setIgnoreWordsWithNumbers, setLanguage, setLearnWords, setMaxSuggestions, validWordsPut
 
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.


setURL

public 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 java.lang.String getURL()
Get the URL of the JSpell Servlet.

Returns:
a String.

setBatchSize

public 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 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 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 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 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 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.

postResponse

protected final void postResponse(java.lang.StringBuffer data)
                           throws java.io.IOException
Throws:
java.io.IOException

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.

learnResponse

protected 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.

getLanguages

public 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.

learnWord

public 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 - Spell Checker for the Java ™ Platform
Copyright © 2009 Page Scholar Inc, All Rights Reserved - http://www.jspell.com