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 #ifndef _I18N_COLLATORIMPL_HXX_ 24 #define _I18N_COLLATORIMPL_HXX_ 25 26 #include <comphelper/processfactory.hxx> 27 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 28 #include <com/sun/star/uno/Reference.h> 29 #include <com/sun/star/i18n/XLocaleData.hpp> 30 #include <com/sun/star/i18n/XCollator.hpp> 31 #include <com/sun/star/lang/Locale.hpp> 32 #include <cppuhelper/weak.hxx> 33 #include <cppuhelper/implbase2.hxx> 34 #include <com/sun/star/lang/XServiceInfo.hpp> 35 #include <sal/alloca.h> 36 #include <vector> 37 38 namespace com { namespace sun { namespace star { namespace i18n { 39 // ---------------------------------------------------- 40 // class CollatorImpl 41 // ---------------------------------------------------- 42 class CollatorImpl : public cppu::WeakImplHelper2 43 < 44 XCollator, 45 com::sun::star::lang::XServiceInfo 46 > 47 { 48 public: 49 50 // Constructors 51 CollatorImpl( const com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory >& rxMSF ); 52 // Destructor 53 ~CollatorImpl(); 54 55 virtual sal_Int32 SAL_CALL compareSubstring(const rtl::OUString& s1, sal_Int32 off1, sal_Int32 len1, 56 const rtl::OUString& s2, sal_Int32 off2, sal_Int32 len2) throw(com::sun::star::uno::RuntimeException); 57 58 virtual sal_Int32 SAL_CALL compareString( const rtl::OUString& s1, 59 const rtl::OUString& s2) throw(com::sun::star::uno::RuntimeException); 60 61 virtual sal_Int32 SAL_CALL loadDefaultCollator( const lang::Locale& rLocale, sal_Int32 collatorOptions) 62 throw(com::sun::star::uno::RuntimeException); 63 64 virtual sal_Int32 SAL_CALL loadCollatorAlgorithm( const rtl::OUString& impl, const lang::Locale& rLocale, 65 sal_Int32 collatorOptions) throw(com::sun::star::uno::RuntimeException); 66 67 virtual void SAL_CALL loadCollatorAlgorithmWithEndUserOption( const rtl::OUString& impl, const lang::Locale& rLocale, 68 const com::sun::star::uno::Sequence< sal_Int32 >& collatorOptions) throw(com::sun::star::uno::RuntimeException); 69 70 virtual com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL listCollatorAlgorithms( const lang::Locale& rLocale ) 71 throw(com::sun::star::uno::RuntimeException); 72 73 virtual com::sun::star::uno::Sequence< sal_Int32 > SAL_CALL listCollatorOptions( const rtl::OUString& collatorAlgorithmName ) 74 throw(com::sun::star::uno::RuntimeException); 75 76 //XServiceInfo 77 virtual rtl::OUString SAL_CALL getImplementationName() throw( com::sun::star::uno::RuntimeException ); 78 virtual sal_Bool SAL_CALL supportsService(const rtl::OUString& ServiceName) throw( com::sun::star::uno::RuntimeException ); 79 virtual com::sun::star::uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames() throw( com::sun::star::uno::RuntimeException ); 80 81 protected: 82 lang::Locale nLocale; 83 private : 84 struct lookupTableItem { 85 lang::Locale aLocale; 86 rtl::OUString algorithm; 87 rtl::OUString service; 88 com::sun::star::uno::Reference < XCollator > xC; lookupTableItemcom::sun::star::i18n::CollatorImpl::lookupTableItem89 lookupTableItem(const lang::Locale& rLocale, const rtl::OUString& _algorithm, const rtl::OUString& _service, 90 com::sun::star::uno::Reference < XCollator >& _xC) : aLocale(rLocale), algorithm(_algorithm), service(_service), xC(_xC) {} equalscom::sun::star::i18n::CollatorImpl::lookupTableItem91 sal_Bool SAL_CALL equals(const lang::Locale& rLocale, const rtl::OUString& _algorithm) { 92 return aLocale.Language == rLocale.Language && 93 aLocale.Country == rLocale.Country && 94 aLocale.Variant == rLocale.Variant && 95 algorithm == _algorithm; 96 } 97 }; 98 std::vector<lookupTableItem*> lookupTable; 99 lookupTableItem *cachedItem; 100 101 // Service Factory 102 com::sun::star::uno::Reference < com::sun::star::lang::XMultiServiceFactory > xMSF; 103 // lang::Locale Data 104 com::sun::star::uno::Reference < XLocaleData > localedata; 105 106 sal_Bool SAL_CALL createCollator(const lang::Locale& rLocale, const rtl::OUString& serviceName, 107 const rtl::OUString& rSortAlgorithm) throw(com::sun::star::uno::RuntimeException); 108 void SAL_CALL loadCachedCollator(const lang::Locale& rLocale, const rtl::OUString& rSortAlgorithm) 109 throw(com::sun::star::uno::RuntimeException); 110 }; 111 112 } } } } 113 114 #endif 115