LCOV - code coverage report
Current view: top level - ucb/source/ucp/tdoc - tdoc_provider.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 77 164 47.0 %
Date: 2012-08-25 Functions: 17 27 63.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 79 376 21.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : /**************************************************************************
      31                 :            :                                 TODO
      32                 :            :  **************************************************************************
      33                 :            : 
      34                 :            :  *************************************************************************/
      35                 :            : 
      36                 :            : #include "rtl/ustrbuf.hxx"
      37                 :            : 
      38                 :            : #include "com/sun/star/container/XNameAccess.hpp"
      39                 :            : #include "com/sun/star/embed/XStorage.hpp"
      40                 :            : 
      41                 :            : #include "ucbhelper/contentidentifier.hxx"
      42                 :            : 
      43                 :            : #include "tdoc_provider.hxx"
      44                 :            : #include "tdoc_content.hxx"
      45                 :            : #include "tdoc_uri.hxx"
      46                 :            : #include "tdoc_docmgr.hxx"
      47                 :            : #include "tdoc_storage.hxx"
      48                 :            : 
      49                 :            : using namespace com::sun::star;
      50                 :            : using namespace tdoc_ucp;
      51                 :            : 
      52                 :            : //=========================================================================
      53                 :            : //=========================================================================
      54                 :            : //
      55                 :            : // ContentProvider Implementation.
      56                 :            : //
      57                 :            : //=========================================================================
      58                 :            : //=========================================================================
      59                 :            : 
      60                 :         17 : ContentProvider::ContentProvider(
      61                 :            :             const uno::Reference< lang::XMultiServiceFactory >& xSMgr )
      62                 :            : : ::ucbhelper::ContentProviderImplHelper( xSMgr ),
      63         [ +  - ]:         17 :   m_xDocsMgr( new OfficeDocumentsManager( xSMgr, this ) ),
      64 [ +  - ][ +  - ]:         34 :   m_xStgElemFac( new StorageElementFactory( xSMgr, m_xDocsMgr ) )
                 [ +  - ]
      65                 :            : {
      66                 :         17 : }
      67                 :            : 
      68                 :            : //=========================================================================
      69                 :            : // virtual
      70         [ +  - ]:         17 : ContentProvider::~ContentProvider()
      71                 :            : {
      72         [ +  - ]:         17 :     if ( m_xDocsMgr.is() )
      73         [ +  - ]:         17 :         m_xDocsMgr->destroy();
      74         [ -  + ]:         34 : }
      75                 :            : 
      76                 :            : //=========================================================================
      77                 :            : //
      78                 :            : // XInterface methods.
      79                 :            : //
      80                 :            : //=========================================================================
      81                 :            : 
      82 [ +  - ][ +  + ]:       2705 : XINTERFACE_IMPL_4( ContentProvider,
                 [ +  - ]
      83                 :            :                    lang::XTypeProvider,
      84                 :            :                    lang::XServiceInfo,
      85                 :            :                    ucb::XContentProvider,
      86                 :            :                    frame::XTransientDocumentsDocumentContentFactory );
      87                 :            : 
      88                 :            : //=========================================================================
      89                 :            : //
      90                 :            : // XTypeProvider methods.
      91                 :            : //
      92                 :            : //=========================================================================
      93                 :            : 
      94 [ #  # ][ #  # ]:          0 : XTYPEPROVIDER_IMPL_4( ContentProvider,
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
      95                 :            :                       lang::XTypeProvider,
      96                 :            :                       lang::XServiceInfo,
      97                 :            :                       ucb::XContentProvider,
      98                 :            :                       frame::XTransientDocumentsDocumentContentFactory );
      99                 :            : 
     100                 :            : //=========================================================================
     101                 :            : //
     102                 :            : // XServiceInfo methods.
     103                 :            : //
     104                 :            : //=========================================================================
     105                 :            : 
     106 [ +  - ][ +  - ]:         85 : XSERVICEINFO_IMPL_1(
         [ +  - ][ +  - ]
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     107                 :            :     ContentProvider,
     108                 :            :     rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
     109                 :            :         "com.sun.star.comp.ucb.TransientDocumentsContentProvider" ) ),
     110                 :            :     rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
     111                 :         17 :         TDOC_CONTENT_PROVIDER_SERVICE_NAME ) ) );
     112                 :            : 
     113                 :            : //=========================================================================
     114                 :            : //
     115                 :            : // Service factory implementation.
     116                 :            : //
     117                 :            : //=========================================================================
     118                 :            : 
     119 [ +  - ][ +  - ]:         17 : ONE_INSTANCE_SERVICE_FACTORY_IMPL( ContentProvider );
     120                 :            : 
     121                 :            : //=========================================================================
     122                 :            : //
     123                 :            : // XContentProvider methods.
     124                 :            : //
     125                 :            : //=========================================================================
     126                 :            : 
     127                 :            : // virtual
     128                 :            : uno::Reference< ucb::XContent > SAL_CALL
     129                 :         45 : ContentProvider::queryContent(
     130                 :            :         const uno::Reference< ucb::XContentIdentifier >& Identifier )
     131                 :            :     throw( ucb::IllegalIdentifierException, uno::RuntimeException )
     132                 :            : {
     133 [ +  - ][ +  - ]:         45 :     Uri aUri( Identifier->getContentIdentifier() );
     134 [ -  + ][ +  - ]:         45 :     if ( !aUri.isValid() )
     135                 :            :         throw ucb::IllegalIdentifierException(
     136                 :            :             rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Invalid URL!" ) ),
     137 [ #  # ][ #  # ]:          0 :             Identifier );
     138                 :            : 
     139                 :            :     // Normalize URI.
     140                 :            :     uno::Reference< ucb::XContentIdentifier > xCanonicId
     141 [ +  - ][ +  - ]:         45 :         = new ::ucbhelper::ContentIdentifier( m_xSMgr, aUri.getUri() );
         [ +  - ][ +  - ]
     142                 :            : 
     143         [ +  - ]:         45 :     osl::MutexGuard aGuard( m_aMutex );
     144                 :            : 
     145                 :            :     // Check, if a content with given id already exists...
     146                 :            :     uno::Reference< ucb::XContent > xContent
     147 [ +  - ][ -  + ]:         45 :         = queryExistingContent( xCanonicId ).get();
                 [ +  - ]
     148                 :            : 
     149         [ +  - ]:         45 :     if ( !xContent.is() )
     150                 :            :     {
     151                 :            :         // Create a new content.
     152 [ +  - ][ +  - ]:         45 :         xContent = Content::create( m_xSMgr, this, xCanonicId );
                 [ +  - ]
     153         [ +  - ]:         45 :         registerNewContent( xContent );
     154                 :            :     }
     155                 :            : 
     156         [ +  - ]:         45 :     return xContent;
     157                 :            : }
     158                 :            : 
     159                 :            : //=========================================================================
     160                 :            : //
     161                 :            : // XTransientDocumentsDocumentContentFactory methods.
     162                 :            : //
     163                 :            : //=========================================================================
     164                 :            : 
     165                 :            : // virtual
     166                 :            : uno::Reference< ucb::XContent > SAL_CALL
     167                 :         50 : ContentProvider::createDocumentContent(
     168                 :            :         const uno::Reference< frame::XModel >& Model )
     169                 :            :     throw ( lang::IllegalArgumentException, uno::RuntimeException )
     170                 :            : {
     171                 :            :     // model -> id -> content identifier -> queryContent
     172         [ +  - ]:         50 :     if ( m_xDocsMgr.is() )
     173                 :            :     {
     174         [ +  - ]:         50 :         rtl::OUString aDocId = m_xDocsMgr->queryDocumentId( Model );
     175         [ +  - ]:         50 :         if ( !aDocId.isEmpty() )
     176                 :            :         {
     177                 :         50 :             rtl::OUStringBuffer aBuffer;
     178         [ +  - ]:         50 :             aBuffer.appendAscii( TDOC_URL_SCHEME ":/" );
     179         [ +  - ]:         50 :             aBuffer.append( aDocId );
     180                 :            : 
     181                 :            :             uno::Reference< ucb::XContentIdentifier > xId
     182                 :            :                 = new ::ucbhelper::ContentIdentifier(
     183 [ +  - ][ +  - ]:         50 :                     m_xSMgr, aBuffer.makeStringAndClear() );
         [ +  - ][ +  - ]
     184                 :            : 
     185         [ +  - ]:         50 :             osl::MutexGuard aGuard( m_aMutex );
     186                 :            : 
     187                 :            :             // Check, if a content with given id already exists...
     188                 :            :             uno::Reference< ucb::XContent > xContent
     189 [ +  - ][ -  + ]:         50 :                 = queryExistingContent( xId ).get();
                 [ +  - ]
     190                 :            : 
     191         [ +  - ]:         50 :             if ( !xContent.is() )
     192                 :            :             {
     193                 :            :                 // Create a new content.
     194 [ +  - ][ +  - ]:         50 :                 xContent = Content::create( m_xSMgr, this, xId );
                 [ +  - ]
     195                 :            :             }
     196                 :            : 
     197         [ +  - ]:         50 :             if ( xContent.is() )
     198                 :        100 :                 return xContent;
     199                 :            : 
     200                 :            :             // no content.
     201                 :            :             throw lang::IllegalArgumentException(
     202                 :            :                 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
     203                 :            :                     "Illegal Content Identifier!" ) ),
     204                 :            :                 static_cast< cppu::OWeakObject * >( this ),
     205 [ #  # ][ #  # ]:         50 :                 1 );
         [ #  # ][ +  - ]
     206                 :            :         }
     207                 :            :         else
     208                 :            :         {
     209                 :            :             throw lang::IllegalArgumentException(
     210                 :            :                 rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
     211                 :            :                     "Unable to obtain document id from model!" ) ),
     212                 :            :                 static_cast< cppu::OWeakObject * >( this ),
     213 [ #  # ][ #  # ]:          0 :                 1 );
                 [ #  # ]
     214                 :         50 :         }
     215                 :            :      }
     216                 :            :      else
     217                 :            :      {
     218                 :            :         throw lang::IllegalArgumentException(
     219                 :            :             rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
     220                 :            :                 "No Document Manager!" ) ),
     221                 :            :             static_cast< cppu::OWeakObject * >( this ),
     222 [ #  # ][ #  # ]:          0 :             1 );
                 [ #  # ]
     223                 :            :      }
     224                 :            : }
     225                 :            : 
     226                 :            : //=========================================================================
     227                 :            : //
     228                 :            : // interface OfficeDocumentsEventListener
     229                 :            : //
     230                 :            : //=========================================================================
     231                 :            : 
     232                 :            : // virtual
     233                 :        191 : void ContentProvider::notifyDocumentClosed( const rtl::OUString & rDocId )
     234                 :            : {
     235         [ +  - ]:        191 :     osl::MutexGuard aGuard( getContentListMutex() );
     236                 :            : 
     237         [ +  - ]:        191 :     ::ucbhelper::ContentRefList aAllContents;
     238         [ +  - ]:        191 :     queryExistingContents( aAllContents );
     239                 :            : 
     240                 :        191 :     ::ucbhelper::ContentRefList::const_iterator it  = aAllContents.begin();
     241                 :        191 :     ::ucbhelper::ContentRefList::const_iterator end = aAllContents.end();
     242                 :            : 
     243                 :            :     // Notify all content objects related to the closed doc.
     244                 :            : 
     245                 :        191 :     bool bFoundDocumentContent = false;
     246                 :        191 :     rtl::Reference< Content > xRoot;
     247                 :            : 
     248         [ -  + ]:        191 :     while ( it != end )
     249                 :            :     {
     250 [ #  # ][ #  # ]:          0 :         Uri aUri( (*it)->getIdentifier()->getContentIdentifier() );
                 [ #  # ]
     251                 :            :         OSL_ENSURE( aUri.isValid(),
     252                 :            :                     "ContentProvider::notifyDocumentClosed - Invalid URI!" );
     253                 :            : 
     254         [ #  # ]:          0 :         if ( !bFoundDocumentContent )
     255                 :            :         {
     256 [ #  # ][ #  # ]:          0 :             if ( aUri.isRoot() )
     257                 :            :             {
     258         [ #  # ]:          0 :                 xRoot = static_cast< Content * >( (*it).get() );
     259                 :            :             }
     260 [ #  # ][ #  # ]:          0 :             else if ( aUri.isDocument() )
     261                 :            :             {
     262 [ #  # ][ #  # ]:          0 :                 if ( aUri.getDocumentId() == rDocId )
     263                 :            :                 {
     264                 :          0 :                     bFoundDocumentContent = true;
     265                 :            : 
     266                 :            :                     // document content will notify removal of child itself;
     267                 :            :                     // no need for the root to propagate this.
     268                 :          0 :                     xRoot.clear();
     269                 :            :                 }
     270                 :            :             }
     271                 :            :         }
     272                 :            : 
     273 [ #  # ][ #  # ]:          0 :         if ( aUri.getDocumentId() == rDocId )
     274                 :            :         {
     275                 :            :             // Inform content.
     276                 :            :             rtl::Reference< Content > xContent
     277                 :          0 :                 = static_cast< Content * >( (*it).get() );
     278                 :            : 
     279         [ #  # ]:          0 :             xContent->notifyDocumentClosed();
     280                 :            :         }
     281                 :            : 
     282                 :          0 :         ++it;
     283                 :          0 :     }
     284                 :            : 
     285         [ -  + ]:        191 :     if ( xRoot.is() )
     286                 :            :     {
     287                 :            :         // No document content found for rDocId but root content
     288                 :            :         // instanciated. Root content must announce document removal
     289                 :            :         // to content event listeners.
     290         [ #  # ]:          0 :         xRoot->notifyChildRemoved( rDocId );
     291         [ +  - ]:        191 :     }
     292                 :        191 : }
     293                 :            : 
     294                 :            : //=========================================================================
     295                 :            : // virtual
     296                 :        174 : void ContentProvider::notifyDocumentOpened( const rtl::OUString & rDocId )
     297                 :            : {
     298         [ +  - ]:        174 :     osl::MutexGuard aGuard( getContentListMutex() );
     299                 :            : 
     300         [ +  - ]:        174 :     ::ucbhelper::ContentRefList aAllContents;
     301         [ +  - ]:        174 :     queryExistingContents( aAllContents );
     302                 :            : 
     303                 :        174 :     ::ucbhelper::ContentRefList::const_iterator it  = aAllContents.begin();
     304                 :        174 :     ::ucbhelper::ContentRefList::const_iterator end = aAllContents.end();
     305                 :            : 
     306                 :            :     // Find root content. If instanciated let it propagate document insertion.
     307                 :            : 
     308         [ -  + ]:        174 :     while ( it != end )
     309                 :            :     {
     310 [ #  # ][ #  # ]:          0 :         Uri aUri( (*it)->getIdentifier()->getContentIdentifier() );
                 [ #  # ]
     311                 :            :         OSL_ENSURE( aUri.isValid(),
     312                 :            :                     "ContentProvider::notifyDocumentOpened - Invalid URI!" );
     313                 :            : 
     314 [ #  # ][ #  # ]:          0 :         if ( aUri.isRoot() )
     315                 :            :         {
     316                 :            :             rtl::Reference< Content > xRoot
     317                 :          0 :                 = static_cast< Content * >( (*it).get() );
     318         [ #  # ]:          0 :             xRoot->notifyChildInserted( rDocId );
     319                 :            : 
     320                 :            :             // Done.
     321                 :          0 :             break;
     322                 :            :         }
     323                 :            : 
     324         [ #  # ]:          0 :         ++it;
     325         [ +  - ]:        174 :     }
     326                 :        174 : }
     327                 :            : 
     328                 :            : //=========================================================================
     329                 :            : //
     330                 :            : // Non-UNO
     331                 :            : //
     332                 :            : //=========================================================================
     333                 :            : 
     334                 :            : uno::Reference< embed::XStorage >
     335                 :         95 : ContentProvider::queryStorage( const rtl::OUString & rUri,
     336                 :            :                                StorageAccessMode eMode ) const
     337                 :            : {
     338         [ +  - ]:         95 :     if ( m_xStgElemFac.is() )
     339                 :            :     {
     340                 :            :         try
     341                 :            :         {
     342         [ +  - ]:         95 :             return m_xStgElemFac->createStorage( rUri, eMode );
     343                 :            :         }
     344                 :          0 :         catch ( embed::InvalidStorageException const & )
     345                 :            :         {
     346                 :            :             OSL_FAIL( "Caught InvalidStorageException!" );
     347                 :            :         }
     348                 :          0 :         catch ( lang::IllegalArgumentException const & )
     349                 :            :         {
     350                 :            :             OSL_FAIL( "Caught IllegalArgumentException!" );
     351                 :            :         }
     352                 :          0 :         catch ( io::IOException const & )
     353                 :            :         {
     354                 :            :             // Okay to happen, for instance when the storage does not exist.
     355                 :            :             //OSL_ENSURE( false, "Caught IOException!" );
     356                 :            :         }
     357                 :          0 :         catch ( embed::StorageWrappedTargetException const & )
     358                 :            :         {
     359                 :            :             OSL_FAIL( "Caught embed::StorageWrappedTargetException!" );
     360                 :            :         }
     361                 :            :     }
     362   [ #  #  #  #  :         95 :     return uno::Reference< embed::XStorage >();
                      # ]
     363                 :            : }
     364                 :            : 
     365                 :            : //=========================================================================
     366                 :            : uno::Reference< embed::XStorage >
     367                 :          0 : ContentProvider::queryStorageClone( const rtl::OUString & rUri ) const
     368                 :            : {
     369         [ #  # ]:          0 :     if ( m_xStgElemFac.is() )
     370                 :            :     {
     371                 :            :         try
     372                 :            :         {
     373                 :          0 :             Uri aUri( rUri );
     374                 :            :             uno::Reference< embed::XStorage > xParentStorage
     375 [ #  # ][ #  # ]:          0 :                 = m_xStgElemFac->createStorage( aUri.getParentUri(), READ );
     376                 :            :             uno::Reference< embed::XStorage > xStorage
     377         [ #  # ]:          0 :                 = m_xStgElemFac->createTemporaryStorage();
     378                 :            : 
     379         [ #  # ]:          0 :             xParentStorage->copyStorageElementLastCommitTo(
     380 [ #  # ][ #  # ]:          0 :                                 aUri.getDecodedName(), xStorage );
     381   [ #  #  #  #  :          0 :             return xStorage;
                      # ]
     382                 :            :         }
     383                 :          0 :         catch ( embed::InvalidStorageException const & )
     384                 :            :         {
     385                 :            :             OSL_FAIL( "Caught InvalidStorageException!" );
     386                 :            :         }
     387                 :          0 :         catch ( lang::IllegalArgumentException const & )
     388                 :            :         {
     389                 :            :             OSL_FAIL( "Caught IllegalArgumentException!" );
     390                 :            :         }
     391                 :          0 :         catch ( io::IOException const & )
     392                 :            :         {
     393                 :            :             // Okay to happen, for instance when the storage does not exist.
     394                 :            :             //OSL_ENSURE( false, "Caught IOException!" );
     395                 :            :         }
     396                 :          0 :         catch ( embed::StorageWrappedTargetException const & )
     397                 :            :         {
     398                 :            :             OSL_FAIL( "Caught embed::StorageWrappedTargetException!" );
     399                 :            :         }
     400                 :            :     }
     401                 :            : 
     402                 :          0 :     return uno::Reference< embed::XStorage >();
     403                 :            : }
     404                 :            : 
     405                 :            : //=========================================================================
     406                 :            : uno::Reference< io::XInputStream >
     407                 :          0 : ContentProvider::queryInputStream( const rtl::OUString & rUri,
     408                 :            :                                    const rtl::OUString & rPassword ) const
     409                 :            :     throw ( packages::WrongPasswordException )
     410                 :            : {
     411         [ #  # ]:          0 :     if ( m_xStgElemFac.is() )
     412                 :            :     {
     413                 :            :         try
     414                 :            :         {
     415         [ #  # ]:          0 :             return m_xStgElemFac->createInputStream( rUri, rPassword );
     416                 :            :         }
     417                 :          0 :         catch ( embed::InvalidStorageException const & )
     418                 :            :         {
     419                 :            :             OSL_FAIL( "Caught InvalidStorageException!" );
     420                 :            :         }
     421                 :          0 :         catch ( lang::IllegalArgumentException const & )
     422                 :            :         {
     423                 :            :             OSL_FAIL( "Caught IllegalArgumentException!" );
     424                 :            :         }
     425                 :          0 :         catch ( io::IOException const & )
     426                 :            :         {
     427                 :            :             OSL_FAIL( "Caught IOException!" );
     428                 :            :         }
     429                 :          0 :         catch ( embed::StorageWrappedTargetException const & )
     430                 :            :         {
     431                 :            :             OSL_FAIL( "Caught embed::StorageWrappedTargetException!" );
     432                 :            :         }
     433                 :            : //        catch ( packages::WrongPasswordException const & )
     434                 :            : //        {
     435                 :            : //            // the key provided is wrong; rethrow; to be handled by caller.
     436                 :            : //            throw;
     437                 :            : //        }
     438                 :            :     }
     439   [ #  #  #  #  :          0 :     return uno::Reference< io::XInputStream >();
                      # ]
     440                 :            : }
     441                 :            : 
     442                 :            : //=========================================================================
     443                 :            : uno::Reference< io::XOutputStream >
     444                 :          0 : ContentProvider::queryOutputStream( const rtl::OUString & rUri,
     445                 :            :                                     const rtl::OUString & rPassword,
     446                 :            :                                     bool bTruncate ) const
     447                 :            :     throw ( packages::WrongPasswordException )
     448                 :            : {
     449         [ #  # ]:          0 :     if ( m_xStgElemFac.is() )
     450                 :            :     {
     451                 :            :         try
     452                 :            :         {
     453                 :            :             return
     454         [ #  # ]:          0 :                 m_xStgElemFac->createOutputStream( rUri, rPassword, bTruncate );
     455                 :            :         }
     456                 :          0 :         catch ( embed::InvalidStorageException const & )
     457                 :            :         {
     458                 :            :             OSL_FAIL( "Caught InvalidStorageException!" );
     459                 :            :         }
     460                 :          0 :         catch ( lang::IllegalArgumentException const & )
     461                 :            :         {
     462                 :            :             OSL_FAIL( "Caught IllegalArgumentException!" );
     463                 :            :         }
     464                 :          0 :         catch ( io::IOException const & )
     465                 :            :         {
     466                 :            :             // Okay to happen, for instance when the storage does not exist.
     467                 :            :             //OSL_ENSURE( false, "Caught IOException!" );
     468                 :            :         }
     469                 :          0 :         catch ( embed::StorageWrappedTargetException const & )
     470                 :            :         {
     471                 :            :             OSL_FAIL( "Caught embed::StorageWrappedTargetException!" );
     472                 :            :         }
     473                 :            : //        catch ( packages::WrongPasswordException const & )
     474                 :            : //        {
     475                 :            : //            // the key provided is wrong; rethrow; to be handled by caller.
     476                 :            : //            throw;
     477                 :            : //        }
     478                 :            :     }
     479   [ #  #  #  #  :          0 :     return uno::Reference< io::XOutputStream >();
                      # ]
     480                 :            : }
     481                 :            : 
     482                 :            : //=========================================================================
     483                 :            : uno::Reference< io::XStream >
     484                 :          0 : ContentProvider::queryStream( const rtl::OUString & rUri,
     485                 :            :                               const rtl::OUString & rPassword,
     486                 :            :                               bool bTruncate ) const
     487                 :            :     throw ( packages::WrongPasswordException )
     488                 :            : {
     489         [ #  # ]:          0 :     if ( m_xStgElemFac.is() )
     490                 :            :     {
     491                 :            :         try
     492                 :            :         {
     493         [ #  # ]:          0 :             return m_xStgElemFac->createStream( rUri, rPassword, bTruncate );
     494                 :            :         }
     495                 :          0 :         catch ( embed::InvalidStorageException const & )
     496                 :            :         {
     497                 :            :             OSL_FAIL( "Caught InvalidStorageException!" );
     498                 :            :         }
     499                 :          0 :         catch ( lang::IllegalArgumentException const & )
     500                 :            :         {
     501                 :            :             OSL_FAIL( "Caught IllegalArgumentException!" );
     502                 :            :         }
     503                 :          0 :         catch ( io::IOException const & )
     504                 :            :         {
     505                 :            :             // Okay to happen, for instance when the storage does not exist.
     506                 :            :             //OSL_ENSURE( false, "Caught IOException!" );
     507                 :            :         }
     508                 :          0 :         catch ( embed::StorageWrappedTargetException const & )
     509                 :            :         {
     510                 :            :             OSL_FAIL( "Caught embed::StorageWrappedTargetException!" );
     511                 :            :         }
     512                 :            : //        catch ( packages::WrongPasswordException const & )
     513                 :            : //        {
     514                 :            : //            // the key provided is wrong; rethrow; to be handled by caller.
     515                 :            : //            throw;
     516                 :            : //        }
     517                 :            :     }
     518   [ #  #  #  #  :          0 :     return uno::Reference< io::XStream >();
                      # ]
     519                 :            : }
     520                 :            : 
     521                 :            : //=========================================================================
     522                 :          0 : bool ContentProvider::queryNamesOfChildren(
     523                 :            :     const rtl::OUString & rUri, uno::Sequence< rtl::OUString > & rNames ) const
     524                 :            : {
     525                 :          0 :     Uri aUri( rUri );
     526 [ #  # ][ #  # ]:          0 :     if ( aUri.isRoot() )
     527                 :            :     {
     528                 :            :         // special handling for root, which has no storage, but children.
     529         [ #  # ]:          0 :         if ( m_xDocsMgr.is() )
     530                 :            :         {
     531 [ #  # ][ #  # ]:          0 :             rNames = m_xDocsMgr->queryDocuments();
                 [ #  # ]
     532                 :          0 :             return true;
     533                 :            :         }
     534                 :            :     }
     535                 :            :     else
     536                 :            :     {
     537         [ #  # ]:          0 :         if ( m_xStgElemFac.is() )
     538                 :            :         {
     539                 :            :             try
     540                 :            :             {
     541                 :            :                 uno::Reference< embed::XStorage > xStorage
     542         [ #  # ]:          0 :                     = m_xStgElemFac->createStorage( rUri, READ );
     543                 :            : 
     544                 :            :                 OSL_ENSURE( xStorage.is(), "Got no Storage!" );
     545                 :            : 
     546         [ #  # ]:          0 :                 if ( xStorage.is() )
     547                 :            :                 {
     548                 :            :                     uno::Reference< container::XNameAccess > xNA(
     549         [ #  # ]:          0 :                         xStorage, uno::UNO_QUERY );
     550                 :            : 
     551                 :            :                     OSL_ENSURE( xNA.is(), "Got no css.container.XNameAccess!" );
     552         [ #  # ]:          0 :                     if ( xNA.is() )
     553                 :            :                     {
     554 [ #  # ][ #  # ]:          0 :                         rNames = xNA->getElementNames();
         [ #  # ][ #  # ]
     555                 :          0 :                         return true;
     556         [ #  # ]:          0 :                     }
     557 [ #  # ][ #  #  :          0 :                 }
                #  #  # ]
     558                 :            :             }
     559         [ #  # ]:          0 :             catch ( embed::InvalidStorageException const & )
     560                 :            :             {
     561                 :            :                 OSL_FAIL( "Caught InvalidStorageException!" );
     562                 :            :             }
     563         [ #  # ]:          0 :             catch ( lang::IllegalArgumentException const & )
     564                 :            :             {
     565                 :            :                 OSL_FAIL( "Caught IllegalArgumentException!" );
     566                 :            :             }
     567         [ #  # ]:          0 :             catch ( io::IOException const & )
     568                 :            :             {
     569                 :            :                 // Okay to happen, for instance if the storage does not exist.
     570                 :            :                 //OSL_ENSURE( false, "Caught IOException!" );
     571                 :            :             }
     572         [ #  # ]:          0 :             catch ( embed::StorageWrappedTargetException const & )
     573                 :            :             {
     574                 :            :                 OSL_FAIL( "Caught embed::StorageWrappedTargetException!" );
     575                 :            :             }
     576                 :            :         }
     577                 :            :     }
     578                 :          0 :     return false;
     579                 :            : }
     580                 :            : 
     581                 :            : //=========================================================================
     582                 :            : rtl::OUString
     583                 :         95 : ContentProvider::queryStorageTitle( const rtl::OUString & rUri ) const
     584                 :            : {
     585                 :         95 :     rtl::OUString aTitle;
     586                 :            : 
     587                 :         95 :     Uri aUri( rUri );
     588 [ -  + ][ +  - ]:         95 :     if ( aUri.isRoot() )
     589                 :            :     {
     590                 :            :         // always empty.
     591                 :          0 :         aTitle = rtl::OUString();
     592                 :            :     }
     593 [ +  - ][ +  - ]:         95 :     else if ( aUri.isDocument() )
     594                 :            :     {
     595                 :            :         // for documents, title shall not be derived from URL. It shall
     596                 :            :         // be somethimg more 'speaking' than just the document UID.
     597         [ +  - ]:         95 :         if ( m_xDocsMgr.is() )
     598 [ +  - ][ +  - ]:         95 :             aTitle = m_xDocsMgr->queryStorageTitle( aUri.getDocumentId() );
     599                 :            :     }
     600                 :            :     else
     601                 :            :     {
     602                 :            :         // derive title from URL
     603         [ #  # ]:          0 :         aTitle = aUri.getDecodedName();
     604                 :            :     }
     605                 :            : 
     606                 :            :     OSL_ENSURE( !aTitle.isEmpty() || aUri.isRoot(),
     607                 :            :                 "ContentProvider::queryStorageTitle - empty title!" );
     608                 :         95 :     return aTitle;
     609                 :            : }
     610                 :            : 
     611                 :            : //=========================================================================
     612                 :            : uno::Reference< frame::XModel >
     613                 :         45 : ContentProvider::queryDocumentModel( const rtl::OUString & rUri ) const
     614                 :            : {
     615                 :         45 :     uno::Reference< frame::XModel > xModel;
     616                 :            : 
     617         [ +  - ]:         45 :     if ( m_xDocsMgr.is() )
     618                 :            :     {
     619                 :         45 :         Uri aUri( rUri );
     620 [ +  - ][ +  - ]:         45 :         xModel = m_xDocsMgr->queryDocumentModel( aUri.getDocumentId() );
                 [ +  - ]
     621                 :            :     }
     622                 :            : 
     623                 :            :     OSL_ENSURE( xModel.is(),
     624                 :            :                 "ContentProvider::queryDocumentModel - no model!" );
     625                 :         45 :     return xModel;
     626                 :            : }
     627                 :            : 
     628                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10