1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_i18npool.hxx"
26
27 #include <indexentrysupplier_common.hxx>
28 #include <com/sun/star/i18n/CollatorOptions.hpp>
29 #include <localedata.hxx>
30
31 using namespace ::com::sun::star::uno;
32 using namespace ::com::sun::star;
33 using namespace ::rtl;
34
35 namespace com { namespace sun { namespace star { namespace i18n {
36
IndexEntrySupplier_Common(const Reference<lang::XMultiServiceFactory> & rxMSF)37 IndexEntrySupplier_Common::IndexEntrySupplier_Common(const Reference < lang::XMultiServiceFactory >& rxMSF)
38 {
39 implementationName = "com.sun.star.i18n.IndexEntrySupplier_Common";
40 collator = new CollatorImpl(rxMSF);
41 usePhonetic = sal_False;
42 }
43
~IndexEntrySupplier_Common()44 IndexEntrySupplier_Common::~IndexEntrySupplier_Common()
45 {
46 delete collator;
47 }
48
getLocaleList()49 Sequence < lang::Locale > SAL_CALL IndexEntrySupplier_Common::getLocaleList()
50 {
51 throw RuntimeException();
52 }
53
getAlgorithmList(const lang::Locale &)54 Sequence < OUString > SAL_CALL IndexEntrySupplier_Common::getAlgorithmList( const lang::Locale& )
55 {
56 throw RuntimeException();
57 }
58
getPhoneticCandidate(const OUString &,const lang::Locale &)59 OUString SAL_CALL IndexEntrySupplier_Common::getPhoneticCandidate( const OUString&,
60 const lang::Locale& )
61 {
62 return OUString();
63 }
64
usePhoneticEntry(const lang::Locale &)65 sal_Bool SAL_CALL IndexEntrySupplier_Common::usePhoneticEntry( const lang::Locale& )
66 {
67 throw RuntimeException();
68 }
69
loadAlgorithm(const lang::Locale & rLocale,const OUString & rAlgorithm,sal_Int32 collatorOptions)70 sal_Bool SAL_CALL IndexEntrySupplier_Common::loadAlgorithm( const lang::Locale& rLocale,
71 const OUString& rAlgorithm, sal_Int32 collatorOptions )
72 {
73 usePhonetic = LocaleData().isPhonetic(rLocale, rAlgorithm);
74 collator->loadCollatorAlgorithm(rAlgorithm, rLocale, collatorOptions);
75 aLocale = rLocale;
76 aAlgorithm = rAlgorithm;
77 return sal_True;
78 }
79
getIndexKey(const OUString & rIndexEntry,const OUString &,const lang::Locale &)80 OUString SAL_CALL IndexEntrySupplier_Common::getIndexKey( const OUString& rIndexEntry,
81 const OUString&, const lang::Locale& )
82 {
83 sal_Int32 nPos=0;
84 sal_uInt32 indexChar=rIndexEntry.iterateCodePoints(&nPos, 0);
85 return OUString(&indexChar, 1);
86 }
87
compareIndexEntry(const OUString & rIndexEntry1,const OUString &,const lang::Locale &,const OUString & rIndexEntry2,const OUString &,const lang::Locale &)88 sal_Int16 SAL_CALL IndexEntrySupplier_Common::compareIndexEntry(
89 const OUString& rIndexEntry1, const OUString&, const lang::Locale&,
90 const OUString& rIndexEntry2, const OUString&, const lang::Locale& )
91 {
92 return sal::static_int_cast< sal_Int16 >(
93 collator->compareString(rIndexEntry1, rIndexEntry2));
94 // return value of compareString in { -1, 0, 1 }
95 }
96
getIndexCharacter(const OUString & rIndexEntry,const lang::Locale & rLocale,const OUString &)97 OUString SAL_CALL IndexEntrySupplier_Common::getIndexCharacter( const OUString& rIndexEntry,
98 const lang::Locale& rLocale, const OUString& )
99 {
100 return getIndexKey(rIndexEntry, rIndexEntry, rLocale);
101 }
102
getIndexFollowPageWord(sal_Bool,const lang::Locale &)103 OUString SAL_CALL IndexEntrySupplier_Common::getIndexFollowPageWord( sal_Bool,
104 const lang::Locale& )
105 {
106 throw RuntimeException();
107 }
108
109 const OUString& SAL_CALL
getEntry(const OUString & IndexEntry,const OUString & PhoneticEntry,const lang::Locale & rLocale)110 IndexEntrySupplier_Common::getEntry( const OUString& IndexEntry,
111 const OUString& PhoneticEntry, const lang::Locale& rLocale )
112 {
113 // The condition for using phonetic entry is:
114 // usePhonetic is set for the algorithm;
115 // rLocale for phonetic entry is same as aLocale for algorithm,
116 // which means Chinese phonetic will not be used for Japanese algorithm;
117 // phonetic entry is not blank.
118 if (usePhonetic && PhoneticEntry.getLength() > 0 && rLocale.Language == aLocale.Language &&
119 rLocale.Country == aLocale.Country && rLocale.Variant == aLocale.Variant)
120 return PhoneticEntry;
121 else
122 return IndexEntry;
123 }
124
125 OUString SAL_CALL
getImplementationName()126 IndexEntrySupplier_Common::getImplementationName()
127 {
128 return OUString::createFromAscii( implementationName );
129 }
130
131 sal_Bool SAL_CALL
supportsService(const OUString & rServiceName)132 IndexEntrySupplier_Common::supportsService(const OUString& rServiceName)
133 {
134 return rServiceName.compareToAscii(implementationName) == 0;
135 }
136
137 Sequence< OUString > SAL_CALL
getSupportedServiceNames()138 IndexEntrySupplier_Common::getSupportedServiceNames()
139 {
140 Sequence< OUString > aRet(1);
141 aRet[0] = OUString::createFromAscii( implementationName );
142 return aRet;
143 }
144
145 } } } }
146