xref: /trunk/main/i18npool/inc/collatorImpl.hxx (revision f7bd9df4)
1*f7bd9df4SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*f7bd9df4SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*f7bd9df4SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*f7bd9df4SAndrew Rist  * distributed with this work for additional information
6*f7bd9df4SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*f7bd9df4SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*f7bd9df4SAndrew Rist  * "License"); you may not use this file except in compliance
9*f7bd9df4SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*f7bd9df4SAndrew Rist  *
11*f7bd9df4SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*f7bd9df4SAndrew Rist  *
13*f7bd9df4SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*f7bd9df4SAndrew Rist  * software distributed under the License is distributed on an
15*f7bd9df4SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f7bd9df4SAndrew Rist  * KIND, either express or implied.  See the License for the
17*f7bd9df4SAndrew Rist  * specific language governing permissions and limitations
18*f7bd9df4SAndrew Rist  * under the License.
19*f7bd9df4SAndrew Rist  *
20*f7bd9df4SAndrew Rist  *************************************************************/
21*f7bd9df4SAndrew Rist 
22*f7bd9df4SAndrew Rist 
23cdf0e10cSrcweir #ifndef _I18N_COLLATORIMPL_HXX_
24cdf0e10cSrcweir #define _I18N_COLLATORIMPL_HXX_
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
27cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
28cdf0e10cSrcweir #include <com/sun/star/uno/Reference.h>
29cdf0e10cSrcweir #include <com/sun/star/i18n/XLocaleData.hpp>
30cdf0e10cSrcweir #include <com/sun/star/i18n/XCollator.hpp>
31cdf0e10cSrcweir #include <com/sun/star/lang/Locale.hpp>
32cdf0e10cSrcweir #include <cppuhelper/weak.hxx>
33cdf0e10cSrcweir #include <cppuhelper/implbase2.hxx>
34cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
35cdf0e10cSrcweir #include <sal/alloca.h>
36cdf0e10cSrcweir #include <vector>
37cdf0e10cSrcweir 
38cdf0e10cSrcweir namespace com { namespace sun { namespace star { namespace i18n {
39cdf0e10cSrcweir //      ----------------------------------------------------
40cdf0e10cSrcweir //      class CollatorImpl
41cdf0e10cSrcweir //      ----------------------------------------------------
42cdf0e10cSrcweir class CollatorImpl : public cppu::WeakImplHelper2
43cdf0e10cSrcweir <
44cdf0e10cSrcweir 	XCollator,
45cdf0e10cSrcweir 	com::sun::star::lang::XServiceInfo
46cdf0e10cSrcweir >
47cdf0e10cSrcweir {
48cdf0e10cSrcweir public:
49cdf0e10cSrcweir 
50cdf0e10cSrcweir 	// Constructors
51cdf0e10cSrcweir 	CollatorImpl( const com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory >& rxMSF );
52cdf0e10cSrcweir 	// Destructor
53cdf0e10cSrcweir 	~CollatorImpl();
54cdf0e10cSrcweir 
55cdf0e10cSrcweir 	virtual sal_Int32 SAL_CALL compareSubstring(const rtl::OUString& s1, sal_Int32 off1, sal_Int32 len1,
56cdf0e10cSrcweir 		const rtl::OUString& s2, sal_Int32 off2, sal_Int32 len2) throw(com::sun::star::uno::RuntimeException);
57cdf0e10cSrcweir 
58cdf0e10cSrcweir 	virtual sal_Int32 SAL_CALL compareString( const rtl::OUString& s1,
59cdf0e10cSrcweir 		const rtl::OUString& s2) throw(com::sun::star::uno::RuntimeException);
60cdf0e10cSrcweir 
61cdf0e10cSrcweir 	virtual sal_Int32 SAL_CALL loadDefaultCollator( const lang::Locale& rLocale,  sal_Int32 collatorOptions)
62cdf0e10cSrcweir 		throw(com::sun::star::uno::RuntimeException);
63cdf0e10cSrcweir 
64cdf0e10cSrcweir 	virtual sal_Int32 SAL_CALL loadCollatorAlgorithm(  const rtl::OUString& impl, const lang::Locale& rLocale,
65cdf0e10cSrcweir 		sal_Int32 collatorOptions) throw(com::sun::star::uno::RuntimeException);
66cdf0e10cSrcweir 
67cdf0e10cSrcweir 	virtual void SAL_CALL loadCollatorAlgorithmWithEndUserOption( const rtl::OUString& impl, const lang::Locale& rLocale,
68cdf0e10cSrcweir 		const com::sun::star::uno::Sequence< sal_Int32 >& collatorOptions) throw(com::sun::star::uno::RuntimeException);
69cdf0e10cSrcweir 
70cdf0e10cSrcweir 	virtual com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL listCollatorAlgorithms( const lang::Locale& rLocale )
71cdf0e10cSrcweir 		throw(com::sun::star::uno::RuntimeException);
72cdf0e10cSrcweir 
73cdf0e10cSrcweir 	virtual com::sun::star::uno::Sequence< sal_Int32 > SAL_CALL listCollatorOptions( const rtl::OUString& collatorAlgorithmName )
74cdf0e10cSrcweir 		throw(com::sun::star::uno::RuntimeException);
75cdf0e10cSrcweir 
76cdf0e10cSrcweir 	//XServiceInfo
77cdf0e10cSrcweir 	virtual rtl::OUString SAL_CALL getImplementationName() throw( com::sun::star::uno::RuntimeException );
78cdf0e10cSrcweir 	virtual sal_Bool SAL_CALL supportsService(const rtl::OUString& ServiceName) throw( com::sun::star::uno::RuntimeException );
79cdf0e10cSrcweir 	virtual com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames() throw( com::sun::star::uno::RuntimeException );
80cdf0e10cSrcweir 
81cdf0e10cSrcweir protected:
82cdf0e10cSrcweir 	lang::Locale nLocale;
83cdf0e10cSrcweir private :
84cdf0e10cSrcweir 	struct lookupTableItem {
85cdf0e10cSrcweir 	    lang::Locale aLocale;
86cdf0e10cSrcweir 	    rtl::OUString algorithm;
87cdf0e10cSrcweir 	    rtl::OUString service;
88cdf0e10cSrcweir 	    com::sun::star::uno::Reference < XCollator > xC;
lookupTableItemcom::sun::star::i18n::CollatorImpl::lookupTableItem89cdf0e10cSrcweir 	    lookupTableItem(const lang::Locale& rLocale, const rtl::OUString& _algorithm, const rtl::OUString& _service,
90cdf0e10cSrcweir 		com::sun::star::uno::Reference < XCollator >& _xC) : aLocale(rLocale), algorithm(_algorithm), service(_service), xC(_xC) {}
equalscom::sun::star::i18n::CollatorImpl::lookupTableItem91cdf0e10cSrcweir 	    sal_Bool SAL_CALL equals(const lang::Locale& rLocale, const rtl::OUString& _algorithm) {
92cdf0e10cSrcweir 		return aLocale.Language == rLocale.Language &&
93cdf0e10cSrcweir 			aLocale.Country == rLocale.Country &&
94cdf0e10cSrcweir 			aLocale.Variant == rLocale.Variant &&
95cdf0e10cSrcweir 			algorithm == _algorithm;
96cdf0e10cSrcweir 	    }
97cdf0e10cSrcweir 	};
98cdf0e10cSrcweir 	std::vector<lookupTableItem*> lookupTable;
99cdf0e10cSrcweir 	lookupTableItem *cachedItem;
100cdf0e10cSrcweir 
101cdf0e10cSrcweir 	// Service Factory
102cdf0e10cSrcweir 	com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > xMSF;
103cdf0e10cSrcweir 	// lang::Locale Data
104cdf0e10cSrcweir 	com::sun::star::uno::Reference < XLocaleData > localedata;
105cdf0e10cSrcweir 
106cdf0e10cSrcweir 	sal_Bool SAL_CALL createCollator(const lang::Locale& rLocale, const rtl::OUString& serviceName,
107cdf0e10cSrcweir 		const rtl::OUString& rSortAlgorithm) throw(com::sun::star::uno::RuntimeException);
108cdf0e10cSrcweir 	void SAL_CALL loadCachedCollator(const lang::Locale& rLocale, const rtl::OUString& rSortAlgorithm)
109cdf0e10cSrcweir 		throw(com::sun::star::uno::RuntimeException);
110cdf0e10cSrcweir };
111cdf0e10cSrcweir 
112cdf0e10cSrcweir } } } }
113cdf0e10cSrcweir 
114cdf0e10cSrcweir #endif
115