/src/libreoffice/lingucomponent/source/thesaurus/libnth/nthesimp.cxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
5 | | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
11 | | * Licensed to the Apache Software Foundation (ASF) under one or more |
12 | | * contributor license agreements. See the NOTICE file distributed |
13 | | * with this work for additional information regarding copyright |
14 | | * ownership. The ASF licenses this file to you under the Apache |
15 | | * License, Version 2.0 (the "License"); you may not use this file |
16 | | * except in compliance with the License. You may obtain a copy of |
17 | | * the License at http://www.apache.org/licenses/LICENSE-2.0 . |
18 | | */ |
19 | | |
20 | | #include <com/sun/star/uno/Reference.h> |
21 | | #include <cppuhelper/factory.hxx> |
22 | | #include <cppuhelper/supportsservice.hxx> |
23 | | #include <cppuhelper/weak.hxx> |
24 | | #include <com/sun/star/linguistic2/LinguServiceManager.hpp> |
25 | | #include <com/sun/star/linguistic2/XLinguProperties.hpp> |
26 | | #include <com/sun/star/linguistic2/XSpellChecker1.hpp> |
27 | | #include <i18nlangtag/languagetag.hxx> |
28 | | #include <tools/debug.hxx> |
29 | | #include <comphelper/lok.hxx> |
30 | | #include <comphelper/processfactory.hxx> |
31 | | #include <comphelper/sequence.hxx> |
32 | | #include <osl/mutex.hxx> |
33 | | #include <osl/thread.h> |
34 | | #include <unotools/lingucfg.hxx> |
35 | | #include <unotools/resmgr.hxx> |
36 | | |
37 | | #include <rtl/string.hxx> |
38 | | #include <rtl/textenc.h> |
39 | | |
40 | | #include <svtools/strings.hrc> |
41 | | |
42 | | #include "nthesimp.hxx" |
43 | | #include <linguistic/misc.hxx> |
44 | | #include "nthesdta.hxx" |
45 | | |
46 | | #include <vector> |
47 | | #include <numeric> |
48 | | #include <set> |
49 | | #include <string.h> |
50 | | |
51 | | // XML-header to query SPELLML support |
52 | | constexpr OUStringLiteral SPELLML_SUPPORT = u"<?xml?>"; |
53 | | |
54 | | using namespace osl; |
55 | | using namespace com::sun::star; |
56 | | using namespace com::sun::star::beans; |
57 | | using namespace com::sun::star::lang; |
58 | | using namespace com::sun::star::uno; |
59 | | using namespace com::sun::star::linguistic2; |
60 | | using namespace linguistic; |
61 | | |
62 | | static uno::Reference< XLinguServiceManager2 > GetLngSvcMgr_Impl() |
63 | 0 | { |
64 | 0 | const uno::Reference< XComponentContext >& xContext( comphelper::getProcessComponentContext() ); |
65 | 0 | uno::Reference< XLinguServiceManager2 > xRes = LinguServiceManager::create( xContext ) ; |
66 | 0 | return xRes; |
67 | 0 | } |
68 | | |
69 | | Thesaurus::Thesaurus() : |
70 | 0 | aEvtListeners ( GetLinguMutex() ), pPropHelper(nullptr), bDisposing(false), |
71 | 0 | prevLocale(LANGUAGE_DONTKNOW) |
72 | 0 | { |
73 | 0 | } |
74 | | |
75 | | Thesaurus::~Thesaurus() |
76 | 0 | { |
77 | 0 | mvThesInfo.clear(); |
78 | 0 | if (pPropHelper) |
79 | 0 | { |
80 | 0 | pPropHelper->RemoveAsPropListener(); |
81 | 0 | } |
82 | 0 | } |
83 | | |
84 | | PropertyHelper_Thesaurus& Thesaurus::GetPropHelper_Impl() |
85 | 0 | { |
86 | 0 | if (!pPropHelper) |
87 | 0 | { |
88 | 0 | Reference< XLinguProperties > xPropSet = GetLinguProperties(); |
89 | |
|
90 | 0 | pPropHelper = new PropertyHelper_Thesaurus( static_cast<XThesaurus *>(this), xPropSet ); |
91 | 0 | pPropHelper->AddAsPropListener(); //! after a reference is established |
92 | 0 | } |
93 | 0 | return *pPropHelper; |
94 | 0 | } |
95 | | |
96 | | Sequence< Locale > SAL_CALL Thesaurus::getLocales() |
97 | 0 | { |
98 | 0 | MutexGuard aGuard( GetLinguMutex() ); |
99 | | |
100 | | // this routine should return the locales supported by the installed |
101 | | // dictionaries. |
102 | 0 | if (mvThesInfo.empty()) |
103 | 0 | { |
104 | 0 | SvtLinguConfig aLinguCfg; |
105 | | |
106 | | // get list of dictionaries-to-use |
107 | 0 | std::vector< SvtLinguConfigDictionaryEntry > aDics; |
108 | 0 | uno::Sequence< OUString > aFormatList; |
109 | 0 | aLinguCfg.GetSupportedDictionaryFormatsFor( u"Thesauri"_ustr, |
110 | 0 | u"org.openoffice.lingu.new.Thesaurus"_ustr, aFormatList ); |
111 | 0 | for (const auto& rFormat : aFormatList) |
112 | 0 | { |
113 | 0 | std::vector< SvtLinguConfigDictionaryEntry > aTmpDic( |
114 | 0 | aLinguCfg.GetActiveDictionariesByFormat( rFormat ) ); |
115 | 0 | aDics.insert( aDics.end(), aTmpDic.begin(), aTmpDic.end() ); |
116 | 0 | } |
117 | | |
118 | | //!! for compatibility with old dictionaries (the ones not using extensions |
119 | | //!! or new configuration entries, but still using the dictionary.lst file) |
120 | | //!! Get the list of old style spell checking dictionaries to use... |
121 | 0 | std::vector< SvtLinguConfigDictionaryEntry > aOldStyleDics( |
122 | 0 | GetOldStyleDics( "THES" ) ); |
123 | | |
124 | | // to prefer dictionaries with configuration entries we will only |
125 | | // use those old style dictionaries that add a language that |
126 | | // is not yet supported by the list of new style dictionaries |
127 | 0 | MergeNewStyleDicsAndOldStyleDics( aDics, aOldStyleDics ); |
128 | |
|
129 | 0 | if (!aDics.empty()) |
130 | 0 | { |
131 | | // get supported locales from the dictionaries-to-use... |
132 | 0 | std::set<OUString> aLocaleNamesSet; |
133 | 0 | for (auto const& dict : aDics) |
134 | 0 | { |
135 | 0 | for (const auto& rLocaleName : dict.aLocaleNames) |
136 | 0 | { |
137 | 0 | if (!comphelper::LibreOfficeKit::isAllowlistedLanguage(rLocaleName)) |
138 | 0 | continue; |
139 | | |
140 | 0 | aLocaleNamesSet.insert( rLocaleName ); |
141 | 0 | } |
142 | 0 | } |
143 | | // ... and add them to the resulting sequence |
144 | 0 | std::vector<Locale> aLocalesVec; |
145 | 0 | aLocalesVec.reserve(aLocaleNamesSet.size()); |
146 | |
|
147 | 0 | std::transform(aLocaleNamesSet.begin(), aLocaleNamesSet.end(), std::back_inserter(aLocalesVec), |
148 | 0 | [](const OUString& localeName) -> Locale { return LanguageTag::convertToLocale(localeName); }); |
149 | |
|
150 | 0 | aSuppLocales = comphelper::containerToSequence(aLocalesVec); |
151 | | |
152 | | //! For each dictionary and each locale we need a separate entry. |
153 | | //! If this results in more than one dictionary per locale than (for now) |
154 | | //! it is undefined which dictionary gets used. |
155 | | //! In the future the implementation should support using several dictionaries |
156 | | //! for one locale. |
157 | 0 | sal_Int32 numthes = std::accumulate(aDics.begin(), aDics.end(), 0, |
158 | 0 | [](const sal_Int32 nSum, const SvtLinguConfigDictionaryEntry& dict) { |
159 | 0 | return nSum + dict.aLocaleNames.getLength(); }); |
160 | | |
161 | | // add dictionary information |
162 | 0 | mvThesInfo.resize(numthes); |
163 | |
|
164 | 0 | sal_Int32 k = 0; |
165 | 0 | for (auto const& dict : aDics) |
166 | 0 | { |
167 | 0 | if (dict.aLocaleNames.hasElements() && |
168 | 0 | dict.aLocations.hasElements()) |
169 | 0 | { |
170 | | // currently only one language per dictionary is supported in the actual implementation... |
171 | | // Thus here we work-around this by adding the same dictionary several times. |
172 | | // Once for each of its supported locales. |
173 | 0 | for (const auto& rLocaleName : dict.aLocaleNames) |
174 | 0 | { |
175 | 0 | LanguageTag aLanguageTag(rLocaleName); |
176 | 0 | mvThesInfo[k].aEncoding = RTL_TEXTENCODING_DONTKNOW; |
177 | 0 | mvThesInfo[k].aLocale = aLanguageTag.getLocale(); |
178 | 0 | mvThesInfo[k].aCharSetInfo.reset( new CharClass( std::move(aLanguageTag) ) ); |
179 | | // also both files have to be in the same directory and the |
180 | | // file names must only differ in the extension (.aff/.dic). |
181 | | // Thus we use the first location only and strip the extension part. |
182 | 0 | OUString aLocation = dict.aLocations[0]; |
183 | 0 | sal_Int32 nPos = aLocation.lastIndexOf( '.' ); |
184 | 0 | aLocation = aLocation.copy( 0, nPos ); |
185 | 0 | mvThesInfo[k].aName = aLocation; |
186 | |
|
187 | 0 | ++k; |
188 | 0 | } |
189 | 0 | } |
190 | 0 | } |
191 | 0 | DBG_ASSERT( k == numthes, "index mismatch?" ); |
192 | 0 | } |
193 | 0 | else |
194 | 0 | { |
195 | | /* no dictionary found so register no dictionaries */ |
196 | 0 | mvThesInfo.clear(); |
197 | 0 | aSuppLocales.realloc(0); |
198 | 0 | } |
199 | 0 | } |
200 | |
|
201 | 0 | return aSuppLocales; |
202 | 0 | } |
203 | | |
204 | | sal_Bool SAL_CALL Thesaurus::hasLocale(const Locale& rLocale) |
205 | 0 | { |
206 | 0 | MutexGuard aGuard( GetLinguMutex() ); |
207 | |
|
208 | 0 | if (!aSuppLocales.hasElements()) |
209 | 0 | getLocales(); |
210 | |
|
211 | 0 | return comphelper::findValue(aSuppLocales, rLocale) != -1; |
212 | 0 | } |
213 | | |
214 | | Sequence < Reference < css::linguistic2::XMeaning > > SAL_CALL Thesaurus::queryMeanings( |
215 | | const OUString& qTerm, const Locale& rLocale, |
216 | | const css::uno::Sequence< css::beans::PropertyValue >& rProperties) |
217 | 0 | { |
218 | 0 | MutexGuard aGuard( GetLinguMutex() ); |
219 | |
|
220 | 0 | uno::Sequence< Reference< XMeaning > > aMeanings( 1 ); |
221 | 0 | uno::Sequence< Reference< XMeaning > > noMeanings( 0 ); |
222 | 0 | uno::Reference< XLinguServiceManager2 > xLngSvcMgr( GetLngSvcMgr_Impl() ); |
223 | 0 | uno::Reference< XSpellChecker1 > xSpell; |
224 | |
|
225 | 0 | OUString aRTerm(qTerm); |
226 | 0 | OUString aPTerm(qTerm); |
227 | 0 | CapType ct = CapType::UNKNOWN; |
228 | 0 | sal_Int32 stem = 0; |
229 | 0 | sal_Int32 stem2 = 0; |
230 | |
|
231 | 0 | LanguageType nLanguage = LinguLocaleToLanguage( rLocale ); |
232 | |
|
233 | 0 | if (LinguIsUnspecified( nLanguage) || aRTerm.isEmpty()) |
234 | 0 | return noMeanings; |
235 | | |
236 | 0 | if (!hasLocale( rLocale )) |
237 | | #ifdef LINGU_EXCEPTIONS |
238 | | throw( IllegalArgumentException() ); |
239 | | #else |
240 | 0 | return noMeanings; |
241 | 0 | #endif |
242 | | |
243 | 0 | if (prevTerm == qTerm && prevLocale == nLanguage) |
244 | 0 | return prevMeanings; |
245 | | |
246 | 0 | mentry * pmean = nullptr; |
247 | 0 | sal_Int32 nmean = 0; |
248 | |
|
249 | 0 | PropertyHelper_Thesaurus &rHelper = GetPropHelper(); |
250 | 0 | rHelper.SetTmpPropVals( rProperties ); |
251 | |
|
252 | 0 | MyThes * pTH = nullptr; |
253 | 0 | rtl_TextEncoding eEnc = RTL_TEXTENCODING_DONTKNOW; |
254 | 0 | CharClass * pCC = nullptr; |
255 | | |
256 | | // find the first thesaurus that matches the locale |
257 | 0 | for (size_t i =0; i < mvThesInfo.size(); i++) |
258 | 0 | { |
259 | 0 | if (rLocale == mvThesInfo[i].aLocale) |
260 | 0 | { |
261 | | // open up and initialize this thesaurus if need be |
262 | 0 | if (!mvThesInfo[i].aThes) |
263 | 0 | { |
264 | 0 | OUString datpath = mvThesInfo[i].aName + ".dat"; |
265 | 0 | OUString idxpath = mvThesInfo[i].aName + ".idx"; |
266 | 0 | OUString ndat; |
267 | 0 | OUString nidx; |
268 | 0 | osl::FileBase::getSystemPathFromFileURL(datpath,ndat); |
269 | 0 | osl::FileBase::getSystemPathFromFileURL(idxpath,nidx); |
270 | |
|
271 | | #if defined(_WIN32) |
272 | | // MyThes waits UTF-8 encoded paths with \\?\ long path prefix. |
273 | | OString aTmpidx = Win_AddLongPathPrefix(OUStringToOString(nidx, RTL_TEXTENCODING_UTF8)); |
274 | | OString aTmpdat = Win_AddLongPathPrefix(OUStringToOString(ndat, RTL_TEXTENCODING_UTF8)); |
275 | | #else |
276 | 0 | OString aTmpidx(OU2ENC(nidx,osl_getThreadTextEncoding())); |
277 | 0 | OString aTmpdat(OU2ENC(ndat,osl_getThreadTextEncoding())); |
278 | 0 | #endif |
279 | |
|
280 | 0 | mvThesInfo[i].aThes.reset( new MyThes(aTmpidx.getStr(),aTmpdat.getStr()) ); |
281 | 0 | mvThesInfo[i].aEncoding = getTextEncodingFromCharset(mvThesInfo[i].aThes->get_th_encoding()); |
282 | 0 | } |
283 | 0 | pTH = mvThesInfo[i].aThes.get(); |
284 | 0 | eEnc = mvThesInfo[i].aEncoding; |
285 | 0 | pCC = mvThesInfo[i].aCharSetInfo.get(); |
286 | |
|
287 | 0 | if (pTH) |
288 | 0 | break; |
289 | 0 | } |
290 | 0 | } |
291 | | |
292 | | // we don't want to work with a default text encoding since following incorrect |
293 | | // results may occur only for specific text and thus may be hard to notice. |
294 | | // Thus better always make a clean exit here if the text encoding is in question. |
295 | | // Hopefully something not working at all will raise proper attention quickly. ;-) |
296 | 0 | DBG_ASSERT( eEnc != RTL_TEXTENCODING_DONTKNOW, "failed to get text encoding! (maybe incorrect encoding string in file)" ); |
297 | 0 | if (eEnc == RTL_TEXTENCODING_DONTKNOW) |
298 | 0 | return noMeanings; |
299 | | |
300 | 0 | while (pTH) |
301 | 0 | { |
302 | | // convert word to all lower case for searching |
303 | 0 | if (!stem) |
304 | 0 | ct = capitalType(aRTerm, pCC); |
305 | 0 | OUString nTerm(makeLowerCase(aRTerm, pCC)); |
306 | 0 | OString aTmp( OU2ENC(nTerm, eEnc) ); |
307 | 0 | nmean = pTH->Lookup(aTmp.getStr(),aTmp.getLength(),&pmean); |
308 | |
|
309 | 0 | if (nmean) |
310 | 0 | aMeanings.realloc( nmean ); |
311 | |
|
312 | 0 | mentry * pe = pmean; |
313 | 0 | OUString codeTerm = qTerm; |
314 | 0 | Reference< XSpellAlternatives > xTmpRes2; |
315 | |
|
316 | 0 | if (stem) |
317 | 0 | { |
318 | 0 | xTmpRes2 = xSpell->spell( "<?xml?><query type='analyze'><word>" + |
319 | 0 | aPTerm + "</word></query>", static_cast<sal_uInt16>(nLanguage), rProperties ); |
320 | 0 | if (xTmpRes2.is()) |
321 | 0 | { |
322 | 0 | Sequence<OUString>seq = xTmpRes2->getAlternatives(); |
323 | 0 | if (seq.hasElements()) |
324 | 0 | { |
325 | 0 | codeTerm = seq[0]; |
326 | 0 | stem2 = 1; |
327 | 0 | } |
328 | 0 | } |
329 | 0 | } |
330 | |
|
331 | 0 | for (int j = 0; j < nmean; j++) |
332 | 0 | { |
333 | 0 | int count = pe->count; |
334 | 0 | if (count) |
335 | 0 | { |
336 | 0 | Sequence< OUString > aStr( count ); |
337 | 0 | OUString *pStr = aStr.getArray(); |
338 | |
|
339 | 0 | for (int i=0; i < count; i++) |
340 | 0 | { |
341 | 0 | OUString sTerm(pe->psyns[i],strlen(pe->psyns[i]),eEnc ); |
342 | 0 | sal_Int32 catpos = sTerm.indexOf('('); |
343 | 0 | OUString catst; |
344 | 0 | if (catpos > 2) |
345 | 0 | { |
346 | | // remove category name for affixation and casing |
347 | 0 | catst = OUString::Concat(" ") + sTerm.subView(catpos); |
348 | 0 | sTerm = sTerm.copy(0, catpos); |
349 | 0 | sTerm = sTerm.trim(); |
350 | 0 | } |
351 | | // generate synonyms with affixes |
352 | 0 | if (stem && stem2) |
353 | 0 | { |
354 | 0 | Reference< XSpellAlternatives > xTmpRes = xSpell->spell( "<?xml?><query type='generate'><word>" + |
355 | 0 | sTerm + "</word>" + codeTerm + "</query>", static_cast<sal_uInt16>(nLanguage), rProperties ); |
356 | 0 | if (xTmpRes.is()) |
357 | 0 | { |
358 | 0 | Sequence<OUString>seq = xTmpRes->getAlternatives(); |
359 | 0 | if (seq.hasElements()) |
360 | 0 | sTerm = seq[0]; |
361 | 0 | } |
362 | 0 | } |
363 | |
|
364 | 0 | CapType ct1 = capitalType(sTerm, pCC); |
365 | 0 | if (CapType::MIXED == ct1) |
366 | 0 | ct = ct1; |
367 | 0 | OUString cTerm; |
368 | 0 | switch (ct) |
369 | 0 | { |
370 | 0 | case CapType::ALLCAP: |
371 | 0 | cTerm = makeUpperCase(sTerm, pCC); |
372 | 0 | break; |
373 | 0 | case CapType::INITCAP: |
374 | 0 | cTerm = makeInitCap(sTerm, pCC); |
375 | 0 | break; |
376 | 0 | default: |
377 | 0 | cTerm = sTerm; |
378 | 0 | break; |
379 | 0 | } |
380 | 0 | pStr[i] = OUString( cTerm + catst); |
381 | 0 | } |
382 | 0 | rtl::Reference<Meaning> pMn = new Meaning(aRTerm); |
383 | 0 | OUString dTerm(pe->defn,strlen(pe->defn),eEnc ); |
384 | 0 | pMn->SetMeaning(dTerm); |
385 | 0 | pMn->SetSynonyms(aStr); |
386 | 0 | Reference<XMeaning>* pMeaning = aMeanings.getArray(); |
387 | 0 | pMeaning[j] = pMn; |
388 | 0 | } |
389 | 0 | pe++; |
390 | 0 | } |
391 | 0 | pTH->CleanUpAfterLookup(&pmean,nmean); |
392 | |
|
393 | 0 | if (nmean) |
394 | 0 | { |
395 | 0 | prevTerm = qTerm; |
396 | 0 | prevMeanings = aMeanings; |
397 | 0 | prevLocale = nLanguage; |
398 | 0 | return aMeanings; |
399 | 0 | } |
400 | | |
401 | 0 | if (stem || !xLngSvcMgr.is()) |
402 | 0 | return noMeanings; |
403 | 0 | stem = 1; |
404 | |
|
405 | 0 | xSpell.set( xLngSvcMgr->getSpellChecker(), UNO_QUERY ); |
406 | 0 | if (!xSpell.is() || !xSpell->isValid( SPELLML_SUPPORT, static_cast<sal_uInt16>(nLanguage), rProperties )) |
407 | 0 | return noMeanings; |
408 | 0 | Reference< XSpellAlternatives > xTmpRes = xSpell->spell( "<?xml?><query type='stem'><word>" + |
409 | 0 | aRTerm + "</word></query>", static_cast<sal_uInt16>(nLanguage), rProperties ); |
410 | 0 | if (xTmpRes.is()) |
411 | 0 | { |
412 | 0 | Sequence<OUString>seq = xTmpRes->getAlternatives(); |
413 | 0 | if (seq.hasElements()) |
414 | 0 | { |
415 | 0 | aRTerm = seq[0]; // XXX Use only the first stem |
416 | 0 | continue; |
417 | 0 | } |
418 | 0 | } |
419 | | |
420 | | // stem the last word of the synonym (for categories after affixation) |
421 | 0 | aRTerm = aRTerm.trim(); |
422 | 0 | sal_Int32 pos = aRTerm.lastIndexOf(' '); |
423 | 0 | if (!pos) |
424 | 0 | return noMeanings; |
425 | 0 | xTmpRes = xSpell->spell( OUString::Concat("<?xml?><query type='stem'><word>") + |
426 | 0 | aRTerm.subView(pos + 1) + "</word></query>", static_cast<sal_uInt16>(nLanguage), rProperties ); |
427 | 0 | if (xTmpRes.is()) |
428 | 0 | { |
429 | 0 | Sequence<OUString>seq = xTmpRes->getAlternatives(); |
430 | 0 | if (seq.hasElements()) |
431 | 0 | { |
432 | 0 | aPTerm = aRTerm.copy(pos + 1); |
433 | 0 | aRTerm = aRTerm.subView(0, pos + 1) + seq[0]; |
434 | | #if 0 |
435 | | for (int i = 0; i < seq.getLength(); i++) |
436 | | { |
437 | | OString o = OUStringToOString(seq[i], RTL_TEXTENCODING_UTF8); |
438 | | fprintf(stderr, "%d: %s\n", i + 1, o.pData->buffer); |
439 | | } |
440 | | #endif |
441 | 0 | continue; |
442 | 0 | } |
443 | 0 | } |
444 | 0 | break; |
445 | 0 | } |
446 | 0 | return noMeanings; |
447 | 0 | } |
448 | | |
449 | | OUString SAL_CALL Thesaurus::getServiceDisplayName(const Locale& rLocale) |
450 | 0 | { |
451 | 0 | std::locale loc(Translate::Create("svt", LanguageTag(rLocale))); |
452 | 0 | return Translate::get(STR_DESCRIPTION_MYTHES, loc); |
453 | 0 | } |
454 | | |
455 | | void SAL_CALL Thesaurus::initialize( const Sequence< Any >& rArguments ) |
456 | 0 | { |
457 | 0 | MutexGuard aGuard( GetLinguMutex() ); |
458 | |
|
459 | 0 | if (pPropHelper) |
460 | 0 | return; |
461 | | |
462 | 0 | sal_Int32 nLen = rArguments.getLength(); |
463 | | // Accept one of two args so we can be compatible with the call site in GetAvailLocales() |
464 | | // linguistic module |
465 | 0 | if (1 == nLen || 2 == nLen) |
466 | 0 | { |
467 | 0 | Reference< XLinguProperties > xPropSet; |
468 | 0 | rArguments[0] >>= xPropSet; |
469 | 0 | assert(xPropSet); |
470 | | |
471 | | //! Pointer allows for access of the non-UNO functions. |
472 | | //! And the reference to the UNO-functions while increasing |
473 | | //! the ref-count and will implicitly free the memory |
474 | | //! when the object is no longer used. |
475 | 0 | pPropHelper = new PropertyHelper_Thesaurus( static_cast<XThesaurus *>(this), xPropSet ); |
476 | 0 | pPropHelper->AddAsPropListener(); //! after a reference is established |
477 | 0 | } |
478 | 0 | else |
479 | 0 | OSL_FAIL( "wrong number of arguments in sequence" ); |
480 | 0 | } |
481 | | |
482 | | OUString Thesaurus::makeLowerCase(const OUString& aTerm, CharClass const * pCC) |
483 | 0 | { |
484 | 0 | if (pCC) |
485 | 0 | return pCC->lowercase(aTerm); |
486 | 0 | return aTerm; |
487 | 0 | } |
488 | | |
489 | | OUString Thesaurus::makeUpperCase(const OUString& aTerm, CharClass const * pCC) |
490 | 0 | { |
491 | 0 | if (pCC) |
492 | 0 | return pCC->uppercase(aTerm); |
493 | 0 | return aTerm; |
494 | 0 | } |
495 | | |
496 | | OUString Thesaurus::makeInitCap(const OUString& aTerm, CharClass const * pCC) |
497 | 0 | { |
498 | 0 | sal_Int32 tlen = aTerm.getLength(); |
499 | 0 | if (pCC && tlen) |
500 | 0 | { |
501 | 0 | OUString bTemp = aTerm.copy(0,1); |
502 | 0 | if (tlen > 1) |
503 | 0 | { |
504 | 0 | return ( pCC->uppercase(bTemp, 0, 1) |
505 | 0 | + pCC->lowercase(aTerm,1,(tlen-1)) ); |
506 | 0 | } |
507 | | |
508 | 0 | return pCC->uppercase(bTemp, 0, 1); |
509 | 0 | } |
510 | 0 | return aTerm; |
511 | 0 | } |
512 | | |
513 | | void SAL_CALL Thesaurus::dispose() |
514 | 0 | { |
515 | 0 | MutexGuard aGuard( GetLinguMutex() ); |
516 | |
|
517 | 0 | if (!bDisposing) |
518 | 0 | { |
519 | 0 | bDisposing = true; |
520 | 0 | EventObject aEvtObj( static_cast<XThesaurus *>(this) ); |
521 | 0 | aEvtListeners.disposeAndClear( aEvtObj ); |
522 | 0 | if (pPropHelper) |
523 | 0 | { |
524 | 0 | pPropHelper->RemoveAsPropListener(); |
525 | 0 | delete pPropHelper; |
526 | 0 | pPropHelper = nullptr; |
527 | 0 | } |
528 | 0 | } |
529 | 0 | } |
530 | | |
531 | | void SAL_CALL Thesaurus::addEventListener( const Reference< XEventListener >& rxListener ) |
532 | 0 | { |
533 | 0 | MutexGuard aGuard( GetLinguMutex() ); |
534 | |
|
535 | 0 | if (!bDisposing && rxListener.is()) |
536 | 0 | aEvtListeners.addInterface( rxListener ); |
537 | 0 | } |
538 | | |
539 | | void SAL_CALL Thesaurus::removeEventListener( const Reference< XEventListener >& rxListener ) |
540 | 0 | { |
541 | 0 | MutexGuard aGuard( GetLinguMutex() ); |
542 | |
|
543 | 0 | if (!bDisposing && rxListener.is()) |
544 | 0 | aEvtListeners.removeInterface( rxListener ); |
545 | 0 | } |
546 | | |
547 | | // Service specific part |
548 | | OUString SAL_CALL Thesaurus::getImplementationName() |
549 | 0 | { |
550 | 0 | return u"org.openoffice.lingu.new.Thesaurus"_ustr; |
551 | 0 | } |
552 | | |
553 | | sal_Bool SAL_CALL Thesaurus::supportsService( const OUString& ServiceName ) |
554 | 0 | { |
555 | 0 | return cppu::supportsService(this, ServiceName); |
556 | 0 | } |
557 | | |
558 | | Sequence< OUString > SAL_CALL Thesaurus::getSupportedServiceNames() |
559 | 0 | { |
560 | 0 | return { SN_THESAURUS }; |
561 | 0 | } |
562 | | |
563 | | extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* |
564 | | lingucomponent_Thesaurus_get_implementation( |
565 | | css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any> const&) |
566 | 0 | { |
567 | 0 | return cppu::acquire(new Thesaurus()); |
568 | 0 | } |
569 | | |
570 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |