xref: /aoo42x/main/i18npool/inc/collatorImpl.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
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.
14  *
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).
20  *
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.
25  *
26  ************************************************************************/
27 #ifndef _I18N_COLLATORIMPL_HXX_
28 #define _I18N_COLLATORIMPL_HXX_
29 
30 #include <comphelper/processfactory.hxx>
31 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
32 #include <com/sun/star/uno/Reference.h>
33 #include <com/sun/star/i18n/XLocaleData.hpp>
34 #include <com/sun/star/i18n/XCollator.hpp>
35 #include <com/sun/star/lang/Locale.hpp>
36 #include <cppuhelper/weak.hxx>
37 #include <cppuhelper/implbase2.hxx>
38 #include <com/sun/star/lang/XServiceInfo.hpp>
39 #include <sal/alloca.h>
40 #include <vector>
41 
42 namespace com { namespace sun { namespace star { namespace i18n {
43 //      ----------------------------------------------------
44 //      class CollatorImpl
45 //      ----------------------------------------------------
46 class CollatorImpl : public cppu::WeakImplHelper2
47 <
48 	XCollator,
49 	com::sun::star::lang::XServiceInfo
50 >
51 {
52 public:
53 
54 	// Constructors
55 	CollatorImpl( const com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory >& rxMSF );
56 	// Destructor
57 	~CollatorImpl();
58 
59 	virtual sal_Int32 SAL_CALL compareSubstring(const rtl::OUString& s1, sal_Int32 off1, sal_Int32 len1,
60 		const rtl::OUString& s2, sal_Int32 off2, sal_Int32 len2) throw(com::sun::star::uno::RuntimeException);
61 
62 	virtual sal_Int32 SAL_CALL compareString( const rtl::OUString& s1,
63 		const rtl::OUString& s2) throw(com::sun::star::uno::RuntimeException);
64 
65 	virtual sal_Int32 SAL_CALL loadDefaultCollator( const lang::Locale& rLocale,  sal_Int32 collatorOptions)
66 		throw(com::sun::star::uno::RuntimeException);
67 
68 	virtual sal_Int32 SAL_CALL loadCollatorAlgorithm(  const rtl::OUString& impl, const lang::Locale& rLocale,
69 		sal_Int32 collatorOptions) throw(com::sun::star::uno::RuntimeException);
70 
71 	virtual void SAL_CALL loadCollatorAlgorithmWithEndUserOption( const rtl::OUString& impl, const lang::Locale& rLocale,
72 		const com::sun::star::uno::Sequence< sal_Int32 >& collatorOptions) throw(com::sun::star::uno::RuntimeException);
73 
74 	virtual com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL listCollatorAlgorithms( const lang::Locale& rLocale )
75 		throw(com::sun::star::uno::RuntimeException);
76 
77 	virtual com::sun::star::uno::Sequence< sal_Int32 > SAL_CALL listCollatorOptions( const rtl::OUString& collatorAlgorithmName )
78 		throw(com::sun::star::uno::RuntimeException);
79 
80 	//XServiceInfo
81 	virtual rtl::OUString SAL_CALL getImplementationName() throw( com::sun::star::uno::RuntimeException );
82 	virtual sal_Bool SAL_CALL supportsService(const rtl::OUString& ServiceName) throw( com::sun::star::uno::RuntimeException );
83 	virtual com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames() throw( com::sun::star::uno::RuntimeException );
84 
85 protected:
86 	lang::Locale nLocale;
87 private :
88 	struct lookupTableItem {
89 	    lang::Locale aLocale;
90 	    rtl::OUString algorithm;
91 	    rtl::OUString service;
92 	    com::sun::star::uno::Reference < XCollator > xC;
93 	    lookupTableItem(const lang::Locale& rLocale, const rtl::OUString& _algorithm, const rtl::OUString& _service,
94 		com::sun::star::uno::Reference < XCollator >& _xC) : aLocale(rLocale), algorithm(_algorithm), service(_service), xC(_xC) {}
95 	    sal_Bool SAL_CALL equals(const lang::Locale& rLocale, const rtl::OUString& _algorithm) {
96 		return aLocale.Language == rLocale.Language &&
97 			aLocale.Country == rLocale.Country &&
98 			aLocale.Variant == rLocale.Variant &&
99 			algorithm == _algorithm;
100 	    }
101 	};
102 	std::vector<lookupTableItem*> lookupTable;
103 	lookupTableItem *cachedItem;
104 
105 	// Service Factory
106 	com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > xMSF;
107 	// lang::Locale Data
108 	com::sun::star::uno::Reference < XLocaleData > localedata;
109 
110 	sal_Bool SAL_CALL createCollator(const lang::Locale& rLocale, const rtl::OUString& serviceName,
111 		const rtl::OUString& rSortAlgorithm) throw(com::sun::star::uno::RuntimeException);
112 	void SAL_CALL loadCachedCollator(const lang::Locale& rLocale, const rtl::OUString& rSortAlgorithm)
113 		throw(com::sun::star::uno::RuntimeException);
114 };
115 
116 } } } }
117 
118 #endif
119