1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_comphelper.hxx"
31 #include "comphelper_module.hxx"
33 #include <com/sun/star/ucb/XAnyCompareFactory.hpp>
34 #include <com/sun/star/i18n/XCollator.hpp>
35 #include <com/sun/star/lang/Locale.hpp>
36 #include <com/sun/star/uno/Sequence.h>
37 #include <com/sun/star/beans/PropertyValue.hpp>
38 #include <cppuhelper/implbase3.hxx>
39 #include <cppuhelper/implbase1.hxx>
40 #include <com/sun/star/lang/XServiceInfo.hpp>
41 #include <com/sun/star/lang/XInitialization.hpp>
42 #include <com/sun/star/lang/IllegalArgumentException.hpp>
43 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
44 #include <comphelper/stl_types.hxx>
48 using namespace com::sun::star::uno
;
49 using namespace com::sun::star::ucb
;
50 using namespace com::sun::star::lang
;
51 using namespace com::sun::star::i18n
;
54 //=============================================================================
56 class AnyCompare
: public ::cppu::WeakImplHelper1
< XAnyCompare
>
58 Reference
< XCollator
> m_rCollator
;
61 AnyCompare( Reference
< XComponentContext
> xContext
, const Locale
& rLocale
) throw()
63 Reference
< XMultiComponentFactory
> xFactory
= xContext
->getServiceManager();
66 m_rCollator
= Reference
< XCollator
>(
67 xFactory
->createInstanceWithContext( OUString::createFromAscii( "com.sun.star.i18n.Collator" ), xContext
),
69 m_rCollator
->loadDefaultCollator( rLocale
,
75 virtual sal_Int16 SAL_CALL
compare( const Any
& any1
, const Any
& any2
) throw(RuntimeException
);
78 //=============================================================================
80 class AnyCompareFactory
: public cppu::WeakImplHelper3
< XAnyCompareFactory
, XInitialization
, XServiceInfo
>
82 Reference
< XAnyCompare
> m_rAnyCompare
;
83 Reference
< XComponentContext
> m_rContext
;
87 AnyCompareFactory( Reference
< XComponentContext
> xContext
) : m_rContext( xContext
)
91 virtual Reference
< XAnyCompare
> SAL_CALL
createAnyCompareByName ( const OUString
& aPropertyName
) throw(::com::sun::star::uno::RuntimeException
);
94 virtual void SAL_CALL
initialize( const Sequence
< Any
>& aArguments
)
95 throw ( Exception
, RuntimeException
);
98 virtual OUString SAL_CALL
getImplementationName( ) throw(RuntimeException
);
99 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) throw(RuntimeException
);
100 virtual Sequence
< OUString
> SAL_CALL
getSupportedServiceNames( ) throw(RuntimeException
);
102 // XServiceInfo - static versions (used for component registration)
103 static ::rtl::OUString SAL_CALL
getImplementationName_static();
104 static Sequence
< ::rtl::OUString
> SAL_CALL
getSupportedServiceNames_static();
105 static Reference
< XInterface
> SAL_CALL
Create( const Reference
< XComponentContext
>& );
108 //===========================================================================================
110 sal_Int16 SAL_CALL
AnyCompare::compare( const Any
& any1
, const Any
& any2
) throw(::com::sun::star::uno::RuntimeException
)
112 sal_Int16 aResult
= 0;
114 if( m_rCollator
.is() )
122 aResult
= ( sal_Int16
)m_rCollator
->compareString( aStr1
, aStr2
);
128 //===========================================================================================
130 Reference
< XAnyCompare
> SAL_CALL
AnyCompareFactory::createAnyCompareByName( const OUString
& aPropertyName
) throw(::com::sun::star::uno::RuntimeException
)
132 // for now only OUString properties compare is implemented
133 // so no check for the property name is done
135 if( aPropertyName
.equals( OUString::createFromAscii( "Title" ) ) )
136 return m_rAnyCompare
;
138 return Reference
< XAnyCompare
>();
141 void SAL_CALL
AnyCompareFactory::initialize( const Sequence
< Any
>& aArguments
) throw ( Exception
, RuntimeException
)
143 if( aArguments
.getLength() )
145 if( aArguments
[0] >>= m_Locale
)
147 m_rAnyCompare
= new AnyCompare( m_rContext
, m_Locale
);
154 OUString SAL_CALL
AnyCompareFactory::getImplementationName( ) throw( RuntimeException
)
156 return getImplementationName_static();
159 OUString SAL_CALL
AnyCompareFactory::getImplementationName_static( )
161 return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AnyCompareFactory" ) );
164 sal_Bool SAL_CALL
AnyCompareFactory::supportsService( const OUString
& ServiceName
) throw(RuntimeException
)
166 rtl::OUString
aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ucb.AnyCompareFactory" ) );
167 return aServiceName
== ServiceName
;
170 Sequence
< OUString
> SAL_CALL
AnyCompareFactory::getSupportedServiceNames( ) throw(RuntimeException
)
172 return getSupportedServiceNames_static();
175 Sequence
< OUString
> SAL_CALL
AnyCompareFactory::getSupportedServiceNames_static( )
177 const rtl::OUString
aServiceName( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ucb.AnyCompareFactory" ) );
178 const Sequence
< rtl::OUString
> aSeq( &aServiceName
, 1 );
182 Reference
< XInterface
> SAL_CALL
AnyCompareFactory::Create(
183 const Reference
< XComponentContext
>& rxContext
)
185 return (cppu::OWeakObject
*)new AnyCompareFactory( rxContext
);
188 void createRegistryInfo_AnyCompareFactory()
190 static ::comphelper::module::OAutoRegistration
< AnyCompareFactory
> aAutoRegistration
;