Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / comphelper / source / compare / AnyCompareFactory.cxx
blob40e5f0806a9596fd70ccfb7326219b8d72d3aaed
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 namespace {
36 class AnyCompare : public ::cppu::WeakImplHelper< XAnyCompare >
38 Reference< XCollator > m_xCollator;
40 public:
41 AnyCompare( Reference< XComponentContext > const & xContext, const Locale& rLocale )
42 : m_xCollator(Collator::create( xContext ))
44 m_xCollator->loadDefaultCollator( rLocale,
45 0 ); //???
48 virtual sal_Int16 SAL_CALL compare( const Any& any1, const Any& any2 ) override;
51 class AnyCompareFactory : public cppu::WeakImplHelper< XAnyCompareFactory, XInitialization, XServiceInfo >
53 Reference< XAnyCompare > m_xAnyCompare;
54 Reference< XComponentContext > m_xContext;
55 Locale m_Locale;
57 public:
58 explicit AnyCompareFactory( Reference< XComponentContext > const & xContext ) : m_xContext( xContext )
61 // XAnyCompareFactory
62 virtual Reference< XAnyCompare > SAL_CALL createAnyCompareByName ( const OUString& aPropertyName ) override;
64 // XInitialization
65 virtual void SAL_CALL initialize( const Sequence< Any >& aArguments ) override;
67 // XServiceInfo
68 virtual OUString SAL_CALL getImplementationName( ) override;
69 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
70 virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override;
75 sal_Int16 SAL_CALL AnyCompare::compare( const Any& any1, const Any& any2 )
77 sal_Int16 aResult = 0;
79 OUString aStr1;
80 OUString aStr2;
82 any1 >>= aStr1;
83 any2 >>= aStr2;
85 aResult = static_cast<sal_Int16>(m_xCollator->compareString(aStr1, aStr2));
87 return aResult;
90 Reference< XAnyCompare > SAL_CALL AnyCompareFactory::createAnyCompareByName( const OUString& aPropertyName )
92 // for now only OUString properties compare is implemented
93 // so no check for the property name is done
95 if( aPropertyName == "Title" )
96 return m_xAnyCompare;
98 return Reference< XAnyCompare >();
101 void SAL_CALL AnyCompareFactory::initialize( const Sequence< Any >& aArguments )
103 if( aArguments.hasElements() )
105 if( aArguments[0] >>= m_Locale )
107 m_xAnyCompare = new AnyCompare( m_xContext, m_Locale );
108 return;
113 OUString SAL_CALL AnyCompareFactory::getImplementationName( )
115 return "AnyCompareFactory";
118 sal_Bool SAL_CALL AnyCompareFactory::supportsService( const OUString& ServiceName )
120 return cppu::supportsService(this, ServiceName);
123 Sequence< OUString > SAL_CALL AnyCompareFactory::getSupportedServiceNames( )
125 return { "com.sun.star.ucb.AnyCompareFactory" };
128 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
129 AnyCompareFactory_get_implementation(
130 css::uno::XComponentContext *context,
131 css::uno::Sequence<css::uno::Any> const &)
133 return cppu::acquire(new AnyCompareFactory(context));
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */