/src/libreoffice/comphelper/source/compare/AnyCompareFactory.cxx
Line | Count | Source (jump to first uncovered line) |
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> |
25 | | #include <cppuhelper/supportsservice.hxx> |
26 | | #include <com/sun/star/lang/XServiceInfo.hpp> |
27 | | #include <com/sun/star/lang/XInitialization.hpp> |
28 | | #include <rtl/ref.hxx> |
29 | | |
30 | | using namespace com::sun::star::uno; |
31 | | using namespace com::sun::star::ucb; |
32 | | using namespace com::sun::star::lang; |
33 | | using namespace com::sun::star::i18n; |
34 | | |
35 | | namespace { |
36 | | |
37 | | class AnyCompare : public ::cppu::WeakImplHelper< XAnyCompare > |
38 | | { |
39 | | Reference< XCollator > m_xCollator; |
40 | | |
41 | | public: |
42 | | AnyCompare( Reference< XComponentContext > const & xContext, const Locale& rLocale ) |
43 | 0 | : m_xCollator(Collator::create( xContext )) |
44 | 0 | { |
45 | 0 | m_xCollator->loadDefaultCollator( rLocale, |
46 | 0 | 0 ); //??? |
47 | 0 | } |
48 | | |
49 | | virtual sal_Int16 SAL_CALL compare( const Any& any1, const Any& any2 ) override; |
50 | | }; |
51 | | |
52 | | class AnyCompareFactory : public cppu::WeakImplHelper< XAnyCompareFactory, XInitialization, XServiceInfo > |
53 | | { |
54 | | rtl::Reference< AnyCompare > m_xAnyCompare; |
55 | | Reference< XComponentContext > m_xContext; |
56 | | Locale m_Locale; |
57 | | |
58 | | public: |
59 | 0 | explicit AnyCompareFactory( Reference< XComponentContext > const & xContext ) : m_xContext( xContext ) |
60 | 0 | {} |
61 | | |
62 | | // XAnyCompareFactory |
63 | | virtual Reference< XAnyCompare > SAL_CALL createAnyCompareByName ( const OUString& aPropertyName ) override; |
64 | | |
65 | | // XInitialization |
66 | | virtual void SAL_CALL initialize( const Sequence< Any >& aArguments ) override; |
67 | | |
68 | | // XServiceInfo |
69 | | virtual OUString SAL_CALL getImplementationName( ) override; |
70 | | virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; |
71 | | virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) override; |
72 | | }; |
73 | | |
74 | | } |
75 | | |
76 | | sal_Int16 SAL_CALL AnyCompare::compare( const Any& any1, const Any& any2 ) |
77 | 0 | { |
78 | 0 | sal_Int16 aResult = 0; |
79 | |
|
80 | 0 | OUString aStr1; |
81 | 0 | OUString aStr2; |
82 | |
|
83 | 0 | any1 >>= aStr1; |
84 | 0 | any2 >>= aStr2; |
85 | |
|
86 | 0 | aResult = static_cast<sal_Int16>(m_xCollator->compareString(aStr1, aStr2)); |
87 | |
|
88 | 0 | return aResult; |
89 | 0 | } |
90 | | |
91 | | Reference< XAnyCompare > SAL_CALL AnyCompareFactory::createAnyCompareByName( const OUString& aPropertyName ) |
92 | 0 | { |
93 | | // for now only OUString properties compare is implemented |
94 | | // so no check for the property name is done |
95 | |
|
96 | 0 | if( aPropertyName == "Title" ) |
97 | 0 | return m_xAnyCompare; |
98 | | |
99 | 0 | return Reference< XAnyCompare >(); |
100 | 0 | } |
101 | | |
102 | | void SAL_CALL AnyCompareFactory::initialize( const Sequence< Any >& aArguments ) |
103 | 0 | { |
104 | 0 | if( aArguments.hasElements() ) |
105 | 0 | { |
106 | 0 | if( aArguments[0] >>= m_Locale ) |
107 | 0 | { |
108 | 0 | m_xAnyCompare = new AnyCompare( m_xContext, m_Locale ); |
109 | 0 | return; |
110 | 0 | } |
111 | 0 | } |
112 | 0 | } |
113 | | |
114 | | OUString SAL_CALL AnyCompareFactory::getImplementationName( ) |
115 | 0 | { |
116 | 0 | return u"AnyCompareFactory"_ustr; |
117 | 0 | } |
118 | | |
119 | | sal_Bool SAL_CALL AnyCompareFactory::supportsService( const OUString& ServiceName ) |
120 | 0 | { |
121 | 0 | return cppu::supportsService(this, ServiceName); |
122 | 0 | } |
123 | | |
124 | | Sequence< OUString > SAL_CALL AnyCompareFactory::getSupportedServiceNames( ) |
125 | 0 | { |
126 | 0 | return { u"com.sun.star.ucb.AnyCompareFactory"_ustr }; |
127 | 0 | } |
128 | | |
129 | | extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * |
130 | | AnyCompareFactory_get_implementation( |
131 | | css::uno::XComponentContext *context, |
132 | | css::uno::Sequence<css::uno::Any> const &) |
133 | 0 | { |
134 | 0 | return cppu::acquire(new AnyCompareFactory(context)); |
135 | 0 | } |
136 | | |
137 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |