| 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 |
|
| 10 |
#include <com/sun/star/ucb/OpenMode.hpp> |
| 11 |
|
| 12 |
#include "cmis_datasupplier.hxx" |
| 13 |
#include "cmis_content.hxx" |
| 14 |
|
| 15 |
using namespace com::sun::star; |
| 16 |
|
| 17 |
namespace cmis |
| 18 |
{ |
| 19 |
|
| 20 |
typedef std::vector< ResultListEntry* > ResultList; |
| 21 |
|
| 22 |
DataSupplier::DataSupplier( ChildrenProvider* pChildrenProvider, sal_Int32 nOpenMode ) |
| 23 |
: m_pChildrenProvider( pChildrenProvider ), mnOpenMode(nOpenMode), mbCountFinal(false) |
| 24 |
{ |
| 25 |
} |
| 26 |
|
| 27 |
void DataSupplier::getData() |
| 28 |
{ |
| 29 |
if ( mbCountFinal ) |
| 30 |
return; |
| 31 |
|
| 32 |
std::vector< uno::Reference< ucb::XContent > > aChildren = m_pChildrenProvider->getChildren( ); |
| 33 |
|
| 34 |
// Loop over the results and filter them |
| 35 |
for ( const auto& rChild : aChildren ) |
| 36 |
{ |
| 37 |
OUString sContentType = rChild->getContentType( ); |
| 38 |
bool bIsFolder = sContentType != CMIS_FILE_TYPE; |
| 39 |
if ( ( mnOpenMode == ucb::OpenMode::FOLDERS && bIsFolder ) || |
| 40 |
( mnOpenMode == ucb::OpenMode::DOCUMENTS && !bIsFolder ) || |
| 41 |
( mnOpenMode == ucb::OpenMode::ALL ) ) |
| 42 |
{ |
| 43 |
maResults.emplace_back( rChild ); |
| 44 |
} |
| 45 |
} |
| 46 |
mbCountFinal = true; |
| 47 |
} |
| 48 |
|
| 49 |
DataSupplier::~DataSupplier() |
| 50 |
{ |
| 51 |
} |
| 52 |
|
| 53 |
OUString DataSupplier::queryContentIdentifierString( std::unique_lock<std::mutex>& rResultSetGuard, sal_uInt32 nIndex ) |
| 54 |
{ |
| 55 |
auto const xTemp(queryContentIdentifier(rResultSetGuard, nIndex)); |
| 56 |
return (xTemp.is()) ? xTemp->getContentIdentifier() : OUString(); |
| 57 |
} |
| 58 |
|
| 59 |
uno::Reference< ucb::XContentIdentifier > DataSupplier::queryContentIdentifier( std::unique_lock<std::mutex>& rResultSetGuard, sal_uInt32 nIndex ) |
| 60 |
{ |
| 61 |
auto const xTemp(queryContent(rResultSetGuard, nIndex)); |
| 62 |
return (xTemp.is()) ? xTemp->getIdentifier() : uno::Reference<ucb::XContentIdentifier>(); |
| 63 |
} |
| 64 |
|
| 65 |
uno::Reference< ucb::XContent > DataSupplier::queryContent( std::unique_lock<std::mutex>& rResultSetGuard, sal_uInt32 nIndex ) |
| 66 |
{ |
| 67 |
if (!getResult(rResultSetGuard, nIndex)) |
| 68 |
return uno::Reference<ucb::XContent>(); |
| 69 |
|
| 70 |
return maResults[ nIndex ].xContent; |
| 71 |
} |
| 72 |
|
| 73 |
bool DataSupplier::getResult( std::unique_lock<std::mutex>& /*rResultSetGuard*/, sal_uInt32 nIndex ) |
| 74 |
{ |
| 75 |
if ( maResults.size() > nIndex ) // Result already present. |
| 76 |
return true; |
| 77 |
|
| 78 |
getData(); |
| 79 |
return maResults.size() > nIndex; |
| 80 |
} |
| 81 |
|
| 82 |
sal_uInt32 DataSupplier::totalCount(std::unique_lock<std::mutex>& /*rResultSetGuard*/) |
| 83 |
{ |
| 84 |
getData(); |
| 85 |
return maResults.size(); |
| 86 |
} |
| 87 |
|
| 88 |
sal_uInt32 DataSupplier::currentCount() |
| 89 |
{ |
| 90 |
return maResults.size(); |
| 91 |
} |
| 92 |
|
| 93 |
bool DataSupplier::isCountFinal() |
| 94 |
{ |
| 95 |
return mbCountFinal; |
| 96 |
} |
| 97 |
|
| 98 |
uno::Reference< sdbc::XRow > DataSupplier::queryPropertyValues( std::unique_lock<std::mutex>& rResultSetGuard, sal_uInt32 nIndex ) |
| 99 |
{ |
| 100 |
if ( nIndex < maResults.size() ) |
| 101 |
{ |
| 102 |
uno::Reference< sdbc::XRow > xRow = maResults[ nIndex ].xRow; |
| 103 |
if ( xRow.is() ) |
| 104 |
{ |
| 105 |
// Already cached. |
| 106 |
return xRow; |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
if ( !getResult( rResultSetGuard, nIndex ) ) |
| 111 |
return {}; |
| 112 |
|
| 113 |
uno::Reference< ucb::XContent > xContent( queryContent( rResultSetGuard, nIndex ) ); |
| 114 |
if ( !xContent ) |
| 115 |
return {}; |
| 116 |
try |
| 117 |
{ |
| 118 |
uno::Reference< ucb::XCommandProcessor > xCmdProc( xContent, uno::UNO_QUERY ); |
| 119 |
if ( !xCmdProc ) |
| 120 |
return {}; |
| 121 |
sal_Int32 nCmdId( xCmdProc->createCommandIdentifier() ); |
| 122 |
ucb::Command aCmd; |
| 123 |
aCmd.Name = "getPropertyValues"; |
| 124 |
aCmd.Handle = -1; |
| 125 |
aCmd.Argument <<= getResultSet()->getProperties(); |
| 126 |
uno::Any aResult( xCmdProc->execute( |
| 127 |
aCmd, nCmdId, getResultSet()->getEnvironment() ) ); |
| 128 |
uno::Reference< sdbc::XRow > xRow; |
| 129 |
if ( aResult >>= xRow ) |
| 130 |
{ |
| 131 |
maResults[ nIndex ].xRow = xRow; |
| 132 |
return xRow; |
| 133 |
} |
| 134 |
} |
| 135 |
catch ( uno::Exception const & ) |
| 136 |
{ |
| 137 |
} |
| 138 |
return uno::Reference< sdbc::XRow >(); |
| 139 |
} |
| 140 |
|
| 141 |
void DataSupplier::releasePropertyValues( sal_uInt32 nIndex ) |
| 142 |
{ |
| 143 |
if ( nIndex < maResults.size() ) |
| 144 |
maResults[ nIndex ].xRow.clear(); |
| 145 |
} |
| 146 |
|
| 147 |
void DataSupplier::close() |
| 148 |
{ |
| 149 |
} |
| 150 |
|
| 151 |
void DataSupplier::validate() |
| 152 |
{ |
| 153 |
} |
| 154 |
|
| 155 |
} |
| 156 |
|
| 157 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |