PATH  Documentation > Mac OS X > Application Kit Reference: Java

Table of Contents

NSSpellServer


Inherits from:
NSObject
Package:
com.apple.yellow.application


Class Description


The NSSpellServer class gives you a way to make your particular spelling checker a service that's available to any application. A service is an application that declares its availability in a standard way, so that any other applications that wish to use it can do so. If you build a spelling checker that makes use of the NSSpellServer class and list it as an available service, then users of any application that makes use of NSSpellChecker or includes a Services menu will see your spelling checker as one of the available dictionaries.

To make use of NSSpellServer, you write a small program that creates an NSSpellServer instance and a delegate that responds to messages asking it to find a misspelled word and to suggest guesses for a misspelled word. Send the NSSpellServer registerLanguage messages to tell it the languages your delegate can handle.

The program that runs your spelling checker should not be built as an Application Kit application, but as a simple program.

Your delegate is an instance of a custom subclass. (It's simplest to make it a subclass of NSObject, but that's not a requirement.) Given a String, your delegate must be able to find a misspelled word by implementing the method spellServer:findMisspelledWordInString:language:wordCount:countOnly:. Usually, this method also reports the number of words it has scanned, but that isn't mandatory.

Optionally, the delegate may also suggest corrections for misspelled words. It does so by implementing the method spellServerSuggestGuessesForWord.


Service Availability Notice


When there's more than one spelling checker available, the user selects the one desired. The application that requests a spelling check uses an NSSpellChecker object, and it provides a Spelling panel; in the panel there's a pop-up list of available spelling checkers. Your spelling checker appears in that list if it has a service descriptor.

A service descriptor is an entry in a text file called services. Usually it's located within the bundle that also contains your spelling checker's executable file. The bundle (or directory) that contains the services file must have a name ending in ".service" or ".app". The system looks for service bundles in a standard set of directories.

A spell checker service availability notice has a standard format, illustrated in the following example for the Acme spelling checker:

Spell Checker: Acme
Language: French
Language: English
Executable: franglais.daemon

The first line identifies the type of service; for a spelling checker, it must say "Spell Checker:" followed by your vendor name. The next line contains the English name of a language your spelling checker is prepared to check. (The language must be one your system recognizes.) If your program can check more than one language, use an additional line for each additional language. The last line of a descriptor gives the name of the service's executable file. (It requires a complete path if it's in a different directory.)

If there's a service descriptor for your Acme spelling checker and also a service descriptor for the English checker provided by a vendor named Consolidated, a user looking at the Spelling panel's pop-up list would see:

English (Acme)
English (Consolidated)
French (Acme)


Illustrative Sequence of Messages to an NSSpellServer


The act of checking spelling usually involves the interplay of objects in two classes: the user application's NSSpellChecker (which responds to interactions with the user) and your spelling checker's NSSpellServer (which provides the application interface for your spelling checker). You can see the interaction between the two in the following list of steps involved in finding a misspelled word.




Method Types


Constructors
NSSpellServer
Registering your service
registerLanguage
Assigning a delegate
setDelegate
delegate
Running the service
run
Checking user dictionaries
isWordInUserDictionaries


Constructors



NSSpellServer

public NSSpellServer()

Description forthcoming.


Instance Methods



delegate

public Object delegate()

Returns the NSSpellServer's delegate.

See Also: setDelegate



isWordInUserDictionaries

public boolean isWordInUserDictionaries( String word, boolean flag)

Indicates whether word is in the user's list of learned words or the document's list of words to ignore. If true, the word is acceptable to the user. flag indicates whether the comparison is to be case-sensitive.

registerLanguage

public boolean registerLanguage( String language, String vendor)

Notifies the NSSpellServer of a language your spelling checker can check. language is the English name of a language on Apple's list of languages. vendor identifies the vendor (to distinguish your spelling checker from those that others may offer for the same language). If your spelling checker supports more than one language, it should invoke this method once for each language. Registering a language/vendor combination causes it to appear in the Spelling Panel's pop-up list of spelling checkers.

Returns true if the language is registered, false if for some reason it can't be registered.



run

public void run()

Causes the NSSpellServer to start listening for spell-checking requests. This method starts a loop that never returns; you need to set the NSSpellServer's delegate before sending this message.

See Also: setDelegate



setDelegate

public void setDelegate(Object anObject)

Assigns a delegate to the NSSpellServer. Because the delegate is where the real work is done, this is an essential step before telling the NSSpellServer to run.

See Also: delegate, run




Methods Implemented By the Delegate


spellServerDidForgetWord

public abstract void spellServerDidForgetWord( NSSpellServer sender, String word, String language)

Notifies the delegate that word has been removed from the user's list of acceptable words. If your delegate maintains a similar auxiliary word list, you may wish to edit the list accordingly.

spellServerDidLearnWord

public abstract void spellServerDidLearnWord( NSSpellServer sender, String word, String language)

Notifies the delegate that word has been added to the user's list of acceptable words. If your delegate maintains a similar auxiliary word list, you may wish to edit the list accordingly.

spellServerSuggestGuessesForWord

public abstract NSArray spellServerSuggestGuessesForWord( NSSpellServer sender, String word, String language)

Gives the delegate the opportunity to suggest guesses for the correct spelling of the misspelled word. Return the guesses as an array of Strings.


Table of Contents