bump product version to 6.3.0.0.beta1
[LibreOffice.git] / comphelper / source / compare / AnyCompareFactory.cxx
blob5ad36c5eb6151eca872a303fe37716915b2e121f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <com/sun/star/ucb/XAnyCompareFactory.hpp>
21 #include <com/sun/star/i18n/Collator.hpp>
22 #include <com/sun/star/lang/Locale.hpp>
23 #include <com/sun/star/uno/Sequence.h>
24 #include <cppuhelper/implbase.hxx>
25 #include <cppuhelper/supportsservice.hxx>
26 #include <com/sun/star/lang/XServiceInfo.hpp>
27 #include <com/sun/star/lang/XInitialization.hpp>
29 using namespace com::sun::star::uno;
30 using namespace com::sun::star::ucb;
31 using namespace com::sun::star::lang;
32 using namespace com::sun::star::i18n;
34 class AnyCompare : public ::cppu::WeakImplHelper< XAnyCompare >
36 Reference< XCollator > m_xCollator;
38 public:
39 AnyCompare( Reference< XComponentContext > const & xContext, const Locale& rLocale )
41 m_xCollator = Collator::create( xContext );
42 m_xCollator->loadDefaultCollator( rLocale,
43 0 ); //???
46 virtual sal_Int16 SAL_CALL compare( const Any& any1, const Any& any2 ) override;
49 class AnyCompareFactory : public cppu::WeakImplHelper< XAnyCompareFactory, XInitialization, XServiceInfo >
51 Reference< XAnyCompare > m_xAnyCompare;
52 Reference< XComponentContext > m_xContext;
53 Locale m_Locale;
55 public:
56 explicit AnyCompareFactory( Reference< XComponentContext > const & xContext ) : m_xContext( xContext )
59 // XAnyCompareFactory
60 virtual Reference< XAnyCompare > SAL_CALL createAnyCompareByName ( const OUString& aPropertyName ) override;
62 // XInitialization
63 virtual void SAL_CALL initialize( const Sequence< Any >& aArguments ) override;
65 // XServiceInfo
66 virtual OUString SAL_CALL getImplementationName( ) override;
67 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
68 virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
71 sal_Int16 SAL_CALL AnyCompare::compare( const Any& any1, const Any& any2 )
73 sal_Int16 aResult = 0;
75 OUString aStr1;
76 OUString aStr2;
78 any1 >>= aStr1;
79 any2 >>= aStr2;
81 aResult = static_cast<sal_Int16>(m_xCollator->compareString(aStr1, aStr2));
83 return aResult;
86 Reference< XAnyCompare > SAL_CALL AnyCompareFactory::createAnyCompareByName( const OUString& aPropertyName )
88 // for now only OUString properties compare is implemented
89 // so no check for the property name is done
91 if( aPropertyName == "Title" )
92 return m_xAnyCompare;
94 return Reference< XAnyCompare >();
97 void SAL_CALL AnyCompareFactory::initialize( const Sequence< Any >& aArguments )
99 if( aArguments.getLength() )
101 if( aArguments[0] >>= m_Locale )
103 m_xAnyCompare = new AnyCompare( m_xContext, m_Locale );
104 return;
109 OUString SAL_CALL AnyCompareFactory::getImplementationName( )
111 return OUString( "AnyCompareFactory" );
114 sal_Bool SAL_CALL AnyCompareFactory::supportsService( const OUString& ServiceName )
116 return cppu::supportsService(this, ServiceName);
119 Sequence< OUString > SAL_CALL AnyCompareFactory::getSupportedServiceNames( )
121 const OUString aServiceName( "com.sun.star.ucb.AnyCompareFactory" );
122 const Sequence< OUString > aSeq( &aServiceName, 1 );
123 return aSeq;
126 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
127 AnyCompareFactory_get_implementation(
128 css::uno::XComponentContext *context,
129 css::uno::Sequence<css::uno::Any> const &)
131 return cppu::acquire(new AnyCompareFactory(context));
134 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */