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

Generated by: LCOV version 1.10