LCOV - code coverage report
Current view: top level - libreoffice/lingucomponent/source/thesaurus/libnth - nthesimp.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 356 0.0 %
Date: 2012-12-27 Functions: 0 22 0.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10