Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / comphelper / source / compare / AnyCompareFactory.cxx
blob69ce7d19ec84428c357584e0eeb8ba4068c48048
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 .
21 #include "comphelper_module.hxx"
23 #include <com/sun/star/ucb/XAnyCompareFactory.hpp>
24 #include <com/sun/star/i18n/Collator.hpp>
25 #include <com/sun/star/lang/Locale.hpp>
26 #include <com/sun/star/uno/Sequence.h>
27 #include <com/sun/star/beans/PropertyValue.hpp>
28 #include <cppuhelper/implbase3.hxx>
29 #include <cppuhelper/implbase1.hxx>
30 #include <com/sun/star/lang/XServiceInfo.hpp>
31 #include <com/sun/star/lang/XInitialization.hpp>
32 #include <com/sun/star/lang/IllegalArgumentException.hpp>
33 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
34 #include <comphelper/stl_types.hxx>
35 #include <map>
38 using namespace com::sun::star::uno;
39 using namespace com::sun::star::ucb;
40 using namespace com::sun::star::lang;
41 using namespace com::sun::star::i18n;
43 using ::rtl::OUString;
45 //=============================================================================
47 class AnyCompare : public ::cppu::WeakImplHelper1< XAnyCompare >
49 Reference< XCollator > m_rCollator;
51 public:
52 AnyCompare( Reference< XComponentContext > xContext, const Locale& rLocale ) throw()
54 m_rCollator = Collator::create( xContext );
55 m_rCollator->loadDefaultCollator( rLocale,
56 0 ); //???
59 virtual sal_Int16 SAL_CALL compare( const Any& any1, const Any& any2 ) throw(RuntimeException);
62 //=============================================================================
64 class AnyCompareFactory : public cppu::WeakImplHelper3< XAnyCompareFactory, XInitialization, XServiceInfo >
66 Reference< XAnyCompare > m_rAnyCompare;
67 Reference< XComponentContext > m_rContext;
68 Locale m_Locale;
70 public:
71 AnyCompareFactory( Reference< XComponentContext > xContext ) : m_rContext( xContext )
74 // XAnyCompareFactory
75 virtual Reference< XAnyCompare > SAL_CALL createAnyCompareByName ( const OUString& aPropertyName ) throw(::com::sun::star::uno::RuntimeException);
77 // XInitialization
78 virtual void SAL_CALL initialize( const Sequence< Any >& aArguments )
79 throw ( Exception, RuntimeException );
81 // XServiceInfo
82 virtual OUString SAL_CALL getImplementationName( ) throw(RuntimeException);
83 virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw(RuntimeException);
84 virtual Sequence< OUString > SAL_CALL getSupportedServiceNames( ) throw(RuntimeException);
86 // XServiceInfo - static versions (used for component registration)
87 static ::rtl::OUString SAL_CALL getImplementationName_static();
88 static Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames_static();
89 static Reference< XInterface > SAL_CALL Create( const Reference< XComponentContext >& );
92 //===========================================================================================
94 sal_Int16 SAL_CALL AnyCompare::compare( const Any& any1, const Any& any2 ) throw(::com::sun::star::uno::RuntimeException)
96 sal_Int16 aResult = 0;
98 OUString aStr1;
99 OUString aStr2;
101 any1 >>= aStr1;
102 any2 >>= aStr2;
104 aResult = ( sal_Int16 )m_rCollator->compareString( aStr1, aStr2 );
106 return aResult;
109 //===========================================================================================
111 Reference< XAnyCompare > SAL_CALL AnyCompareFactory::createAnyCompareByName( const OUString& aPropertyName ) throw(::com::sun::star::uno::RuntimeException)
113 // for now only OUString properties compare is implemented
114 // so no check for the property name is done
116 if( aPropertyName == "Title" )
117 return m_rAnyCompare;
119 return Reference< XAnyCompare >();
122 void SAL_CALL AnyCompareFactory::initialize( const Sequence< Any >& aArguments ) throw ( Exception, RuntimeException )
124 if( aArguments.getLength() )
126 if( aArguments[0] >>= m_Locale )
128 m_rAnyCompare = new AnyCompare( m_rContext, m_Locale );
129 return;
135 OUString SAL_CALL AnyCompareFactory::getImplementationName( ) throw( RuntimeException )
137 return getImplementationName_static();
140 OUString SAL_CALL AnyCompareFactory::getImplementationName_static( )
142 return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AnyCompareFactory" ) );
145 sal_Bool SAL_CALL AnyCompareFactory::supportsService( const OUString& ServiceName ) throw(RuntimeException)
147 rtl::OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ucb.AnyCompareFactory" ) );
148 return aServiceName == ServiceName;
151 Sequence< OUString > SAL_CALL AnyCompareFactory::getSupportedServiceNames( ) throw(RuntimeException)
153 return getSupportedServiceNames_static();
156 Sequence< OUString > SAL_CALL AnyCompareFactory::getSupportedServiceNames_static( )
158 const rtl::OUString aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ucb.AnyCompareFactory" ) );
159 const Sequence< rtl::OUString > aSeq( &aServiceName, 1 );
160 return aSeq;
163 Reference< XInterface > SAL_CALL AnyCompareFactory::Create(
164 const Reference< XComponentContext >& rxContext )
166 return (cppu::OWeakObject*)new AnyCompareFactory( rxContext );
169 void createRegistryInfo_AnyCompareFactory()
171 static ::comphelper::module::OAutoRegistration< AnyCompareFactory > aAutoRegistration;
174 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */