LibreOffice Module comphelper (master)  1
AnyCompareFactory.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
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>
26 #include <com/sun/star/lang/XServiceInfo.hpp>
27 #include <com/sun/star/lang/XInitialization.hpp>
28 
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;
33 
34 class AnyCompare : public ::cppu::WeakImplHelper< XAnyCompare >
35 {
37 
38 public:
39  AnyCompare( Reference< XComponentContext > const & xContext, const Locale& rLocale )
40  {
41  m_xCollator = Collator::create( xContext );
42  m_xCollator->loadDefaultCollator( rLocale,
43  0 ); //???
44  }
45 
46  virtual sal_Int16 SAL_CALL compare( const Any& any1, const Any& any2 ) override;
47 };
48 
49 class AnyCompareFactory : public cppu::WeakImplHelper< XAnyCompareFactory, XInitialization, XServiceInfo >
50 {
54 
55 public:
56  explicit AnyCompareFactory( Reference< XComponentContext > const & xContext ) : m_xContext( xContext )
57  {}
58 
59  // XAnyCompareFactory
60  virtual Reference< XAnyCompare > SAL_CALL createAnyCompareByName ( const OUString& aPropertyName ) override;
61 
62  // XInitialization
63  virtual void SAL_CALL initialize( const Sequence< Any >& aArguments ) override;
64 
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;
69 };
70 
71 sal_Int16 SAL_CALL AnyCompare::compare( const Any& any1, const Any& any2 )
72 {
73  sal_Int16 aResult = 0;
74 
75  OUString aStr1;
76  OUString aStr2;
77 
78  any1 >>= aStr1;
79  any2 >>= aStr2;
80 
81  aResult = static_cast<sal_Int16>(m_xCollator->compareString(aStr1, aStr2));
82 
83  return aResult;
84 }
85 
87 {
88  // for now only OUString properties compare is implemented
89  // so no check for the property name is done
90 
91  if( aPropertyName == "Title" )
92  return m_xAnyCompare;
93 
94  return Reference< XAnyCompare >();
95 }
96 
97 void SAL_CALL AnyCompareFactory::initialize( const Sequence< Any >& aArguments )
98 {
99  if( aArguments.hasElements() )
100  {
101  if( aArguments[0] >>= m_Locale )
102  {
103  m_xAnyCompare = new AnyCompare( m_xContext, m_Locale );
104  return;
105  }
106  }
107 }
108 
110 {
111  return "AnyCompareFactory";
112 }
113 
114 sal_Bool SAL_CALL AnyCompareFactory::supportsService( const OUString& ServiceName )
115 {
116  return cppu::supportsService(this, ServiceName);
117 }
118 
120 {
121  return { "com.sun.star.ucb.AnyCompareFactory" };
122 }
123 
124 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
126  css::uno::XComponentContext *context,
127  css::uno::Sequence<css::uno::Any> const &)
128 {
129  return cppu::acquire(new AnyCompareFactory(context));
130 }
131 
132 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString getImplementationName()
virtual Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual void SAL_CALL initialize(const Sequence< Any > &aArguments) override
AnyCompare(Reference< XComponentContext > const &xContext, const Locale &rLocale)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
css::uno::Sequence< OUString > getSupportedServiceNames()
unsigned char sal_Bool
Reference< XAnyCompare > m_xAnyCompare
virtual sal_Int16 SAL_CALL compare(const Any &any1, const Any &any2) override
virtual OUString SAL_CALL getImplementationName() override
AnyCompareFactory(Reference< XComponentContext > const &xContext)
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Reference< XComponentContext > m_xContext
virtual Reference< XAnyCompare > SAL_CALL createAnyCompareByName(const OUString &aPropertyName) override
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * AnyCompareFactory_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
Reference< XCollator > m_xCollator
SbxDecimal::CmpResult compare(SAL_UNUSED_PARAMETER const SbxDecimal &, SAL_UNUSED_PARAMETER const SbxDecimal &)
const uno::Reference< uno::XComponentContext > m_xContext