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 	delete pPropHelper;
107 }
108 
109 
110 PropertyHelper_Spelling & SpellChecker::GetPropHelper_Impl()
111 {
112 	if (!pPropHelper)
113 	{
114 		Reference< XPropertySet	>	xPropSet( GetLinguProperties(), UNO_QUERY );
115 
116 		pPropHelper	= new PropertyHelper_Spelling( (XSpellChecker *) this, xPropSet );
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_Spelling& 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         String aTmp(rWord);
492         xRes = SpellAlternatives::CreateSpellAlternatives( aTmp, nLang, SpellFailure::SPELLING_ERROR, aStr );
493         return xRes;
494 	}
495     return xRes;
496 }
497 
498 
499 Reference< XSpellAlternatives > SAL_CALL SpellChecker::spell(
500         const OUString& rWord, const Locale& rLocale,
501         const PropertyValues& rProperties )
502 		throw(IllegalArgumentException, RuntimeException)
503 {
504 	MutexGuard	aGuard( GetLinguMutex() );
505 
506  	if (rLocale == Locale()  ||  !rWord.getLength())
507 		return NULL;
508 
509 	if (!hasLocale( rLocale ))
510 #ifdef LINGU_EXCEPTIONS
511 		throw( IllegalArgumentException() );
512 #else
513 		return NULL;
514 #endif
515 
516 	Reference< XSpellAlternatives > xAlt;
517 	if (!isValid( rWord, rLocale, rProperties ))
518 	{
519 		xAlt =  GetProposals( rWord, rLocale );
520 	}
521 	return xAlt;
522 }
523 
524 
525 Reference< XInterface > SAL_CALL SpellChecker_CreateInstance(
526         const Reference< XMultiServiceFactory > & /*rSMgr*/ )
527         throw(Exception)
528 {
529 
530 	Reference< XInterface > xService = (cppu::OWeakObject*) new SpellChecker;
531 	return xService;
532 }
533 
534 
535 sal_Bool SAL_CALL SpellChecker::addLinguServiceEventListener(
536         const Reference< XLinguServiceEventListener >& rxLstnr )
537         throw(RuntimeException)
538 {
539 	MutexGuard	aGuard( GetLinguMutex() );
540 
541 	sal_Bool bRes = sal_False;
542 	if (!bDisposing && rxLstnr.is())
543 	{
544 		bRes = GetPropHelper().addLinguServiceEventListener( rxLstnr );
545 	}
546 	return bRes;
547 }
548 
549 
550 sal_Bool SAL_CALL SpellChecker::removeLinguServiceEventListener(
551         const Reference< XLinguServiceEventListener >& rxLstnr )
552         throw(RuntimeException)
553 {
554 	MutexGuard	aGuard( GetLinguMutex() );
555 
556 	sal_Bool bRes = sal_False;
557 	if (!bDisposing && rxLstnr.is())
558 	{
559 		bRes = GetPropHelper().removeLinguServiceEventListener( rxLstnr );
560 	}
561 	return bRes;
562 }
563 
564 
565 OUString SAL_CALL SpellChecker::getServiceDisplayName( const Locale& /*rLocale*/ )
566 		throw(RuntimeException)
567 {
568 	MutexGuard	aGuard( GetLinguMutex() );
569 	return A2OU( "Hunspell SpellChecker" );
570 }
571 
572 
573 void SAL_CALL SpellChecker::initialize( const Sequence< Any >& rArguments )
574 		throw(Exception, RuntimeException)
575 {
576 	MutexGuard	aGuard( GetLinguMutex() );
577 
578 	if (!pPropHelper)
579 	{
580 		sal_Int32 nLen = rArguments.getLength();
581 		if (2 == nLen)
582 		{
583 			Reference< XPropertySet	>	xPropSet;
584 			rArguments.getConstArray()[0] >>= xPropSet;
585 			//rArguments.getConstArray()[1] >>= xDicList;
586 
587 			//! Pointer allows for access of the non-UNO functions.
588 			//! And the reference to the UNO-functions while increasing
589 			//! the ref-count and will implicitly free the memory
590 			//! when the object is not longer used.
591 			pPropHelper = new PropertyHelper_Spelling( (XSpellChecker *) this, xPropSet );
592 			pPropHelper->AddAsPropListener();	//! after a reference is established
593 		}
594         else
595         {
596 			DBG_ERROR( "wrong number of arguments in sequence" );
597         }
598 	}
599 }
600 
601 
602 void SAL_CALL SpellChecker::dispose()
603 		throw(RuntimeException)
604 {
605 	MutexGuard	aGuard( GetLinguMutex() );
606 
607 	if (!bDisposing)
608 	{
609 		bDisposing = sal_True;
610 		EventObject	aEvtObj( (XSpellChecker *) this );
611 		aEvtListeners.disposeAndClear( aEvtObj );
612 	}
613 }
614 
615 
616 void SAL_CALL SpellChecker::addEventListener( const Reference< XEventListener >& rxListener )
617 		throw(RuntimeException)
618 {
619 	MutexGuard	aGuard( GetLinguMutex() );
620 
621 	if (!bDisposing && rxListener.is())
622 		aEvtListeners.addInterface( rxListener );
623 }
624 
625 
626 void SAL_CALL SpellChecker::removeEventListener( const Reference< XEventListener >& rxListener )
627 		throw(RuntimeException)
628 {
629 	MutexGuard	aGuard( GetLinguMutex() );
630 
631 	if (!bDisposing && rxListener.is())
632 		aEvtListeners.removeInterface( rxListener );
633 }
634 
635 
636 ///////////////////////////////////////////////////////////////////////////
637 // Service specific part
638 //
639 
640 OUString SAL_CALL SpellChecker::getImplementationName()
641 		throw(RuntimeException)
642 {
643 	MutexGuard	aGuard( GetLinguMutex() );
644 
645 	return getImplementationName_Static();
646 }
647 
648 
649 sal_Bool SAL_CALL SpellChecker::supportsService( const OUString& ServiceName )
650 		throw(RuntimeException)
651 {
652 	MutexGuard	aGuard( GetLinguMutex() );
653 
654 	Sequence< OUString > aSNL = getSupportedServiceNames();
655 	const OUString * pArray = aSNL.getConstArray();
656 	for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
657 		if( pArray[i] == ServiceName )
658 			return sal_True;
659 	return sal_False;
660 }
661 
662 
663 Sequence< OUString > SAL_CALL SpellChecker::getSupportedServiceNames()
664 		throw(RuntimeException)
665 {
666 	MutexGuard	aGuard( GetLinguMutex() );
667 
668 	return getSupportedServiceNames_Static();
669 }
670 
671 
672 Sequence< OUString > SpellChecker::getSupportedServiceNames_Static()
673 		throw()
674 {
675 	MutexGuard	aGuard( GetLinguMutex() );
676 
677 	Sequence< OUString > aSNS( 1 );	// auch mehr als 1 Service moeglich
678 	aSNS.getArray()[0] = A2OU( SN_SPELLCHECKER );
679 	return aSNS;
680 }
681 
682 void * SAL_CALL SpellChecker_getFactory( const sal_Char * pImplName,
683 			XMultiServiceFactory * pServiceManager, void *  )
684 {
685 	void * pRet = 0;
686 	if ( !SpellChecker::getImplementationName_Static().compareToAscii( pImplName ) )
687 	{
688 		Reference< XSingleServiceFactory > xFactory =
689 			cppu::createOneInstanceFactory(
690 				pServiceManager,
691 				SpellChecker::getImplementationName_Static(),
692 				SpellChecker_CreateInstance,
693 				SpellChecker::getSupportedServiceNames_Static());
694 		// acquire, because we return an interface pointer instead of a reference
695 		xFactory->acquire();
696 		pRet = xFactory.get();
697 	}
698 	return pRet;
699 }
700 
701 
702 ///////////////////////////////////////////////////////////////////////////
703