1b0844812SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3b0844812SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4b0844812SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5b0844812SAndrew Rist  * distributed with this work for additional information
6b0844812SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7b0844812SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8b0844812SAndrew Rist  * "License"); you may not use this file except in compliance
9b0844812SAndrew Rist  * with the License.  You may obtain a copy of the License at
10b0844812SAndrew Rist  *
11b0844812SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12b0844812SAndrew Rist  *
13b0844812SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14b0844812SAndrew Rist  * software distributed under the License is distributed on an
15b0844812SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b0844812SAndrew Rist  * KIND, either express or implied.  See the License for the
17b0844812SAndrew Rist  * specific language governing permissions and limitations
18b0844812SAndrew Rist  * under the License.
19b0844812SAndrew Rist  *
20b0844812SAndrew Rist  *************************************************************/
21b0844812SAndrew Rist 
22b0844812SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25*c4c42a0eSDamjan Jovanovic #include "precompiled_lnth.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <com/sun/star/uno/Reference.h>
28cdf0e10cSrcweir #include <cppuhelper/factory.hxx>	// helper for factories
29cdf0e10cSrcweir #include <com/sun/star/registry/XRegistryKey.hpp>
30cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
31cdf0e10cSrcweir #include <i18npool/mslangid.hxx>
32cdf0e10cSrcweir #include <tools/debug.hxx>
33cdf0e10cSrcweir #include <unotools/processfactory.hxx>
34cdf0e10cSrcweir #include <osl/mutex.hxx>
35cdf0e10cSrcweir #include <unotools/pathoptions.hxx>
36cdf0e10cSrcweir #include <unotools/lingucfg.hxx>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir #include <rtl/string.hxx>
39cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
40cdf0e10cSrcweir #include <rtl/textenc.h>
41cdf0e10cSrcweir 
42cdf0e10cSrcweir #include "nthesimp.hxx"
43cdf0e10cSrcweir #include <linguistic/misc.hxx>
44cdf0e10cSrcweir #include <linguistic/lngprops.hxx>
45cdf0e10cSrcweir #include "nthesdta.hxx"
46cdf0e10cSrcweir 
47cdf0e10cSrcweir #include <list>
48cdf0e10cSrcweir #include <set>
49cdf0e10cSrcweir #include <string.h>
50cdf0e10cSrcweir 
5130acf5e8Spfg // values assigned to capitalization types
52cdf0e10cSrcweir #define CAPTYPE_UNKNOWN 0
53cdf0e10cSrcweir #define CAPTYPE_NOCAP   1
54cdf0e10cSrcweir #define CAPTYPE_INITCAP 2
55cdf0e10cSrcweir #define CAPTYPE_ALLCAP  3
56cdf0e10cSrcweir #define CAPTYPE_MIXED   4
57cdf0e10cSrcweir 
58cdf0e10cSrcweir // XML-header to query SPELLML support
59cdf0e10cSrcweir #define SPELLML_SUPPORT "<?xml?>"
60cdf0e10cSrcweir 
61cdf0e10cSrcweir using namespace utl;
62cdf0e10cSrcweir using namespace osl;
63cdf0e10cSrcweir using namespace rtl;
64cdf0e10cSrcweir using namespace com::sun::star;
65cdf0e10cSrcweir using namespace com::sun::star::beans;
66cdf0e10cSrcweir using namespace com::sun::star::lang;
67cdf0e10cSrcweir using namespace com::sun::star::uno;
68cdf0e10cSrcweir using namespace com::sun::star::linguistic2;
69cdf0e10cSrcweir using namespace linguistic;
70cdf0e10cSrcweir 
71cdf0e10cSrcweir 
72cdf0e10cSrcweir 
73cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////
74cdf0e10cSrcweir 
75cdf0e10cSrcweir static uno::Reference< XLinguServiceManager > GetLngSvcMgr_Impl()
76cdf0e10cSrcweir {
77cdf0e10cSrcweir 	uno::Reference< XLinguServiceManager > xRes;
78cdf0e10cSrcweir 	uno::Reference< XMultiServiceFactory >  xMgr = getProcessServiceFactory();
79cdf0e10cSrcweir 	if (xMgr.is())
80cdf0e10cSrcweir 	{
81cdf0e10cSrcweir 		xRes = uno::Reference< XLinguServiceManager > ( xMgr->createInstance(
82cdf0e10cSrcweir 				OUString( RTL_CONSTASCII_USTRINGPARAM(
83cdf0e10cSrcweir 					"com.sun.star.linguistic2.LinguServiceManager" ) ) ), UNO_QUERY ) ;
84cdf0e10cSrcweir 	}
85cdf0e10cSrcweir 	return xRes;
86cdf0e10cSrcweir }
87cdf0e10cSrcweir 
88cdf0e10cSrcweir Thesaurus::Thesaurus() :
89cdf0e10cSrcweir 	aEvtListeners	( GetLinguMutex() )
90cdf0e10cSrcweir {
91cdf0e10cSrcweir 	bDisposing = sal_False;
92cdf0e10cSrcweir 	pPropHelper = NULL;
93cdf0e10cSrcweir 	aThes = NULL;
94cdf0e10cSrcweir 	aCharSetInfo = NULL;
95cdf0e10cSrcweir 	aTEncs = NULL;
96cdf0e10cSrcweir 	aTLocs = NULL;
97cdf0e10cSrcweir 	aTNames = NULL;
98cdf0e10cSrcweir     numthes = 0;
99cdf0e10cSrcweir }
100cdf0e10cSrcweir 
101cdf0e10cSrcweir 
102cdf0e10cSrcweir Thesaurus::~Thesaurus()
103cdf0e10cSrcweir {
104cdf0e10cSrcweir 
105cdf0e10cSrcweir     if (aThes)
106cdf0e10cSrcweir     {
107cdf0e10cSrcweir         for (int i = 0; i < numthes; i++)
108cdf0e10cSrcweir         {
109cdf0e10cSrcweir             if (aThes[i]) delete aThes[i];
110cdf0e10cSrcweir             aThes[i] = NULL;
111cdf0e10cSrcweir         }
112cdf0e10cSrcweir         delete[] aThes;
113cdf0e10cSrcweir     }
114cdf0e10cSrcweir     aThes = NULL;
115cdf0e10cSrcweir     if (aCharSetInfo)
116cdf0e10cSrcweir     {
117cdf0e10cSrcweir         for (int i = 0; i < numthes; i++)
118cdf0e10cSrcweir         {
119cdf0e10cSrcweir             if (aCharSetInfo[i]) delete aCharSetInfo[i];
120cdf0e10cSrcweir             aCharSetInfo[i] = NULL;
121cdf0e10cSrcweir         }
122cdf0e10cSrcweir         delete[] aCharSetInfo;
123cdf0e10cSrcweir     }
124cdf0e10cSrcweir     aCharSetInfo = NULL;
125cdf0e10cSrcweir     numthes = 0;
126cdf0e10cSrcweir     if (aTEncs) delete[] aTEncs;
127cdf0e10cSrcweir     aTEncs = NULL;
128cdf0e10cSrcweir     if (aTLocs) delete[] aTLocs;
129cdf0e10cSrcweir     aTLocs = NULL;
130cdf0e10cSrcweir     if (aTNames) delete[] aTNames;
131cdf0e10cSrcweir     aTNames = NULL;
132cdf0e10cSrcweir 
133cdf0e10cSrcweir     if (pPropHelper)
134cdf0e10cSrcweir 		pPropHelper->RemoveAsPropListener();
135b63233d8Sdamjan 	delete pPropHelper;
136cdf0e10cSrcweir }
137cdf0e10cSrcweir 
138cdf0e10cSrcweir 
139b63233d8Sdamjan PropertyHelper_Thesaurus& Thesaurus::GetPropHelper_Impl()
140cdf0e10cSrcweir {
141cdf0e10cSrcweir 	if (!pPropHelper)
142cdf0e10cSrcweir 	{
143cdf0e10cSrcweir 		Reference< XPropertySet	>	xPropSet( GetLinguProperties(), UNO_QUERY );
144cdf0e10cSrcweir 
145b63233d8Sdamjan 		pPropHelper	= new PropertyHelper_Thesaurus( (XThesaurus *) this, xPropSet );
146cdf0e10cSrcweir 		pPropHelper->AddAsPropListener();	//! after a reference is established
147cdf0e10cSrcweir 	}
148cdf0e10cSrcweir 	return *pPropHelper;
149cdf0e10cSrcweir }
150cdf0e10cSrcweir 
151cdf0e10cSrcweir 
152cdf0e10cSrcweir Sequence< Locale > SAL_CALL Thesaurus::getLocales()
153cdf0e10cSrcweir         throw(RuntimeException)
154cdf0e10cSrcweir {
155cdf0e10cSrcweir     MutexGuard  aGuard( GetLinguMutex() );
156cdf0e10cSrcweir 
157cdf0e10cSrcweir     // this routine should return the locales supported by the installed
158cdf0e10cSrcweir     // dictionaries.
159cdf0e10cSrcweir 
160cdf0e10cSrcweir     if (!numthes)
161cdf0e10cSrcweir     {
162cdf0e10cSrcweir         SvtLinguConfig aLinguCfg;
163cdf0e10cSrcweir 
164cdf0e10cSrcweir         // get list of dictionaries-to-use
165cdf0e10cSrcweir         std::list< SvtLinguConfigDictionaryEntry > aDics;
166cdf0e10cSrcweir         uno::Sequence< rtl::OUString > aFormatList;
167cdf0e10cSrcweir         aLinguCfg.GetSupportedDictionaryFormatsFor( A2OU("Thesauri"),
168cdf0e10cSrcweir                 A2OU("org.openoffice.lingu.new.Thesaurus"), aFormatList );
169cdf0e10cSrcweir         sal_Int32 nLen = aFormatList.getLength();
170cdf0e10cSrcweir         for (sal_Int32 i = 0;  i < nLen;  ++i)
171cdf0e10cSrcweir         {
172cdf0e10cSrcweir             std::vector< SvtLinguConfigDictionaryEntry > aTmpDic(
173cdf0e10cSrcweir                     aLinguCfg.GetActiveDictionariesByFormat( aFormatList[i] ) );
174cdf0e10cSrcweir             aDics.insert( aDics.end(), aTmpDic.begin(), aTmpDic.end() );
175cdf0e10cSrcweir         }
176cdf0e10cSrcweir 
177cdf0e10cSrcweir         //!! for compatibility with old dictionaries (the ones not using extensions
178cdf0e10cSrcweir         //!! or new configuration entries, but still using the dictionary.lst file)
179cdf0e10cSrcweir 		//!! Get the list of old style spell checking dictionaries to use...
180cdf0e10cSrcweir         std::vector< SvtLinguConfigDictionaryEntry > aOldStyleDics(
181cdf0e10cSrcweir 				GetOldStyleDics( "THES" ) );
182cdf0e10cSrcweir 
183cdf0e10cSrcweir 		// to prefer dictionaries with configuration entries we will only
184cdf0e10cSrcweir 		// use those old style dictionaries that add a language that
185cdf0e10cSrcweir 		// is not yet supported by the list od new style dictionaries
186cdf0e10cSrcweir 		MergeNewStyleDicsAndOldStyleDics( aDics, aOldStyleDics );
187cdf0e10cSrcweir 
188cdf0e10cSrcweir         numthes = aDics.size();
189cdf0e10cSrcweir         if (numthes)
190cdf0e10cSrcweir         {
191cdf0e10cSrcweir             // get supported locales from the dictionaries-to-use...
192cdf0e10cSrcweir             sal_Int32 k = 0;
193cdf0e10cSrcweir             std::set< rtl::OUString, lt_rtl_OUString > aLocaleNamesSet;
194cdf0e10cSrcweir             std::list< SvtLinguConfigDictionaryEntry >::const_iterator aDictIt;
195cdf0e10cSrcweir             for (aDictIt = aDics.begin();  aDictIt != aDics.end();  ++aDictIt)
196cdf0e10cSrcweir             {
197cdf0e10cSrcweir                 uno::Sequence< rtl::OUString > aLocaleNames( aDictIt->aLocaleNames );
198cdf0e10cSrcweir                 sal_Int32 nLen2 = aLocaleNames.getLength();
199cdf0e10cSrcweir                 for (k = 0;  k < nLen2;  ++k)
200cdf0e10cSrcweir                 {
201cdf0e10cSrcweir                     aLocaleNamesSet.insert( aLocaleNames[k] );
202cdf0e10cSrcweir                 }
203cdf0e10cSrcweir             }
204cdf0e10cSrcweir             // ... and add them to the resulting sequence
205cdf0e10cSrcweir             aSuppLocales.realloc( aLocaleNamesSet.size() );
206cdf0e10cSrcweir             std::set< rtl::OUString, lt_rtl_OUString >::const_iterator aItB;
207cdf0e10cSrcweir             k = 0;
208cdf0e10cSrcweir             for (aItB = aLocaleNamesSet.begin();  aItB != aLocaleNamesSet.end();  ++aItB)
209cdf0e10cSrcweir             {
210cdf0e10cSrcweir                 Locale aTmp( MsLangId::convertLanguageToLocale(
211cdf0e10cSrcweir                         MsLangId::convertIsoStringToLanguage( *aItB )));
212cdf0e10cSrcweir                 aSuppLocales[k++] = aTmp;
213cdf0e10cSrcweir             }
214cdf0e10cSrcweir 
215a893be29SPedro Giffuni             //! For each dictionary and each locale we need a separate entry.
216cdf0e10cSrcweir             //! If this results in more than one dictionary per locale than (for now)
217cdf0e10cSrcweir 			//! it is undefined which dictionary gets used.
218cdf0e10cSrcweir 			//! In the future the implementation should support using several dictionaries
219cdf0e10cSrcweir 			//! for one locale.
220cdf0e10cSrcweir 			numthes = 0;
221cdf0e10cSrcweir             for (aDictIt = aDics.begin();  aDictIt != aDics.end();  ++aDictIt)
222cdf0e10cSrcweir 				numthes = numthes + aDictIt->aLocaleNames.getLength();
223cdf0e10cSrcweir 
224cdf0e10cSrcweir             // add dictionary information
225cdf0e10cSrcweir             aThes   = new MyThes* [numthes];
226cdf0e10cSrcweir             aTEncs  = new rtl_TextEncoding [numthes];
227cdf0e10cSrcweir             aTLocs  = new Locale [numthes];
228cdf0e10cSrcweir             aTNames = new OUString [numthes];
229cdf0e10cSrcweir             aCharSetInfo = new CharClass* [numthes];
230cdf0e10cSrcweir 
231cdf0e10cSrcweir             k = 0;
232cdf0e10cSrcweir             for (aDictIt = aDics.begin();  aDictIt != aDics.end();  ++aDictIt)
233cdf0e10cSrcweir             {
234cdf0e10cSrcweir                 if (aDictIt->aLocaleNames.getLength() > 0 &&
235cdf0e10cSrcweir                     aDictIt->aLocations.getLength() > 0)
236cdf0e10cSrcweir                 {
237cdf0e10cSrcweir                     uno::Sequence< rtl::OUString > aLocaleNames( aDictIt->aLocaleNames );
238cdf0e10cSrcweir                     sal_Int32 nLocales = aLocaleNames.getLength();
239cdf0e10cSrcweir 
240cdf0e10cSrcweir                     // currently only one language per dictionary is supported in the actual implementation...
241cdf0e10cSrcweir                     // Thus here we work-around this by adding the same dictionary several times.
242cdf0e10cSrcweir                     // Once for each of it's supported locales.
243cdf0e10cSrcweir                     for (sal_Int32 i = 0;  i < nLocales;  ++i)
244cdf0e10cSrcweir                     {
245cdf0e10cSrcweir                         aThes[k]  = NULL;
246cdf0e10cSrcweir                         aTEncs[k]  = RTL_TEXTENCODING_DONTKNOW;
247cdf0e10cSrcweir                         aTLocs[k]  = MsLangId::convertLanguageToLocale(
248cdf0e10cSrcweir                                         MsLangId::convertIsoStringToLanguage( aDictIt->aLocaleNames[i] ));
249cdf0e10cSrcweir                         aCharSetInfo[k] = new CharClass( aTLocs[k] );
250cdf0e10cSrcweir                         // also both files have to be in the same directory and the
251cdf0e10cSrcweir                         // file names must only differ in the extension (.aff/.dic).
252cdf0e10cSrcweir                         // Thus we use the first location only and strip the extension part.
253cdf0e10cSrcweir                         rtl::OUString aLocation = aDictIt->aLocations[0];
254cdf0e10cSrcweir                         sal_Int32 nPos = aLocation.lastIndexOf( '.' );
255cdf0e10cSrcweir                         aLocation = aLocation.copy( 0, nPos );
256cdf0e10cSrcweir                         aTNames[k] = aLocation;
257cdf0e10cSrcweir 
258cdf0e10cSrcweir                         ++k;
259cdf0e10cSrcweir                     }
260cdf0e10cSrcweir                 }
261cdf0e10cSrcweir             }
262cdf0e10cSrcweir             DBG_ASSERT( k == numthes, "index mismatch?" );
263cdf0e10cSrcweir         }
264cdf0e10cSrcweir         else
265cdf0e10cSrcweir         {
266cdf0e10cSrcweir             /* no dictionary found so register no dictionaries */
267cdf0e10cSrcweir             numthes = 0;
268cdf0e10cSrcweir             aThes  = NULL;
269cdf0e10cSrcweir             aTEncs  = NULL;
270cdf0e10cSrcweir             aTLocs  = NULL;
271cdf0e10cSrcweir             aTNames = NULL;
272cdf0e10cSrcweir             aCharSetInfo = NULL;
273cdf0e10cSrcweir             aSuppLocales.realloc(0);
274cdf0e10cSrcweir         }
275cdf0e10cSrcweir     }
276cdf0e10cSrcweir 
277cdf0e10cSrcweir     return aSuppLocales;
278cdf0e10cSrcweir }
279cdf0e10cSrcweir 
280cdf0e10cSrcweir 
281cdf0e10cSrcweir 
282cdf0e10cSrcweir sal_Bool SAL_CALL Thesaurus::hasLocale(const Locale& rLocale)
283cdf0e10cSrcweir 		throw(RuntimeException)
284cdf0e10cSrcweir {
285cdf0e10cSrcweir 	MutexGuard	aGuard( GetLinguMutex() );
286cdf0e10cSrcweir 
287cdf0e10cSrcweir 	sal_Bool bRes = sal_False;
288cdf0e10cSrcweir 	if (!aSuppLocales.getLength())
289cdf0e10cSrcweir 		getLocales();
290cdf0e10cSrcweir 	sal_Int32 nLen = aSuppLocales.getLength();
291cdf0e10cSrcweir 	for (sal_Int32 i = 0;  i < nLen;  ++i)
292cdf0e10cSrcweir 	{
293cdf0e10cSrcweir 		const Locale *pLocale = aSuppLocales.getConstArray();
294cdf0e10cSrcweir 		if (rLocale == pLocale[i])
295cdf0e10cSrcweir 		{
296cdf0e10cSrcweir 			bRes = sal_True;
297cdf0e10cSrcweir 			break;
298cdf0e10cSrcweir 		}
299cdf0e10cSrcweir 	}
300cdf0e10cSrcweir 	return bRes;
301cdf0e10cSrcweir }
302cdf0e10cSrcweir 
303cdf0e10cSrcweir 
304cdf0e10cSrcweir Sequence < Reference < ::com::sun::star::linguistic2::XMeaning > > SAL_CALL Thesaurus::queryMeanings(
305cdf0e10cSrcweir     const OUString& qTerm, const Locale& rLocale,
306cdf0e10cSrcweir     const PropertyValues& rProperties)
307cdf0e10cSrcweir     throw(IllegalArgumentException, RuntimeException)
308cdf0e10cSrcweir {
309cdf0e10cSrcweir     MutexGuard      aGuard( GetLinguMutex() );
310cdf0e10cSrcweir 
311cdf0e10cSrcweir     uno::Sequence< Reference< XMeaning > > aMeanings( 1 );
312cdf0e10cSrcweir     uno::Sequence< Reference< XMeaning > > noMeanings( 0 );
313cdf0e10cSrcweir     uno::Reference< XLinguServiceManager > xLngSvcMgr( GetLngSvcMgr_Impl() );
314cdf0e10cSrcweir     uno::Reference< XSpellChecker1 > xSpell;
315cdf0e10cSrcweir 
316cdf0e10cSrcweir     OUString rTerm(qTerm);
317cdf0e10cSrcweir     OUString pTerm(qTerm);
318cdf0e10cSrcweir     sal_uInt16 ct = CAPTYPE_UNKNOWN;
319cdf0e10cSrcweir     sal_Int32 stem = 0;
320cdf0e10cSrcweir     sal_Int32 stem2 = 0;
321cdf0e10cSrcweir 
322cdf0e10cSrcweir     sal_Int16 nLanguage = LocaleToLanguage( rLocale );
323cdf0e10cSrcweir 
324cdf0e10cSrcweir     if (nLanguage == LANGUAGE_NONE || !rTerm.getLength())
325cdf0e10cSrcweir         return noMeanings;
326cdf0e10cSrcweir 
327cdf0e10cSrcweir     if (!hasLocale( rLocale ))
328cdf0e10cSrcweir #ifdef LINGU_EXCEPTIONS
329cdf0e10cSrcweir         throw( IllegalArgumentException() );
330cdf0e10cSrcweir #else
331cdf0e10cSrcweir         return noMeanings;
332cdf0e10cSrcweir #endif
333cdf0e10cSrcweir 
334cdf0e10cSrcweir     if (prevTerm == qTerm && prevLocale == nLanguage)
335cdf0e10cSrcweir         return prevMeanings;
336cdf0e10cSrcweir 
337cdf0e10cSrcweir     mentry * pmean = NULL;
338cdf0e10cSrcweir     sal_Int32 nmean = 0;
339cdf0e10cSrcweir 
340b63233d8Sdamjan     PropertyHelper_Thesaurus &rHelper = GetPropHelper();
341cdf0e10cSrcweir     rHelper.SetTmpPropVals( rProperties );
342cdf0e10cSrcweir 
343cdf0e10cSrcweir     MyThes * pTH = NULL;
344cdf0e10cSrcweir     rtl_TextEncoding eEnc = RTL_TEXTENCODING_DONTKNOW;
345cdf0e10cSrcweir     CharClass * pCC = NULL;
346cdf0e10cSrcweir 
347cdf0e10cSrcweir     // find the first thesaurus that matches the locale
348cdf0e10cSrcweir     for (int i =0; i < numthes; i++)
349cdf0e10cSrcweir     {
350cdf0e10cSrcweir         if (rLocale == aTLocs[i])
351cdf0e10cSrcweir         {
352cdf0e10cSrcweir             // open up and intialize this thesaurus if need be
353cdf0e10cSrcweir             if (!aThes[i])
354cdf0e10cSrcweir             {
355cdf0e10cSrcweir                 OUString datpath = aTNames[i] + A2OU(".dat");
356cdf0e10cSrcweir                 OUString idxpath = aTNames[i] + A2OU(".idx");
357cdf0e10cSrcweir                 OUString ndat;
358cdf0e10cSrcweir                 OUString nidx;
359cdf0e10cSrcweir                 osl::FileBase::getSystemPathFromFileURL(datpath,ndat);
360cdf0e10cSrcweir                 osl::FileBase::getSystemPathFromFileURL(idxpath,nidx);
361cdf0e10cSrcweir                 OString aTmpidx(OU2ENC(nidx,osl_getThreadTextEncoding()));
362cdf0e10cSrcweir                 OString aTmpdat(OU2ENC(ndat,osl_getThreadTextEncoding()));
363cdf0e10cSrcweir 
364cdf0e10cSrcweir #if defined(WNT)
365cdf0e10cSrcweir                 // workaround for Windows specifc problem that the
366cdf0e10cSrcweir                 // path length in calls to 'fopen' is limted to somewhat
367cdf0e10cSrcweir                 // about 120+ characters which will usually be exceed when
368cdf0e10cSrcweir                 // using dictionaries as extensions.
369cdf0e10cSrcweir                 aTmpidx = Win_GetShortPathName( nidx );
370cdf0e10cSrcweir                 aTmpdat = Win_GetShortPathName( ndat );
371cdf0e10cSrcweir #endif
372cdf0e10cSrcweir 
373cdf0e10cSrcweir                 aThes[i] = new MyThes(aTmpidx.getStr(),aTmpdat.getStr());
374cdf0e10cSrcweir                 if (aThes[i])
375cdf0e10cSrcweir                     aTEncs[i] = getTextEncodingFromCharset(aThes[i]->get_th_encoding());
376cdf0e10cSrcweir             }
377cdf0e10cSrcweir             pTH = aThes[i];
378cdf0e10cSrcweir             eEnc = aTEncs[i];
379cdf0e10cSrcweir             pCC = aCharSetInfo[i];
380cdf0e10cSrcweir 
381cdf0e10cSrcweir             if (pTH)
382cdf0e10cSrcweir                 break;
383cdf0e10cSrcweir         }
384cdf0e10cSrcweir     }
385cdf0e10cSrcweir 
386cdf0e10cSrcweir     // we don't want to work with a default text encoding since following incorrect
387cdf0e10cSrcweir     // results may occur only for specific text and thus may be hard to notice.
388cdf0e10cSrcweir     // Thus better always make a clean exit here if the text encoding is in question.
389cdf0e10cSrcweir     // Hopefully something not working at all will raise proper attention quickly. ;-)
390cdf0e10cSrcweir     DBG_ASSERT( eEnc != RTL_TEXTENCODING_DONTKNOW, "failed to get text encoding! (maybe incorrect encoding string in file)" );
391cdf0e10cSrcweir     if (eEnc == RTL_TEXTENCODING_DONTKNOW)
392cdf0e10cSrcweir         return noMeanings;
393cdf0e10cSrcweir 
394cdf0e10cSrcweir     while (pTH)
395cdf0e10cSrcweir     {
396cdf0e10cSrcweir         // convert word to all lower case for searching
397cdf0e10cSrcweir         if (!stem)
398cdf0e10cSrcweir             ct = capitalType(rTerm, pCC);
399cdf0e10cSrcweir         OUString nTerm(makeLowerCase(rTerm, pCC));
400cdf0e10cSrcweir         OString aTmp( OU2ENC(nTerm, eEnc) );
401cdf0e10cSrcweir         nmean = pTH->Lookup(aTmp.getStr(),aTmp.getLength(),&pmean);
402cdf0e10cSrcweir 
403cdf0e10cSrcweir         if (nmean)
404cdf0e10cSrcweir             aMeanings.realloc( nmean );
405cdf0e10cSrcweir 
406cdf0e10cSrcweir         mentry * pe = pmean;
407cdf0e10cSrcweir         OUString codeTerm = qTerm;
408cdf0e10cSrcweir         Reference< XSpellAlternatives > xTmpRes2;
409cdf0e10cSrcweir 
410cdf0e10cSrcweir         if (stem)
411cdf0e10cSrcweir         {
412cdf0e10cSrcweir             xTmpRes2 = xSpell->spell( A2OU("<?xml?><query type='analyze'><word>") +
413cdf0e10cSrcweir             pTerm + A2OU("</word></query>"), nLanguage, rProperties );
414cdf0e10cSrcweir             if (xTmpRes2.is())
415cdf0e10cSrcweir             {
416cdf0e10cSrcweir                 Sequence<OUString>seq = xTmpRes2->getAlternatives();
417cdf0e10cSrcweir                 if (seq.getLength() > 0)
418cdf0e10cSrcweir                 {
419cdf0e10cSrcweir                     codeTerm = seq[0];
420cdf0e10cSrcweir                     stem2 = 1;
421cdf0e10cSrcweir                 }
422cdf0e10cSrcweir #if 0
423cdf0e10cSrcweir                 OString o = OUStringToOString(codeTerm, RTL_TEXTENCODING_UTF8);
424cdf0e10cSrcweir                 fprintf(stderr, "CODETERM: %s\n", o.pData->buffer);
425cdf0e10cSrcweir #endif
426cdf0e10cSrcweir             }
427cdf0e10cSrcweir         }
428cdf0e10cSrcweir 
429cdf0e10cSrcweir         for (int j = 0; j < nmean; j++)
430cdf0e10cSrcweir         {
431cdf0e10cSrcweir             int count = pe->count;
432cdf0e10cSrcweir             if (count)
433cdf0e10cSrcweir             {
434cdf0e10cSrcweir                 Sequence< OUString > aStr( count );
435cdf0e10cSrcweir                 OUString *pStr = aStr.getArray();
436cdf0e10cSrcweir 
437cdf0e10cSrcweir                 for (int i=0; i < count; i++)
438cdf0e10cSrcweir                 {
439cdf0e10cSrcweir                     OUString sTerm(pe->psyns[i],strlen(pe->psyns[i]),eEnc );
440cdf0e10cSrcweir                     sal_Int32 catpos = sTerm.indexOf('(');
441cdf0e10cSrcweir                     sal_Int32 catpos2 = 0;
442cdf0e10cSrcweir                     OUString catst;
443cdf0e10cSrcweir                     OUString catst2;
444cdf0e10cSrcweir                     if (catpos > 2)
445cdf0e10cSrcweir                     {
446cdf0e10cSrcweir                         // remove category name for affixation and casing
447cdf0e10cSrcweir                         catst = A2OU(" ") + sTerm.copy(catpos);
448cdf0e10cSrcweir                         sTerm = sTerm.copy(0, catpos);
449cdf0e10cSrcweir                         sTerm = sTerm.trim();
450cdf0e10cSrcweir                     }
451cdf0e10cSrcweir                     // generate synonyms with affixes
452cdf0e10cSrcweir                     if (stem && stem2)
453cdf0e10cSrcweir                     {
454cdf0e10cSrcweir                         Reference< XSpellAlternatives > xTmpRes;
455cdf0e10cSrcweir                         xTmpRes = xSpell->spell( A2OU("<?xml?><query type='generate'><word>") +
456cdf0e10cSrcweir                         sTerm + A2OU("</word>") + codeTerm + A2OU("</query>"), nLanguage, rProperties );
457cdf0e10cSrcweir                         if (xTmpRes.is())
458cdf0e10cSrcweir                         {
459cdf0e10cSrcweir                             Sequence<OUString>seq = xTmpRes->getAlternatives();
460cdf0e10cSrcweir                             if (seq.getLength() > 0)
461cdf0e10cSrcweir                                 sTerm = seq[0];
462cdf0e10cSrcweir                         }
463cdf0e10cSrcweir                     }
464cdf0e10cSrcweir                     if (catpos2)
465cdf0e10cSrcweir                         sTerm = catst2 + sTerm;
466cdf0e10cSrcweir 
467cdf0e10cSrcweir                     sal_uInt16 ct1 = capitalType(sTerm, pCC);
468cdf0e10cSrcweir                     if (CAPTYPE_MIXED == ct1)
469cdf0e10cSrcweir                         ct = ct1;
470cdf0e10cSrcweir                     OUString cTerm;
471cdf0e10cSrcweir                     switch (ct)
472cdf0e10cSrcweir                     {
473cdf0e10cSrcweir                         case CAPTYPE_ALLCAP:
474cdf0e10cSrcweir                             cTerm = makeUpperCase(sTerm, pCC);
475cdf0e10cSrcweir                             break;
476cdf0e10cSrcweir                         case CAPTYPE_INITCAP:
477cdf0e10cSrcweir                             cTerm = makeInitCap(sTerm, pCC);
478cdf0e10cSrcweir                             break;
479cdf0e10cSrcweir                         default:
480cdf0e10cSrcweir                             cTerm = sTerm;
481cdf0e10cSrcweir                             break;
482cdf0e10cSrcweir                     }
483cdf0e10cSrcweir                     OUString aAlt( cTerm + catst);
484cdf0e10cSrcweir                     pStr[i] = aAlt;
485cdf0e10cSrcweir                 }
486cdf0e10cSrcweir #if 0
487cdf0e10cSrcweir                 Meaning * pMn = new Meaning(rTerm,nLanguage,rHelper);
488cdf0e10cSrcweir #endif
489cdf0e10cSrcweir                 Meaning * pMn = new Meaning(rTerm,nLanguage);
490cdf0e10cSrcweir                 OUString dTerm(pe->defn,strlen(pe->defn),eEnc );
491cdf0e10cSrcweir                 pMn->SetMeaning(dTerm);
492cdf0e10cSrcweir                 pMn->SetSynonyms(aStr);
493cdf0e10cSrcweir                 Reference<XMeaning>* pMeaning = aMeanings.getArray();
494cdf0e10cSrcweir                 pMeaning[j] = pMn;
495cdf0e10cSrcweir             }
496cdf0e10cSrcweir             pe++;
497cdf0e10cSrcweir         }
498cdf0e10cSrcweir         pTH->CleanUpAfterLookup(&pmean,nmean);
499cdf0e10cSrcweir 
500cdf0e10cSrcweir         if (nmean)
501cdf0e10cSrcweir         {
502cdf0e10cSrcweir             prevTerm = qTerm;
503cdf0e10cSrcweir             prevMeanings = aMeanings;
504cdf0e10cSrcweir             prevLocale = nLanguage;
505cdf0e10cSrcweir             return aMeanings;
506cdf0e10cSrcweir         }
507cdf0e10cSrcweir 
508cdf0e10cSrcweir         if (stem || !xLngSvcMgr.is())
509cdf0e10cSrcweir             return noMeanings;
510cdf0e10cSrcweir         stem = 1;
511cdf0e10cSrcweir 
512cdf0e10cSrcweir         xSpell = uno::Reference< XSpellChecker1 >( xLngSvcMgr->getSpellChecker(), UNO_QUERY );
513cdf0e10cSrcweir         if (!xSpell.is() || !xSpell->isValid( A2OU(SPELLML_SUPPORT), nLanguage, rProperties ))
514cdf0e10cSrcweir             return noMeanings;
515cdf0e10cSrcweir         Reference< XSpellAlternatives > xTmpRes;
516cdf0e10cSrcweir         xTmpRes = xSpell->spell( A2OU("<?xml?><query type='stem'><word>") +
517cdf0e10cSrcweir             rTerm + A2OU("</word></query>"), nLanguage, rProperties );
518cdf0e10cSrcweir         if (xTmpRes.is())
519cdf0e10cSrcweir         {
520cdf0e10cSrcweir             Sequence<OUString>seq = xTmpRes->getAlternatives();
521cdf0e10cSrcweir #if 0
522cdf0e10cSrcweir             for (int i = 0; i < seq.getLength(); i++)
523cdf0e10cSrcweir             {
524cdf0e10cSrcweir                 OString o = OUStringToOString(seq[i], RTL_TEXTENCODING_UTF8);
525cdf0e10cSrcweir                 fprintf(stderr, "%d: %s\n", i + 1, o.pData->buffer);
526cdf0e10cSrcweir             }
527cdf0e10cSrcweir #endif
528cdf0e10cSrcweir             if (seq.getLength() > 0)
529cdf0e10cSrcweir             {
530cdf0e10cSrcweir                 rTerm = seq[0];  // XXX Use only the first stem
531cdf0e10cSrcweir                 continue;
532cdf0e10cSrcweir             }
533cdf0e10cSrcweir         }
534cdf0e10cSrcweir 
535cdf0e10cSrcweir         // stem the last word of the synonym (for categories after affixation)
536cdf0e10cSrcweir         rTerm = rTerm.trim();
537cdf0e10cSrcweir         sal_Int32 pos = rTerm.lastIndexOf(' ');
538cdf0e10cSrcweir         if (!pos)
539cdf0e10cSrcweir             return noMeanings;
540cdf0e10cSrcweir         xTmpRes = xSpell->spell( A2OU("<?xml?><query type='stem'><word>") +
541cdf0e10cSrcweir             rTerm.copy(pos + 1) + A2OU("</word></query>"), nLanguage, rProperties );
542cdf0e10cSrcweir         if (xTmpRes.is())
543cdf0e10cSrcweir         {
544cdf0e10cSrcweir             Sequence<OUString>seq = xTmpRes->getAlternatives();
545cdf0e10cSrcweir             if (seq.getLength() > 0)
546cdf0e10cSrcweir             {
547cdf0e10cSrcweir                 pTerm = rTerm.copy(pos + 1);
548cdf0e10cSrcweir                 rTerm = rTerm.copy(0, pos + 1) + seq[0];
549cdf0e10cSrcweir #if  0
550cdf0e10cSrcweir                 for (int i = 0; i < seq.getLength(); i++)
551cdf0e10cSrcweir                 {
552cdf0e10cSrcweir                     OString o = OUStringToOString(seq[i], RTL_TEXTENCODING_UTF8);
553cdf0e10cSrcweir                     fprintf(stderr, "%d: %s\n", i + 1, o.pData->buffer);
554cdf0e10cSrcweir                 }
555cdf0e10cSrcweir #endif
556cdf0e10cSrcweir                 continue;
557cdf0e10cSrcweir             }
558cdf0e10cSrcweir         }
559cdf0e10cSrcweir         break;
560cdf0e10cSrcweir     }
561cdf0e10cSrcweir     return noMeanings;
562cdf0e10cSrcweir }
563cdf0e10cSrcweir 
564cdf0e10cSrcweir 
565cdf0e10cSrcweir Reference< XInterface > SAL_CALL Thesaurus_CreateInstance(
566cdf0e10cSrcweir             const Reference< XMultiServiceFactory > & /*rSMgr*/ )
567cdf0e10cSrcweir 		throw(Exception)
568cdf0e10cSrcweir {
569cdf0e10cSrcweir 	Reference< XInterface > xService = (cppu::OWeakObject*) new Thesaurus;
570cdf0e10cSrcweir 	return xService;
571cdf0e10cSrcweir }
572cdf0e10cSrcweir 
573cdf0e10cSrcweir 
574cdf0e10cSrcweir OUString SAL_CALL Thesaurus::getServiceDisplayName( const Locale& /*rLocale*/ )
575cdf0e10cSrcweir 		throw(RuntimeException)
576cdf0e10cSrcweir {
577cdf0e10cSrcweir 	MutexGuard	aGuard( GetLinguMutex() );
578cdf0e10cSrcweir 	return A2OU( "OpenOffice.org New Thesaurus" );
579cdf0e10cSrcweir }
580cdf0e10cSrcweir 
581cdf0e10cSrcweir 
582cdf0e10cSrcweir void SAL_CALL Thesaurus::initialize( const Sequence< Any >& rArguments )
583cdf0e10cSrcweir 		throw(Exception, RuntimeException)
584cdf0e10cSrcweir {
585cdf0e10cSrcweir 	MutexGuard	aGuard( GetLinguMutex() );
586cdf0e10cSrcweir 
587cdf0e10cSrcweir 	if (!pPropHelper)
588cdf0e10cSrcweir 	{
589cdf0e10cSrcweir 		sal_Int32 nLen = rArguments.getLength();
590cdf0e10cSrcweir 		if (1 == nLen)
591cdf0e10cSrcweir 		{
592cdf0e10cSrcweir 			Reference< XPropertySet	>	xPropSet;
593cdf0e10cSrcweir 			rArguments.getConstArray()[0] >>= xPropSet;
594cdf0e10cSrcweir 
595cdf0e10cSrcweir 			//! Pointer allows for access of the non-UNO functions.
596cdf0e10cSrcweir 			//! And the reference to the UNO-functions while increasing
597cdf0e10cSrcweir 			//! the ref-count and will implicitly free the memory
598cdf0e10cSrcweir 			//! when the object is not longer used.
599b63233d8Sdamjan 			pPropHelper = new PropertyHelper_Thesaurus( (XThesaurus *) this, xPropSet );
600cdf0e10cSrcweir 			pPropHelper->AddAsPropListener();	//! after a reference is established
601cdf0e10cSrcweir 		}
602cdf0e10cSrcweir 		else
603cdf0e10cSrcweir 			DBG_ERROR( "wrong number of arguments in sequence" );
604cdf0e10cSrcweir 	}
605cdf0e10cSrcweir }
606cdf0e10cSrcweir 
607cdf0e10cSrcweir 
608cdf0e10cSrcweir 
609cdf0e10cSrcweir sal_uInt16 SAL_CALL Thesaurus::capitalType(const OUString& aTerm, CharClass * pCC)
610cdf0e10cSrcweir {
611cdf0e10cSrcweir         sal_Int32 tlen = aTerm.getLength();
612cdf0e10cSrcweir         if ((pCC) && (tlen))
613cdf0e10cSrcweir         {
614cdf0e10cSrcweir             String aStr(aTerm);
615cdf0e10cSrcweir             sal_Int32 nc = 0;
616cdf0e10cSrcweir             for (sal_uInt16 tindex = 0; tindex < tlen;  tindex++)
617cdf0e10cSrcweir             {
618cdf0e10cSrcweir                 if (pCC->getCharacterType(aStr,tindex) &
619cdf0e10cSrcweir                    ::com::sun::star::i18n::KCharacterType::UPPER) nc++;
620cdf0e10cSrcweir             }
621cdf0e10cSrcweir 
622cdf0e10cSrcweir             if (nc == 0)
623cdf0e10cSrcweir                 return (sal_uInt16) CAPTYPE_NOCAP;
624cdf0e10cSrcweir             if (nc == tlen)
625cdf0e10cSrcweir                 return (sal_uInt16) CAPTYPE_ALLCAP;
626cdf0e10cSrcweir             if ((nc == 1) && (pCC->getCharacterType(aStr,0) &
627cdf0e10cSrcweir                   ::com::sun::star::i18n::KCharacterType::UPPER))
628cdf0e10cSrcweir                 return (sal_uInt16) CAPTYPE_INITCAP;
629cdf0e10cSrcweir 
630cdf0e10cSrcweir             return (sal_uInt16) CAPTYPE_MIXED;
631cdf0e10cSrcweir         }
632cdf0e10cSrcweir         return (sal_uInt16) CAPTYPE_UNKNOWN;
633cdf0e10cSrcweir }
634cdf0e10cSrcweir 
635cdf0e10cSrcweir 
636cdf0e10cSrcweir 
637cdf0e10cSrcweir OUString SAL_CALL Thesaurus::makeLowerCase(const OUString& aTerm, CharClass * pCC)
638cdf0e10cSrcweir {
639cdf0e10cSrcweir     if (pCC)
640cdf0e10cSrcweir         return pCC->toLower_rtl(aTerm, 0, aTerm.getLength());
641cdf0e10cSrcweir     return aTerm;
642cdf0e10cSrcweir }
643cdf0e10cSrcweir 
644cdf0e10cSrcweir 
645cdf0e10cSrcweir OUString SAL_CALL Thesaurus::makeUpperCase(const OUString& aTerm, CharClass * pCC)
646cdf0e10cSrcweir {
647cdf0e10cSrcweir     if (pCC)
648cdf0e10cSrcweir         return pCC->toUpper_rtl(aTerm, 0, aTerm.getLength());
649cdf0e10cSrcweir     return aTerm;
650cdf0e10cSrcweir }
651cdf0e10cSrcweir 
652cdf0e10cSrcweir 
653cdf0e10cSrcweir OUString SAL_CALL Thesaurus::makeInitCap(const OUString& aTerm, CharClass * pCC)
654cdf0e10cSrcweir {
655cdf0e10cSrcweir     sal_Int32 tlen = aTerm.getLength();
656cdf0e10cSrcweir     if ((pCC) && (tlen))
657cdf0e10cSrcweir     {
658cdf0e10cSrcweir         OUString bTemp = aTerm.copy(0,1);
659cdf0e10cSrcweir         if (tlen > 1)
660cdf0e10cSrcweir         {
661cdf0e10cSrcweir             return ( pCC->toUpper_rtl(bTemp, 0, 1)
662cdf0e10cSrcweir                      + pCC->toLower_rtl(aTerm,1,(tlen-1)) );
663cdf0e10cSrcweir         }
664cdf0e10cSrcweir 
665cdf0e10cSrcweir         return pCC->toUpper_rtl(bTemp, 0, 1);
666cdf0e10cSrcweir     }
667cdf0e10cSrcweir     return aTerm;
668cdf0e10cSrcweir }
669cdf0e10cSrcweir 
670cdf0e10cSrcweir 
671cdf0e10cSrcweir 
672cdf0e10cSrcweir void SAL_CALL Thesaurus::dispose()
673cdf0e10cSrcweir 		throw(RuntimeException)
674cdf0e10cSrcweir {
675cdf0e10cSrcweir 	MutexGuard	aGuard( GetLinguMutex() );
676cdf0e10cSrcweir 
677cdf0e10cSrcweir 	if (!bDisposing)
678cdf0e10cSrcweir 	{
679cdf0e10cSrcweir 		bDisposing = sal_True;
680cdf0e10cSrcweir 		EventObject	aEvtObj( (XThesaurus *) this );
681cdf0e10cSrcweir 		aEvtListeners.disposeAndClear( aEvtObj );
682cdf0e10cSrcweir 	}
683cdf0e10cSrcweir }
684cdf0e10cSrcweir 
685cdf0e10cSrcweir 
686cdf0e10cSrcweir void SAL_CALL Thesaurus::addEventListener( const Reference< XEventListener >& rxListener )
687cdf0e10cSrcweir 		throw(RuntimeException)
688cdf0e10cSrcweir {
689cdf0e10cSrcweir 	MutexGuard	aGuard( GetLinguMutex() );
690cdf0e10cSrcweir 
691cdf0e10cSrcweir 	if (!bDisposing && rxListener.is())
692cdf0e10cSrcweir 		aEvtListeners.addInterface( rxListener );
693cdf0e10cSrcweir }
694cdf0e10cSrcweir 
695cdf0e10cSrcweir 
696cdf0e10cSrcweir void SAL_CALL Thesaurus::removeEventListener( const Reference< XEventListener >& rxListener )
697cdf0e10cSrcweir 		throw(RuntimeException)
698cdf0e10cSrcweir {
699cdf0e10cSrcweir 	MutexGuard	aGuard( GetLinguMutex() );
700cdf0e10cSrcweir 
701cdf0e10cSrcweir 	if (!bDisposing && rxListener.is())
702cdf0e10cSrcweir 		aEvtListeners.removeInterface( rxListener );
703cdf0e10cSrcweir }
704cdf0e10cSrcweir 
705cdf0e10cSrcweir 
706cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////
707cdf0e10cSrcweir // Service specific part
708cdf0e10cSrcweir //
709cdf0e10cSrcweir 
710cdf0e10cSrcweir OUString SAL_CALL Thesaurus::getImplementationName()
711cdf0e10cSrcweir 		throw(RuntimeException)
712cdf0e10cSrcweir {
713cdf0e10cSrcweir 	MutexGuard	aGuard( GetLinguMutex() );
714cdf0e10cSrcweir 	return getImplementationName_Static();
715cdf0e10cSrcweir }
716cdf0e10cSrcweir 
717cdf0e10cSrcweir 
718cdf0e10cSrcweir sal_Bool SAL_CALL Thesaurus::supportsService( const OUString& ServiceName )
719cdf0e10cSrcweir 		throw(RuntimeException)
720cdf0e10cSrcweir {
721cdf0e10cSrcweir 	MutexGuard	aGuard( GetLinguMutex() );
722cdf0e10cSrcweir 
723cdf0e10cSrcweir 	Sequence< OUString > aSNL = getSupportedServiceNames();
724cdf0e10cSrcweir 	const OUString * pArray = aSNL.getConstArray();
725cdf0e10cSrcweir 	for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
726cdf0e10cSrcweir 		if( pArray[i] == ServiceName )
727cdf0e10cSrcweir 			return sal_True;
728cdf0e10cSrcweir 	return sal_False;
729cdf0e10cSrcweir }
730cdf0e10cSrcweir 
731cdf0e10cSrcweir 
732cdf0e10cSrcweir Sequence< OUString > SAL_CALL Thesaurus::getSupportedServiceNames()
733cdf0e10cSrcweir 		throw(RuntimeException)
734cdf0e10cSrcweir {
735cdf0e10cSrcweir 	MutexGuard	aGuard( GetLinguMutex() );
736cdf0e10cSrcweir 	return getSupportedServiceNames_Static();
737cdf0e10cSrcweir }
738cdf0e10cSrcweir 
739cdf0e10cSrcweir 
740cdf0e10cSrcweir Sequence< OUString > Thesaurus::getSupportedServiceNames_Static()
741cdf0e10cSrcweir 		throw()
742cdf0e10cSrcweir {
743cdf0e10cSrcweir 	MutexGuard	aGuard( GetLinguMutex() );
744cdf0e10cSrcweir 
745cdf0e10cSrcweir 	Sequence< OUString > aSNS( 1 );	// auch mehr als 1 Service moeglich
746cdf0e10cSrcweir 	aSNS.getArray()[0] = A2OU( SN_THESAURUS );
747cdf0e10cSrcweir 	return aSNS;
748cdf0e10cSrcweir }
749cdf0e10cSrcweir 
750cdf0e10cSrcweir void * SAL_CALL Thesaurus_getFactory( const sal_Char * pImplName,
751cdf0e10cSrcweir 			XMultiServiceFactory * pServiceManager, void *  )
752cdf0e10cSrcweir {
753cdf0e10cSrcweir 	void * pRet = 0;
754cdf0e10cSrcweir 	if ( !Thesaurus::getImplementationName_Static().compareToAscii( pImplName ) )
755cdf0e10cSrcweir 	{
756cdf0e10cSrcweir 
757cdf0e10cSrcweir 		Reference< XSingleServiceFactory > xFactory =
758cdf0e10cSrcweir 			cppu::createOneInstanceFactory(
759cdf0e10cSrcweir 				pServiceManager,
760cdf0e10cSrcweir 				Thesaurus::getImplementationName_Static(),
761cdf0e10cSrcweir 				Thesaurus_CreateInstance,
762cdf0e10cSrcweir 				Thesaurus::getSupportedServiceNames_Static());
763cdf0e10cSrcweir 		// acquire, because we return an interface pointer instead of a reference
764cdf0e10cSrcweir 		xFactory->acquire();
765cdf0e10cSrcweir 		pRet = xFactory.get();
766cdf0e10cSrcweir 	}
767cdf0e10cSrcweir 	return pRet;
768cdf0e10cSrcweir }
769cdf0e10cSrcweir 
770cdf0e10cSrcweir 
771cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////
772cdf0e10cSrcweir 
773cdf0e10cSrcweir 
774cdf0e10cSrcweir #undef CAPTYPE_UNKNOWN
775cdf0e10cSrcweir #undef CAPTYPE_NOCAP
776cdf0e10cSrcweir #undef CAPTYPE_INITCAP
777cdf0e10cSrcweir #undef CAPTYPE_ALLCAP
778cdf0e10cSrcweir #undef CAPTYPE_MIXED
779