LCOV - code coverage report
Current view: top level - lingucomponent/source/spellcheck/spell - sspellimp.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 191 303 63.0 %
Date: 2014-04-11 Functions: 15 23 65.2 %
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             : #include <com/sun/star/uno/Reference.h>
      21             : #include <com/sun/star/linguistic2/XSearchableDictionaryList.hpp>
      22             : 
      23             : #include <com/sun/star/linguistic2/SpellFailure.hpp>
      24             : #include <cppuhelper/factory.hxx>
      25             : #include <cppuhelper/supportsservice.hxx>
      26             : #include <com/sun/star/registry/XRegistryKey.hpp>
      27             : #include <tools/debug.hxx>
      28             : #include <osl/mutex.hxx>
      29             : 
      30             : #include <lingutil.hxx>
      31             : #include <hunspell.hxx>
      32             : #include <dictmgr.hxx>
      33             : #include <sspellimp.hxx>
      34             : 
      35             : #include <linguistic/lngprops.hxx>
      36             : #include <linguistic/spelldta.hxx>
      37             : #include <i18nlangtag/languagetag.hxx>
      38             : #include <unotools/pathoptions.hxx>
      39             : #include <unotools/lingucfg.hxx>
      40             : #include <unotools/useroptions.hxx>
      41             : #include <osl/file.hxx>
      42             : #include <rtl/ustrbuf.hxx>
      43             : #include <rtl/textenc.h>
      44             : 
      45             : #include <list>
      46             : #include <set>
      47             : #include <string.h>
      48             : 
      49             : using namespace utl;
      50             : using namespace osl;
      51             : using namespace com::sun::star;
      52             : using namespace com::sun::star::beans;
      53             : using namespace com::sun::star::lang;
      54             : using namespace com::sun::star::uno;
      55             : using namespace com::sun::star::linguistic2;
      56             : using namespace linguistic;
      57             : 
      58             : // XML-header of SPELLML queries
      59             : #define SPELLML_HEADER "<?xml?>"
      60             : 
      61          21 : SpellChecker::SpellChecker() :
      62             :     aDicts(NULL),
      63             :     aDEncs(NULL),
      64             :     aDLocs(NULL),
      65             :     aDNames(NULL),
      66             :     numdict(0),
      67          21 :     aEvtListeners(GetLinguMutex()),
      68             :     pPropHelper(NULL),
      69          42 :     bDisposing(false)
      70             : {
      71          21 : }
      72             : 
      73          48 : SpellChecker::~SpellChecker()
      74             : {
      75          16 :     if (aDicts)
      76             :     {
      77          32 :        for (int i = 0; i < numdict; ++i)
      78             :        {
      79          16 :             delete aDicts[i];
      80             :        }
      81          16 :        delete[] aDicts;
      82             :     }
      83          16 :     delete[] aDEncs;
      84          16 :     delete[] aDLocs;
      85          16 :     delete[] aDNames;
      86          16 :     if (pPropHelper)
      87             :     {
      88           0 :         pPropHelper->RemoveAsPropListener();
      89           0 :         delete pPropHelper;
      90             :     }
      91          32 : }
      92             : 
      93          18 : PropertyHelper_Spelling & SpellChecker::GetPropHelper_Impl()
      94             : {
      95          18 :     if (!pPropHelper)
      96             :     {
      97          18 :         Reference< XLinguProperties >   xPropSet( GetLinguProperties(), UNO_QUERY );
      98             : 
      99          18 :         pPropHelper = new PropertyHelper_Spelling( (XSpellChecker *) this, xPropSet );
     100          18 :         pPropHelper->AddAsPropListener();   //! after a reference is established
     101             :     }
     102          18 :     return *pPropHelper;
     103             : }
     104             : 
     105          42 : Sequence< Locale > SAL_CALL SpellChecker::getLocales()
     106             :         throw(RuntimeException, std::exception)
     107             : {
     108          42 :     MutexGuard  aGuard( GetLinguMutex() );
     109             : 
     110             :     // this routine should return the locales supported by the installed
     111             :     // dictionaries.
     112          42 :     if (!numdict)
     113             :     {
     114          21 :         SvtLinguConfig aLinguCfg;
     115             : 
     116             :         // get list of extension dictionaries-to-use
     117             :         // (or better speaking: the list of dictionaries using the
     118             :         // new configuration entries).
     119          42 :         std::list< SvtLinguConfigDictionaryEntry > aDics;
     120          42 :         uno::Sequence< OUString > aFormatList;
     121             :         aLinguCfg.GetSupportedDictionaryFormatsFor( "SpellCheckers",
     122          21 :                 "org.openoffice.lingu.MySpellSpellChecker", aFormatList );
     123          21 :         sal_Int32 nLen = aFormatList.getLength();
     124          42 :         for (sal_Int32 i = 0;  i < nLen;  ++i)
     125             :         {
     126             :             std::vector< SvtLinguConfigDictionaryEntry > aTmpDic(
     127          21 :                     aLinguCfg.GetActiveDictionariesByFormat( aFormatList[i] ) );
     128          21 :             aDics.insert( aDics.end(), aTmpDic.begin(), aTmpDic.end() );
     129          21 :         }
     130             : 
     131             :         //!! for compatibility with old dictionaries (the ones not using extensions
     132             :         //!! or new configuration entries, but still using the dictionary.lst file)
     133             :         //!! Get the list of old style spell checking dictionaries to use...
     134             :         std::vector< SvtLinguConfigDictionaryEntry > aOldStyleDics(
     135          42 :                 GetOldStyleDics( "DICT" ) );
     136             : 
     137             :         // to prefer dictionaries with configuration entries we will only
     138             :         // use those old style dictionaries that add a language that
     139             :         // is not yet supported by the list od new style dictionaries
     140          21 :         MergeNewStyleDicsAndOldStyleDics( aDics, aOldStyleDics );
     141             : 
     142          21 :         if (!aDics.empty())
     143             :         {
     144             :             // get supported locales from the dictionaries-to-use...
     145          21 :             sal_Int32 k = 0;
     146          21 :             std::set< OUString, lt_rtl_OUString > aLocaleNamesSet;
     147          21 :             std::list< SvtLinguConfigDictionaryEntry >::const_iterator aDictIt;
     148          42 :             for (aDictIt = aDics.begin();  aDictIt != aDics.end();  ++aDictIt)
     149             :             {
     150          21 :                 uno::Sequence< OUString > aLocaleNames( aDictIt->aLocaleNames );
     151          21 :                 sal_Int32 nLen2 = aLocaleNames.getLength();
     152          42 :                 for (k = 0;  k < nLen2;  ++k)
     153             :                 {
     154          21 :                     aLocaleNamesSet.insert( aLocaleNames[k] );
     155             :                 }
     156          21 :             }
     157             :             // ... and add them to the resulting sequence
     158          21 :             aSuppLocales.realloc( aLocaleNamesSet.size() );
     159          21 :             std::set< OUString, lt_rtl_OUString >::const_iterator aItB;
     160          21 :             k = 0;
     161          42 :             for (aItB = aLocaleNamesSet.begin();  aItB != aLocaleNamesSet.end();  ++aItB)
     162             :             {
     163          21 :                 Locale aTmp( LanguageTag::convertToLocale( *aItB ));
     164          21 :                 aSuppLocales[k++] = aTmp;
     165          21 :             }
     166             : 
     167             :             //! For each dictionary and each locale we need a separate entry.
     168             :             //! If this results in more than one dictionary per locale than (for now)
     169             :             //! it is undefined which dictionary gets used.
     170             :             //! In the future the implementation should support using several dictionaries
     171             :             //! for one locale.
     172          21 :             numdict = 0;
     173          42 :             for (aDictIt = aDics.begin();  aDictIt != aDics.end();  ++aDictIt)
     174          21 :                 numdict = numdict + aDictIt->aLocaleNames.getLength();
     175             : 
     176             :             // add dictionary information
     177          21 :             aDicts  = new Hunspell* [numdict];
     178          21 :             aDEncs  = new rtl_TextEncoding [numdict];
     179          21 :             aDLocs  = new Locale [numdict];
     180          21 :             aDNames = new OUString [numdict];
     181          21 :             k = 0;
     182          42 :             for (aDictIt = aDics.begin();  aDictIt != aDics.end();  ++aDictIt)
     183             :             {
     184          42 :                 if (aDictIt->aLocaleNames.getLength() > 0 &&
     185          21 :                     aDictIt->aLocations.getLength() > 0)
     186             :                 {
     187          21 :                     uno::Sequence< OUString > aLocaleNames( aDictIt->aLocaleNames );
     188          21 :                     sal_Int32 nLocales = aLocaleNames.getLength();
     189             : 
     190             :                     // currently only one language per dictionary is supported in the actual implementation...
     191             :                     // Thus here we work-around this by adding the same dictionary several times.
     192             :                     // Once for each of it's supported locales.
     193          42 :                     for (sal_Int32 i = 0;  i < nLocales;  ++i)
     194             :                     {
     195          21 :                         aDicts[k]  = NULL;
     196          21 :                         aDEncs[k]  = RTL_TEXTENCODING_DONTKNOW;
     197          21 :                         aDLocs[k]  = LanguageTag::convertToLocale( aLocaleNames[i] );
     198             :                         // also both files have to be in the same directory and the
     199             :                         // file names must only differ in the extension (.aff/.dic).
     200             :                         // Thus we use the first location only and strip the extension part.
     201          21 :                         OUString aLocation = aDictIt->aLocations[0];
     202          21 :                         sal_Int32 nPos = aLocation.lastIndexOf( '.' );
     203          21 :                         aLocation = aLocation.copy( 0, nPos );
     204          21 :                         aDNames[k] = aLocation;
     205             : 
     206          21 :                         ++k;
     207          42 :                     }
     208             :                 }
     209             :             }
     210          21 :             DBG_ASSERT( k == numdict, "index mismatch?" );
     211             :         }
     212             :         else
     213             :         {
     214             :             // no dictionary found so register no dictionaries
     215           0 :             numdict = 0;
     216           0 :             delete[] aDicts;
     217           0 :             aDicts  = NULL;
     218           0 :             delete[] aDEncs;
     219           0 :             aDEncs = NULL;
     220           0 :             delete[] aDLocs;
     221           0 :             aDLocs  = NULL;
     222           0 :             delete[] aDNames;
     223           0 :             aDNames = NULL;
     224           0 :             aSuppLocales.realloc(0);
     225          21 :         }
     226             :     }
     227             : 
     228          42 :     return aSuppLocales;
     229             : }
     230             : 
     231       16754 : sal_Bool SAL_CALL SpellChecker::hasLocale(const Locale& rLocale)
     232             :         throw(RuntimeException, std::exception)
     233             : {
     234       16754 :     MutexGuard  aGuard( GetLinguMutex() );
     235             : 
     236       16754 :     sal_Bool bRes = sal_False;
     237       16754 :     if (!aSuppLocales.getLength())
     238           0 :         getLocales();
     239             : 
     240       16754 :     const Locale *pLocale = aSuppLocales.getConstArray();
     241       16754 :     sal_Int32 nLen = aSuppLocales.getLength();
     242       16754 :     for (sal_Int32 i = 0;  i < nLen;  ++i)
     243             :     {
     244       16754 :         if (rLocale == pLocale[i])
     245             :         {
     246       16754 :             bRes = sal_True;
     247       16754 :             break;
     248             :         }
     249             :     }
     250       16754 :     return bRes;
     251             : }
     252             : 
     253        6603 : sal_Int16 SpellChecker::GetSpellFailure( const OUString &rWord, const Locale &rLocale )
     254             : {
     255        6603 :     Hunspell * pMS = NULL;
     256        6603 :     rtl_TextEncoding eEnc = RTL_TEXTENCODING_DONTKNOW;
     257             : 
     258             :     // initialize a myspell object for each dictionary once
     259             :     // (note: mutex is held higher up in isValid)
     260             : 
     261        6603 :     sal_Int16 nRes = -1;
     262             : 
     263             :     // first handle smart quotes both single and double
     264        6603 :     OUStringBuffer rBuf(rWord);
     265        6603 :     sal_Int32 n = rBuf.getLength();
     266             :     sal_Unicode c;
     267        6603 :     sal_Int32 extrachar = 0;
     268             : 
     269       89425 :     for (sal_Int32 ix=0; ix < n; ix++)
     270             :     {
     271       82822 :         c = rBuf[ix];
     272       82822 :         if ((c == 0x201C) || (c == 0x201D))
     273           0 :             rBuf[ix] = (sal_Unicode)0x0022;
     274       82822 :         else if ((c == 0x2018) || (c == 0x2019))
     275           0 :             rBuf[ix] = (sal_Unicode)0x0027;
     276             : 
     277             :         // recognize words with Unicode ligatures and ZWNJ/ZWJ characters (only
     278             :         // with 8-bit encoded dictionaries. For UTF-8 encoded dictionaries
     279             :         // set ICONV and IGNORE aff file options, if needed.)
     280       82822 :         else if ((c == 0x200C) || (c == 0x200D) ||
     281           1 :             ((c >= 0xFB00) && (c <= 0xFB04)))
     282           0 :                 extrachar = 1;
     283             :     }
     284       13206 :     OUString nWord(rBuf.makeStringAndClear());
     285             : 
     286        6603 :     if (n)
     287             :     {
     288       12166 :         for (sal_Int32 i = 0; i < numdict; ++i)
     289             :         {
     290        6603 :             pMS = NULL;
     291        6603 :             eEnc = RTL_TEXTENCODING_DONTKNOW;
     292             : 
     293        6603 :             if (rLocale == aDLocs[i])
     294             :             {
     295        6603 :                 if (!aDicts[i])
     296             :                 {
     297          18 :                     OUString dicpath = aDNames[i] + ".dic";
     298          36 :                     OUString affpath = aDNames[i] + ".aff";
     299          36 :                     OUString dict;
     300          36 :                     OUString aff;
     301          18 :                     osl::FileBase::getSystemPathFromFileURL(dicpath,dict);
     302          18 :                     osl::FileBase::getSystemPathFromFileURL(affpath,aff);
     303          36 :                     OString aTmpaff(OU2ENC(aff,osl_getThreadTextEncoding()));
     304          36 :                     OString aTmpdict(OU2ENC(dict,osl_getThreadTextEncoding()));
     305             : 
     306             : #if defined(WNT)
     307             :                     // workaround for Windows specific problem that the
     308             :                     // path length in calls to 'fopen' is limted to somewhat
     309             :                     // about 120+ characters which will usually be exceed when
     310             :                     // using dictionaries as extensions.
     311             :                     aTmpaff = Win_GetShortPathName( aff );
     312             :                     aTmpdict = Win_GetShortPathName( dict );
     313             : #endif
     314             : 
     315          18 :                     aDicts[i] = new Hunspell(aTmpaff.getStr(),aTmpdict.getStr());
     316          18 :                     aDEncs[i] = RTL_TEXTENCODING_DONTKNOW;
     317          18 :                     if (aDicts[i])
     318          36 :                         aDEncs[i] = getTextEncodingFromCharset(aDicts[i]->get_dic_encoding());
     319             :                 }
     320        6603 :                 pMS = aDicts[i];
     321        6603 :                 eEnc = aDEncs[i];
     322             :             }
     323             : 
     324        6603 :             if (pMS)
     325             :             {
     326             :                 // we don't want to work with a default text encoding since following incorrect
     327             :                 // results may occur only for specific text and thus may be hard to notice.
     328             :                 // Thus better always make a clean exit here if the text encoding is in question.
     329             :                 // Hopefully something not working at all will raise proper attention quickly. ;-)
     330             :                 DBG_ASSERT( eEnc != RTL_TEXTENCODING_DONTKNOW, "failed to get text encoding! (maybe incorrect encoding string in file)" );
     331        6603 :                 if (eEnc == RTL_TEXTENCODING_DONTKNOW)
     332        1040 :                     return -1;
     333             : 
     334        6603 :                 OString aWrd(OU2ENC(nWord,eEnc));
     335        6603 :                 int rVal = pMS->spell((char*)aWrd.getStr());
     336        6603 :                 if (rVal != 1) {
     337        5563 :                     if (extrachar && (eEnc != RTL_TEXTENCODING_UTF8)) {
     338           0 :                         OUStringBuffer mBuf(nWord);
     339           0 :                         n = mBuf.getLength();
     340           0 :                         for (sal_Int32 ix=n-1; ix >= 0; ix--)
     341             :                         {
     342           0 :                           switch (mBuf[ix]) {
     343           0 :                             case 0xFB00: mBuf.remove(ix, 1); mBuf.insert(ix, "ff"); break;
     344           0 :                             case 0xFB01: mBuf.remove(ix, 1); mBuf.insert(ix, "fi"); break;
     345           0 :                             case 0xFB02: mBuf.remove(ix, 1); mBuf.insert(ix, "fl"); break;
     346           0 :                             case 0xFB03: mBuf.remove(ix, 1); mBuf.insert(ix, "ffi"); break;
     347           0 :                             case 0xFB04: mBuf.remove(ix, 1); mBuf.insert(ix, "ffl"); break;
     348             :                             case 0x200C:
     349           0 :                             case 0x200D: mBuf.remove(ix, 1); break;
     350             :                           }
     351             :                         }
     352           0 :                         OUString mWord(mBuf.makeStringAndClear());
     353           0 :                         OString bWrd(OU2ENC(mWord, eEnc));
     354           0 :                         rVal = pMS->spell((char*)bWrd.getStr());
     355           0 :                         if (rVal == 1) return -1;
     356             :                     }
     357        5563 :                     nRes = SpellFailure::SPELLING_ERROR;
     358             :                 } else {
     359        1040 :                     return -1;
     360             :                 }
     361        5563 :                 pMS = NULL;
     362             :             }
     363             :         }
     364             :     }
     365             : 
     366       12166 :     return nRes;
     367             : }
     368             : 
     369        6603 : sal_Bool SAL_CALL SpellChecker::isValid( const OUString& rWord, const Locale& rLocale,
     370             :             const PropertyValues& rProperties )
     371             :         throw(IllegalArgumentException, RuntimeException, std::exception)
     372             : {
     373        6603 :     MutexGuard  aGuard( GetLinguMutex() );
     374             : 
     375        6603 :      if (rLocale == Locale()  ||  rWord.isEmpty())
     376           0 :         return sal_True;
     377             : 
     378        6603 :     if (!hasLocale( rLocale ))
     379           0 :         return sal_True;
     380             : 
     381             :     // return sal_False to process SPELLML requests (they are longer than the header)
     382        6603 :     if (rWord.match(SPELLML_HEADER, 0) && (rWord.getLength() > 10)) return sal_False;
     383             : 
     384             :     // Get property values to be used.
     385             :     // These are be the default values set in the SN_LINGU_PROPERTIES
     386             :     // PropertySet which are overridden by the supplied ones from the
     387             :     // last argument.
     388             :     // You'll probably like to use a simplier solution than the provided
     389             :     // one using the PropertyHelper_Spell.
     390        6603 :     PropertyHelper_Spelling& rHelper = GetPropHelper();
     391        6603 :     rHelper.SetTmpPropVals( rProperties );
     392             : 
     393        6603 :     sal_Int16 nFailure = GetSpellFailure( rWord, rLocale );
     394        6603 :     if (nFailure != -1 && !rWord.match(SPELLML_HEADER, 0))
     395             :     {
     396        5563 :         sal_Int16 nLang = LinguLocaleToLanguage( rLocale );
     397             :         // postprocess result for errors that should be ignored
     398             :         const bool bIgnoreError =
     399       16615 :                 (!rHelper.IsSpellUpperCase()  && IsUpper( rWord, nLang )) ||
     400       22104 :                 (!rHelper.IsSpellWithDigits() && HasDigits( rWord )) ||
     401        6686 :                 (!rHelper.IsSpellCapitalization()  &&  nFailure == SpellFailure::CAPTION_ERROR);
     402        5563 :         if (bIgnoreError)
     403        4440 :             nFailure = -1;
     404             :     }
     405             : 
     406        6603 :     return (nFailure == -1);
     407             : }
     408             : 
     409             : Reference< XSpellAlternatives >
     410           0 :     SpellChecker::GetProposals( const OUString &rWord, const Locale &rLocale )
     411             : {
     412             :     // Retrieves the return values for the 'spell' function call in case
     413             :     // of a misspelled word.
     414             :     // Especially it may give a list of suggested (correct) words:
     415           0 :     Reference< XSpellAlternatives > xRes;
     416             :     // note: mutex is held by higher up by spell which covers both
     417             : 
     418           0 :     Hunspell* pMS = NULL;
     419           0 :     rtl_TextEncoding eEnc = RTL_TEXTENCODING_DONTKNOW;
     420             : 
     421             :     // first handle smart quotes (single and double)
     422           0 :     OUStringBuffer rBuf(rWord);
     423           0 :     sal_Int32 n = rBuf.getLength();
     424             :     sal_Unicode c;
     425           0 :     for (sal_Int32 ix=0; ix < n; ix++)
     426             :     {
     427           0 :         c = rBuf[ix];
     428           0 :         if ((c == 0x201C) || (c == 0x201D))
     429           0 :             rBuf[ix] = (sal_Unicode)0x0022;
     430           0 :         if ((c == 0x2018) || (c == 0x2019))
     431           0 :             rBuf[ix] = (sal_Unicode)0x0027;
     432             :     }
     433           0 :     OUString nWord(rBuf.makeStringAndClear());
     434             : 
     435           0 :     if (n)
     436             :     {
     437           0 :         sal_Int16 nLang = LinguLocaleToLanguage( rLocale );
     438           0 :         int numsug = 0;
     439             : 
     440           0 :         Sequence< OUString > aStr( 0 );
     441           0 :         for (int i = 0; i < numdict; i++)
     442             :         {
     443           0 :             pMS = NULL;
     444           0 :             eEnc = RTL_TEXTENCODING_DONTKNOW;
     445             : 
     446           0 :             if (rLocale == aDLocs[i])
     447             :             {
     448           0 :                 pMS = aDicts[i];
     449           0 :                 eEnc = aDEncs[i];
     450             :             }
     451             : 
     452           0 :             if (pMS)
     453             :             {
     454           0 :                 char ** suglst = NULL;
     455           0 :                 OString aWrd(OU2ENC(nWord,eEnc));
     456           0 :                 int count = pMS->suggest(&suglst, (const char *) aWrd.getStr());
     457             : 
     458           0 :                 if (count)
     459             :                 {
     460           0 :                     aStr.realloc( numsug + count );
     461           0 :                     OUString *pStr = aStr.getArray();
     462           0 :                     for (int ii=0; ii < count; ++ii)
     463             :                     {
     464           0 :                         OUString cvtwrd(suglst[ii],strlen(suglst[ii]),eEnc);
     465           0 :                         pStr[numsug + ii] = cvtwrd;
     466           0 :                     }
     467           0 :                     numsug += count;
     468             :                 }
     469             : 
     470           0 :                 pMS->free_list(&suglst, count);
     471             :             }
     472             :         }
     473             : 
     474             :         // now return an empty alternative for no suggestions or the list of alternatives if some found
     475           0 :         OUString aTmp(rWord);
     476           0 :         xRes = SpellAlternatives::CreateSpellAlternatives( aTmp, nLang, SpellFailure::SPELLING_ERROR, aStr );
     477           0 :         return xRes;
     478             :     }
     479           0 :     return xRes;
     480             : }
     481             : 
     482           0 : Reference< XSpellAlternatives > SAL_CALL SpellChecker::spell(
     483             :         const OUString& rWord, const Locale& rLocale,
     484             :         const PropertyValues& rProperties )
     485             :         throw(IllegalArgumentException, RuntimeException, std::exception)
     486             : {
     487           0 :     MutexGuard  aGuard( GetLinguMutex() );
     488             : 
     489           0 :      if (rLocale == Locale()  ||  rWord.isEmpty())
     490           0 :         return NULL;
     491             : 
     492           0 :     if (!hasLocale( rLocale ))
     493           0 :         return NULL;
     494             : 
     495           0 :     Reference< XSpellAlternatives > xAlt;
     496           0 :     if (!isValid( rWord, rLocale, rProperties ))
     497             :     {
     498           0 :         xAlt =  GetProposals( rWord, rLocale );
     499             :     }
     500           0 :     return xAlt;
     501             : }
     502             : 
     503          21 : Reference< XInterface > SAL_CALL SpellChecker_CreateInstance(
     504             :         const Reference< XMultiServiceFactory > & /*rSMgr*/ )
     505             :         throw(Exception)
     506             : {
     507             : 
     508          21 :     Reference< XInterface > xService = (cppu::OWeakObject*) new SpellChecker;
     509          21 :     return xService;
     510             : }
     511             : 
     512          18 : sal_Bool SAL_CALL SpellChecker::addLinguServiceEventListener(
     513             :         const Reference< XLinguServiceEventListener >& rxLstnr )
     514             :         throw(RuntimeException, std::exception)
     515             : {
     516          18 :     MutexGuard  aGuard( GetLinguMutex() );
     517             : 
     518          18 :     sal_Bool bRes = sal_False;
     519          18 :     if (!bDisposing && rxLstnr.is())
     520             :     {
     521          18 :         bRes = GetPropHelper().addLinguServiceEventListener( rxLstnr );
     522             :     }
     523          18 :     return bRes;
     524             : }
     525             : 
     526          18 : sal_Bool SAL_CALL SpellChecker::removeLinguServiceEventListener(
     527             :         const Reference< XLinguServiceEventListener >& rxLstnr )
     528             :         throw(RuntimeException, std::exception)
     529             : {
     530          18 :     MutexGuard  aGuard( GetLinguMutex() );
     531             : 
     532          18 :     sal_Bool bRes = sal_False;
     533          18 :     if (!bDisposing && rxLstnr.is())
     534             :     {
     535           0 :         bRes = GetPropHelper().removeLinguServiceEventListener( rxLstnr );
     536             :     }
     537          18 :     return bRes;
     538             : }
     539             : 
     540           0 : OUString SAL_CALL SpellChecker::getServiceDisplayName( const Locale& /*rLocale*/ )
     541             :         throw(RuntimeException, std::exception)
     542             : {
     543           0 :     MutexGuard  aGuard( GetLinguMutex() );
     544           0 :     return OUString( "Hunspell SpellChecker" );
     545             : }
     546             : 
     547           0 : void SAL_CALL SpellChecker::initialize( const Sequence< Any >& rArguments )
     548             :         throw(Exception, RuntimeException, std::exception)
     549             : {
     550           0 :     MutexGuard  aGuard( GetLinguMutex() );
     551             : 
     552           0 :     if (!pPropHelper)
     553             :     {
     554           0 :         sal_Int32 nLen = rArguments.getLength();
     555           0 :         if (2 == nLen)
     556             :         {
     557           0 :             Reference< XLinguProperties >   xPropSet;
     558           0 :             rArguments.getConstArray()[0] >>= xPropSet;
     559             :             // rArguments.getConstArray()[1] >>= xDicList;
     560             : 
     561             :             //! Pointer allows for access of the non-UNO functions.
     562             :             //! And the reference to the UNO-functions while increasing
     563             :             //! the ref-count and will implicitly free the memory
     564             :             //! when the object is not longer used.
     565           0 :             pPropHelper = new PropertyHelper_Spelling( (XSpellChecker *) this, xPropSet );
     566           0 :             pPropHelper->AddAsPropListener();   //! after a reference is established
     567             :         }
     568             :         else {
     569             :             OSL_FAIL( "wrong number of arguments in sequence" );
     570             :         }
     571           0 :     }
     572           0 : }
     573             : 
     574          21 : void SAL_CALL SpellChecker::dispose()
     575             :         throw(RuntimeException, std::exception)
     576             : {
     577          21 :     MutexGuard  aGuard( GetLinguMutex() );
     578             : 
     579          21 :     if (!bDisposing)
     580             :     {
     581          21 :         bDisposing = true;
     582          21 :         EventObject aEvtObj( (XSpellChecker *) this );
     583          21 :         aEvtListeners.disposeAndClear( aEvtObj );
     584          21 :         if (pPropHelper)
     585             :         {
     586          18 :             pPropHelper->RemoveAsPropListener();
     587          18 :             delete pPropHelper;
     588          18 :             pPropHelper = NULL;
     589          21 :         }
     590          21 :     }
     591          21 : }
     592             : 
     593           0 : void SAL_CALL SpellChecker::addEventListener( const Reference< XEventListener >& rxListener )
     594             :         throw(RuntimeException, std::exception)
     595             : {
     596           0 :     MutexGuard  aGuard( GetLinguMutex() );
     597             : 
     598           0 :     if (!bDisposing && rxListener.is())
     599           0 :         aEvtListeners.addInterface( rxListener );
     600           0 : }
     601             : 
     602           0 : void SAL_CALL SpellChecker::removeEventListener( const Reference< XEventListener >& rxListener )
     603             :         throw(RuntimeException, std::exception)
     604             : {
     605           0 :     MutexGuard  aGuard( GetLinguMutex() );
     606             : 
     607           0 :     if (!bDisposing && rxListener.is())
     608           0 :         aEvtListeners.removeInterface( rxListener );
     609           0 : }
     610             : 
     611             : // Service specific part
     612          21 : OUString SAL_CALL SpellChecker::getImplementationName()
     613             :         throw(RuntimeException, std::exception)
     614             : {
     615          21 :     MutexGuard  aGuard( GetLinguMutex() );
     616             : 
     617          21 :     return getImplementationName_Static();
     618             : }
     619             : 
     620           0 : sal_Bool SAL_CALL SpellChecker::supportsService( const OUString& ServiceName )
     621             :         throw(RuntimeException, std::exception)
     622             : {
     623           0 :     return cppu::supportsService(this, ServiceName);
     624             : }
     625             : 
     626           0 : Sequence< OUString > SAL_CALL SpellChecker::getSupportedServiceNames()
     627             :         throw(RuntimeException, std::exception)
     628             : {
     629           0 :     MutexGuard  aGuard( GetLinguMutex() );
     630             : 
     631           0 :     return getSupportedServiceNames_Static();
     632             : }
     633             : 
     634          21 : Sequence< OUString > SpellChecker::getSupportedServiceNames_Static()
     635             :         throw()
     636             : {
     637          21 :     MutexGuard  aGuard( GetLinguMutex() );
     638             : 
     639          21 :     Sequence< OUString > aSNS( 1 ); // more than 1 service is possible, too
     640          21 :     aSNS.getArray()[0] = SN_SPELLCHECKER;
     641          21 :     return aSNS;
     642             : }
     643             : 
     644          21 : void * SAL_CALL SpellChecker_getFactory( const sal_Char * pImplName,
     645             :             XMultiServiceFactory * pServiceManager, void *  )
     646             : {
     647          21 :     void * pRet = 0;
     648          21 :     if ( SpellChecker::getImplementationName_Static().equalsAscii( pImplName ) )
     649             :     {
     650             :         Reference< XSingleServiceFactory > xFactory =
     651             :             cppu::createOneInstanceFactory(
     652             :                 pServiceManager,
     653             :                 SpellChecker::getImplementationName_Static(),
     654             :                 SpellChecker_CreateInstance,
     655          21 :                 SpellChecker::getSupportedServiceNames_Static());
     656             :         // acquire, because we return an interface pointer instead of a reference
     657          21 :         xFactory->acquire();
     658          21 :         pRet = xFactory.get();
     659             :     }
     660          21 :     return pRet;
     661             : }
     662             : 
     663             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10