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