LCOV - code coverage report
Current view: top level - dbaccess/source/core/dataaccess - ContentHelper.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 47 273 17.2 %
Date: 2012-08-25 Functions: 12 33 36.4 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 49 586 8.4 %

           Branch data     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 "ContentHelper.hxx"
      21                 :            : #include <ucbhelper/cancelcommandexecution.hxx>
      22                 :            : #include <comphelper/property.hxx>
      23                 :            : #include <com/sun/star/ucb/UnsupportedCommandException.hpp>
      24                 :            : #include <com/sun/star/lang/IllegalArgumentException.hpp>
      25                 :            : #include <com/sun/star/lang/IllegalAccessException.hpp>
      26                 :            : #include <com/sun/star/io/XOutputStream.hpp>
      27                 :            : #include <com/sun/star/io/XActiveDataSink.hpp>
      28                 :            : #include <com/sun/star/beans/PropertyAttribute.hpp>
      29                 :            : #include <ucbhelper/propertyvalueset.hxx>
      30                 :            : #include <ucbhelper/contentidentifier.hxx>
      31                 :            : #include "myucp_resultset.hxx"
      32                 :            : #include <com/sun/star/container/XNameContainer.hpp>
      33                 :            : #include "sdbcoretools.hxx"
      34                 :            : #include "dbastrings.hrc"
      35                 :            : #include <tools/debug.hxx>
      36                 :            : 
      37                 :            : 
      38                 :            : namespace dbaccess
      39                 :            : {
      40                 :            : using namespace ::com::sun::star::uno;
      41                 :            : using namespace ::com::sun::star::ucb;
      42                 :            : using namespace ::com::sun::star::beans;
      43                 :            : using namespace ::com::sun::star::lang;
      44                 :            : using namespace ::com::sun::star::sdbc;
      45                 :            : using namespace ::com::sun::star::io;
      46                 :            : using namespace ::com::sun::star::util;
      47                 :            : using namespace ::com::sun::star::embed;
      48                 :            : using namespace ::com::sun::star::container;
      49                 :            : using namespace ::comphelper;
      50                 :            : using namespace ::cppu;
      51                 :            : 
      52                 :            : DBG_NAME(OContentHelper_Impl)
      53                 :        838 : OContentHelper_Impl::OContentHelper_Impl()
      54                 :            : {
      55                 :            :     DBG_CTOR(OContentHelper_Impl,NULL);
      56                 :        838 : }
      57                 :            : 
      58                 :        838 : OContentHelper_Impl::~OContentHelper_Impl()
      59                 :            : {
      60                 :            :     DBG_DTOR(OContentHelper_Impl,NULL);
      61         [ -  + ]:        838 : }
      62                 :            : 
      63                 :       1434 : OContentHelper::OContentHelper(const Reference< XMultiServiceFactory >& _xORB
      64                 :            :                                ,const Reference< XInterface >&  _xParentContainer
      65                 :            :                                ,const TContentPtr& _pImpl)
      66                 :            :     : OContentHelper_COMPBASE(m_aMutex)
      67                 :            :     ,m_aContentListeners(m_aMutex)
      68                 :            :     ,m_aPropertyChangeListeners(m_aMutex)
      69                 :            :     ,m_xParentContainer(_xParentContainer)
      70                 :            :     ,m_aContext( _xORB )
      71                 :            :     ,m_aErrorHelper( m_aContext )
      72                 :            :     ,m_pImpl(_pImpl)
      73 [ +  - ][ +  - ]:       1434 :     ,m_nCommandId(0)
         [ +  - ][ +  - ]
                 [ +  - ]
      74                 :            : {
      75                 :       1434 : }
      76                 :            : 
      77                 :       1434 : void SAL_CALL OContentHelper::disposing()
      78                 :            : {
      79         [ +  - ]:       1434 :     ::osl::MutexGuard aGuard(m_aMutex);
      80                 :            : 
      81                 :            :     // say goodbye to our listeners
      82 [ +  - ][ +  - ]:       1434 :     EventObject aEvt(*this);
      83         [ +  - ]:       1434 :     m_aContentListeners.disposeAndClear(aEvt);
      84                 :            : 
      85 [ +  - ][ +  - ]:       1434 :     m_xParentContainer = NULL;
                 [ +  - ]
      86                 :       1434 : }
      87                 :            : 
      88 [ #  # ][ +  - ]:          2 : IMPLEMENT_SERVICE_INFO1(OContentHelper,"com.sun.star.comp.sdb.Content","com.sun.star.ucb.Content");
         [ +  - ][ +  - ]
                 [ +  - ]
      89 [ +  + ][ +  - ]:        160 : IMPLEMENT_IMPLEMENTATION_ID(OContentHelper)
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
      90                 :            : 
      91                 :            : // XContent
      92                 :          0 : Reference< XContentIdentifier > SAL_CALL OContentHelper::getIdentifier(  ) throw (RuntimeException)
      93                 :            : {
      94         [ #  # ]:          0 :     ::osl::MutexGuard aGuard(m_aMutex);
      95                 :          0 :     ::rtl::OUStringBuffer aIdentifier;
      96         [ #  # ]:          0 :     aIdentifier.appendAscii( "private:" );
      97 [ #  # ][ #  # ]:          0 :     aIdentifier.append( impl_getHierarchicalName( true ) );
      98 [ #  # ][ #  # ]:          0 :     return new ::ucbhelper::ContentIdentifier( m_aContext.getLegacyServiceFactory(), aIdentifier.makeStringAndClear() );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      99                 :            : }
     100                 :            : 
     101                 :          0 : ::rtl::OUString OContentHelper::impl_getHierarchicalName( bool _includingRootContainer ) const
     102                 :            : {
     103         [ #  # ]:          0 :     ::rtl::OUStringBuffer aHierarchicalName( m_pImpl->m_aProps.aTitle );
     104                 :          0 :     Reference< XInterface > xParent = m_xParentContainer;
     105         [ #  # ]:          0 :     while( xParent.is() )
     106                 :            :     {
     107         [ #  # ]:          0 :         Reference<XPropertySet> xProp( xParent, UNO_QUERY );
     108         [ #  # ]:          0 :         Reference< XChild > xChild( xParent, UNO_QUERY );
     109 [ #  # ][ #  # ]:          0 :         xParent.set( xChild.is() ? xChild->getParent() : Reference< XInterface >(), UNO_QUERY );
         [ #  # ][ #  # ]
     110 [ #  # ][ #  # ]:          0 :         if ( xProp.is() && xParent.is() )
                 [ #  # ]
     111                 :            :         {
     112                 :          0 :             ::rtl::OUString sName;
     113 [ #  # ][ #  # ]:          0 :             xProp->getPropertyValue( PROPERTY_NAME ) >>= sName;
                 [ #  # ]
     114                 :            : 
     115         [ #  # ]:          0 :             ::rtl::OUString sPrevious = aHierarchicalName.makeStringAndClear();
     116         [ #  # ]:          0 :             aHierarchicalName.append( sName );
     117         [ #  # ]:          0 :             aHierarchicalName.append( sal_Unicode( '/' ) );
     118         [ #  # ]:          0 :             aHierarchicalName.append( sPrevious );
     119                 :            :         }
     120                 :          0 :     }
     121         [ #  # ]:          0 :     ::rtl::OUString sHierarchicalName( aHierarchicalName.makeStringAndClear() );
     122         [ #  # ]:          0 :     if ( !_includingRootContainer )
     123                 :          0 :         sHierarchicalName = sHierarchicalName.copy( sHierarchicalName.indexOf( '/' ) + 1 );
     124                 :          0 :     return sHierarchicalName;
     125                 :            : }
     126                 :            : 
     127                 :          0 : ::rtl::OUString SAL_CALL OContentHelper::getContentType() throw (RuntimeException)
     128                 :            : {
     129         [ #  # ]:          0 :     ::osl::MutexGuard aGuard(m_aMutex);
     130                 :            : 
     131 [ #  # ][ #  # ]:          0 :     if ( !m_pImpl->m_aProps.aContentType )
     132                 :            :     {   // content type not yet retrieved
     133 [ #  # ][ #  # ]:          0 :         m_pImpl->m_aProps.aContentType.reset( determineContentType() );
     134                 :            :     }
     135                 :            : 
     136 [ #  # ][ #  # ]:          0 :     return *m_pImpl->m_aProps.aContentType;
     137                 :            : }
     138                 :            : 
     139                 :          0 : void SAL_CALL OContentHelper::addContentEventListener( const Reference< XContentEventListener >& _rxListener ) throw (RuntimeException)
     140                 :            : {
     141         [ #  # ]:          0 :     ::osl::MutexGuard aGuard(m_aMutex);
     142         [ #  # ]:          0 :     if ( _rxListener.is() )
     143 [ #  # ][ #  # ]:          0 :         m_aContentListeners.addInterface(_rxListener);
     144                 :          0 : }
     145                 :            : 
     146                 :          0 : void SAL_CALL OContentHelper::removeContentEventListener( const Reference< XContentEventListener >& _rxListener ) throw (RuntimeException)
     147                 :            : {
     148         [ #  # ]:          0 :     ::osl::MutexGuard aGuard(m_aMutex);
     149         [ #  # ]:          0 :     if (_rxListener.is())
     150 [ #  # ][ #  # ]:          0 :         m_aContentListeners.removeInterface(_rxListener);
     151                 :          0 : }
     152                 :            : 
     153                 :            : // XCommandProcessor
     154                 :          0 : sal_Int32 SAL_CALL OContentHelper::createCommandIdentifier(  ) throw (RuntimeException)
     155                 :            : {
     156         [ #  # ]:          0 :     ::osl::MutexGuard aGuard(m_aMutex);
     157                 :            :     // Just increase counter on every call to generate an identifier.
     158         [ #  # ]:          0 :     return ++m_nCommandId;
     159                 :            : }
     160                 :            : 
     161                 :          0 : Any SAL_CALL OContentHelper::execute( const Command& aCommand, sal_Int32 /*CommandId*/, const Reference< XCommandEnvironment >& Environment ) throw (Exception, CommandAbortedException, RuntimeException)
     162                 :            : {
     163                 :          0 :     Any aRet;
     164         [ #  # ]:          0 :     if ( aCommand.Name.compareToAscii( "getPropertyValues" ) == 0 )
     165                 :            :     {
     166                 :            :         //////////////////////////////////////////////////////////////////
     167                 :            :         // getPropertyValues
     168                 :            :         //////////////////////////////////////////////////////////////////
     169                 :            : 
     170         [ #  # ]:          0 :         Sequence< Property > Properties;
     171 [ #  # ][ #  # ]:          0 :         if ( !( aCommand.Argument >>= Properties ) )
     172                 :            :         {
     173                 :            :             OSL_FAIL( "Wrong argument type!" );
     174                 :            :             ucbhelper::cancelCommandExecution(
     175                 :            :                 makeAny( IllegalArgumentException(
     176                 :            :                                     rtl::OUString(),
     177                 :            :                                     static_cast< cppu::OWeakObject * >( this ),
     178                 :            :                                     -1 ) ),
     179 [ #  # ][ #  # ]:          0 :                 Environment );
         [ #  # ][ #  # ]
                 [ #  # ]
     180                 :            :             // Unreachable
     181                 :            :         }
     182 [ #  # ][ #  # ]:          0 :         aRet <<= getPropertyValues( Properties);
                 [ #  # ]
     183                 :            :     }
     184         [ #  # ]:          0 :     else if ( aCommand.Name.compareToAscii( "setPropertyValues" ) == 0 )
     185                 :            :     {
     186                 :            :         //////////////////////////////////////////////////////////////////
     187                 :            :         // setPropertyValues
     188                 :            :         //////////////////////////////////////////////////////////////////
     189                 :            : 
     190         [ #  # ]:          0 :         Sequence< PropertyValue > aProperties;
     191 [ #  # ][ #  # ]:          0 :         if ( !( aCommand.Argument >>= aProperties ) )
     192                 :            :         {
     193                 :            :             OSL_FAIL( "Wrong argument type!" );
     194                 :            :             ucbhelper::cancelCommandExecution(
     195                 :            :                 makeAny( IllegalArgumentException(
     196                 :            :                                     rtl::OUString(),
     197                 :            :                                     static_cast< cppu::OWeakObject * >( this ),
     198                 :            :                                     -1 ) ),
     199 [ #  # ][ #  # ]:          0 :                 Environment );
         [ #  # ][ #  # ]
                 [ #  # ]
     200                 :            :             // Unreachable
     201                 :            :         }
     202                 :            : 
     203         [ #  # ]:          0 :         if ( !aProperties.getLength() )
     204                 :            :         {
     205                 :            :             OSL_FAIL( "No properties!" );
     206                 :            :             ucbhelper::cancelCommandExecution(
     207                 :            :                 makeAny( IllegalArgumentException(
     208                 :            :                                     rtl::OUString(),
     209                 :            :                                     static_cast< cppu::OWeakObject * >( this ),
     210                 :            :                                     -1 ) ),
     211 [ #  # ][ #  # ]:          0 :                 Environment );
         [ #  # ][ #  # ]
                 [ #  # ]
     212                 :            :             // Unreachable
     213                 :            :         }
     214                 :            : 
     215 [ #  # ][ #  # ]:          0 :         aRet <<= setPropertyValues( aProperties, Environment );
         [ #  # ][ #  # ]
     216                 :            :     }
     217         [ #  # ]:          0 :     else if ( aCommand.Name.compareToAscii( "getPropertySetInfo" ) == 0 )
     218                 :            :     {
     219                 :            :         //////////////////////////////////////////////////////////////////
     220                 :            :         // getPropertySetInfo
     221                 :            :         //////////////////////////////////////////////////////////////////
     222                 :            : 
     223 [ #  # ][ #  # ]:          0 :         Reference<XPropertySet> xProp(*this,UNO_QUERY);
     224         [ #  # ]:          0 :         if ( xProp.is() )
     225 [ #  # ][ #  # ]:          0 :             aRet <<= xProp->getPropertySetInfo();
                 [ #  # ]
     226                 :            :         //  aRet <<= getPropertySetInfo(); // TODO
     227                 :            :     }
     228                 :            :     else
     229                 :            :     {
     230                 :            :         //////////////////////////////////////////////////////////////////
     231                 :            :         // Unsupported command
     232                 :            :         //////////////////////////////////////////////////////////////////
     233                 :            : 
     234                 :            :         OSL_FAIL( "Content::execute - unsupported command!" );
     235                 :            : 
     236                 :            :         ucbhelper::cancelCommandExecution(
     237                 :            :             makeAny( UnsupportedCommandException(
     238                 :            :                             rtl::OUString(),
     239                 :            :                             static_cast< cppu::OWeakObject * >( this ) ) ),
     240 [ #  # ][ #  # ]:          0 :             Environment );
         [ #  # ][ #  # ]
                 [ #  # ]
     241                 :            :         // Unreachable
     242                 :            :     }
     243                 :            : 
     244                 :          0 :     return aRet;
     245                 :            : }
     246                 :            : 
     247                 :          0 : void SAL_CALL OContentHelper::abort( sal_Int32 /*CommandId*/ ) throw (RuntimeException)
     248                 :            : {
     249                 :          0 : }
     250                 :            : 
     251                 :            : // XPropertiesChangeNotifier
     252                 :          0 : void SAL_CALL OContentHelper::addPropertiesChangeListener( const Sequence< ::rtl::OUString >& PropertyNames, const Reference< XPropertiesChangeListener >& Listener ) throw (RuntimeException)
     253                 :            : {
     254         [ #  # ]:          0 :     ::osl::MutexGuard aGuard(m_aMutex);
     255                 :          0 :     sal_Int32 nCount = PropertyNames.getLength();
     256         [ #  # ]:          0 :     if ( !nCount )
     257                 :            :     {
     258                 :            :         // Note: An empty sequence means a listener for "all" properties.
     259         [ #  # ]:          0 :         m_aPropertyChangeListeners.addInterface(::rtl::OUString(), Listener );
     260                 :            :     }
     261                 :            :     else
     262                 :            :     {
     263                 :          0 :         const ::rtl::OUString* pSeq = PropertyNames.getConstArray();
     264                 :            : 
     265         [ #  # ]:          0 :         for ( sal_Int32 n = 0; n < nCount; ++n )
     266                 :            :         {
     267                 :          0 :             const ::rtl::OUString& rName = pSeq[ n ];
     268         [ #  # ]:          0 :             if ( !rName.isEmpty() )
     269         [ #  # ]:          0 :                 m_aPropertyChangeListeners.addInterface(rName, Listener );
     270                 :            :         }
     271         [ #  # ]:          0 :     }
     272                 :          0 : }
     273                 :            : 
     274                 :          0 : void SAL_CALL OContentHelper::removePropertiesChangeListener( const Sequence< ::rtl::OUString >& PropertyNames, const Reference< XPropertiesChangeListener >& Listener ) throw (RuntimeException)
     275                 :            : {
     276         [ #  # ]:          0 :     ::osl::MutexGuard aGuard(m_aMutex);
     277                 :          0 :     sal_Int32 nCount = PropertyNames.getLength();
     278         [ #  # ]:          0 :     if ( !nCount )
     279                 :            :     {
     280                 :            :         // Note: An empty sequence means a listener for "all" properties.
     281         [ #  # ]:          0 :         m_aPropertyChangeListeners.removeInterface( ::rtl::OUString(), Listener );
     282                 :            :     }
     283                 :            :     else
     284                 :            :     {
     285                 :          0 :         const ::rtl::OUString* pSeq = PropertyNames.getConstArray();
     286                 :            : 
     287         [ #  # ]:          0 :         for ( sal_Int32 n = 0; n < nCount; ++n )
     288                 :            :         {
     289                 :          0 :             const ::rtl::OUString& rName = pSeq[ n ];
     290         [ #  # ]:          0 :             if ( !rName.isEmpty() )
     291         [ #  # ]:          0 :                 m_aPropertyChangeListeners.removeInterface( rName, Listener );
     292                 :            :         }
     293         [ #  # ]:          0 :     }
     294                 :          0 : }
     295                 :            : 
     296                 :            : // XPropertyContainer
     297                 :          0 : void SAL_CALL OContentHelper::addProperty( const ::rtl::OUString& /*Name*/, sal_Int16 /*Attributes*/, const Any& /*DefaultValue*/ ) throw (PropertyExistException, IllegalTypeException, IllegalArgumentException, RuntimeException)
     298                 :            : {
     299                 :            :     OSL_FAIL( "OContentHelper::addProperty: not implemented!" );
     300                 :          0 : }
     301                 :            : 
     302                 :          0 : void SAL_CALL OContentHelper::removeProperty( const ::rtl::OUString& /*Name*/ ) throw (UnknownPropertyException, NotRemoveableException, RuntimeException)
     303                 :            : {
     304                 :            :     OSL_FAIL( "OContentHelper::removeProperty: not implemented!" );
     305                 :          0 : }
     306                 :            : 
     307                 :            : // XInitialization
     308                 :         40 : void SAL_CALL OContentHelper::initialize( const Sequence< Any >& _aArguments ) throw(Exception, RuntimeException)
     309                 :            : {
     310                 :         40 :     const Any* pBegin = _aArguments.getConstArray();
     311                 :         40 :     const Any* pEnd = pBegin + _aArguments.getLength();
     312                 :         40 :     PropertyValue aValue;
     313         [ +  + ]:        104 :     for(;pBegin != pEnd;++pBegin)
     314                 :            :     {
     315         [ +  - ]:         64 :         *pBegin >>= aValue;
     316         [ +  + ]:         64 :         if ( aValue.Name == "Parent" )
     317                 :            :         {
     318         [ +  - ]:         24 :             m_xParentContainer.set(aValue.Value,UNO_QUERY);
     319                 :            :         }
     320         [ +  - ]:         40 :         else if ( aValue.Name.equalsAsciiL(PROPERTY_NAME.ascii, PROPERTY_NAME.length) )
     321                 :            :         {
     322                 :         40 :             aValue.Value >>= m_pImpl->m_aProps.aTitle;
     323                 :            :         }
     324         [ #  # ]:          0 :         else if ( aValue.Name.equalsAsciiL(PROPERTY_PERSISTENT_NAME.ascii, PROPERTY_PERSISTENT_NAME.length) )
     325                 :            :         {
     326                 :          0 :             aValue.Value >>= m_pImpl->m_aProps.sPersistentName;
     327                 :            :         }
     328                 :         40 :     }
     329                 :         40 : }
     330                 :            : 
     331                 :          0 : Sequence< Any > OContentHelper::setPropertyValues(const Sequence< PropertyValue >& rValues,const Reference< XCommandEnvironment >& /*xEnv*/ )
     332                 :            : {
     333         [ #  # ]:          0 :     osl::ClearableGuard< osl::Mutex > aGuard( m_aMutex );
     334                 :            : 
     335         [ #  # ]:          0 :     Sequence< Any > aRet( rValues.getLength() );
     336         [ #  # ]:          0 :     Sequence< PropertyChangeEvent > aChanges( rValues.getLength() );
     337                 :          0 :     sal_Int32 nChanged = 0;
     338                 :            : 
     339         [ #  # ]:          0 :     PropertyChangeEvent aEvent;
     340         [ #  # ]:          0 :     aEvent.Source         = static_cast< cppu::OWeakObject * >( this );
     341                 :          0 :     aEvent.Further        = sal_False;
     342                 :          0 :     aEvent.PropertyHandle = -1;
     343                 :            : 
     344                 :          0 :     const PropertyValue* pValues = rValues.getConstArray();
     345                 :          0 :     sal_Int32 nCount = rValues.getLength();
     346                 :            : 
     347         [ #  # ]:          0 :     for ( sal_Int32 n = 0; n < nCount; ++n )
     348                 :            :     {
     349                 :          0 :         const PropertyValue& rValue = pValues[ n ];
     350                 :            : 
     351         [ #  # ]:          0 :         if ( rValue.Name == "ContentType" )
     352                 :            :         {
     353                 :            :             // Read-only property!
     354         [ #  # ]:          0 :             aRet[ n ] <<= IllegalAccessException(
     355                 :            :                             ::rtl::OUString(
     356                 :            :                                 RTL_CONSTASCII_USTRINGPARAM("Property is read-only!")
     357                 :            :                             ),
     358 [ #  # ][ #  # ]:          0 :                             static_cast< cppu::OWeakObject * >( this ) );
         [ #  # ][ #  # ]
                 [ #  # ]
     359                 :            :         }
     360         [ #  # ]:          0 :         else if ( rValue.Name == "IsDocument" )
     361                 :            :         {
     362                 :            :             // Read-only property!
     363         [ #  # ]:          0 :             aRet[ n ] <<= IllegalAccessException(
     364                 :            :                             ::rtl::OUString(
     365                 :            :                                 RTL_CONSTASCII_USTRINGPARAM("Property is read-only!")
     366                 :            :                             ),
     367 [ #  # ][ #  # ]:          0 :                             static_cast< cppu::OWeakObject * >( this ) );
         [ #  # ][ #  # ]
                 [ #  # ]
     368                 :            :         }
     369         [ #  # ]:          0 :         else if ( rValue.Name == "IsFolder" )
     370                 :            :         {
     371                 :            :             // Read-only property!
     372         [ #  # ]:          0 :             aRet[ n ] <<= IllegalAccessException(
     373                 :            :                             ::rtl::OUString(
     374                 :            :                                 RTL_CONSTASCII_USTRINGPARAM("Property is read-only!")
     375                 :            :                             ),
     376 [ #  # ][ #  # ]:          0 :                             static_cast< cppu::OWeakObject * >( this ) );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
     377                 :            :         }
     378         [ #  # ]:          0 :         else if ( rValue.Name == "Title" )
     379                 :            :         {
     380                 :          0 :             rtl::OUString aNewValue;
     381         [ #  # ]:          0 :             if ( rValue.Value >>= aNewValue )
     382                 :            :             {
     383         [ #  # ]:          0 :                 if ( aNewValue != m_pImpl->m_aProps.aTitle )
     384                 :            :                 {
     385                 :          0 :                     aEvent.PropertyName = rValue.Name;
     386         [ #  # ]:          0 :                     aEvent.OldValue     = makeAny( m_pImpl->m_aProps.aTitle );
     387                 :            : 
     388                 :            :                     try
     389                 :            :                     {
     390         [ #  # ]:          0 :                         impl_rename_throw( aNewValue ,false);
     391                 :            :                         OSL_ENSURE( m_pImpl->m_aProps.aTitle == aNewValue, "OContentHelper::setPropertyValues('Title'): rename did not work!" );
     392                 :            : 
     393         [ #  # ]:          0 :                         aEvent.NewValue     = makeAny( aNewValue );
     394 [ #  # ][ #  # ]:          0 :                         aChanges.getArray()[ nChanged ] = aEvent;
     395                 :          0 :                         nChanged++;
     396                 :            :                     }
     397         [ #  # ]:          0 :                     catch( const Exception& )
     398                 :            :                     {
     399                 :            :                         OSL_FAIL( "OContentHelper::setPropertyValues('Title'): caught an exception while renaming!" );
     400                 :            :                     }
     401                 :            :                 }
     402                 :            :                 else
     403                 :            :                 {
     404                 :            :                     // Old value equals new value. No error!
     405                 :            :                 }
     406                 :            :             }
     407                 :            :             else
     408                 :            :             {
     409         [ #  # ]:          0 :                 aRet[ n ] <<= IllegalTypeException(
     410                 :            :                                 ::rtl::OUString(
     411                 :            :                                     RTL_CONSTASCII_USTRINGPARAM("Property value has wrong type!")
     412                 :            :                                 ),
     413 [ #  # ][ #  # ]:          0 :                                 static_cast< cppu::OWeakObject * >( this ) );
         [ #  # ][ #  # ]
                 [ #  # ]
     414                 :          0 :             }
     415                 :            :         }
     416                 :            : 
     417                 :            :         else
     418                 :            :         {
     419         [ #  # ]:          0 :             aRet[ n ] <<= Exception(
     420                 :            :                             ::rtl::OUString(
     421                 :            :                                     RTL_CONSTASCII_USTRINGPARAM("No property set for storing the value!")
     422                 :            :                             ),
     423 [ #  # ][ #  # ]:          0 :                             static_cast< cppu::OWeakObject * >( this ) );
         [ #  # ][ #  # ]
                 [ #  # ]
     424                 :            :         }
     425                 :            :     }
     426                 :            : 
     427         [ #  # ]:          0 :     if ( nChanged > 0 )
     428                 :            :     {
     429         [ #  # ]:          0 :         notifyDataSourceModified();
     430         [ #  # ]:          0 :         aGuard.clear();
     431         [ #  # ]:          0 :         aChanges.realloc( nChanged );
     432         [ #  # ]:          0 :         notifyPropertiesChange( aChanges );
     433                 :            :     }
     434                 :            : 
     435 [ #  # ][ #  # ]:          0 :     return aRet;
                 [ #  # ]
     436                 :            : }
     437                 :            : 
     438                 :            : //=========================================================================
     439                 :            : // static
     440                 :          0 : Reference< XRow > OContentHelper::getPropertyValues( const Sequence< Property >& rProperties)
     441                 :            : {
     442                 :            :     // Note: Empty sequence means "get values of all supported properties".
     443                 :            : 
     444 [ #  # ][ #  # ]:          0 :     rtl::Reference< ::ucbhelper::PropertyValueSet > xRow = new ::ucbhelper::PropertyValueSet( m_aContext.getLegacyServiceFactory() );
     445                 :            : 
     446                 :          0 :     sal_Int32 nCount = rProperties.getLength();
     447         [ #  # ]:          0 :     if ( nCount )
     448                 :            :     {
     449                 :          0 :         const Property* pProps = rProperties.getConstArray();
     450         [ #  # ]:          0 :         for ( sal_Int32 n = 0; n < nCount; ++n )
     451                 :            :         {
     452                 :          0 :             const Property& rProp = pProps[ n ];
     453                 :            : 
     454                 :            :             // Process Core properties.
     455                 :            : 
     456         [ #  # ]:          0 :             if ( rProp.Name == "ContentType" )
     457                 :            :             {
     458 [ #  # ][ #  # ]:          0 :                 xRow->appendString ( rProp, getContentType() );
     459                 :            :             }
     460         [ #  # ]:          0 :             else if ( rProp.Name == "Title" )
     461                 :            :             {
     462         [ #  # ]:          0 :                 xRow->appendString ( rProp, m_pImpl->m_aProps.aTitle );
     463                 :            :             }
     464         [ #  # ]:          0 :             else if ( rProp.Name == "IsDocument" )
     465                 :            :             {
     466         [ #  # ]:          0 :                 xRow->appendBoolean( rProp, m_pImpl->m_aProps.bIsDocument );
     467                 :            :             }
     468         [ #  # ]:          0 :             else if ( rProp.Name == "IsFolder" )
     469                 :            :             {
     470         [ #  # ]:          0 :                 xRow->appendBoolean( rProp, m_pImpl->m_aProps.bIsFolder );
     471                 :            :             }
     472                 :            :             else
     473         [ #  # ]:          0 :                 xRow->appendVoid(rProp);
     474                 :            :         }
     475                 :            :     }
     476                 :            :     else
     477                 :            :     {
     478                 :            :         // Append all Core Properties.
     479                 :            :         xRow->appendString (
     480                 :            :             Property( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ContentType")),
     481                 :            :                       -1,
     482         [ #  # ]:          0 :                       getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
     483                 :            :                       PropertyAttribute::BOUND
     484                 :            :                         | PropertyAttribute::READONLY ),
     485 [ #  # ][ #  # ]:          0 :             getContentType() );
                 [ #  # ]
     486                 :            :         xRow->appendString (
     487                 :            :             Property( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Title" )),
     488                 :            :                       -1,
     489         [ #  # ]:          0 :                       getCppuType( static_cast< const rtl::OUString * >( 0 ) ),
     490                 :            :                       PropertyAttribute::BOUND ),
     491 [ #  # ][ #  # ]:          0 :             m_pImpl->m_aProps.aTitle );
     492                 :            :         xRow->appendBoolean(
     493                 :            :             Property( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IsDocument")),
     494                 :            :                       -1,
     495         [ #  # ]:          0 :                       getCppuBooleanType(),
     496                 :            :                       PropertyAttribute::BOUND
     497                 :            :                         | PropertyAttribute::READONLY ),
     498 [ #  # ][ #  # ]:          0 :             m_pImpl->m_aProps.bIsDocument );
     499                 :            :         xRow->appendBoolean(
     500                 :            :             Property( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("IsFolder")),
     501                 :            :                       -1,
     502         [ #  # ]:          0 :                       getCppuBooleanType(),
     503                 :            :                       PropertyAttribute::BOUND
     504                 :            :                         | PropertyAttribute::READONLY ),
     505 [ #  # ][ #  # ]:          0 :             m_pImpl->m_aProps.bIsFolder );
     506                 :            : 
     507                 :            :         // @@@ Append other properties supported directly.
     508                 :            :     }
     509                 :            : 
     510 [ #  # ][ #  # ]:          0 :     return Reference< XRow >( xRow.get() );
     511                 :            : }
     512                 :            : 
     513                 :          0 : void OContentHelper::notifyPropertiesChange( const Sequence< PropertyChangeEvent >& evt ) const
     514                 :            : {
     515                 :            : 
     516                 :          0 :     sal_Int32 nCount = evt.getLength();
     517         [ #  # ]:          0 :     if ( nCount )
     518                 :            :     {
     519                 :            :         // First, notify listeners interested in changes of every property.
     520         [ #  # ]:          0 :         OInterfaceContainerHelper* pAllPropsContainer = m_aPropertyChangeListeners.getContainer( ::rtl::OUString() );
     521         [ #  # ]:          0 :         if ( pAllPropsContainer )
     522                 :            :         {
     523         [ #  # ]:          0 :             OInterfaceIteratorHelper aIter( *pAllPropsContainer );
     524         [ #  # ]:          0 :             while ( aIter.hasMoreElements() )
     525                 :            :             {
     526                 :            :                 // Propagate event.
     527 [ #  # ][ #  # ]:          0 :                 Reference< XPropertiesChangeListener > xListener( aIter.next(), UNO_QUERY );
     528         [ #  # ]:          0 :                 if ( xListener.is() )
     529 [ #  # ][ #  # ]:          0 :                     xListener->propertiesChange( evt );
     530         [ #  # ]:          0 :             }
     531                 :            :         }
     532                 :            : 
     533                 :            :         typedef Sequence< PropertyChangeEvent > PropertyEventSequence;
     534                 :            :         typedef ::std::map< XPropertiesChangeListener*, PropertyEventSequence* > PropertiesEventListenerMap;
     535         [ #  # ]:          0 :         PropertiesEventListenerMap aListeners;
     536                 :            : 
     537                 :          0 :         const PropertyChangeEvent* propertyChangeEvent = evt.getConstArray();
     538                 :            : 
     539         [ #  # ]:          0 :         for ( sal_Int32 n = 0; n < nCount; ++n, ++propertyChangeEvent )
     540                 :            :         {
     541                 :          0 :             const PropertyChangeEvent& rEvent = *propertyChangeEvent;
     542                 :          0 :             const ::rtl::OUString& rName = rEvent.PropertyName;
     543                 :            : 
     544         [ #  # ]:          0 :             OInterfaceContainerHelper* pPropsContainer = m_aPropertyChangeListeners.getContainer( rName );
     545         [ #  # ]:          0 :             if ( pPropsContainer )
     546                 :            :             {
     547         [ #  # ]:          0 :                 OInterfaceIteratorHelper aIter( *pPropsContainer );
     548         [ #  # ]:          0 :                 while ( aIter.hasMoreElements() )
     549                 :            :                 {
     550                 :          0 :                     PropertyEventSequence* propertyEvents = NULL;
     551                 :            : 
     552         [ #  # ]:          0 :                     XPropertiesChangeListener* pListener = static_cast< XPropertiesChangeListener * >( aIter.next() );
     553         [ #  # ]:          0 :                     PropertiesEventListenerMap::iterator it = aListeners.find( pListener );
     554         [ #  # ]:          0 :                     if ( it == aListeners.end() )
     555                 :            :                     {
     556                 :            :                         // Not in map - create and insert new entry.
     557         [ #  # ]:          0 :                         propertyEvents = new PropertyEventSequence( nCount );
     558         [ #  # ]:          0 :                         aListeners[ pListener ] = propertyEvents;
     559                 :            :                     }
     560                 :            :                     else
     561                 :          0 :                         propertyEvents = (*it).second;
     562                 :            : 
     563         [ #  # ]:          0 :                     if ( propertyEvents )
     564 [ #  # ][ #  # ]:          0 :                         (*propertyEvents)[n] = rEvent;
     565         [ #  # ]:          0 :                 }
     566                 :            :             }
     567                 :            :         }
     568                 :            : 
     569                 :            :         // Notify listeners.
     570                 :          0 :         PropertiesEventListenerMap::iterator it = aListeners.begin();
     571         [ #  # ]:          0 :         while ( !aListeners.empty() )
     572                 :            :         {
     573                 :            :             XPropertiesChangeListener* pListener =
     574                 :          0 :                     static_cast< XPropertiesChangeListener * >( (*it).first );
     575                 :          0 :             PropertyEventSequence* pSeq = (*it).second;
     576                 :            : 
     577                 :            :             // Remove current element.
     578         [ #  # ]:          0 :             aListeners.erase( it );
     579                 :            : 
     580                 :            :             // Propagate event.
     581         [ #  # ]:          0 :             pListener->propertiesChange( *pSeq );
     582                 :            : 
     583 [ #  # ][ #  # ]:          0 :             delete pSeq;
     584                 :            : 
     585                 :          0 :             it = aListeners.begin();
     586                 :          0 :         }
     587                 :            :     }
     588                 :          0 : }
     589                 :            : 
     590                 :            : // com::sun::star::lang::XUnoTunnel
     591                 :         80 : sal_Int64 OContentHelper::getSomething( const Sequence< sal_Int8 > & rId ) throw (RuntimeException)
     592                 :            : {
     593 [ +  - ][ +  - ]:         80 :     if (rId.getLength() == 16 && 0 == rtl_compareMemory(getUnoTunnelImplementationId().getConstArray(),  rId.getConstArray(), 16 ) )
         [ +  - ][ +  - ]
                 [ +  - ]
           [ +  -  #  # ]
     594                 :         80 :         return reinterpret_cast<sal_Int64>(this);
     595                 :            : 
     596                 :         80 :     return 0;
     597                 :            : }
     598                 :            : 
     599                 :         80 : OContentHelper* OContentHelper::getImplementation( const Reference< XInterface >& _rxComponent )
     600                 :            : {
     601                 :         80 :     OContentHelper* pContent( NULL );
     602                 :            : 
     603         [ +  - ]:         80 :     Reference< XUnoTunnel > xUnoTunnel( _rxComponent, UNO_QUERY );
     604         [ +  - ]:         80 :     if ( xUnoTunnel.is() )
     605 [ +  - ][ +  - ]:         80 :         pContent = reinterpret_cast< OContentHelper* >( xUnoTunnel->getSomething( getUnoTunnelImplementationId() ) );
         [ +  - ][ +  - ]
     606                 :            : 
     607                 :         80 :     return pContent;
     608                 :            : }
     609                 :            : 
     610                 :       3028 : Reference< XInterface > SAL_CALL OContentHelper::getParent(  ) throw (RuntimeException)
     611                 :            : {
     612         [ +  - ]:       3028 :     ::osl::MutexGuard aGuard(m_aMutex);
     613         [ +  - ]:       3028 :     return m_xParentContainer;
     614                 :            : }
     615                 :            : 
     616                 :        396 : void SAL_CALL OContentHelper::setParent( const Reference< XInterface >& _xParent ) throw (NoSupportException, RuntimeException)
     617                 :            : {
     618         [ +  - ]:        396 :     ::osl::MutexGuard aGuard(m_aMutex);
     619 [ +  - ][ +  - ]:        396 :     m_xParentContainer = _xParent;
     620                 :        396 : }
     621                 :            : 
     622                 :          0 : void OContentHelper::impl_rename_throw(const ::rtl::OUString& _sNewName,bool _bNotify )
     623                 :            : {
     624         [ #  # ]:          0 :     osl::ClearableGuard< osl::Mutex > aGuard(m_aMutex);
     625         [ #  # ]:          0 :     if ( _sNewName.equals( m_pImpl->m_aProps.aTitle ) )
     626                 :          0 :         return;
     627                 :            :     try
     628                 :            :     {
     629         [ #  # ]:          0 :         Sequence< PropertyChangeEvent > aChanges( 1 );
     630                 :            : 
     631 [ #  # ][ #  # ]:          0 :         aChanges[0].Source          = static_cast< cppu::OWeakObject * >( this );
     632         [ #  # ]:          0 :         aChanges[0].Further         = sal_False;
     633 [ #  # ][ #  # ]:          0 :         aChanges[0].PropertyName    = PROPERTY_NAME;
     634         [ #  # ]:          0 :         aChanges[0].PropertyHandle  = PROPERTY_ID_NAME;
     635 [ #  # ][ #  # ]:          0 :         aChanges[0].OldValue        <<= m_pImpl->m_aProps.aTitle;
     636 [ #  # ][ #  # ]:          0 :         aChanges[0].NewValue        <<= _sNewName;
     637                 :            : 
     638         [ #  # ]:          0 :         aGuard.clear();
     639                 :            : 
     640                 :          0 :         m_pImpl->m_aProps.aTitle = _sNewName;
     641         [ #  # ]:          0 :         if ( _bNotify )
     642         [ #  # ]:          0 :             notifyPropertiesChange( aChanges );
     643 [ #  # ][ #  # ]:          0 :         notifyDataSourceModified();
     644                 :            :     }
     645         [ #  # ]:          0 :     catch(const PropertyVetoException&)
     646                 :            :     {
     647   [ #  #  #  # ]:          0 :         throw ElementExistException(_sNewName,*this);
     648 [ #  # ][ #  # ]:          0 :     }
     649                 :            : }
     650                 :            : 
     651                 :          0 : void SAL_CALL OContentHelper::rename( const ::rtl::OUString& newName ) throw (SQLException, ElementExistException, RuntimeException)
     652                 :            : {
     653                 :            : 
     654                 :          0 :     impl_rename_throw(newName);
     655                 :            : 
     656                 :          0 : }
     657                 :            : 
     658                 :        902 : void OContentHelper::notifyDataSourceModified()
     659                 :            : {
     660                 :        902 :     ::dbaccess::notifyDataSourceModified(m_xParentContainer,sal_True);
     661                 :        902 : }
     662                 :            : 
     663                 :            : }   // namespace dbaccess
     664                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10