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

Generated by: LCOV version 1.10