xref: /trunk/main/lingucomponent/source/spellcheck/spell/sspellimp.cxx (revision 30acf5e801d38c3701bf451b42e514ce81855b4c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_lingucomponent.hxx"
26 
27 #include <com/sun/star/uno/Reference.h>
28 #include <com/sun/star/linguistic2/XSearchableDictionaryList.hpp>
29 
30 #include <com/sun/star/linguistic2/SpellFailure.hpp>
31 #include <cppuhelper/factory.hxx>   // helper for factories
32 #include <com/sun/star/registry/XRegistryKey.hpp>
33 #include <tools/debug.hxx>
34 #include <unotools/processfactory.hxx>
35 #include <osl/mutex.hxx>
36 #include <com/sun/star/ucb/XSimpleFileAccess.hpp>
37 
38 #include <lingutil.hxx>
39 #include <hunspell.hxx>
40 #include <dictmgr.hxx>
41 #include <sspellimp.hxx>
42 
43 #include <linguistic/lngprops.hxx>
44 #include <linguistic/spelldta.hxx>
45 #include <i18npool/mslangid.hxx>
46 #include <unotools/pathoptions.hxx>
47 #include <unotools/lingucfg.hxx>
48 #include <unotools/useroptions.hxx>
49 #include <osl/file.hxx>
50 #include <rtl/ustrbuf.hxx>
51 #include <rtl/textenc.h>
52 
53 #include <list>
54 #include <set>
55 #include <string.h>
56 
57 using namespace utl;
58 using namespace osl;
59 using namespace rtl;
60 using namespace com::sun::star;
61 using namespace com::sun::star::beans;
62 using namespace com::sun::star::lang;
63 using namespace com::sun::star::uno;
64 using namespace com::sun::star::linguistic2;
65 using namespace linguistic;
66 
67 // XML-header of SPELLML queries
68 #define SPELLML_HEADER "<?xml?>"
69 
70 ///////////////////////////////////////////////////////////////////////////
71 
72 SpellChecker::SpellChecker() :
73     aEvtListeners   ( GetLinguMutex() )
74 {
75     aDicts = NULL;
76     aDEncs = NULL;
77     aDLocs = NULL;
78     aDNames = NULL;
79     bDisposing = sal_False;
80     pPropHelper = NULL;
81     numdict = 0;
82 }
83 
84 
85 SpellChecker::~SpellChecker()
86 {
87     if (aDicts)
88     {
89        for (int i = 0; i < numdict; i++)
90        {
91             if (aDicts[i]) delete aDicts[i];
92             aDicts[i] = NULL;
93        }
94        delete[] aDicts;
95     }
96     aDicts = NULL;
97     numdict = 0;
98     if (aDEncs) delete[] aDEncs;
99     aDEncs = NULL;
100     if (aDLocs) delete[] aDLocs;
101     aDLocs = NULL;
102     if (aDNames) delete[] aDNames;
103     aDNames = NULL;
104     if (pPropHelper)
105         pPropHelper->RemoveAsPropListener();
106 }
107 
108 
109 PropertyHelper_Spell & SpellChecker::GetPropHelper_Impl()
110 {
111     if (!pPropHelper)
112     {
113         Reference< XPropertySet >   xPropSet( GetLinguProperties(), UNO_QUERY );
114 
115         pPropHelper = new PropertyHelper_Spell( (XSpellChecker *) this, xPropSet );
116         xPropHelper = pPropHelper;
117         pPropHelper->AddAsPropListener();   //! after a reference is established
118     }
119     return *pPropHelper;
120 }
121 
122 
123 Sequence< Locale > SAL_CALL SpellChecker::getLocales()
124         throw(RuntimeException)
125 {
126     MutexGuard  aGuard( GetLinguMutex() );
127 
128     // this routine should return the locales supported by the installed
129     // dictionaries.
130 
131     if (!numdict)
132     {
133         SvtLinguConfig aLinguCfg;
134 
135         // get list of extension dictionaries-to-use
136         // (or better speaking: the list of dictionaries using the
137         // new configuration entries).
138         std::list< SvtLinguConfigDictionaryEntry > aDics;
139         uno::Sequence< rtl::OUString > aFormatList;
140         aLinguCfg.GetSupportedDictionaryFormatsFor( A2OU("SpellCheckers"),
141                 A2OU("org.openoffice.lingu.MySpellSpellChecker"), aFormatList );
142         sal_Int32 nLen = aFormatList.getLength();
143         for (sal_Int32 i = 0;  i < nLen;  ++i)
144         {
145             std::vector< SvtLinguConfigDictionaryEntry > aTmpDic(
146                     aLinguCfg.GetActiveDictionariesByFormat( aFormatList[i] ) );
147             aDics.insert( aDics.end(), aTmpDic.begin(), aTmpDic.end() );
148         }
149 
150         //!! for compatibility with old dictionaries (the ones not using extensions
151         //!! or new configuration entries, but still using the dictionary.lst file)
152         //!! Get the list of old style spell checking dictionaries to use...
153         std::vector< SvtLinguConfigDictionaryEntry > aOldStyleDics(
154                 GetOldStyleDics( "DICT" ) );
155 
156         // to prefer dictionaries with configuration entries we will only
157         // use those old style dictionaries that add a language that
158         // is not yet supported by the list od new style dictionaries
159         MergeNewStyleDicsAndOldStyleDics( aDics, aOldStyleDics );
160 
161         numdict = aDics.size();
162         if (numdict)
163         {
164             uno::Reference< lang::XMultiServiceFactory > xServiceFactory( utl::getProcessServiceFactory() );
165             uno::Reference< ucb::XSimpleFileAccess > xAccess;
166             try
167             {
168                 xAccess.set( xServiceFactory->createInstance(
169                         A2OU( "com.sun.star.ucb.SimpleFileAccess" ) ), uno::UNO_QUERY_THROW );
170             }
171             catch (uno::Exception & e)
172             {
173                 DBG_ASSERT( 0, "failed to get input stream" );
174                 (void) e;
175             }
176             // get supported locales from the dictionaries-to-use...
177             sal_Int32 k = 0;
178             std::set< rtl::OUString, lt_rtl_OUString > aLocaleNamesSet;
179             std::list< SvtLinguConfigDictionaryEntry >::const_iterator aDictIt;
180             for (aDictIt = aDics.begin();  aDictIt != aDics.end();  ++aDictIt)
181             {
182                 uno::Sequence< rtl::OUString > aLocaleNames( aDictIt->aLocaleNames );
183                 uno::Sequence< rtl::OUString > aLocations( aDictIt->aLocations );
184                 sal_Int32 nLen2 = aLocaleNames.getLength();
185                 for (k = 0;  k < nLen2;  ++k)
186                 {
187                     if (xAccess.is() && xAccess->exists(aLocations[k]))
188                     {
189                         aLocaleNamesSet.insert( aLocaleNames[k] );
190                     }
191                 }
192             }
193             // ... and add them to the resulting sequence
194             aSuppLocales.realloc( aLocaleNamesSet.size() );
195             std::set< rtl::OUString, lt_rtl_OUString >::const_iterator aItB;
196             k = 0;
197             for (aItB = aLocaleNamesSet.begin();  aItB != aLocaleNamesSet.end();  ++aItB)
198             {
199                 Locale aTmp( MsLangId::convertLanguageToLocale(
200                         MsLangId::convertIsoStringToLanguage( *aItB )));
201                 aSuppLocales[k++] = aTmp;
202             }
203 
204             //! For each dictionary and each locale we need a separate entry.
205             //! If this results in more than one dictionary per locale than (for now)
206             //! it is undefined which dictionary gets used.
207             //! In the future the implementation should support using several dictionaries
208             //! for one locale.
209             numdict = 0;
210             for (aDictIt = aDics.begin();  aDictIt != aDics.end();  ++aDictIt)
211                 numdict = numdict + aDictIt->aLocaleNames.getLength();
212 
213             // add dictionary information
214             aDicts  = new Hunspell* [numdict];
215             aDEncs  = new rtl_TextEncoding [numdict];
216             aDLocs  = new Locale [numdict];
217             aDNames = new OUString [numdict];
218             k = 0;
219             for (aDictIt = aDics.begin();  aDictIt != aDics.end();  ++aDictIt)
220             {
221                 if (aDictIt->aLocaleNames.getLength() > 0 &&
222                     aDictIt->aLocations.getLength() > 0)
223                 {
224                     uno::Sequence< rtl::OUString > aLocaleNames( aDictIt->aLocaleNames );
225                     sal_Int32 nLocales = aLocaleNames.getLength();
226 
227                     // currently only one language per dictionary is supported in the actual implementation...
228                     // Thus here we work-around this by adding the same dictionary several times.
229                     // Once for each of it's supported locales.
230                     for (sal_Int32 i = 0;  i < nLocales;  ++i)
231                     {
232                         aDicts[k]  = NULL;
233                         aDEncs[k]  = RTL_TEXTENCODING_DONTKNOW;
234                         aDLocs[k]  = MsLangId::convertLanguageToLocale(
235                                         MsLangId::convertIsoStringToLanguage( aLocaleNames[i] ));
236                         // also both files have to be in the same directory and the
237                         // file names must only differ in the extension (.aff/.dic).
238                         // Thus we use the first location only and strip the extension part.
239                         rtl::OUString aLocation = aDictIt->aLocations[0];
240                         sal_Int32 nPos = aLocation.lastIndexOf( '.' );
241                         aLocation = aLocation.copy( 0, nPos );
242                         aDNames[k] = aLocation;
243 
244                         ++k;
245                     }
246                 }
247             }
248             DBG_ASSERT( k == numdict, "index mismatch?" );
249         }
250         else
251         {
252             /* no dictionary found so register no dictionaries */
253             numdict = 0;
254             aDicts  = NULL;
255             aDEncs  = NULL;
256             aDLocs  = NULL;
257             aDNames = NULL;
258             aSuppLocales.realloc(0);
259         }
260     }
261 
262     return aSuppLocales;
263 }
264 
265 
266 sal_Bool SAL_CALL SpellChecker::hasLocale(const Locale& rLocale)
267         throw(RuntimeException)
268 {
269     MutexGuard  aGuard( GetLinguMutex() );
270 
271     sal_Bool bRes = sal_False;
272     if (!aSuppLocales.getLength())
273         getLocales();
274 
275     sal_Int32 nLen = aSuppLocales.getLength();
276     for (sal_Int32 i = 0;  i < nLen;  ++i)
277     {
278         const Locale *pLocale = aSuppLocales.getConstArray();
279         if (rLocale == pLocale[i])
280         {
281             bRes = sal_True;
282             break;
283         }
284     }
285     return bRes;
286 }
287 
288 
289 sal_Int16 SpellChecker::GetSpellFailure( const OUString &rWord, const Locale &rLocale )
290 {
291     Hunspell * pMS = NULL;
292     rtl_TextEncoding eEnc = RTL_TEXTENCODING_DONTKNOW;
293 
294     // initialize a myspell object for each dictionary once
295     // (note: mutex is held higher up in isValid)
296 
297     sal_Int16 nRes = -1;
298 
299     // first handle smart quotes both single and double
300     OUStringBuffer rBuf(rWord);
301     sal_Int32 n = rBuf.getLength();
302     sal_Unicode c;
303     for (sal_Int32 ix=0; ix < n; ix++)
304     {
305         c = rBuf.charAt(ix);
306         if ((c == 0x201C) || (c == 0x201D))
307             rBuf.setCharAt(ix,(sal_Unicode)0x0022);
308         if ((c == 0x2018) || (c == 0x2019))
309             rBuf.setCharAt(ix,(sal_Unicode)0x0027);
310     }
311     OUString nWord(rBuf.makeStringAndClear());
312 
313     if (n)
314     {
315         for (sal_Int32 i = 0; i < numdict; ++i)
316         {
317             pMS = NULL;
318             eEnc = RTL_TEXTENCODING_DONTKNOW;
319 
320             if (rLocale == aDLocs[i])
321             {
322                 if (!aDicts[i])
323                 {
324                     OUString dicpath = aDNames[i] + A2OU(".dic");
325                     OUString affpath = aDNames[i] + A2OU(".aff");
326                     OUString dict;
327                     OUString aff;
328                     osl::FileBase::getSystemPathFromFileURL(dicpath,dict);
329                     osl::FileBase::getSystemPathFromFileURL(affpath,aff);
330                     OString aTmpaff(OU2ENC(aff,osl_getThreadTextEncoding()));
331                     OString aTmpdict(OU2ENC(dict,osl_getThreadTextEncoding()));
332 
333 #if defined(WNT)
334                     // workaround for Windows specifc problem that the
335                     // path length in calls to 'fopen' is limted to somewhat
336                     // about 120+ characters which will usually be exceed when
337                     // using dictionaries as extensions.
338                     aTmpaff = Win_GetShortPathName( aff );
339                     aTmpdict = Win_GetShortPathName( dict );
340 #endif
341 
342                     aDicts[i] = new Hunspell(aTmpaff.getStr(),aTmpdict.getStr());
343                     aDEncs[i] = RTL_TEXTENCODING_DONTKNOW;
344                     if (aDicts[i])
345                         aDEncs[i] = getTextEncodingFromCharset(aDicts[i]->get_dic_encoding());
346                 }
347                 pMS = aDicts[i];
348                 eEnc = aDEncs[i];
349             }
350 
351             if (pMS)
352             {
353                 // we don't want to work with a default text encoding since following incorrect
354                 // results may occur only for specific text and thus may be hard to notice.
355                 // Thus better always make a clean exit here if the text encoding is in question.
356                 // Hopefully something not working at all will raise proper attention quickly. ;-)
357                 DBG_ASSERT( eEnc != RTL_TEXTENCODING_DONTKNOW, "failed to get text encoding! (maybe incorrect encoding string in file)" );
358                 if (eEnc == RTL_TEXTENCODING_DONTKNOW)
359                     return -1;
360 
361                 OString aWrd(OU2ENC(nWord,eEnc));
362                 int rVal = pMS->spell((char*)aWrd.getStr());
363                 if (rVal != 1)
364                     nRes = SpellFailure::SPELLING_ERROR;
365                 else
366                     return -1;
367                 pMS = NULL;
368             }
369         }
370     }
371 
372     return nRes;
373 }
374 
375 
376 sal_Bool SAL_CALL SpellChecker::isValid( const OUString& rWord, const Locale& rLocale,
377             const PropertyValues& rProperties )
378         throw(IllegalArgumentException, RuntimeException)
379 {
380     MutexGuard  aGuard( GetLinguMutex() );
381 
382     if (rLocale == Locale()  ||  !rWord.getLength())
383         return sal_True;
384 
385     if (!hasLocale( rLocale ))
386 #ifdef LINGU_EXCEPTIONS
387         throw( IllegalArgumentException() );
388 #else
389         return sal_True;
390 #endif
391 
392     // return sal_False to process SPELLML requests (they are longer than the header)
393     if (rWord.match(A2OU(SPELLML_HEADER), 0) && (rWord.getLength() > 10)) return sal_False;
394 
395     // Get property values to be used.
396     // These are be the default values set in the SN_LINGU_PROPERTIES
397     // PropertySet which are overridden by the supplied ones from the
398     // last argument.
399     // You'll probably like to use a simpler solution than the provided
400     // one using the PropertyHelper_Spell.
401 
402     PropertyHelper_Spell &rHelper = GetPropHelper();
403     rHelper.SetTmpPropVals( rProperties );
404 
405     sal_Int16 nFailure = GetSpellFailure( rWord, rLocale );
406     if (nFailure != -1 && !rWord.match(A2OU(SPELLML_HEADER), 0))
407     {
408         sal_Int16 nLang = LocaleToLanguage( rLocale );
409         // postprocess result for errors that should be ignored
410         const bool bIgnoreError =
411                 (!rHelper.IsSpellUpperCase()  && IsUpper( rWord, nLang )) ||
412                 (!rHelper.IsSpellWithDigits() && HasDigits( rWord )) ||
413                 (!rHelper.IsSpellCapitalization()  &&  nFailure == SpellFailure::CAPTION_ERROR);
414         if (bIgnoreError)
415             nFailure = -1;
416     }
417 
418     return (nFailure == -1);
419 }
420 
421 
422 Reference< XSpellAlternatives >
423     SpellChecker::GetProposals( const OUString &rWord, const Locale &rLocale )
424 {
425     // Retrieves the return values for the 'spell' function call in case
426     // of a misspelled word.
427     // Especially it may give a list of suggested (correct) words:
428 
429     Reference< XSpellAlternatives > xRes;
430     // note: mutex is held by higher up by spell which covers both
431 
432     Hunspell* pMS = NULL;
433     rtl_TextEncoding eEnc = RTL_TEXTENCODING_DONTKNOW;
434     int count = 0;
435     int numsug = 0;
436 
437     // first handle smart quotes (single and double)
438     OUStringBuffer rBuf(rWord);
439     sal_Int32 n = rBuf.getLength();
440     sal_Unicode c;
441     for (sal_Int32 ix=0; ix < n; ix++)
442     {
443         c = rBuf.charAt(ix);
444         if ((c == 0x201C) || (c == 0x201D))
445             rBuf.setCharAt(ix,(sal_Unicode)0x0022);
446         if ((c == 0x2018) || (c == 0x2019))
447             rBuf.setCharAt(ix,(sal_Unicode)0x0027);
448     }
449     OUString nWord(rBuf.makeStringAndClear());
450 
451     if (n)
452     {
453         sal_Int16 nLang = LocaleToLanguage( rLocale );
454 
455         Sequence< OUString > aStr( 0 );
456 
457         for (int i =0; i < numdict; i++)
458         {
459             pMS = NULL;
460             eEnc = RTL_TEXTENCODING_DONTKNOW;
461             count = 0;
462 
463             if (rLocale == aDLocs[i])
464             {
465                 pMS = aDicts[i];
466                 eEnc = aDEncs[i];
467             }
468 
469             if (pMS)
470             {
471                 char ** suglst = NULL;
472                 OString aWrd(OU2ENC(nWord,eEnc));
473                 count = pMS->suggest(&suglst, (const char *) aWrd.getStr());
474 
475                 if (count)
476                 {
477                     aStr.realloc( numsug + count );
478                     OUString *pStr = aStr.getArray();
479                     for (int ii=0; ii < count; ++ii)
480                     {
481                         OUString cvtwrd(suglst[ii],strlen(suglst[ii]),eEnc);
482                         pStr[numsug + ii] = cvtwrd;
483                     }
484                     pMS->free_list(&suglst, count);
485                     numsug += count;
486                 }
487             }
488         }
489 
490         // now return an empty alternative for no suggestions or the list of alternatives if some found
491         SpellAlternatives *pAlt = new SpellAlternatives;
492         String aTmp(rWord);
493         pAlt->SetWordLanguage( aTmp, nLang );
494         pAlt->SetFailureType( SpellFailure::SPELLING_ERROR );
495         pAlt->SetAlternatives( aStr );
496         xRes = pAlt;
497         return xRes;
498     }
499     return xRes;
500 }
501 
502 
503 Reference< XSpellAlternatives > SAL_CALL SpellChecker::spell(
504         const OUString& rWord, const Locale& rLocale,
505         const PropertyValues& rProperties )
506         throw(IllegalArgumentException, RuntimeException)
507 {
508     MutexGuard  aGuard( GetLinguMutex() );
509 
510     if (rLocale == Locale()  ||  !rWord.getLength())
511         return NULL;
512 
513     if (!hasLocale( rLocale ))
514 #ifdef LINGU_EXCEPTIONS
515         throw( IllegalArgumentException() );
516 #else
517         return NULL;
518 #endif
519 
520     Reference< XSpellAlternatives > xAlt;
521     if (!isValid( rWord, rLocale, rProperties ))
522     {
523         xAlt =  GetProposals( rWord, rLocale );
524     }
525     return xAlt;
526 }
527 
528 
529 Reference< XInterface > SAL_CALL SpellChecker_CreateInstance(
530         const Reference< XMultiServiceFactory > & /*rSMgr*/ )
531         throw(Exception)
532 {
533 
534     Reference< XInterface > xService = (cppu::OWeakObject*) new SpellChecker;
535     return xService;
536 }
537 
538 
539 sal_Bool SAL_CALL SpellChecker::addLinguServiceEventListener(
540         const Reference< XLinguServiceEventListener >& rxLstnr )
541         throw(RuntimeException)
542 {
543     MutexGuard  aGuard( GetLinguMutex() );
544 
545     sal_Bool bRes = sal_False;
546     if (!bDisposing && rxLstnr.is())
547     {
548         bRes = GetPropHelper().addLinguServiceEventListener( rxLstnr );
549     }
550     return bRes;
551 }
552 
553 
554 sal_Bool SAL_CALL SpellChecker::removeLinguServiceEventListener(
555         const Reference< XLinguServiceEventListener >& rxLstnr )
556         throw(RuntimeException)
557 {
558     MutexGuard  aGuard( GetLinguMutex() );
559 
560     sal_Bool bRes = sal_False;
561     if (!bDisposing && rxLstnr.is())
562     {
563         DBG_ASSERT( xPropHelper.is(), "xPropHelper non existent" );
564         bRes = GetPropHelper().removeLinguServiceEventListener( rxLstnr );
565     }
566     return bRes;
567 }
568 
569 
570 OUString SAL_CALL SpellChecker::getServiceDisplayName( const Locale& /*rLocale*/ )
571         throw(RuntimeException)
572 {
573     MutexGuard  aGuard( GetLinguMutex() );
574     return A2OU( "Hunspell SpellChecker" );
575 }
576 
577 
578 void SAL_CALL SpellChecker::initialize( const Sequence< Any >& rArguments )
579         throw(Exception, RuntimeException)
580 {
581     MutexGuard  aGuard( GetLinguMutex() );
582 
583     if (!pPropHelper)
584     {
585         sal_Int32 nLen = rArguments.getLength();
586         if (2 == nLen)
587         {
588             Reference< XPropertySet >   xPropSet;
589             rArguments.getConstArray()[0] >>= xPropSet;
590             //rArguments.getConstArray()[1] >>= xDicList;
591 
592             //! Pointer allows for access of the non-UNO functions.
593             //! And the reference to the UNO-functions while increasing
594             //! the ref-count and will implicitly free the memory
595             //! when the object is not longer used.
596             pPropHelper = new PropertyHelper_Spell( (XSpellChecker *) this, xPropSet );
597             xPropHelper = pPropHelper;
598             pPropHelper->AddAsPropListener();   //! after a reference is established
599         }
600         else
601         {
602             DBG_ERROR( "wrong number of arguments in sequence" );
603         }
604     }
605 }
606 
607 
608 void SAL_CALL SpellChecker::dispose()
609         throw(RuntimeException)
610 {
611     MutexGuard  aGuard( GetLinguMutex() );
612 
613     if (!bDisposing)
614     {
615         bDisposing = sal_True;
616         EventObject aEvtObj( (XSpellChecker *) this );
617         aEvtListeners.disposeAndClear( aEvtObj );
618     }
619 }
620 
621 
622 void SAL_CALL SpellChecker::addEventListener( const Reference< XEventListener >& rxListener )
623         throw(RuntimeException)
624 {
625     MutexGuard  aGuard( GetLinguMutex() );
626 
627     if (!bDisposing && rxListener.is())
628         aEvtListeners.addInterface( rxListener );
629 }
630 
631 
632 void SAL_CALL SpellChecker::removeEventListener( const Reference< XEventListener >& rxListener )
633         throw(RuntimeException)
634 {
635     MutexGuard  aGuard( GetLinguMutex() );
636 
637     if (!bDisposing && rxListener.is())
638         aEvtListeners.removeInterface( rxListener );
639 }
640 
641 
642 ///////////////////////////////////////////////////////////////////////////
643 // Service specific part
644 //
645 
646 OUString SAL_CALL SpellChecker::getImplementationName()
647         throw(RuntimeException)
648 {
649     MutexGuard  aGuard( GetLinguMutex() );
650 
651     return getImplementationName_Static();
652 }
653 
654 
655 sal_Bool SAL_CALL SpellChecker::supportsService( const OUString& ServiceName )
656         throw(RuntimeException)
657 {
658     MutexGuard  aGuard( GetLinguMutex() );
659 
660     Sequence< OUString > aSNL = getSupportedServiceNames();
661     const OUString * pArray = aSNL.getConstArray();
662     for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
663         if( pArray[i] == ServiceName )
664             return sal_True;
665     return sal_False;
666 }
667 
668 
669 Sequence< OUString > SAL_CALL SpellChecker::getSupportedServiceNames()
670         throw(RuntimeException)
671 {
672     MutexGuard  aGuard( GetLinguMutex() );
673 
674     return getSupportedServiceNames_Static();
675 }
676 
677 
678 Sequence< OUString > SpellChecker::getSupportedServiceNames_Static()
679         throw()
680 {
681     MutexGuard  aGuard( GetLinguMutex() );
682 
683     Sequence< OUString > aSNS( 1 ); // auch mehr als 1 Service moeglich
684     aSNS.getArray()[0] = A2OU( SN_SPELLCHECKER );
685     return aSNS;
686 }
687 
688 void * SAL_CALL SpellChecker_getFactory( const sal_Char * pImplName,
689             XMultiServiceFactory * pServiceManager, void *  )
690 {
691     void * pRet = 0;
692     if ( !SpellChecker::getImplementationName_Static().compareToAscii( pImplName ) )
693     {
694         Reference< XSingleServiceFactory > xFactory =
695             cppu::createOneInstanceFactory(
696                 pServiceManager,
697                 SpellChecker::getImplementationName_Static(),
698                 SpellChecker_CreateInstance,
699                 SpellChecker::getSupportedServiceNames_Static());
700         // acquire, because we return an interface pointer instead of a reference
701         xFactory->acquire();
702         pRet = xFactory.get();
703     }
704     return pRet;
705 }
706 
707 
708 ///////////////////////////////////////////////////////////////////////////
709