1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_comphelper.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "comphelper_module.hxx" 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include <com/sun/star/ucb/XAnyCompareFactory.hpp> 34*cdf0e10cSrcweir #include <com/sun/star/i18n/XCollator.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/lang/Locale.hpp> 36*cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.h> 37*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 38*cdf0e10cSrcweir #include <cppuhelper/implbase3.hxx> 39*cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 40*cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp> 41*cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp> 42*cdf0e10cSrcweir #include <com/sun/star/lang/IllegalArgumentException.hpp> 43*cdf0e10cSrcweir #include <com/sun/star/lang/XMultiComponentFactory.hpp> 44*cdf0e10cSrcweir #include <comphelper/stl_types.hxx> 45*cdf0e10cSrcweir #include <map> 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir using namespace com::sun::star::uno; 49*cdf0e10cSrcweir using namespace com::sun::star::ucb; 50*cdf0e10cSrcweir using namespace com::sun::star::lang; 51*cdf0e10cSrcweir using namespace com::sun::star::i18n; 52*cdf0e10cSrcweir using namespace rtl; 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir //============================================================================= 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir class AnyCompare : public ::cppu::WeakImplHelper1< XAnyCompare > 57*cdf0e10cSrcweir { 58*cdf0e10cSrcweir Reference< XCollator > m_rCollator; 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir public: 61*cdf0e10cSrcweir AnyCompare( Reference< XComponentContext > xContext, const Locale& rLocale ) throw() 62*cdf0e10cSrcweir { 63*cdf0e10cSrcweir Reference< XMultiComponentFactory > xFactory = xContext->getServiceManager(); 64*cdf0e10cSrcweir if ( xFactory.is() ) 65*cdf0e10cSrcweir { 66*cdf0e10cSrcweir m_rCollator = Reference< XCollator >( 67*cdf0e10cSrcweir xFactory->createInstanceWithContext( OUString::createFromAscii( "com.sun.star.i18n.Collator" ), xContext ), 68*cdf0e10cSrcweir UNO_QUERY ); 69*cdf0e10cSrcweir m_rCollator->loadDefaultCollator( rLocale, 70*cdf0e10cSrcweir 0 ); //??? 71*cdf0e10cSrcweir } 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir } 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir virtual sal_Int16 SAL_CALL compare( const Any& any1, const Any& any2 ) throw(RuntimeException); 76*cdf0e10cSrcweir }; 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir //============================================================================= 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir class AnyCompareFactory : public cppu::WeakImplHelper3< XAnyCompareFactory, XInitialization, XServiceInfo > 81*cdf0e10cSrcweir { 82*cdf0e10cSrcweir Reference< XAnyCompare > m_rAnyCompare; 83*cdf0e10cSrcweir Reference< XComponentContext > m_rContext; 84*cdf0e10cSrcweir Locale m_Locale; 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir public: 87*cdf0e10cSrcweir AnyCompareFactory( Reference< XComponentContext > xContext ) : m_rContext( xContext ) 88*cdf0e10cSrcweir {} 89*cdf0e10cSrcweir 90*cdf0e10cSrcweir // XAnyCompareFactory 91*cdf0e10cSrcweir virtual Reference< XAnyCompare > SAL_CALL createAnyCompareByName ( const OUString& aPropertyName ) throw(::com::sun::star::uno::RuntimeException); 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir // XInitialization 94*cdf0e10cSrcweir virtual void SAL_CALL initialize( const Sequence< Any >& aArguments ) 95*cdf0e10cSrcweir throw ( Exception, RuntimeException ); 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir // XServiceInfo 98*cdf0e10cSrcweir virtual OUString SAL_CALL getImplementationName( ) throw(RuntimeException); 99*cdf0e10cSrcweir virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw(RuntimeException); 100*cdf0e10cSrcweir virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw(RuntimeException); 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir // XServiceInfo - static versions (used for component registration) 103*cdf0e10cSrcweir static ::rtl::OUString SAL_CALL getImplementationName_static(); 104*cdf0e10cSrcweir static Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames_static(); 105*cdf0e10cSrcweir static Reference< XInterface > SAL_CALL Create( const Reference< XComponentContext >& ); 106*cdf0e10cSrcweir }; 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir //=========================================================================================== 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir sal_Int16 SAL_CALL AnyCompare::compare( const Any& any1, const Any& any2 ) throw(::com::sun::star::uno::RuntimeException) 111*cdf0e10cSrcweir { 112*cdf0e10cSrcweir sal_Int16 aResult = 0; 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir if( m_rCollator.is() ) 115*cdf0e10cSrcweir { 116*cdf0e10cSrcweir OUString aStr1; 117*cdf0e10cSrcweir OUString aStr2; 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir any1 >>= aStr1; 120*cdf0e10cSrcweir any2 >>= aStr2; 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir aResult = ( sal_Int16 )m_rCollator->compareString( aStr1, aStr2 ); 123*cdf0e10cSrcweir } 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir return aResult; 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir //=========================================================================================== 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir Reference< XAnyCompare > SAL_CALL AnyCompareFactory::createAnyCompareByName( const OUString& aPropertyName ) throw(::com::sun::star::uno::RuntimeException) 131*cdf0e10cSrcweir { 132*cdf0e10cSrcweir // for now only OUString properties compare is implemented 133*cdf0e10cSrcweir // so no check for the property name is done 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir if( aPropertyName.equals( OUString::createFromAscii( "Title" ) ) ) 136*cdf0e10cSrcweir return m_rAnyCompare; 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir return Reference< XAnyCompare >(); 139*cdf0e10cSrcweir } 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir void SAL_CALL AnyCompareFactory::initialize( const Sequence< Any >& aArguments ) throw ( Exception, RuntimeException ) 142*cdf0e10cSrcweir { 143*cdf0e10cSrcweir if( aArguments.getLength() ) 144*cdf0e10cSrcweir { 145*cdf0e10cSrcweir if( aArguments[0] >>= m_Locale ) 146*cdf0e10cSrcweir { 147*cdf0e10cSrcweir m_rAnyCompare = new AnyCompare( m_rContext, m_Locale ); 148*cdf0e10cSrcweir return; 149*cdf0e10cSrcweir } 150*cdf0e10cSrcweir } 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir OUString SAL_CALL AnyCompareFactory::getImplementationName( ) throw( RuntimeException ) 155*cdf0e10cSrcweir { 156*cdf0e10cSrcweir return getImplementationName_static(); 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir OUString SAL_CALL AnyCompareFactory::getImplementationName_static( ) 160*cdf0e10cSrcweir { 161*cdf0e10cSrcweir return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AnyCompareFactory" ) ); 162*cdf0e10cSrcweir } 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir sal_Bool SAL_CALL AnyCompareFactory::supportsService( const OUString& ServiceName ) throw(RuntimeException) 165*cdf0e10cSrcweir { 166*cdf0e10cSrcweir rtl::OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ucb.AnyCompareFactory" ) ); 167*cdf0e10cSrcweir return aServiceName == ServiceName; 168*cdf0e10cSrcweir } 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir Sequence< OUString > SAL_CALL AnyCompareFactory::getSupportedServiceNames( ) throw(RuntimeException) 171*cdf0e10cSrcweir { 172*cdf0e10cSrcweir return getSupportedServiceNames_static(); 173*cdf0e10cSrcweir } 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir Sequence< OUString > SAL_CALL AnyCompareFactory::getSupportedServiceNames_static( ) 176*cdf0e10cSrcweir { 177*cdf0e10cSrcweir const rtl::OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ucb.AnyCompareFactory" ) ); 178*cdf0e10cSrcweir const Sequence< rtl::OUString > aSeq( &aServiceName, 1 ); 179*cdf0e10cSrcweir return aSeq; 180*cdf0e10cSrcweir } 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir Reference< XInterface > SAL_CALL AnyCompareFactory::Create( 183*cdf0e10cSrcweir const Reference< XComponentContext >& rxContext ) 184*cdf0e10cSrcweir { 185*cdf0e10cSrcweir return (cppu::OWeakObject*)new AnyCompareFactory( rxContext ); 186*cdf0e10cSrcweir } 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir void createRegistryInfo_AnyCompareFactory() 189*cdf0e10cSrcweir { 190*cdf0e10cSrcweir static ::comphelper::module::OAutoRegistration< AnyCompareFactory > aAutoRegistration; 191*cdf0e10cSrcweir } 192