LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/ucb/source/ucp/webdav-neon - webdavdatasupplier.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 164 0.0 %
Date: 2013-07-09 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             :  *
       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             : #include <boost/ptr_container/ptr_vector.hpp>
      36             : #include <boost/shared_ptr.hpp>
      37             : #include <osl/diagnose.h>
      38             : #include <com/sun/star/ucb/OpenMode.hpp>
      39             : #include <ucbhelper/contentidentifier.hxx>
      40             : #include <ucbhelper/providerhelper.hxx>
      41             : #include "webdavdatasupplier.hxx"
      42             : #include "webdavcontent.hxx"
      43             : #include "ContentProperties.hxx"
      44             : #include "DAVSession.hxx"
      45             : #include "NeonUri.hxx"
      46             : 
      47             : using namespace com::sun::star;
      48             : using namespace webdav_ucp;
      49             : 
      50             : namespace webdav_ucp
      51             : {
      52             : 
      53             : //=========================================================================
      54             : //
      55             : // struct ResultListEntry.
      56             : //
      57             : //=========================================================================
      58             : 
      59           0 : struct ResultListEntry
      60             : {
      61             :     OUString                             aId;
      62             :     uno::Reference< ucb::XContentIdentifier > xId;
      63             :     uno::Reference< ucb::XContent >           xContent;
      64             :     uno::Reference< sdbc::XRow >              xRow;
      65             :     boost::shared_ptr<ContentProperties> const pData;
      66             : 
      67           0 :     ResultListEntry(boost::shared_ptr<ContentProperties> const& pEntry)
      68           0 :         : pData(pEntry)
      69           0 :     {}
      70             : };
      71             : 
      72             : //=========================================================================
      73             : //
      74             : // ResultList.
      75             : //
      76             : //=========================================================================
      77             : 
      78             : typedef boost::ptr_vector<ResultListEntry> ResultList;
      79             : 
      80             : //=========================================================================
      81             : //
      82             : // struct DataSupplier_Impl.
      83             : //
      84             : //=========================================================================
      85             : 
      86           0 : struct DataSupplier_Impl
      87             : {
      88             :     osl::Mutex                                   m_aMutex;
      89             :     ResultList                                   m_aResults;
      90             :     rtl::Reference< Content >                    m_xContent;
      91             :     uno::Reference< uno::XComponentContext >     m_xContext;
      92             :     sal_Int32                                    m_nOpenMode;
      93             :     sal_Bool                                     m_bCountFinal;
      94             :     sal_Bool                                     m_bThrowException;
      95             : 
      96           0 :     DataSupplier_Impl(
      97             :                 const uno::Reference< uno::XComponentContext >& rxContext,
      98             :                 const rtl::Reference< Content >& rContent,
      99             :                 sal_Int32 nOpenMode )
     100             :     : m_xContent( rContent ), m_xContext( rxContext ), m_nOpenMode( nOpenMode ),
     101           0 :       m_bCountFinal( sal_False ), m_bThrowException( sal_False ) {}
     102             : };
     103             : 
     104             : }
     105             : 
     106             : //=========================================================================
     107             : //=========================================================================
     108             : //
     109             : // DataSupplier Implementation.
     110             : //
     111             : //=========================================================================
     112             : //=========================================================================
     113             : 
     114           0 : DataSupplier::DataSupplier(
     115             :             const uno::Reference< uno::XComponentContext >& rxContext,
     116             :             const rtl::Reference< Content >& rContent,
     117             :             sal_Int32 nOpenMode )
     118           0 : : m_pImpl( new DataSupplier_Impl( rxContext, rContent, nOpenMode ) )
     119             : {
     120           0 : }
     121             : 
     122             : //=========================================================================
     123             : // virtual
     124           0 : DataSupplier::~DataSupplier()
     125             : {
     126           0 : }
     127             : 
     128             : //=========================================================================
     129             : // virtual
     130           0 : OUString DataSupplier::queryContentIdentifierString( sal_uInt32 nIndex )
     131             : {
     132           0 :     osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
     133             : 
     134           0 :     if ( nIndex < m_pImpl->m_aResults.size() )
     135             :     {
     136           0 :         OUString aId = m_pImpl->m_aResults[ nIndex ].aId;
     137           0 :         if ( !aId.isEmpty() )
     138             :         {
     139             :             // Already cached.
     140           0 :             return aId;
     141           0 :         }
     142             :     }
     143             : 
     144           0 :     if ( getResult( nIndex ) )
     145             :     {
     146           0 :         OUString aId = m_pImpl->m_xContent->getResourceAccess().getURL();
     147             : 
     148             :         const ContentProperties& props
     149           0 :                             = *( m_pImpl->m_aResults[ nIndex ].pData );
     150             : 
     151           0 :         if ( ( aId.lastIndexOf( '/' ) + 1 ) != aId.getLength() )
     152           0 :             aId += OUString("/");
     153             : 
     154           0 :         aId += props.getEscapedTitle();
     155             : 
     156           0 :         if ( props.isTrailingSlash() )
     157           0 :             aId += OUString("/");
     158             : 
     159           0 :         m_pImpl->m_aResults[ nIndex ].aId = aId;
     160           0 :         return aId;
     161             :     }
     162           0 :     return OUString();
     163             : }
     164             : 
     165             : //=========================================================================
     166             : // virtual
     167             : uno::Reference< ucb::XContentIdentifier >
     168           0 : DataSupplier::queryContentIdentifier( sal_uInt32 nIndex )
     169             : {
     170           0 :     osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
     171             : 
     172           0 :     if ( nIndex < m_pImpl->m_aResults.size() )
     173             :     {
     174             :         uno::Reference< ucb::XContentIdentifier > xId
     175           0 :             = m_pImpl->m_aResults[ nIndex ].xId;
     176           0 :         if ( xId.is() )
     177             :         {
     178             :             // Already cached.
     179           0 :             return xId;
     180           0 :         }
     181             :     }
     182             : 
     183           0 :     OUString aId = queryContentIdentifierString( nIndex );
     184           0 :     if ( !aId.isEmpty() )
     185             :     {
     186             :         uno::Reference< ucb::XContentIdentifier > xId
     187           0 :             = new ::ucbhelper::ContentIdentifier( aId );
     188           0 :         m_pImpl->m_aResults[ nIndex ].xId = xId;
     189           0 :         return xId;
     190             :     }
     191           0 :     return uno::Reference< ucb::XContentIdentifier >();
     192             : }
     193             : 
     194             : //=========================================================================
     195             : // virtual
     196             : uno::Reference< ucb::XContent >
     197           0 : DataSupplier::queryContent( sal_uInt32 nIndex )
     198             : {
     199           0 :     osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
     200             : 
     201           0 :     if ( nIndex < m_pImpl->m_aResults.size() )
     202             :     {
     203             :         uno::Reference< ucb::XContent > xContent
     204           0 :             = m_pImpl->m_aResults[ nIndex ].xContent;
     205           0 :         if ( xContent.is() )
     206             :         {
     207             :             // Already cached.
     208           0 :             return xContent;
     209           0 :         }
     210             :     }
     211             : 
     212             :     uno::Reference< ucb::XContentIdentifier > xId
     213           0 :         = queryContentIdentifier( nIndex );
     214           0 :     if ( xId.is() )
     215             :     {
     216             :         try
     217             :         {
     218             :             uno::Reference< ucb::XContent > xContent
     219           0 :                 = m_pImpl->m_xContent->getProvider()->queryContent( xId );
     220           0 :             m_pImpl->m_aResults[ nIndex ].xContent = xContent;
     221           0 :             return xContent;
     222             : 
     223             :         }
     224           0 :         catch ( ucb::IllegalIdentifierException& )
     225             :         {
     226             :         }
     227             :     }
     228           0 :     return uno::Reference< ucb::XContent >();
     229             : }
     230             : 
     231             : //=========================================================================
     232             : // virtual
     233           0 : sal_Bool DataSupplier::getResult( sal_uInt32 nIndex )
     234             : {
     235           0 :     osl::ClearableGuard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
     236             : 
     237           0 :     if ( m_pImpl->m_aResults.size() > nIndex )
     238             :     {
     239             :         // Result already present.
     240           0 :         return sal_True;
     241             :     }
     242             : 
     243             :     // Obtain values...
     244           0 :     if ( getData() )
     245             :     {
     246           0 :         if ( m_pImpl->m_aResults.size() > nIndex )
     247             :         {
     248             :             // Result already present.
     249           0 :             return sal_True;
     250             :         }
     251             :     }
     252             : 
     253           0 :     return sal_False;
     254             : }
     255             : 
     256             : //=========================================================================
     257             : // virtual
     258           0 : sal_uInt32 DataSupplier::totalCount()
     259             : {
     260             :   // Obtain values...
     261           0 :   getData();
     262             : 
     263           0 :   return m_pImpl->m_aResults.size();
     264             : }
     265             : 
     266             : //=========================================================================
     267             : // virtual
     268           0 : sal_uInt32 DataSupplier::currentCount()
     269             : {
     270           0 :     return m_pImpl->m_aResults.size();
     271             : }
     272             : 
     273             : //=========================================================================
     274             : // virtual
     275           0 : sal_Bool DataSupplier::isCountFinal()
     276             : {
     277           0 :     return m_pImpl->m_bCountFinal;
     278             : }
     279             : 
     280             : //=========================================================================
     281             : // virtual
     282           0 : uno::Reference< sdbc::XRow > DataSupplier::queryPropertyValues(
     283             :                                                     sal_uInt32 nIndex  )
     284             : {
     285           0 :     osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
     286             : 
     287           0 :     if ( nIndex < m_pImpl->m_aResults.size() )
     288             :     {
     289           0 :         uno::Reference< sdbc::XRow > xRow = m_pImpl->m_aResults[ nIndex ].xRow;
     290           0 :         if ( xRow.is() )
     291             :         {
     292             :             // Already cached.
     293           0 :             return xRow;
     294           0 :         }
     295             :     }
     296             : 
     297           0 :     if ( getResult( nIndex ) )
     298             :     {
     299             :         uno::Reference< sdbc::XRow > xRow
     300             :             = Content::getPropertyValues(
     301           0 :                 m_pImpl->m_xContext,
     302           0 :                 getResultSet()->getProperties(),
     303           0 :                 *(m_pImpl->m_aResults[ nIndex ].pData),
     304             :                 rtl::Reference< ::ucbhelper::ContentProviderImplHelper >(
     305           0 :                     m_pImpl->m_xContent->getProvider().get() ),
     306           0 :                 queryContentIdentifierString( nIndex ) );
     307           0 :         m_pImpl->m_aResults[ nIndex ].xRow = xRow;
     308           0 :         return xRow;
     309             :     }
     310             : 
     311           0 :     return uno::Reference< sdbc::XRow >();
     312             : }
     313             : 
     314             : //=========================================================================
     315             : // virtual
     316           0 : void DataSupplier::releasePropertyValues( sal_uInt32 nIndex )
     317             : {
     318           0 :     osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
     319             : 
     320           0 :     if ( nIndex < m_pImpl->m_aResults.size() )
     321           0 :         m_pImpl->m_aResults[ nIndex ].xRow = uno::Reference< sdbc::XRow >();
     322           0 : }
     323             : 
     324             : //=========================================================================
     325             : // virtual
     326           0 : void DataSupplier::close()
     327             : {
     328           0 : }
     329             : 
     330             : //=========================================================================
     331             : // virtual
     332           0 : void DataSupplier::validate()
     333             :     throw( ucb::ResultSetException )
     334             : {
     335           0 :     if ( m_pImpl->m_bThrowException )
     336           0 :         throw ucb::ResultSetException();
     337           0 : }
     338             : 
     339             : //=========================================================================
     340           0 : sal_Bool DataSupplier::getData()
     341             : {
     342           0 :     osl::ClearableGuard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
     343             : 
     344           0 :     if ( !m_pImpl->m_bCountFinal )
     345             :     {
     346           0 :         std::vector< OUString > propertyNames;
     347             :         ContentProperties::UCBNamesToDAVNames(
     348           0 :                         getResultSet()->getProperties(), propertyNames );
     349             : 
     350             :         // Append "resourcetype", if not already present. It's value is
     351             :         // needed to get a valid ContentProperties::pIsFolder value, which
     352             :         // is needed for OpenMode handling.
     353             : 
     354             :         std::vector< OUString >::const_iterator it
     355           0 :             = propertyNames.begin();
     356             :         std::vector< OUString >::const_iterator end
     357           0 :             = propertyNames.end();
     358             : 
     359           0 :         while ( it != end )
     360             :         {
     361           0 :             if ( (*it).equals( DAVProperties::RESOURCETYPE ) )
     362           0 :                 break;
     363             : 
     364           0 :             ++it;
     365             :         }
     366             : 
     367           0 :         if ( it == end )
     368           0 :             propertyNames.push_back( DAVProperties::RESOURCETYPE );
     369             : 
     370           0 :         std::vector< DAVResource > resources;
     371             :         try
     372             :         {
     373             :             // propfind depth 1, get property values for parent AND for each
     374             :             // child
     375           0 :             m_pImpl->m_xContent->getResourceAccess()
     376             :                 .PROPFIND( DAVONE,
     377             :                            propertyNames,
     378             :                            resources,
     379           0 :                            getResultSet()->getEnvironment() );
     380             :           }
     381           0 :           catch ( DAVException & )
     382             :         {
     383             : //          OSL_FAIL( "PROPFIND : DAVException" );
     384           0 :             m_pImpl->m_bThrowException = sal_True;
     385             :           }
     386             : 
     387           0 :         if ( !m_pImpl->m_bThrowException )
     388             :         {
     389             :             try
     390             :             {
     391             :                 NeonUri aURI(
     392           0 :                     m_pImpl->m_xContent->getResourceAccess().getURL() );
     393           0 :                 OUString aPath = aURI.GetPath();
     394             : 
     395           0 :                 if ( aPath.getStr()[ aPath.getLength() - 1 ]
     396           0 :                      == sal_Unicode( '/' ) )
     397           0 :                     aPath = aPath.copy( 0, aPath.getLength() - 1 );
     398             : 
     399           0 :                 aPath = NeonUri::unescape( aPath );
     400           0 :                 bool bFoundParent = false;
     401             : 
     402           0 :                 for ( sal_uInt32 n = 0; n < resources.size(); ++n )
     403             :                 {
     404           0 :                     const DAVResource & rRes = resources[ n ];
     405             : 
     406             :                     // Filter parent, which is contained somewhere(!) in
     407             :                     // the vector.
     408           0 :                     if ( !bFoundParent )
     409             :                     {
     410             :                         try
     411             :                         {
     412           0 :                             NeonUri aCurrURI( rRes.uri );
     413           0 :                             OUString aCurrPath = aCurrURI.GetPath();
     414           0 :                             if ( aCurrPath.getStr()[
     415           0 :                                      aCurrPath.getLength() - 1 ]
     416           0 :                                  == sal_Unicode( '/' ) )
     417             :                                 aCurrPath
     418           0 :                                     = aCurrPath.copy(
     419             :                                         0,
     420           0 :                                         aCurrPath.getLength() - 1 );
     421             : 
     422           0 :                             aCurrPath = NeonUri::unescape( aCurrPath );
     423           0 :                             if ( aPath == aCurrPath )
     424             :                             {
     425           0 :                                 bFoundParent = true;
     426           0 :                                 continue;
     427           0 :                             }
     428             :                         }
     429           0 :                         catch ( DAVException const & )
     430             :                         {
     431             :                             // do nothing, ignore error. continue.
     432             :                         }
     433             :                     }
     434             : 
     435             :                     boost::shared_ptr<ContentProperties> const
     436           0 :                         pContentProperties(new ContentProperties(rRes));
     437             : 
     438             :                     // Check resource against open mode.
     439           0 :                     switch ( m_pImpl->m_nOpenMode )
     440             :                     {
     441             :                     case ucb::OpenMode::FOLDERS:
     442             :                         {
     443           0 :                             sal_Bool bFolder = sal_False;
     444             : 
     445             :                             const uno::Any & rValue
     446             :                                 = pContentProperties->getValue(
     447           0 :                                     OUString( "IsFolder"  ) );
     448           0 :                             rValue >>= bFolder;
     449             : 
     450           0 :                             if ( !bFolder )
     451           0 :                                 continue;
     452             : 
     453           0 :                             break;
     454             :                         }
     455             : 
     456             :                     case ucb::OpenMode::DOCUMENTS:
     457             :                         {
     458           0 :                             sal_Bool bDocument = sal_False;
     459             : 
     460             :                             const uno::Any & rValue
     461             :                                 = pContentProperties->getValue(
     462           0 :                                     OUString( "IsDocument"  ) );
     463           0 :                             rValue >>= bDocument;
     464             : 
     465           0 :                             if ( !bDocument )
     466           0 :                                 continue;
     467             : 
     468           0 :                             break;
     469             :                         }
     470             : 
     471             :                     case ucb::OpenMode::ALL:
     472             :                     default:
     473           0 :                         break;
     474             :                     }
     475             : 
     476           0 :                     m_pImpl->m_aResults.push_back(
     477           0 :                         new ResultListEntry( pContentProperties ) );
     478           0 :                 }
     479             :             }
     480           0 :             catch ( DAVException const & )
     481             :             {
     482             :             }
     483             :         }
     484             : 
     485           0 :           m_pImpl->m_bCountFinal = sal_True;
     486             : 
     487             :         // Callback possible, because listeners may be informed!
     488           0 :         aGuard.clear();
     489           0 :         getResultSet()->rowCountFinal();
     490             :     }
     491           0 :     return !m_pImpl->m_bThrowException;
     492             : }
     493             : 
     494             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10