LCOV - code coverage report
Current view: top level - i18npool/source/indexentry - indexentrysupplier.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 51 80 63.8 %
Date: 2015-06-13 12:38:46 Functions: 8 15 53.3 %
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           8 : IndexEntrySupplier::IndexEntrySupplier( const Reference < XComponentContext >& rxContext ) : m_xContext( rxContext )
      31             : {
      32           8 : }
      33             : 
      34           0 : Sequence < Locale > SAL_CALL IndexEntrySupplier::getLocaleList() throw (RuntimeException, std::exception)
      35             : {
      36           0 :     return LocaleDataImpl().getAllInstalledLocaleNames();
      37             : }
      38             : 
      39          12 : Sequence < OUString > SAL_CALL IndexEntrySupplier::getAlgorithmList( const Locale& rLocale ) throw (RuntimeException, std::exception)
      40             : {
      41          12 :     return LocaleDataImpl().getIndexAlgorithm(rLocale);
      42             : }
      43             : 
      44           7 : sal_Bool SAL_CALL IndexEntrySupplier::loadAlgorithm( const Locale& rLocale, const OUString& SortAlgorithm,
      45             :         sal_Int32 collatorOptions ) throw (RuntimeException, std::exception)
      46             : {
      47           7 :     Sequence < OUString > algorithmList = getAlgorithmList( rLocale );
      48           9 :     for (sal_Int32 i = 0; i < algorithmList.getLength(); i++) {
      49           7 :         if (algorithmList[i] == SortAlgorithm) {
      50           5 :             if (getLocaleSpecificIndexEntrySupplier(rLocale, SortAlgorithm).is())
      51           5 :                 return xIES->loadAlgorithm(rLocale, SortAlgorithm, collatorOptions);
      52             :         }
      53             :     }
      54           2 :     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           1 : OUString SAL_CALL IndexEntrySupplier::getIndexKey( const OUString& rIndexEntry,
      72             :         const OUString& rPhoneticEntry, const Locale& rLocale ) throw (RuntimeException, std::exception)
      73             : {
      74           1 :     if (xIES.is())
      75           0 :         return xIES->getIndexKey(rIndexEntry, rPhoneticEntry, rLocale);
      76             :     else
      77           1 :         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          20 : bool SAL_CALL IndexEntrySupplier::createLocaleSpecificIndexEntrySupplier(const OUString& name) throw( RuntimeException )
     101             : {
     102          40 :     Reference < XInterface > xI = m_xContext->getServiceManager()->createInstanceWithContext(
     103          20 :             "com.sun.star.i18n.IndexEntrySupplier_" + name, m_xContext);
     104             : 
     105          20 :     if ( xI.is() ) {
     106           5 :         xIES.set( xI, UNO_QUERY );
     107           5 :         return xIES.is();
     108             :     }
     109          15 :     return false;
     110             : }
     111             : 
     112             : Reference < com::sun::star::i18n::XExtendedIndexEntrySupplier > SAL_CALL
     113           5 : IndexEntrySupplier::getLocaleSpecificIndexEntrySupplier(const Locale& rLocale, const OUString& rSortAlgorithm) throw (RuntimeException)
     114             : {
     115          10 :     if (xIES.is() && rSortAlgorithm == aSortAlgorithm && rLocale.Language == aLocale.Language &&
     116           5 :             rLocale.Country == aLocale.Country && rLocale.Variant == aLocale.Variant)
     117           0 :         return xIES;
     118             :     else {
     119           5 :         LocaleDataImpl ld;
     120           5 :         aLocale = rLocale;
     121           5 :         if (rSortAlgorithm.isEmpty())
     122           0 :             aSortAlgorithm = ld.getDefaultIndexAlgorithm( rLocale );
     123             :         else
     124           5 :             aSortAlgorithm = rSortAlgorithm;
     125             : 
     126          10 :         OUString module = ld.getIndexModuleByAlgorithm(rLocale, aSortAlgorithm);
     127           5 :         if (!module.isEmpty() && createLocaleSpecificIndexEntrySupplier(module))
     128           0 :             return xIES;
     129             : 
     130           5 :         bool bLoaded = false;
     131           5 :         if (!aSortAlgorithm.isEmpty())
     132             :         {
     133             :             // Load service with name <base>_<lang>_<country>_<algorithm>
     134             :             // or <base>_<bcp47>_<algorithm> and fallbacks.
     135             :             bLoaded = createLocaleSpecificIndexEntrySupplier(
     136           5 :                     LocaleDataImpl::getFirstLocaleServiceName( rLocale) + "_" + aSortAlgorithm);
     137           5 :             if (!bLoaded)
     138             :             {
     139           5 :                 ::std::vector< OUString > aFallbacks( LocaleDataImpl::getFallbackLocaleServiceNames( rLocale));
     140          10 :                 for (::std::vector< OUString >::const_iterator it( aFallbacks.begin()); it != aFallbacks.end(); ++it)
     141             :                 {
     142           5 :                     bLoaded = createLocaleSpecificIndexEntrySupplier( *it + "_" + aSortAlgorithm);
     143           5 :                     if (bLoaded)
     144           0 :                         break;
     145             :                 }
     146           5 :                 if (!bLoaded)
     147             :                 {
     148             :                     // load service with name <base>_<algorithm>
     149           5 :                     bLoaded = createLocaleSpecificIndexEntrySupplier( aSortAlgorithm);
     150           5 :                 }
     151             :             }
     152             :         }
     153           5 :         if (!bLoaded)
     154             :         {
     155             :             // load default service with name <base>_Unicode
     156           5 :             bLoaded = createLocaleSpecificIndexEntrySupplier( "Unicode");
     157           5 :             if (!bLoaded)
     158             :             {
     159           0 :                 throw RuntimeException();   // could not load any service
     160             :             }
     161             :         }
     162          10 :         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           1 : IndexEntrySupplier::getImplementationName() throw( RuntimeException, std::exception )
     180             : {
     181           1 :     return OUString( 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           1 : IndexEntrySupplier::getSupportedServiceNames() throw( RuntimeException, std::exception )
     192             : {
     193           1 :     Sequence< OUString > aRet(1);
     194           1 :     aRet[0] = implementationName;
     195           1 :     return aRet;
     196             : }
     197             : 
     198             : } } } }
     199             : 
     200             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11