LCOV - code coverage report
Current view: top level - libreoffice/ucb/source/ucp/package - pkgdatasupplier.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 160 0.0 %
Date: 2012-12-17 Functions: 0 19 0.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             : /**************************************************************************
      22             :                                 TODO
      23             :  **************************************************************************
      24             : 
      25             :  *************************************************************************/
      26             : 
      27             : #include <vector>
      28             : #include <osl/diagnose.h>
      29             : #include <com/sun/star/container/XEnumeration.hpp>
      30             : #include <com/sun/star/container/XNamed.hpp>
      31             : #include <ucbhelper/contentidentifier.hxx>
      32             : #include <ucbhelper/providerhelper.hxx>
      33             : #include "pkgdatasupplier.hxx"
      34             : #include "pkgcontent.hxx"
      35             : #include "pkgprovider.hxx"
      36             : 
      37             : #include "../inc/urihelper.hxx"
      38             : 
      39             : using namespace com::sun::star;
      40             : using namespace package_ucp;
      41             : 
      42             : namespace package_ucp
      43             : {
      44             : 
      45             : //=========================================================================
      46             : //
      47             : // struct ResultListEntry.
      48             : //
      49             : //=========================================================================
      50             : 
      51           0 : struct ResultListEntry
      52             : {
      53             :     rtl::OUString                             aURL;
      54             :     uno::Reference< ucb::XContentIdentifier > xId;
      55             :     uno::Reference< ucb::XContent >           xContent;
      56             :     uno::Reference< sdbc::XRow >              xRow;
      57             : 
      58           0 :     ResultListEntry( const rtl::OUString& rURL ) : aURL( rURL ) {}
      59             : };
      60             : 
      61             : //=========================================================================
      62             : //
      63             : // ResultList.
      64             : //
      65             : //=========================================================================
      66             : 
      67             : typedef std::vector< ResultListEntry* > ResultList;
      68             : 
      69             : //=========================================================================
      70             : //
      71             : // struct DataSupplier_Impl.
      72             : //
      73             : //=========================================================================
      74             : 
      75             : struct DataSupplier_Impl
      76             : {
      77             :     osl::Mutex                                   m_aMutex;
      78             :     ResultList                                   m_aResults;
      79             :     rtl::Reference< Content >                    m_xContent;
      80             :     uno::Reference< uno::XComponentContext >     m_xContext;
      81             :     uno::Reference< container::XEnumeration >    m_xFolderEnum;
      82             :     sal_Int32                                    m_nOpenMode;
      83             :     sal_Bool                                     m_bCountFinal;
      84             :     sal_Bool                                     m_bThrowException;
      85             : 
      86           0 :     DataSupplier_Impl(
      87             :             const uno::Reference< uno::XComponentContext >& rxContext,
      88             :             const rtl::Reference< Content >& rContent,
      89             :             sal_Int32 nOpenMode )
      90             :     : m_xContent( rContent ), m_xContext( rxContext ),
      91             :       m_xFolderEnum( rContent->getIterator() ), m_nOpenMode( nOpenMode ),
      92           0 :       m_bCountFinal( !m_xFolderEnum.is() ), m_bThrowException( m_bCountFinal )
      93           0 :     {}
      94             :     ~DataSupplier_Impl();
      95             : };
      96             : 
      97             : //=========================================================================
      98           0 : DataSupplier_Impl::~DataSupplier_Impl()
      99             : {
     100           0 :     ResultList::const_iterator it  = m_aResults.begin();
     101           0 :     ResultList::const_iterator end = m_aResults.end();
     102             : 
     103           0 :     while ( it != end )
     104             :     {
     105           0 :         delete (*it);
     106           0 :         ++it;
     107             :     }
     108           0 : }
     109             : 
     110             : }
     111             : 
     112             : //=========================================================================
     113             : //=========================================================================
     114             : //
     115             : // DataSupplier Implementation.
     116             : //
     117             : //=========================================================================
     118             : //=========================================================================
     119             : 
     120           0 : DataSupplier::DataSupplier(
     121             :                 const uno::Reference< uno::XComponentContext >& rxContext,
     122             :                 const rtl::Reference< Content >& rContent,
     123             :                 sal_Int32 nOpenMode )
     124           0 : : m_pImpl( new DataSupplier_Impl( rxContext, rContent, nOpenMode ) )
     125             : {
     126           0 : }
     127             : 
     128             : //=========================================================================
     129             : // virtual
     130           0 : DataSupplier::~DataSupplier()
     131             : {
     132           0 :     delete m_pImpl;
     133           0 : }
     134             : 
     135             : //=========================================================================
     136             : // virtual
     137           0 : rtl::OUString DataSupplier::queryContentIdentifierString( sal_uInt32 nIndex )
     138             : {
     139           0 :     osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
     140             : 
     141           0 :     if ( nIndex < m_pImpl->m_aResults.size() )
     142             :     {
     143           0 :         rtl::OUString aId = m_pImpl->m_aResults[ nIndex ]->aURL;
     144           0 :         if ( !aId.isEmpty() )
     145             :         {
     146             :             // Already cached.
     147           0 :             return aId;
     148           0 :         }
     149             :     }
     150             : 
     151           0 :     if ( getResult( nIndex ) )
     152             :     {
     153             :         // Note: getResult fills m_pImpl->m_aResults[ nIndex ]->aURL.
     154           0 :         return m_pImpl->m_aResults[ nIndex ]->aURL;
     155             :     }
     156           0 :     return rtl::OUString();
     157             : }
     158             : 
     159             : //=========================================================================
     160             : // virtual
     161             : uno::Reference< ucb::XContentIdentifier >
     162           0 : DataSupplier::queryContentIdentifier( sal_uInt32 nIndex )
     163             : {
     164           0 :     osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
     165             : 
     166           0 :     if ( nIndex < m_pImpl->m_aResults.size() )
     167             :     {
     168             :         uno::Reference< ucb::XContentIdentifier > xId
     169           0 :                                 = m_pImpl->m_aResults[ nIndex ]->xId;
     170           0 :         if ( xId.is() )
     171             :         {
     172             :             // Already cached.
     173           0 :             return xId;
     174           0 :         }
     175             :     }
     176             : 
     177           0 :     rtl::OUString aId = queryContentIdentifierString( nIndex );
     178           0 :     if ( !aId.isEmpty() )
     179             :     {
     180             :         uno::Reference< ucb::XContentIdentifier > xId
     181           0 :             = new ::ucbhelper::ContentIdentifier( aId );
     182           0 :         m_pImpl->m_aResults[ nIndex ]->xId = xId;
     183           0 :         return xId;
     184             :     }
     185           0 :     return uno::Reference< ucb::XContentIdentifier >();
     186             : }
     187             : 
     188             : //=========================================================================
     189             : // virtual
     190           0 : uno::Reference< ucb::XContent > DataSupplier::queryContent(
     191             :                                                         sal_uInt32 nIndex )
     192             : {
     193           0 :     osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
     194             : 
     195           0 :     if ( nIndex < m_pImpl->m_aResults.size() )
     196             :     {
     197             :         uno::Reference< ucb::XContent > xContent
     198           0 :                                 = m_pImpl->m_aResults[ nIndex ]->xContent;
     199           0 :         if ( xContent.is() )
     200             :         {
     201             :             // Already cached.
     202           0 :             return xContent;
     203           0 :         }
     204             :     }
     205             : 
     206             :     uno::Reference< ucb::XContentIdentifier > xId
     207           0 :         = queryContentIdentifier( nIndex );
     208           0 :     if ( xId.is() )
     209             :     {
     210             :         try
     211             :         {
     212             :             uno::Reference< ucb::XContent > xContent
     213           0 :                 = m_pImpl->m_xContent->getProvider()->queryContent( xId );
     214           0 :             m_pImpl->m_aResults[ nIndex ]->xContent = xContent;
     215           0 :             return xContent;
     216             : 
     217             :         }
     218           0 :         catch ( ucb::IllegalIdentifierException const & )
     219             :         {
     220             :         }
     221             :     }
     222           0 :     return uno::Reference< ucb::XContent >();
     223             : }
     224             : 
     225             : //=========================================================================
     226             : // virtual
     227           0 : sal_Bool DataSupplier::getResult( sal_uInt32 nIndex )
     228             : {
     229           0 :     osl::ClearableGuard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
     230             : 
     231           0 :     if ( m_pImpl->m_aResults.size() > nIndex )
     232             :     {
     233             :         // Result already present.
     234           0 :         return sal_True;
     235             :     }
     236             : 
     237             :     // Result not (yet) present.
     238             : 
     239           0 :     if ( m_pImpl->m_bCountFinal )
     240           0 :         return sal_False;
     241             : 
     242             :     // Try to obtain result...
     243             : 
     244           0 :     sal_uInt32 nOldCount = m_pImpl->m_aResults.size();
     245           0 :     sal_Bool bFound = sal_False;
     246           0 :     sal_uInt32 nPos = nOldCount;
     247             : 
     248           0 :     while ( m_pImpl->m_xFolderEnum->hasMoreElements() )
     249             :     {
     250             :         try
     251             :         {
     252           0 :             uno::Reference< container::XNamed > xNamed;
     253           0 :             m_pImpl->m_xFolderEnum->nextElement() >>= xNamed;
     254             : 
     255           0 :             if ( !xNamed.is() )
     256             :             {
     257             :                 OSL_FAIL( "DataSupplier::getResult - Got no XNamed!" );
     258             :                 break;
     259             :             }
     260             : 
     261           0 :             rtl::OUString aName = xNamed->getName();
     262             : 
     263           0 :             if ( aName.isEmpty() )
     264             :             {
     265             :                 OSL_FAIL( "DataSupplier::getResult - Empty name!" );
     266             :                 break;
     267             :             }
     268             : 
     269             :             // Assemble URL for child.
     270           0 :             rtl::OUString aURL = assembleChildURL( aName );
     271             : 
     272           0 :             m_pImpl->m_aResults.push_back( new ResultListEntry( aURL ) );
     273             : 
     274           0 :             if ( nPos == nIndex )
     275             :             {
     276             :                 // Result obtained.
     277           0 :                 bFound = sal_True;
     278             :                 break;
     279             :             }
     280             : 
     281           0 :             nPos++;
     282             :         }
     283           0 :         catch ( container::NoSuchElementException const & )
     284             :         {
     285           0 :             m_pImpl->m_bThrowException = sal_True;
     286             :             break;
     287             :         }
     288           0 :         catch ( lang::WrappedTargetException const & )
     289             :         {
     290           0 :             m_pImpl->m_bThrowException = sal_True;
     291             :             break;
     292             :         }
     293             :     }
     294             : 
     295           0 :     if ( !bFound )
     296           0 :         m_pImpl->m_bCountFinal = sal_True;
     297             : 
     298           0 :     rtl::Reference< ::ucbhelper::ResultSet > xResultSet = getResultSet().get();
     299           0 :     if ( xResultSet.is() )
     300             :     {
     301             :         // Callbacks follow!
     302           0 :         aGuard.clear();
     303             : 
     304           0 :         if ( nOldCount < m_pImpl->m_aResults.size() )
     305             :             xResultSet->rowCountChanged(
     306           0 :                                     nOldCount, m_pImpl->m_aResults.size() );
     307             : 
     308           0 :         if ( m_pImpl->m_bCountFinal )
     309           0 :             xResultSet->rowCountFinal();
     310             :     }
     311             : 
     312           0 :     return bFound;
     313             : }
     314             : 
     315             : //=========================================================================
     316             : // virtual
     317           0 : sal_uInt32 DataSupplier::totalCount()
     318             : {
     319           0 :     osl::ClearableGuard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
     320             : 
     321           0 :     if ( m_pImpl->m_bCountFinal )
     322           0 :         return m_pImpl->m_aResults.size();
     323             : 
     324           0 :     sal_uInt32 nOldCount = m_pImpl->m_aResults.size();
     325             : 
     326           0 :     while ( m_pImpl->m_xFolderEnum->hasMoreElements() )
     327             :     {
     328             :         try
     329             :         {
     330           0 :             uno::Reference< container::XNamed > xNamed;
     331           0 :             m_pImpl->m_xFolderEnum->nextElement() >>= xNamed;
     332             : 
     333           0 :             if ( !xNamed.is() )
     334             :             {
     335             :                 OSL_FAIL( "DataSupplier::getResult - Got no XNamed!" );
     336             :                 break;
     337             :             }
     338             : 
     339           0 :             rtl::OUString aName = xNamed->getName();
     340             : 
     341           0 :             if ( aName.isEmpty() )
     342             :             {
     343             :                 OSL_FAIL( "DataSupplier::getResult - Empty name!" );
     344             :                 break;
     345             :             }
     346             : 
     347             :             // Assemble URL for child.
     348           0 :             rtl::OUString aURL = assembleChildURL( aName );
     349             : 
     350           0 :             m_pImpl->m_aResults.push_back( new ResultListEntry( aURL ) );
     351             :         }
     352           0 :         catch ( container::NoSuchElementException const & )
     353             :         {
     354           0 :             m_pImpl->m_bThrowException = sal_True;
     355             :             break;
     356             :         }
     357           0 :         catch ( lang::WrappedTargetException const & )
     358             :         {
     359           0 :             m_pImpl->m_bThrowException = sal_True;
     360             :             break;
     361             :         }
     362             :     }
     363             : 
     364           0 :     m_pImpl->m_bCountFinal = sal_True;
     365             : 
     366           0 :     rtl::Reference< ::ucbhelper::ResultSet > xResultSet = getResultSet().get();
     367           0 :     if ( xResultSet.is() )
     368             :     {
     369             :         // Callbacks follow!
     370           0 :         aGuard.clear();
     371             : 
     372           0 :         if ( nOldCount < m_pImpl->m_aResults.size() )
     373             :             xResultSet->rowCountChanged(
     374           0 :                                     nOldCount, m_pImpl->m_aResults.size() );
     375             : 
     376           0 :         xResultSet->rowCountFinal();
     377             :     }
     378             : 
     379           0 :     return m_pImpl->m_aResults.size();
     380             : }
     381             : 
     382             : //=========================================================================
     383             : // virtual
     384           0 : sal_uInt32 DataSupplier::currentCount()
     385             : {
     386           0 :     return m_pImpl->m_aResults.size();
     387             : }
     388             : 
     389             : //=========================================================================
     390             : // virtual
     391           0 : sal_Bool DataSupplier::isCountFinal()
     392             : {
     393           0 :     return m_pImpl->m_bCountFinal;
     394             : }
     395             : 
     396             : //=========================================================================
     397             : // virtual
     398           0 : uno::Reference< sdbc::XRow > DataSupplier::queryPropertyValues(
     399             :                                                         sal_uInt32 nIndex  )
     400             : {
     401           0 :     osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
     402             : 
     403           0 :     if ( nIndex < m_pImpl->m_aResults.size() )
     404             :     {
     405           0 :         uno::Reference< sdbc::XRow > xRow = m_pImpl->m_aResults[ nIndex ]->xRow;
     406           0 :         if ( xRow.is() )
     407             :         {
     408             :             // Already cached.
     409           0 :             return xRow;
     410           0 :         }
     411             :     }
     412             : 
     413           0 :     if ( getResult( nIndex ) )
     414             :     {
     415             :         uno::Reference< sdbc::XRow > xRow = Content::getPropertyValues(
     416             :                         m_pImpl->m_xContext,
     417           0 :                         getResultSet()->getProperties(),
     418             :                         static_cast< ContentProvider * >(
     419           0 :                             m_pImpl->m_xContent->getProvider().get() ),
     420           0 :                         queryContentIdentifierString( nIndex ) );
     421           0 :         m_pImpl->m_aResults[ nIndex ]->xRow = xRow;
     422           0 :         return xRow;
     423             :     }
     424             : 
     425           0 :     return uno::Reference< sdbc::XRow >();
     426             : }
     427             : 
     428             : //=========================================================================
     429             : // virtual
     430           0 : void DataSupplier::releasePropertyValues( sal_uInt32 nIndex )
     431             : {
     432           0 :     osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
     433             : 
     434           0 :     if ( nIndex < m_pImpl->m_aResults.size() )
     435           0 :         m_pImpl->m_aResults[ nIndex ]->xRow = uno::Reference< sdbc::XRow >();
     436           0 : }
     437             : 
     438             : //=========================================================================
     439             : // virtual
     440           0 : void DataSupplier::close()
     441             : {
     442           0 : }
     443             : 
     444             : //=========================================================================
     445             : // virtual
     446           0 : void DataSupplier::validate()
     447             :     throw( ucb::ResultSetException )
     448             : {
     449           0 :     if ( m_pImpl->m_bThrowException )
     450           0 :         throw ucb::ResultSetException();
     451           0 : }
     452             : 
     453             : //=========================================================================
     454           0 : ::rtl::OUString DataSupplier::assembleChildURL( const ::rtl::OUString& aName )
     455             : {
     456           0 :     rtl::OUString aURL;
     457             :     rtl::OUString aContURL
     458           0 :         = m_pImpl->m_xContent->getIdentifier()->getContentIdentifier();
     459           0 :     sal_Int32 nParam = aContURL.indexOf( '?' );
     460           0 :     if ( nParam >= 0 )
     461             :     {
     462           0 :         aURL = aContURL.copy( 0, nParam );
     463             : 
     464           0 :         sal_Int32 nPackageUrlEnd = aURL.lastIndexOf( '/' );
     465           0 :         if ( nPackageUrlEnd != aURL.getLength() - 1 )
     466           0 :             aURL += rtl::OUString("/");
     467             : 
     468           0 :         aURL += ::ucb_impl::urihelper::encodeSegment( aName );
     469           0 :         aURL += aContURL.copy( nParam );
     470             :     }
     471             :     else
     472             :     {
     473           0 :         aURL = aContURL;
     474             : 
     475           0 :         sal_Int32 nPackageUrlEnd = aURL.lastIndexOf( '/' );
     476           0 :         if ( nPackageUrlEnd != aURL.getLength() - 1 )
     477           0 :             aURL += rtl::OUString("/");
     478             : 
     479           0 :         aURL += ::ucb_impl::urihelper::encodeSegment( aName );
     480             :     }
     481           0 :     return aURL;
     482             : }
     483             : 
     484             : 
     485             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10