LCOV - code coverage report
Current view: top level - i18npool/source/indexentry - indexentrysupplier.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 45 80 56.2 %
Date: 2014-11-03 Functions: 6 15 40.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 <rtl/ustrbuf.hxx>
      21             : #include <cppuhelper/supportsservice.hxx>
      22             : #include <indexentrysupplier.hxx>
      23             : #include <localedata.hxx>
      24             : 
      25             : using namespace ::com::sun::star::uno;
      26             : using namespace ::com::sun::star::lang;
      27             : 
      28             : namespace com { namespace sun { namespace star { namespace i18n {
      29             : 
      30          16 : IndexEntrySupplier::IndexEntrySupplier( const Reference < XComponentContext >& rxContext ) : m_xContext( rxContext )
      31             : {
      32          16 : }
      33             : 
      34           0 : Sequence < Locale > SAL_CALL IndexEntrySupplier::getLocaleList() throw (RuntimeException, std::exception)
      35             : {
      36           0 :     return LocaleDataImpl().getAllInstalledLocaleNames();
      37             : }
      38             : 
      39          24 : Sequence < OUString > SAL_CALL IndexEntrySupplier::getAlgorithmList( const Locale& rLocale ) throw (RuntimeException, std::exception)
      40             : {
      41          24 :     return LocaleDataImpl().getIndexAlgorithm(rLocale);
      42             : }
      43             : 
      44          14 : sal_Bool SAL_CALL IndexEntrySupplier::loadAlgorithm( const Locale& rLocale, const OUString& SortAlgorithm,
      45             :         sal_Int32 collatorOptions ) throw (RuntimeException, std::exception)
      46             : {
      47          14 :     Sequence < OUString > algorithmList = getAlgorithmList( rLocale );
      48          18 :     for (sal_Int32 i = 0; i < algorithmList.getLength(); i++) {
      49          14 :         if (algorithmList[i] == SortAlgorithm) {
      50          10 :             if (getLocaleSpecificIndexEntrySupplier(rLocale, SortAlgorithm).is())
      51          10 :                 return xIES->loadAlgorithm(rLocale, SortAlgorithm, collatorOptions);
      52             :         }
      53             :     }
      54           4 :     return sal_False;
      55             : }
      56             : 
      57           0 : sal_Bool SAL_CALL IndexEntrySupplier::usePhoneticEntry( const Locale& rLocale ) throw (RuntimeException, std::exception)
      58             : {
      59           0 :     return LocaleDataImpl().hasPhonetic(rLocale);
      60             : }
      61             : 
      62           0 : OUString SAL_CALL IndexEntrySupplier::getPhoneticCandidate( const OUString& rIndexEntry,
      63             :         const Locale& rLocale ) throw (RuntimeException, std::exception)
      64             : {
      65           0 :     if (getLocaleSpecificIndexEntrySupplier(rLocale, OUString()).is())
      66           0 :         return xIES->getPhoneticCandidate(rIndexEntry, rLocale);
      67             :     else
      68           0 :         throw RuntimeException();
      69             : }
      70             : 
      71           2 : OUString SAL_CALL IndexEntrySupplier::getIndexKey( const OUString& rIndexEntry,
      72             :         const OUString& rPhoneticEntry, const Locale& rLocale ) throw (RuntimeException, std::exception)
      73             : {
      74           2 :     if (xIES.is())
      75           0 :         return xIES->getIndexKey(rIndexEntry, rPhoneticEntry, rLocale);
      76             :     else
      77           2 :         throw RuntimeException();
      78             : }
      79             : 
      80           0 : sal_Int16 SAL_CALL IndexEntrySupplier::compareIndexEntry(
      81             :         const OUString& rIndexEntry1, const OUString& rPhoneticEntry1, const Locale& rLocale1,
      82             :         const OUString& rIndexEntry2, const OUString& rPhoneticEntry2, const Locale& rLocale2 )
      83             : throw (com::sun::star::uno::RuntimeException, std::exception)
      84             : {
      85           0 :     if (xIES.is())
      86           0 :         return xIES->compareIndexEntry(rIndexEntry1, rPhoneticEntry1, rLocale1,
      87           0 :                 rIndexEntry2, rPhoneticEntry2, rLocale2);
      88             :     else
      89           0 :         throw RuntimeException();
      90             : }
      91             : 
      92           0 : OUString SAL_CALL IndexEntrySupplier::getIndexCharacter( const OUString& rIndexEntry,
      93             :         const Locale& rLocale, const OUString& rSortAlgorithm )
      94             : throw (RuntimeException, std::exception)
      95             : {
      96           0 :     return getLocaleSpecificIndexEntrySupplier(rLocale, rSortAlgorithm)->
      97           0 :         getIndexCharacter( rIndexEntry, rLocale, rSortAlgorithm );
      98             : }
      99             : 
     100          40 : bool SAL_CALL IndexEntrySupplier::createLocaleSpecificIndexEntrySupplier(const OUString& name) throw( RuntimeException )
     101             : {
     102          80 :     Reference < XInterface > xI = m_xContext->getServiceManager()->createInstanceWithContext(
     103          40 :             OUString("com.sun.star.i18n.IndexEntrySupplier_") + name, m_xContext);
     104             : 
     105          40 :     if ( xI.is() ) {
     106          10 :         xIES.set( xI, UNO_QUERY );
     107          10 :         return xIES.is();
     108             :     }
     109          30 :     return false;
     110             : }
     111             : 
     112             : Reference < com::sun::star::i18n::XExtendedIndexEntrySupplier > SAL_CALL
     113          10 : IndexEntrySupplier::getLocaleSpecificIndexEntrySupplier(const Locale& rLocale, const OUString& rSortAlgorithm) throw (RuntimeException)
     114             : {
     115          20 :     if (xIES.is() && rSortAlgorithm == aSortAlgorithm && rLocale.Language == aLocale.Language &&
     116          10 :             rLocale.Country == aLocale.Country && rLocale.Variant == aLocale.Variant)
     117           0 :         return xIES;
     118             :     else {
     119          10 :         LocaleDataImpl ld;
     120          10 :         aLocale = rLocale;
     121          10 :         if (rSortAlgorithm.isEmpty())
     122           0 :             aSortAlgorithm = ld.getDefaultIndexAlgorithm( rLocale );
     123             :         else
     124          10 :             aSortAlgorithm = rSortAlgorithm;
     125             : 
     126          20 :         OUString module = ld.getIndexModuleByAlgorithm(rLocale, aSortAlgorithm);
     127          10 :         if (!module.isEmpty() && createLocaleSpecificIndexEntrySupplier(module))
     128           0 :             return xIES;
     129             : 
     130          10 :         bool bLoaded = false;
     131          10 :         if (!aSortAlgorithm.isEmpty())
     132             :         {
     133             :             // Load service with name <base>_<lang>_<country>_<algorithm>
     134             :             // or <base>_<bcp47>_<algorithm> and fallbacks.
     135             :             bLoaded = createLocaleSpecificIndexEntrySupplier(
     136          10 :                     LocaleDataImpl::getFirstLocaleServiceName( rLocale) + "_" + aSortAlgorithm);
     137          10 :             if (!bLoaded)
     138             :             {
     139          10 :                 ::std::vector< OUString > aFallbacks( LocaleDataImpl::getFallbackLocaleServiceNames( rLocale));
     140          20 :                 for (::std::vector< OUString >::const_iterator it( aFallbacks.begin()); it != aFallbacks.end(); ++it)
     141             :                 {
     142          10 :                     bLoaded = createLocaleSpecificIndexEntrySupplier( *it + "_" + aSortAlgorithm);
     143          10 :                     if (bLoaded)
     144           0 :                         break;
     145             :                 }
     146          10 :                 if (!bLoaded)
     147             :                 {
     148             :                     // load service with name <base>_<algorithm>
     149          10 :                     bLoaded = createLocaleSpecificIndexEntrySupplier( aSortAlgorithm);
     150          10 :                 }
     151             :             }
     152             :         }
     153          10 :         if (!bLoaded)
     154             :         {
     155             :             // load default service with name <base>_Unicode
     156          10 :             bLoaded = createLocaleSpecificIndexEntrySupplier( "Unicode");
     157          10 :             if (!bLoaded)
     158             :             {
     159           0 :                 throw RuntimeException();   // could not load any service
     160             :             }
     161             :         }
     162          20 :         return xIES;
     163             :     }
     164             : }
     165             : 
     166           0 : OUString SAL_CALL IndexEntrySupplier::getIndexFollowPageWord( sal_Bool bMorePages,
     167             :         const Locale& rLocale ) throw (RuntimeException, std::exception)
     168             : {
     169           0 :     Sequence< OUString > aFollowPageWords = LocaleDataImpl().getFollowPageWords(rLocale);
     170             : 
     171           0 :     return (bMorePages && aFollowPageWords.getLength() > 1) ?
     172           0 :         aFollowPageWords[1] : (aFollowPageWords.getLength() > 0 ?
     173           0 :                 aFollowPageWords[0] : OUString());
     174             : }
     175             : 
     176             : #define implementationName "com.sun.star.i18n.IndexEntrySupplier"
     177             : 
     178             : OUString SAL_CALL
     179           0 : IndexEntrySupplier::getImplementationName() throw( RuntimeException, std::exception )
     180             : {
     181           0 :     return OUString::createFromAscii( implementationName );
     182             : }
     183             : 
     184             : sal_Bool SAL_CALL
     185           0 : IndexEntrySupplier::supportsService(const OUString& rServiceName) throw( RuntimeException, std::exception )
     186             : {
     187           0 :     return cppu::supportsService(this, rServiceName);
     188             : }
     189             : 
     190             : Sequence< OUString > SAL_CALL
     191           0 : IndexEntrySupplier::getSupportedServiceNames() throw( RuntimeException, std::exception )
     192             : {
     193           0 :     Sequence< OUString > aRet(1);
     194           0 :     aRet[0] = OUString::createFromAscii( implementationName );
     195           0 :     return aRet;
     196             : }
     197             : 
     198             : } } } }
     199             : 
     200             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10