1*dde7d3faSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*dde7d3faSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*dde7d3faSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*dde7d3faSAndrew Rist * distributed with this work for additional information
6*dde7d3faSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*dde7d3faSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*dde7d3faSAndrew Rist * "License"); you may not use this file except in compliance
9*dde7d3faSAndrew Rist * with the License. You may obtain a copy of the License at
10*dde7d3faSAndrew Rist *
11*dde7d3faSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*dde7d3faSAndrew Rist *
13*dde7d3faSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*dde7d3faSAndrew Rist * software distributed under the License is distributed on an
15*dde7d3faSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*dde7d3faSAndrew Rist * KIND, either express or implied. See the License for the
17*dde7d3faSAndrew Rist * specific language governing permissions and limitations
18*dde7d3faSAndrew Rist * under the License.
19*dde7d3faSAndrew Rist *
20*dde7d3faSAndrew Rist *************************************************************/
21*dde7d3faSAndrew Rist
22*dde7d3faSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_comphelper.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include "comphelper_module.hxx"
28cdf0e10cSrcweir
29cdf0e10cSrcweir #include <com/sun/star/ucb/XAnyCompareFactory.hpp>
30cdf0e10cSrcweir #include <com/sun/star/i18n/XCollator.hpp>
31cdf0e10cSrcweir #include <com/sun/star/lang/Locale.hpp>
32cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.h>
33cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
34cdf0e10cSrcweir #include <cppuhelper/implbase3.hxx>
35cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx>
36cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
37cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp>
38cdf0e10cSrcweir #include <com/sun/star/lang/IllegalArgumentException.hpp>
39cdf0e10cSrcweir #include <com/sun/star/lang/XMultiComponentFactory.hpp>
40cdf0e10cSrcweir #include <comphelper/stl_types.hxx>
41cdf0e10cSrcweir #include <map>
42cdf0e10cSrcweir
43cdf0e10cSrcweir
44cdf0e10cSrcweir using namespace com::sun::star::uno;
45cdf0e10cSrcweir using namespace com::sun::star::ucb;
46cdf0e10cSrcweir using namespace com::sun::star::lang;
47cdf0e10cSrcweir using namespace com::sun::star::i18n;
48cdf0e10cSrcweir using namespace rtl;
49cdf0e10cSrcweir
50cdf0e10cSrcweir //=============================================================================
51cdf0e10cSrcweir
52cdf0e10cSrcweir class AnyCompare : public ::cppu::WeakImplHelper1< XAnyCompare >
53cdf0e10cSrcweir {
54cdf0e10cSrcweir Reference< XCollator > m_rCollator;
55cdf0e10cSrcweir
56cdf0e10cSrcweir public:
AnyCompare(Reference<XComponentContext> xContext,const Locale & rLocale)57cdf0e10cSrcweir AnyCompare( Reference< XComponentContext > xContext, const Locale& rLocale ) throw()
58cdf0e10cSrcweir {
59cdf0e10cSrcweir Reference< XMultiComponentFactory > xFactory = xContext->getServiceManager();
60cdf0e10cSrcweir if ( xFactory.is() )
61cdf0e10cSrcweir {
62cdf0e10cSrcweir m_rCollator = Reference< XCollator >(
63cdf0e10cSrcweir xFactory->createInstanceWithContext( OUString::createFromAscii( "com.sun.star.i18n.Collator" ), xContext ),
64cdf0e10cSrcweir UNO_QUERY );
65cdf0e10cSrcweir m_rCollator->loadDefaultCollator( rLocale,
66cdf0e10cSrcweir 0 ); //???
67cdf0e10cSrcweir }
68cdf0e10cSrcweir
69cdf0e10cSrcweir }
70cdf0e10cSrcweir
71cdf0e10cSrcweir virtual sal_Int16 SAL_CALL compare( const Any& any1, const Any& any2 ) throw(RuntimeException);
72cdf0e10cSrcweir };
73cdf0e10cSrcweir
74cdf0e10cSrcweir //=============================================================================
75cdf0e10cSrcweir
76cdf0e10cSrcweir class AnyCompareFactory : public cppu::WeakImplHelper3< XAnyCompareFactory, XInitialization, XServiceInfo >
77cdf0e10cSrcweir {
78cdf0e10cSrcweir Reference< XAnyCompare > m_rAnyCompare;
79cdf0e10cSrcweir Reference< XComponentContext > m_rContext;
80cdf0e10cSrcweir Locale m_Locale;
81cdf0e10cSrcweir
82cdf0e10cSrcweir public:
AnyCompareFactory(Reference<XComponentContext> xContext)83cdf0e10cSrcweir AnyCompareFactory( Reference< XComponentContext > xContext ) : m_rContext( xContext )
84cdf0e10cSrcweir {}
85cdf0e10cSrcweir
86cdf0e10cSrcweir // XAnyCompareFactory
87cdf0e10cSrcweir virtual Reference< XAnyCompare > SAL_CALL createAnyCompareByName ( const OUString& aPropertyName ) throw(::com::sun::star::uno::RuntimeException);
88cdf0e10cSrcweir
89cdf0e10cSrcweir // XInitialization
90cdf0e10cSrcweir virtual void SAL_CALL initialize( const Sequence< Any >& aArguments )
91cdf0e10cSrcweir throw ( Exception, RuntimeException );
92cdf0e10cSrcweir
93cdf0e10cSrcweir // XServiceInfo
94cdf0e10cSrcweir virtual OUString SAL_CALL getImplementationName( ) throw(RuntimeException);
95cdf0e10cSrcweir virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw(RuntimeException);
96cdf0e10cSrcweir virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw(RuntimeException);
97cdf0e10cSrcweir
98cdf0e10cSrcweir // XServiceInfo - static versions (used for component registration)
99cdf0e10cSrcweir static ::rtl::OUString SAL_CALL getImplementationName_static();
100cdf0e10cSrcweir static Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames_static();
101cdf0e10cSrcweir static Reference< XInterface > SAL_CALL Create( const Reference< XComponentContext >& );
102cdf0e10cSrcweir };
103cdf0e10cSrcweir
104cdf0e10cSrcweir //===========================================================================================
105cdf0e10cSrcweir
compare(const Any & any1,const Any & any2)106cdf0e10cSrcweir sal_Int16 SAL_CALL AnyCompare::compare( const Any& any1, const Any& any2 ) throw(::com::sun::star::uno::RuntimeException)
107cdf0e10cSrcweir {
108cdf0e10cSrcweir sal_Int16 aResult = 0;
109cdf0e10cSrcweir
110cdf0e10cSrcweir if( m_rCollator.is() )
111cdf0e10cSrcweir {
112cdf0e10cSrcweir OUString aStr1;
113cdf0e10cSrcweir OUString aStr2;
114cdf0e10cSrcweir
115cdf0e10cSrcweir any1 >>= aStr1;
116cdf0e10cSrcweir any2 >>= aStr2;
117cdf0e10cSrcweir
118cdf0e10cSrcweir aResult = ( sal_Int16 )m_rCollator->compareString( aStr1, aStr2 );
119cdf0e10cSrcweir }
120cdf0e10cSrcweir
121cdf0e10cSrcweir return aResult;
122cdf0e10cSrcweir }
123cdf0e10cSrcweir
124cdf0e10cSrcweir //===========================================================================================
125cdf0e10cSrcweir
createAnyCompareByName(const OUString & aPropertyName)126cdf0e10cSrcweir Reference< XAnyCompare > SAL_CALL AnyCompareFactory::createAnyCompareByName( const OUString& aPropertyName ) throw(::com::sun::star::uno::RuntimeException)
127cdf0e10cSrcweir {
128cdf0e10cSrcweir // for now only OUString properties compare is implemented
129cdf0e10cSrcweir // so no check for the property name is done
130cdf0e10cSrcweir
131cdf0e10cSrcweir if( aPropertyName.equals( OUString::createFromAscii( "Title" ) ) )
132cdf0e10cSrcweir return m_rAnyCompare;
133cdf0e10cSrcweir
134cdf0e10cSrcweir return Reference< XAnyCompare >();
135cdf0e10cSrcweir }
136cdf0e10cSrcweir
initialize(const Sequence<Any> & aArguments)137cdf0e10cSrcweir void SAL_CALL AnyCompareFactory::initialize( const Sequence< Any >& aArguments ) throw ( Exception, RuntimeException )
138cdf0e10cSrcweir {
139cdf0e10cSrcweir if( aArguments.getLength() )
140cdf0e10cSrcweir {
141cdf0e10cSrcweir if( aArguments[0] >>= m_Locale )
142cdf0e10cSrcweir {
143cdf0e10cSrcweir m_rAnyCompare = new AnyCompare( m_rContext, m_Locale );
144cdf0e10cSrcweir return;
145cdf0e10cSrcweir }
146cdf0e10cSrcweir }
147cdf0e10cSrcweir
148cdf0e10cSrcweir }
149cdf0e10cSrcweir
getImplementationName()150cdf0e10cSrcweir OUString SAL_CALL AnyCompareFactory::getImplementationName( ) throw( RuntimeException )
151cdf0e10cSrcweir {
152cdf0e10cSrcweir return getImplementationName_static();
153cdf0e10cSrcweir }
154cdf0e10cSrcweir
getImplementationName_static()155cdf0e10cSrcweir OUString SAL_CALL AnyCompareFactory::getImplementationName_static( )
156cdf0e10cSrcweir {
157cdf0e10cSrcweir return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AnyCompareFactory" ) );
158cdf0e10cSrcweir }
159cdf0e10cSrcweir
supportsService(const OUString & ServiceName)160cdf0e10cSrcweir sal_Bool SAL_CALL AnyCompareFactory::supportsService( const OUString& ServiceName ) throw(RuntimeException)
161cdf0e10cSrcweir {
162cdf0e10cSrcweir rtl::OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ucb.AnyCompareFactory" ) );
163cdf0e10cSrcweir return aServiceName == ServiceName;
164cdf0e10cSrcweir }
165cdf0e10cSrcweir
getSupportedServiceNames()166cdf0e10cSrcweir Sequence< OUString > SAL_CALL AnyCompareFactory::getSupportedServiceNames( ) throw(RuntimeException)
167cdf0e10cSrcweir {
168cdf0e10cSrcweir return getSupportedServiceNames_static();
169cdf0e10cSrcweir }
170cdf0e10cSrcweir
getSupportedServiceNames_static()171cdf0e10cSrcweir Sequence< OUString > SAL_CALL AnyCompareFactory::getSupportedServiceNames_static( )
172cdf0e10cSrcweir {
173cdf0e10cSrcweir const rtl::OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ucb.AnyCompareFactory" ) );
174cdf0e10cSrcweir const Sequence< rtl::OUString > aSeq( &aServiceName, 1 );
175cdf0e10cSrcweir return aSeq;
176cdf0e10cSrcweir }
177cdf0e10cSrcweir
Create(const Reference<XComponentContext> & rxContext)178cdf0e10cSrcweir Reference< XInterface > SAL_CALL AnyCompareFactory::Create(
179cdf0e10cSrcweir const Reference< XComponentContext >& rxContext )
180cdf0e10cSrcweir {
181cdf0e10cSrcweir return (cppu::OWeakObject*)new AnyCompareFactory( rxContext );
182cdf0e10cSrcweir }
183cdf0e10cSrcweir
createRegistryInfo_AnyCompareFactory()184cdf0e10cSrcweir void createRegistryInfo_AnyCompareFactory()
185cdf0e10cSrcweir {
186cdf0e10cSrcweir static ::comphelper::module::OAutoRegistration< AnyCompareFactory > aAutoRegistration;
187cdf0e10cSrcweir }
188