LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/i18npool/source/indexentry - indexentrysupplier.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 48 88 54.5 %
Date: 2013-07-09 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 <indexentrysupplier.hxx>
      22             : #include <localedata.hxx>
      23             : 
      24             : using namespace ::com::sun::star::uno;
      25             : using namespace ::com::sun::star::lang;
      26             : using namespace ::rtl;
      27             : 
      28             : static const sal_Unicode under = sal_Unicode('_');
      29             : 
      30             : namespace com { namespace sun { namespace star { namespace i18n {
      31             : 
      32          12 : IndexEntrySupplier::IndexEntrySupplier( const Reference < XComponentContext >& rxContext ) : m_xContext( rxContext )
      33             : {
      34          12 : }
      35             : 
      36           0 : Sequence < Locale > SAL_CALL IndexEntrySupplier::getLocaleList() throw (RuntimeException)
      37             : {
      38           0 :         return LocaleData().getAllInstalledLocaleNames();
      39             : }
      40             : 
      41          22 : Sequence < OUString > SAL_CALL IndexEntrySupplier::getAlgorithmList( const Locale& rLocale ) throw (RuntimeException)
      42             : {
      43          22 :         return LocaleData().getIndexAlgorithm(rLocale);
      44             : }
      45             : 
      46          12 : sal_Bool SAL_CALL IndexEntrySupplier::loadAlgorithm( const Locale& rLocale, const OUString& SortAlgorithm,
      47             :         sal_Int32 collatorOptions ) throw (RuntimeException)
      48             : {
      49          12 :         Sequence < OUString > algorithmList = getAlgorithmList( rLocale );
      50          14 :         for (sal_Int32 i = 0; i < algorithmList.getLength(); i++) {
      51          12 :             if (algorithmList[i] == SortAlgorithm) {
      52          10 :                 if (getLocaleSpecificIndexEntrySupplier(rLocale, SortAlgorithm).is())
      53          10 :                     return xIES->loadAlgorithm(rLocale, SortAlgorithm, collatorOptions);
      54             :             }
      55             :         }
      56           2 :         return sal_False;
      57             : }
      58             : 
      59           0 : sal_Bool SAL_CALL IndexEntrySupplier::usePhoneticEntry( const Locale& rLocale ) throw (RuntimeException)
      60             : {
      61           0 :         return LocaleData().hasPhonetic(rLocale);
      62             : }
      63             : 
      64           0 : OUString SAL_CALL IndexEntrySupplier::getPhoneticCandidate( const OUString& rIndexEntry,
      65             :         const Locale& rLocale ) throw (RuntimeException)
      66             : {
      67           0 :         if (getLocaleSpecificIndexEntrySupplier(rLocale, OUString()).is())
      68           0 :             return xIES->getPhoneticCandidate(rIndexEntry, rLocale);
      69             :         else
      70           0 :             throw RuntimeException();
      71             : }
      72             : 
      73           1 : OUString SAL_CALL IndexEntrySupplier::getIndexKey( const OUString& rIndexEntry,
      74             :         const OUString& rPhoneticEntry, const Locale& rLocale ) throw (RuntimeException)
      75             : {
      76           1 :         if (xIES.is())
      77           0 :             return xIES->getIndexKey(rIndexEntry, rPhoneticEntry, rLocale);
      78             :         else
      79           1 :             throw RuntimeException();
      80             : }
      81             : 
      82           0 : sal_Int16 SAL_CALL IndexEntrySupplier::compareIndexEntry(
      83             :         const OUString& rIndexEntry1, const OUString& rPhoneticEntry1, const Locale& rLocale1,
      84             :         const OUString& rIndexEntry2, const OUString& rPhoneticEntry2, const Locale& rLocale2 )
      85             :         throw (com::sun::star::uno::RuntimeException)
      86             : {
      87           0 :         if (xIES.is())
      88           0 :             return xIES->compareIndexEntry(rIndexEntry1, rPhoneticEntry1, rLocale1,
      89           0 :                                         rIndexEntry2, rPhoneticEntry2, rLocale2);
      90             :         else
      91           0 :             throw RuntimeException();
      92             : }
      93             : 
      94           0 : OUString SAL_CALL IndexEntrySupplier::getIndexCharacter( const OUString& rIndexEntry,
      95             :         const Locale& rLocale, const OUString& rSortAlgorithm )
      96             :         throw (RuntimeException)
      97             : {
      98           0 :         return getLocaleSpecificIndexEntrySupplier(rLocale, rSortAlgorithm)->
      99           0 :                         getIndexCharacter( rIndexEntry, rLocale, rSortAlgorithm );
     100             : }
     101             : 
     102          40 : sal_Bool SAL_CALL IndexEntrySupplier::createLocaleSpecificIndexEntrySupplier(const OUString& name) throw( RuntimeException )
     103             : {
     104          80 :         Reference < XInterface > xI = m_xContext->getServiceManager()->createInstanceWithContext(
     105          40 :             OUString("com.sun.star.i18n.IndexEntrySupplier_") + name, m_xContext);
     106             : 
     107          40 :         if ( xI.is() ) {
     108          10 :             xIES.set( xI, UNO_QUERY );
     109          10 :             return xIES.is();
     110             :         }
     111          30 :         return sal_False;
     112             : }
     113             : 
     114             : Reference < com::sun::star::i18n::XExtendedIndexEntrySupplier > SAL_CALL
     115          10 : IndexEntrySupplier::getLocaleSpecificIndexEntrySupplier(const Locale& rLocale, const OUString& rSortAlgorithm) throw (RuntimeException)
     116             : {
     117          20 :         if (xIES.is() && rSortAlgorithm == aSortAlgorithm && rLocale.Language == aLocale.Language &&
     118          10 :                 rLocale.Country == aLocale.Country && rLocale.Variant == aLocale.Variant)
     119           0 :             return xIES;
     120             :         else {
     121          10 :             LocaleData ld;
     122          10 :             aLocale = rLocale;
     123          10 :             if (rSortAlgorithm.isEmpty())
     124           0 :                 aSortAlgorithm = ld.getDefaultIndexAlgorithm( rLocale );
     125             :             else
     126          10 :                 aSortAlgorithm = rSortAlgorithm;
     127             : 
     128          10 :             OUString module = ld.getIndexModuleByAlgorithm(rLocale, aSortAlgorithm);
     129          10 :             if (!module.isEmpty() && createLocaleSpecificIndexEntrySupplier(module))
     130           0 :                 return xIES;
     131             : 
     132          10 :             sal_Int32 l = rLocale.Language.getLength();
     133          10 :             sal_Int32 c = rLocale.Country.getLength();
     134          10 :             sal_Int32 v = rLocale.Variant.getLength();
     135          10 :             sal_Int32 a = aSortAlgorithm.getLength();
     136          10 :             OUStringBuffer aBuf(l+c+v+a+4);
     137             : 
     138          40 :             if ((l > 0 && c > 0 && v > 0 && a > 0 &&
     139             :                         // load service with name <base>_<lang>_<country>_<varian>_<algorithm>
     140           0 :                         createLocaleSpecificIndexEntrySupplier(aBuf.append(rLocale.Language).append(under).append(
     141           0 :                                     rLocale.Country).append(under).append(rLocale.Variant).append(under).append(
     142          20 :                                     aSortAlgorithm).makeStringAndClear())) ||
     143          30 :                 (l > 0 && c > 0 && a > 0 &&
     144             :                         // load service with name <base>_<lang>_<country>_<algorithm>
     145          10 :                         createLocaleSpecificIndexEntrySupplier(aBuf.append(rLocale.Language).append(under).append(
     146          50 :                                     rLocale.Country).append(under).append(aSortAlgorithm).makeStringAndClear())) ||
     147          10 :                 (l > 0 && c > 0 && a > 0 && rLocale.Language.compareToAscii("zh") == 0 &&
     148           0 :                                             (rLocale.Country.compareToAscii("HK") == 0 ||
     149           0 :                                             rLocale.Country.compareToAscii("MO") == 0) &&
     150             :                         // if the country code is HK or MO, one more step to try TW.
     151           0 :                         createLocaleSpecificIndexEntrySupplier(aBuf.append(rLocale.Language).append(under).appendAscii(
     152          20 :                                     "TW").append(under).append(aSortAlgorithm).makeStringAndClear())) ||
     153          30 :                 (l > 0 && a > 0 &&
     154             :                         // load service with name <base>_<lang>_<algorithm>
     155          10 :                         createLocaleSpecificIndexEntrySupplier(aBuf.append(rLocale.Language).append(under).append(
     156          50 :                                     aSortAlgorithm).makeStringAndClear())) ||
     157             :                         // load service with name <base>_<algorithm>
     158          40 :                 (a > 0 && createLocaleSpecificIndexEntrySupplier(aSortAlgorithm)) ||
     159             :                         // load default service with name <base>_Unicode
     160          30 :                         createLocaleSpecificIndexEntrySupplier(OUString("Unicode"))) {
     161          10 :                 return xIES;
     162           0 :             }
     163             :         }
     164           0 :         throw RuntimeException();
     165             : }
     166             : 
     167           0 : OUString SAL_CALL IndexEntrySupplier::getIndexFollowPageWord( sal_Bool bMorePages,
     168             :         const Locale& rLocale ) throw (RuntimeException)
     169             : {
     170           0 :         Sequence< OUString > aFollowPageWords = LocaleData().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 )
     181             : {
     182           0 :         return OUString::createFromAscii( implementationName );
     183             : }
     184             : 
     185             : sal_Bool SAL_CALL
     186           0 : IndexEntrySupplier::supportsService(const OUString& rServiceName) throw( RuntimeException )
     187             : {
     188           0 :         return rServiceName.compareToAscii(implementationName) == 0;
     189             : }
     190             : 
     191             : Sequence< OUString > SAL_CALL
     192           0 : IndexEntrySupplier::getSupportedServiceNames() throw( RuntimeException )
     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