LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/dbaccess/source/core/misc - sdbcoretools.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 33 53 62.3 %
Date: 2013-07-09 Functions: 4 5 80.0 %
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             : 
      21             : #include "sdbcoretools.hxx"
      22             : #include "dbastrings.hrc"
      23             : 
      24             : #include <com/sun/star/beans/XPropertySet.hpp>
      25             : #include <com/sun/star/beans/PropertyValue.hpp>
      26             : #include <com/sun/star/container/XChild.hpp>
      27             : #include <com/sun/star/util/XModifiable.hpp>
      28             : #include <com/sun/star/sdb/XDocumentDataSource.hpp>
      29             : #include <com/sun/star/task/InteractionRequestStringResolver.hpp>
      30             : #include <com/sun/star/embed/XTransactedObject.hpp>
      31             : #include <com/sun/star/embed/ElementModes.hpp>
      32             : 
      33             : #include <tools/diagnose_ex.h>
      34             : #include <tools/debug.hxx>
      35             : #include <comphelper/interaction.hxx>
      36             : #include <rtl/ref.hxx>
      37             : #include <rtl/ustrbuf.hxx>
      38             : 
      39             : //.........................................................................
      40             : namespace dbaccess
      41             : {
      42             : //.........................................................................
      43             : 
      44             :     using namespace ::com::sun::star::uno;
      45             :     using namespace ::com::sun::star::lang;
      46             :     using namespace ::com::sun::star::util;
      47             :     using namespace ::com::sun::star::io;
      48             :     using namespace ::com::sun::star::sdbc;
      49             :     using namespace ::com::sun::star::sdb;
      50             :     using namespace ::com::sun::star::beans;
      51             :     using namespace ::com::sun::star::task;
      52             :     using namespace ::com::sun::star::embed;
      53             :     using namespace ::com::sun::star::container;
      54             : 
      55             :     // =========================================================================
      56             :     // -------------------------------------------------------------------------
      57        1885 :     void notifyDataSourceModified(const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxObject,sal_Bool _bModified)
      58             :     {
      59        1885 :         Reference< XInterface > xDs = getDataSource( _rxObject );
      60        3770 :         Reference<XDocumentDataSource> xDocumentDataSource(xDs,UNO_QUERY);
      61        1885 :         if ( xDocumentDataSource.is() )
      62        1320 :             xDs = xDocumentDataSource->getDatabaseDocument();
      63        3770 :         Reference< XModifiable > xModi( xDs, UNO_QUERY );
      64        1885 :         if ( xModi.is() )
      65        3205 :             xModi->setModified(_bModified);
      66        1885 :     }
      67             : 
      68             :     // -------------------------------------------------------------------------
      69        1946 :     Reference< XInterface > getDataSource( const Reference< XInterface >& _rxDependentObject )
      70             :     {
      71        1946 :         Reference< XInterface > xParent = _rxDependentObject;
      72        1946 :         Reference< XInterface > xReturn;
      73        7830 :         while( xParent.is() )
      74             :         {
      75        3938 :             xReturn = xParent;
      76        3938 :             Reference<XChild> xChild(xParent,UNO_QUERY);
      77        3938 :             xParent.set(xChild.is() ? xChild->getParent() : Reference< XInterface >(),UNO_QUERY);
      78        3938 :         }
      79        1946 :         return xReturn;
      80             :     }
      81             : 
      82             : // -----------------------------------------------------------------------------
      83           0 :     OUString extractExceptionMessage( const Reference<XComponentContext> & _rContext, const Any& _rError )
      84             :     {
      85           0 :         OUString sDisplayMessage;
      86             : 
      87             :         try
      88             :         {
      89           0 :             Reference< XInteractionRequestStringResolver > xStringResolver = InteractionRequestStringResolver::create(_rContext);
      90             : 
      91           0 :             ::rtl::Reference< ::comphelper::OInteractionRequest > pRequest( new ::comphelper::OInteractionRequest( _rError ) );
      92           0 :             ::rtl::Reference< ::comphelper::OInteractionApprove > pApprove( new ::comphelper::OInteractionApprove );
      93           0 :             pRequest->addContinuation( pApprove.get() );
      94           0 :             Optional< OUString > aMessage = xStringResolver->getStringFromInformationalRequest( pRequest.get() );
      95           0 :             if ( aMessage.IsPresent )
      96           0 :                 sDisplayMessage = aMessage.Value;
      97             :         }
      98           0 :         catch( const Exception& )
      99             :         {
     100             :             DBG_UNHANDLED_EXCEPTION();
     101             :         }
     102             : 
     103           0 :         if ( sDisplayMessage.isEmpty() )
     104             :         {
     105           0 :             Exception aExcept;
     106           0 :             _rError >>= aExcept;
     107             : 
     108           0 :             OUStringBuffer aBuffer;
     109           0 :             aBuffer.append( _rError.getValueTypeName() );
     110           0 :             aBuffer.appendAscii( ":\n" );
     111           0 :             aBuffer.append( aExcept.Message );
     112             : 
     113           0 :             sDisplayMessage = aBuffer.makeStringAndClear();
     114             :         }
     115             : 
     116           0 :         return sDisplayMessage;
     117             :     }
     118             : 
     119             :     namespace tools { namespace stor {
     120             : 
     121             :     // -----------------------------------------------------------------------------
     122         315 :     bool storageIsWritable_nothrow( const Reference< XStorage >& _rxStorage )
     123             :     {
     124         315 :         if ( !_rxStorage.is() )
     125         108 :             return false;
     126             : 
     127         207 :         sal_Int32 nMode = ElementModes::READ;
     128             :         try
     129             :         {
     130         207 :             Reference< XPropertySet > xStorageProps( _rxStorage, UNO_QUERY_THROW );
     131         207 :             xStorageProps->getPropertyValue( "OpenMode" ) >>= nMode;
     132             :         }
     133           0 :         catch( const Exception& )
     134             :         {
     135             :             DBG_UNHANDLED_EXCEPTION();
     136             :         }
     137         207 :         return ( nMode & ElementModes::WRITE ) != 0;
     138             :     }
     139             : 
     140             :     // -----------------------------------------------------------------------------
     141         112 :     bool commitStorageIfWriteable( const Reference< XStorage >& _rxStorage ) SAL_THROW(( IOException, WrappedTargetException, RuntimeException ))
     142             :     {
     143         112 :         bool bSuccess = false;
     144         112 :         Reference< XTransactedObject > xTrans( _rxStorage, UNO_QUERY );
     145         112 :         if ( xTrans.is() )
     146             :         {
     147         112 :             if ( storageIsWritable_nothrow( _rxStorage ) )
     148         112 :                 xTrans->commit();
     149         112 :             bSuccess = true;
     150             :         }
     151         112 :         return bSuccess;
     152             :     }
     153             : 
     154             :     } } // tools::stor
     155             : 
     156             : //.........................................................................
     157             : }   // namespace dbaccess
     158             : //.........................................................................
     159             : 
     160             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10