1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_i18npool.hxx"
31 #include <indexentrysupplier_common.hxx>
32 #include <com/sun/star/i18n/CollatorOptions.hpp>
33 #include <localedata.hxx>
35 using namespace ::com::sun::star::uno
;
36 using namespace ::com::sun::star
;
37 using namespace ::rtl
;
39 namespace com
{ namespace sun
{ namespace star
{ namespace i18n
{
41 IndexEntrySupplier_Common::IndexEntrySupplier_Common(const Reference
< lang::XMultiServiceFactory
>& rxMSF
)
43 implementationName
= "com.sun.star.i18n.IndexEntrySupplier_Common";
44 collator
= new CollatorImpl(rxMSF
);
45 usePhonetic
= sal_False
;
48 IndexEntrySupplier_Common::~IndexEntrySupplier_Common()
53 Sequence
< lang::Locale
> SAL_CALL
IndexEntrySupplier_Common::getLocaleList() throw (RuntimeException
)
55 throw RuntimeException();
58 Sequence
< OUString
> SAL_CALL
IndexEntrySupplier_Common::getAlgorithmList( const lang::Locale
& ) throw (RuntimeException
)
60 throw RuntimeException();
63 OUString SAL_CALL
IndexEntrySupplier_Common::getPhoneticCandidate( const OUString
&,
64 const lang::Locale
& ) throw (RuntimeException
)
69 sal_Bool SAL_CALL
IndexEntrySupplier_Common::usePhoneticEntry( const lang::Locale
& ) throw (RuntimeException
)
71 throw RuntimeException();
74 sal_Bool SAL_CALL
IndexEntrySupplier_Common::loadAlgorithm( const lang::Locale
& rLocale
,
75 const OUString
& rAlgorithm
, sal_Int32 collatorOptions
) throw (RuntimeException
)
77 usePhonetic
= LocaleData().isPhonetic(rLocale
, rAlgorithm
);
78 collator
->loadCollatorAlgorithm(rAlgorithm
, rLocale
, collatorOptions
);
80 aAlgorithm
= rAlgorithm
;
84 OUString SAL_CALL
IndexEntrySupplier_Common::getIndexKey( const OUString
& rIndexEntry
,
85 const OUString
&, const lang::Locale
& ) throw (RuntimeException
)
88 sal_uInt32 indexChar
=rIndexEntry
.iterateCodePoints(&nPos
, 0);
89 return OUString(&indexChar
, 1);
92 sal_Int16 SAL_CALL
IndexEntrySupplier_Common::compareIndexEntry(
93 const OUString
& rIndexEntry1
, const OUString
&, const lang::Locale
&,
94 const OUString
& rIndexEntry2
, const OUString
&, const lang::Locale
& )
95 throw (RuntimeException
)
97 return sal::static_int_cast
< sal_Int16
>(
98 collator
->compareString(rIndexEntry1
, rIndexEntry2
));
99 // return value of compareString in { -1, 0, 1 }
102 OUString SAL_CALL
IndexEntrySupplier_Common::getIndexCharacter( const OUString
& rIndexEntry
,
103 const lang::Locale
& rLocale
, const OUString
& ) throw (RuntimeException
)
105 return getIndexKey(rIndexEntry
, rIndexEntry
, rLocale
);
108 OUString SAL_CALL
IndexEntrySupplier_Common::getIndexFollowPageWord( sal_Bool
,
109 const lang::Locale
& ) throw (RuntimeException
)
111 throw RuntimeException();
114 const OUString
& SAL_CALL
115 IndexEntrySupplier_Common::getEntry( const OUString
& IndexEntry
,
116 const OUString
& PhoneticEntry
, const lang::Locale
& rLocale
) throw (RuntimeException
)
118 // The condition for using phonetic entry is:
119 // usePhonetic is set for the algorithm;
120 // rLocale for phonetic entry is same as aLocale for algorithm,
121 // which means Chinese phonetic will not be used for Japanese algorithm;
122 // phonetic entry is not blank.
123 if (usePhonetic
&& PhoneticEntry
.getLength() > 0 && rLocale
.Language
== aLocale
.Language
&&
124 rLocale
.Country
== aLocale
.Country
&& rLocale
.Variant
== aLocale
.Variant
)
125 return PhoneticEntry
;
131 IndexEntrySupplier_Common::getImplementationName() throw( RuntimeException
)
133 return OUString::createFromAscii( implementationName
);
137 IndexEntrySupplier_Common::supportsService(const OUString
& rServiceName
) throw( RuntimeException
)
139 return rServiceName
.compareToAscii(implementationName
) == 0;
142 Sequence
< OUString
> SAL_CALL
143 IndexEntrySupplier_Common::getSupportedServiceNames() throw( RuntimeException
)
145 Sequence
< OUString
> aRet(1);
146 aRet
[0] = OUString::createFromAscii( implementationName
);