LCOV - code coverage report
Current view: top level - lingucomponent/source/spellcheck/spell - sspellimp.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 303 0.0 %
Date: 2014-04-14 Functions: 0 23 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             : #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           0 : SpellChecker::SpellChecker() :
      62             :     aDicts(NULL),
      63             :     aDEncs(NULL),
      64             :     aDLocs(NULL),
      65             :     aDNames(NULL),
      66             :     numdict(0),
      67           0 :     aEvtListeners(GetLinguMutex()),
      68             :     pPropHelper(NULL),
      69           0 :     bDisposing(false)
      70             : {
      71           0 : }
      72             : 
      73           0 : SpellChecker::~SpellChecker()
      74             : {
      75           0 :     if (aDicts)
      76             :     {
      77           0 :        for (int i = 0; i < numdict; ++i)
      78             :        {
      79           0 :             delete aDicts[i];
      80             :        }
      81           0 :        delete[] aDicts;
      82             :     }
      83           0 :     delete[] aDEncs;
      84           0 :     delete[] aDLocs;
      85           0 :     delete[] aDNames;
      86           0 :     if (pPropHelper)
      87             :     {
      88           0 :         pPropHelper->RemoveAsPropListener();
      89           0 :         delete pPropHelper;
      90             :     }
      91           0 : }
      92             : 
      93           0 : PropertyHelper_Spelling & SpellChecker::GetPropHelper_Impl()
      94             : {
      95           0 :     if (!pPropHelper)
      96             :     {
      97           0 :         Reference< XLinguProperties >   xPropSet( GetLinguProperties(), UNO_QUERY );
      98             : 
      99           0 :         pPropHelper = new PropertyHelper_Spelling( (XSpellChecker *) this, xPropSet );
     100           0 :         pPropHelper->AddAsPropListener();   //! after a reference is established
     101             :     }
     102           0 :     return *pPropHelper;
     103             : }
     104             : 
     105           0 : Sequence< Locale > SAL_CALL SpellChecker::getLocales()
     106             :         throw(RuntimeException, std::exception)
     107             : {
     108           0 :     MutexGuard  aGuard( GetLinguMutex() );
     109             : 
     110             :     // this routine should return the locales supported by the installed
     111             :     // dictionaries.
     112           0 :     if (!numdict)
     113             :     {
     114           0 :         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           0 :         std::list< SvtLinguConfigDictionaryEntry > aDics;
     120           0 :         uno::Sequence< OUString > aFormatList;
     121             :         aLinguCfg.GetSupportedDictionaryFormatsFor( "SpellCheckers",
     122           0 :                 "org.openoffice.lingu.MySpellSpellChecker", aFormatList );
     123           0 :         sal_Int32 nLen = aFormatList.getLength();
     124           0 :         for (sal_Int32 i = 0;  i < nLen;  ++i)
     125             :         {
     126             :             std::vector< SvtLinguConfigDictionaryEntry > aTmpDic(
     127           0 :                     aLinguCfg.GetActiveDictionariesByFormat( aFormatList[i] ) );
     128           0 :             aDics.insert( aDics.end(), aTmpDic.begin(), aTmpDic.end() );
     129           0 :         }
     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           0 :                 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           0 :         MergeNewStyleDicsAndOldStyleDics( aDics, aOldStyleDics );
     141             : 
     142           0 :         if (!aDics.empty())
     143             :         {
     144             :             // get supported locales from the dictionaries-to-use...
     145           0 :             sal_Int32 k = 0;
     146           0 :             std::set< OUString, lt_rtl_OUString > aLocaleNamesSet;
     147           0 :             std::list< SvtLinguConfigDictionaryEntry >::const_iterator aDictIt;
     148           0 :             for (aDictIt = aDics.begin();  aDictIt != aDics.end();  ++aDictIt)
     149             :             {
     150           0 :                 uno::Sequence< OUString > aLocaleNames( aDictIt->aLocaleNames );
     151           0 :                 sal_Int32 nLen2 = aLocaleNames.getLength();
     152           0 :                 for (k = 0;  k < nLen2;  ++k)
     153             :                 {
     154           0 :                     aLocaleNamesSet.insert( aLocaleNames[k] );
     155             :                 }
     156           0 :             }
     157             :             // ... and add them to the resulting sequence
     158           0 :             aSuppLocales.realloc( aLocaleNamesSet.size() );
     159           0 :             std::set< OUString, lt_rtl_OUString >::const_iterator aItB;
     160           0 :             k = 0;
     161           0 :             for (aItB = aLocaleNamesSet.begin();  aItB != aLocaleNamesSet.end();  ++aItB)
     162             :             {
     163           0 :                 Locale aTmp( LanguageTag::convertToLocale( *aItB ));
     164           0 :                 aSuppLocales[k++] = aTmp;
     165           0 :             }
     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           0 :             numdict = 0;
     173           0 :             for (aDictIt = aDics.begin();  aDictIt != aDics.end();  ++aDictIt)
     174           0 :                 numdict = numdict + aDictIt->aLocaleNames.getLength();
     175             : 
     176             :             // add dictionary information
     177           0 :             aDicts  = new Hunspell* [numdict];
     178           0 :             aDEncs  = new rtl_TextEncoding [numdict];
     179           0 :             aDLocs  = new Locale [numdict];
     180           0 :             aDNames = new OUString [numdict];
     181           0 :             k = 0;
     182           0 :             for (aDictIt = aDics.begin();  aDictIt != aDics.end();  ++aDictIt)
     183             :             {
     184           0 :                 if (aDictIt->aLocaleNames.getLength() > 0 &&
     185           0 :                     aDictIt->aLocations.getLength() > 0)
     186             :                 {
     187           0 :                     uno::Sequence< OUString > aLocaleNames( aDictIt->aLocaleNames );
     188           0 :                     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           0 :                     for (sal_Int32 i = 0;  i < nLocales;  ++i)
     194             :                     {
     195           0 :                         aDicts[k]  = NULL;
     196           0 :                         aDEncs[k]  = RTL_TEXTENCODING_DONTKNOW;
     197           0 :                         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           0 :                         OUString aLocation = aDictIt->aLocations[0];
     202           0 :                         sal_Int32 nPos = aLocation.lastIndexOf( '.' );
     203           0 :                         aLocation = aLocation.copy( 0, nPos );
     204           0 :                         aDNames[k] = aLocation;
     205             : 
     206           0 :                         ++k;
     207           0 :                     }
     208             :                 }
     209             :             }
     210           0 :             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           0 :         }
     226             :     }
     227             : 
     228           0 :     return aSuppLocales;
     229             : }
     230             : 
     231           0 : sal_Bool SAL_CALL SpellChecker::hasLocale(const Locale& rLocale)
     232             :         throw(RuntimeException, std::exception)
     233             : {
     234           0 :     MutexGuard  aGuard( GetLinguMutex() );
     235             : 
     236           0 :     sal_Bool bRes = sal_False;
     237           0 :     if (!aSuppLocales.getLength())
     238           0 :         getLocales();
     239             : 
     240           0 :     const Locale *pLocale = aSuppLocales.getConstArray();
     241           0 :     sal_Int32 nLen = aSuppLocales.getLength();
     242           0 :     for (sal_Int32 i = 0;  i < nLen;  ++i)
     243             :     {
     244           0 :         if (rLocale == pLocale[i])
     245             :         {
     246           0 :             bRes = sal_True;
     247           0 :             break;
     248             :         }
     249             :     }
     250           0 :     return bRes;
     251             : }
     252             : 
     253           0 : sal_Int16 SpellChecker::GetSpellFailure( const OUString &rWord, const Locale &rLocale )
     254             : {
     255           0 :     Hunspell * pMS = NULL;
     256           0 :     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           0 :     sal_Int16 nRes = -1;
     262             : 
     263             :     // first handle smart quotes both single and double
     264           0 :     OUStringBuffer rBuf(rWord);
     265           0 :     sal_Int32 n = rBuf.getLength();
     266             :     sal_Unicode c;
     267           0 :     sal_Int32 extrachar = 0;
     268             : 
     269           0 :     for (sal_Int32 ix=0; ix < n; ix++)
     270             :     {
     271           0 :         c = rBuf[ix];
     272           0 :         if ((c == 0x201C) || (c == 0x201D))
     273           0 :             rBuf[ix] = (sal_Unicode)0x0022;
     274           0 :         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           0 :         else if ((c == 0x200C) || (c == 0x200D) ||
     281           0 :             ((c >= 0xFB00) && (c <= 0xFB04)))
     282           0 :                 extrachar = 1;
     283             :     }
     284           0 :     OUString nWord(rBuf.makeStringAndClear());
     285             : 
     286           0 :     if (n)
     287             :     {
     288           0 :         for (sal_Int32 i = 0; i < numdict; ++i)
     289             :         {
     290           0 :             pMS = NULL;
     291           0 :             eEnc = RTL_TEXTENCODING_DONTKNOW;
     292             : 
     293           0 :             if (rLocale == aDLocs[i])
     294             :             {
     295           0 :                 if (!aDicts[i])
     296             :                 {
     297           0 :                     OUString dicpath = aDNames[i] + ".dic";
     298           0 :                     OUString affpath = aDNames[i] + ".aff";
     299           0 :                     OUString dict;
     300           0 :                     OUString aff;
     301           0 :                     osl::FileBase::getSystemPathFromFileURL(dicpath,dict);
     302           0 :                     osl::FileBase::getSystemPathFromFileURL(affpath,aff);
     303           0 :                     OString aTmpaff(OU2ENC(aff,osl_getThreadTextEncoding()));
     304           0 :                     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           0 :                     aDicts[i] = new Hunspell(aTmpaff.getStr(),aTmpdict.getStr());
     316           0 :                     aDEncs[i] = RTL_TEXTENCODING_DONTKNOW;
     317           0 :                     if (aDicts[i])
     318           0 :                         aDEncs[i] = getTextEncodingFromCharset(aDicts[i]->get_dic_encoding());
     319             :                 }
     320           0 :                 pMS = aDicts[i];
     321           0 :                 eEnc = aDEncs[i];
     322             :             }
     323             : 
     324           0 :             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           0 :                 if (eEnc == RTL_TEXTENCODING_DONTKNOW)
     332           0 :                     return -1;
     333             : 
     334           0 :                 OString aWrd(OU2ENC(nWord,eEnc));
     335           0 :                 int rVal = pMS->spell((char*)aWrd.getStr());
     336           0 :                 if (rVal != 1) {
     337           0 :                     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           0 :                     nRes = SpellFailure::SPELLING_ERROR;
     358             :                 } else {
     359           0 :                     return -1;
     360             :                 }
     361           0 :                 pMS = NULL;
     362             :             }
     363             :         }
     364             :     }
     365             : 
     366           0 :     return nRes;
     367             : }
     368             : 
     369           0 : sal_Bool SAL_CALL SpellChecker::isValid( const OUString& rWord, const Locale& rLocale,
     370             :             const PropertyValues& rProperties )
     371             :         throw(IllegalArgumentException, RuntimeException, std::exception)
     372             : {
     373           0 :     MutexGuard  aGuard( GetLinguMutex() );
     374             : 
     375           0 :      if (rLocale == Locale()  ||  rWord.isEmpty())
     376           0 :         return sal_True;
     377             : 
     378           0 :     if (!hasLocale( rLocale ))
     379           0 :         return sal_True;
     380             : 
     381             :     // return sal_False to process SPELLML requests (they are longer than the header)
     382           0 :     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           0 :     PropertyHelper_Spelling& rHelper = GetPropHelper();
     391           0 :     rHelper.SetTmpPropVals( rProperties );
     392             : 
     393           0 :     sal_Int16 nFailure = GetSpellFailure( rWord, rLocale );
     394           0 :     if (nFailure != -1 && !rWord.match(SPELLML_HEADER, 0))
     395             :     {
     396           0 :         sal_Int16 nLang = LinguLocaleToLanguage( rLocale );
     397             :         // postprocess result for errors that should be ignored
     398             :         const bool bIgnoreError =
     399           0 :                 (!rHelper.IsSpellUpperCase()  && IsUpper( rWord, nLang )) ||
     400           0 :                 (!rHelper.IsSpellWithDigits() && HasDigits( rWord )) ||
     401           0 :                 (!rHelper.IsSpellCapitalization()  &&  nFailure == SpellFailure::CAPTION_ERROR);
     402           0 :         if (bIgnoreError)
     403           0 :             nFailure = -1;
     404             :     }
     405             : 
     406           0 :     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           0 : Reference< XInterface > SAL_CALL SpellChecker_CreateInstance(
     504             :         const Reference< XMultiServiceFactory > & /*rSMgr*/ )
     505             :         throw(Exception)
     506             : {
     507             : 
     508           0 :     Reference< XInterface > xService = (cppu::OWeakObject*) new SpellChecker;
     509           0 :     return xService;
     510             : }
     511             : 
     512           0 : sal_Bool SAL_CALL SpellChecker::addLinguServiceEventListener(
     513             :         const Reference< XLinguServiceEventListener >& rxLstnr )
     514             :         throw(RuntimeException, std::exception)
     515             : {
     516           0 :     MutexGuard  aGuard( GetLinguMutex() );
     517             : 
     518           0 :     sal_Bool bRes = sal_False;
     519           0 :     if (!bDisposing && rxLstnr.is())
     520             :     {
     521           0 :         bRes = GetPropHelper().addLinguServiceEventListener( rxLstnr );
     522             :     }
     523           0 :     return bRes;
     524             : }
     525             : 
     526           0 : sal_Bool SAL_CALL SpellChecker::removeLinguServiceEventListener(
     527             :         const Reference< XLinguServiceEventListener >& rxLstnr )
     528             :         throw(RuntimeException, std::exception)
     529             : {
     530           0 :     MutexGuard  aGuard( GetLinguMutex() );
     531             : 
     532           0 :     sal_Bool bRes = sal_False;
     533           0 :     if (!bDisposing && rxLstnr.is())
     534             :     {
     535           0 :         bRes = GetPropHelper().removeLinguServiceEventListener( rxLstnr );
     536             :     }
     537           0 :     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           0 : void SAL_CALL SpellChecker::dispose()
     575             :         throw(RuntimeException, std::exception)
     576             : {
     577           0 :     MutexGuard  aGuard( GetLinguMutex() );
     578             : 
     579           0 :     if (!bDisposing)
     580             :     {
     581           0 :         bDisposing = true;
     582           0 :         EventObject aEvtObj( (XSpellChecker *) this );
     583           0 :         aEvtListeners.disposeAndClear( aEvtObj );
     584           0 :         if (pPropHelper)
     585             :         {
     586           0 :             pPropHelper->RemoveAsPropListener();
     587           0 :             delete pPropHelper;
     588           0 :             pPropHelper = NULL;
     589           0 :         }
     590           0 :     }
     591           0 : }
     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           0 : OUString SAL_CALL SpellChecker::getImplementationName()
     613             :         throw(RuntimeException, std::exception)
     614             : {
     615           0 :     MutexGuard  aGuard( GetLinguMutex() );
     616             : 
     617           0 :     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           0 : Sequence< OUString > SpellChecker::getSupportedServiceNames_Static()
     635             :         throw()
     636             : {
     637           0 :     MutexGuard  aGuard( GetLinguMutex() );
     638             : 
     639           0 :     Sequence< OUString > aSNS( 1 ); // more than 1 service is possible, too
     640           0 :     aSNS.getArray()[0] = SN_SPELLCHECKER;
     641           0 :     return aSNS;
     642             : }
     643             : 
     644           0 : void * SAL_CALL SpellChecker_getFactory( const sal_Char * pImplName,
     645             :             XMultiServiceFactory * pServiceManager, void *  )
     646             : {
     647           0 :     void * pRet = 0;
     648           0 :     if ( SpellChecker::getImplementationName_Static().equalsAscii( pImplName ) )
     649             :     {
     650             :         Reference< XSingleServiceFactory > xFactory =
     651             :             cppu::createOneInstanceFactory(
     652             :                 pServiceManager,
     653             :                 SpellChecker::getImplementationName_Static(),
     654             :                 SpellChecker_CreateInstance,
     655           0 :                 SpellChecker::getSupportedServiceNames_Static());
     656             :         // acquire, because we return an interface pointer instead of a reference
     657           0 :         xFactory->acquire();
     658           0 :         pRet = xFactory.get();
     659             :     }
     660           0 :     return pRet;
     661             : }
     662             : 
     663             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10