LCOV - code coverage report
Current view: top level - comphelper/source/compare - AnyCompareFactory.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 26 44 59.1 %
Date: 2015-06-13 12:38:46 Functions: 11 16 68.8 %
Legend: Lines: hit not hit

          Line data    Source code
       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 "comphelper_module.hxx"
      21             : #include "comphelper_services.hxx"
      22             : 
      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 <cppuhelper/supportsservice.hxx>
      31             : #include <com/sun/star/lang/XServiceInfo.hpp>
      32             : #include <com/sun/star/lang/XInitialization.hpp>
      33             : #include <com/sun/star/lang/IllegalArgumentException.hpp>
      34             : #include <com/sun/star/lang/XMultiComponentFactory.hpp>
      35             : #include <map>
      36             : 
      37             : using namespace com::sun::star::uno;
      38             : using namespace com::sun::star::ucb;
      39             : using namespace com::sun::star::lang;
      40             : using namespace com::sun::star::i18n;
      41             : 
      42          72 : class AnyCompare : public ::cppu::WeakImplHelper1< XAnyCompare >
      43             : {
      44             :     Reference< XCollator > m_xCollator;
      45             : 
      46             : public:
      47          39 :     AnyCompare( Reference< XComponentContext > xContext, const Locale& rLocale )
      48          39 :     {
      49          39 :         m_xCollator = Collator::create( xContext );
      50          39 :         m_xCollator->loadDefaultCollator( rLocale,
      51          39 :                                           0 ); //???
      52          39 :     }
      53             : 
      54             :     virtual sal_Int16 SAL_CALL compare( const Any& any1, const Any& any2 ) throw(RuntimeException, std::exception) SAL_OVERRIDE;
      55             : };
      56             : 
      57          72 : class AnyCompareFactory : public cppu::WeakImplHelper3< XAnyCompareFactory, XInitialization, XServiceInfo >
      58             : {
      59             :     Reference< XAnyCompare >            m_xAnyCompare;
      60             :     Reference< XComponentContext >      m_xContext;
      61             :     Locale                              m_Locale;
      62             : 
      63             : public:
      64          39 :     explicit AnyCompareFactory( Reference< XComponentContext > xContext ) : m_xContext( xContext )
      65          39 :     {}
      66             : 
      67             :     // XAnyCompareFactory
      68             :     virtual Reference< XAnyCompare > SAL_CALL createAnyCompareByName ( const OUString& aPropertyName ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
      69             : 
      70             :     // XInitialization
      71             :     virtual void SAL_CALL initialize( const Sequence< Any >& aArguments )
      72             :             throw ( Exception, RuntimeException, std::exception ) SAL_OVERRIDE;
      73             : 
      74             :     // XServiceInfo
      75             :     virtual OUString SAL_CALL getImplementationName(  ) throw(RuntimeException, std::exception) SAL_OVERRIDE;
      76             :     virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) throw(RuntimeException, std::exception) SAL_OVERRIDE;
      77             :     virtual Sequence< OUString > SAL_CALL getSupportedServiceNames(  ) throw(RuntimeException, std::exception) SAL_OVERRIDE;
      78             : 
      79             :     // XServiceInfo - static versions (used for component registration)
      80             :     static OUString SAL_CALL getImplementationName_static();
      81             :     static Sequence< OUString > SAL_CALL getSupportedServiceNames_static();
      82             :     static Reference< XInterface > SAL_CALL Create( const Reference< XComponentContext >& );
      83             : };
      84             : 
      85           0 : sal_Int16 SAL_CALL AnyCompare::compare( const Any& any1, const Any& any2 ) throw(::com::sun::star::uno::RuntimeException, std::exception)
      86             : {
      87           0 :     sal_Int16 aResult = 0;
      88             : 
      89           0 :     OUString aStr1;
      90           0 :     OUString aStr2;
      91             : 
      92           0 :     any1 >>= aStr1;
      93           0 :     any2 >>= aStr2;
      94             : 
      95           0 :     aResult = static_cast<sal_Int16>(m_xCollator->compareString(aStr1, aStr2));
      96             : 
      97           0 :     return aResult;
      98             : }
      99             : 
     100           0 : Reference< XAnyCompare > SAL_CALL AnyCompareFactory::createAnyCompareByName( const OUString& aPropertyName ) throw(::com::sun::star::uno::RuntimeException, std::exception)
     101             : {
     102             :     // for now only OUString properties compare is implemented
     103             :     // so no check for the property name is done
     104             : 
     105           0 :     if( aPropertyName == "Title" )
     106           0 :         return m_xAnyCompare;
     107             : 
     108           0 :     return Reference< XAnyCompare >();
     109             : }
     110             : 
     111          39 : void SAL_CALL AnyCompareFactory::initialize( const Sequence< Any >& aArguments ) throw ( Exception, RuntimeException, std::exception )
     112             : {
     113          39 :     if( aArguments.getLength() )
     114             :     {
     115          39 :         if( aArguments[0] >>= m_Locale )
     116             :         {
     117          39 :             m_xAnyCompare = new AnyCompare( m_xContext, m_Locale );
     118          39 :             return;
     119             :         }
     120             :     }
     121             : }
     122             : 
     123           0 : OUString SAL_CALL AnyCompareFactory::getImplementationName(  ) throw( RuntimeException, std::exception )
     124             : {
     125           0 :     return getImplementationName_static();
     126             : }
     127             : 
     128         191 : OUString SAL_CALL AnyCompareFactory::getImplementationName_static(  )
     129             : {
     130         191 :     return OUString( "AnyCompareFactory" );
     131             : }
     132             : 
     133           0 : sal_Bool SAL_CALL AnyCompareFactory::supportsService( const OUString& ServiceName ) throw(RuntimeException, std::exception)
     134             : {
     135           0 :     return cppu::supportsService(this, ServiceName);
     136             : }
     137             : 
     138           0 : Sequence< OUString > SAL_CALL AnyCompareFactory::getSupportedServiceNames(  ) throw(RuntimeException, std::exception)
     139             : {
     140           0 :     return getSupportedServiceNames_static();
     141             : }
     142             : 
     143         191 : Sequence< OUString > SAL_CALL AnyCompareFactory::getSupportedServiceNames_static(  )
     144             : {
     145         191 :     const OUString aServiceName( "com.sun.star.ucb.AnyCompareFactory" );
     146         191 :     const Sequence< OUString > aSeq( &aServiceName, 1 );
     147         191 :     return aSeq;
     148             : }
     149             : 
     150          39 : Reference< XInterface > SAL_CALL AnyCompareFactory::Create(
     151             :                 const Reference< XComponentContext >& rxContext )
     152             : {
     153          39 :     return static_cast<cppu::OWeakObject*>(new AnyCompareFactory( rxContext ));
     154             : }
     155             : 
     156         191 : void createRegistryInfo_AnyCompareFactory()
     157             : {
     158         191 :     static ::comphelper::module::OAutoRegistration< AnyCompareFactory > aAutoRegistration;
     159         191 : }
     160             : 
     161             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11