bump product version to 7.6.3.2-android
[LibreOffice.git] / ucb / source / ucp / cmis / cmis_datasupplier.cxx
blob2a91770cd8f625527d8e15c8ba8a4e34f6653fc8
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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 */
10 #include <com/sun/star/ucb/OpenMode.hpp>
12 #include "cmis_datasupplier.hxx"
13 #include "cmis_content.hxx"
15 using namespace com::sun::star;
17 namespace cmis
20 typedef std::vector< ResultListEntry* > ResultList;
22 DataSupplier::DataSupplier( ChildrenProvider* pChildrenProvider, sal_Int32 nOpenMode )
23 : m_pChildrenProvider( pChildrenProvider ), mnOpenMode(nOpenMode), mbCountFinal(false)
27 void DataSupplier::getData()
29 if ( mbCountFinal )
30 return;
32 std::vector< uno::Reference< ucb::XContent > > aChildren = m_pChildrenProvider->getChildren( );
34 // Loop over the results and filter them
35 for ( const auto& rChild : aChildren )
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 ) )
43 maResults.emplace_back( rChild );
46 mbCountFinal = true;
49 DataSupplier::~DataSupplier()
53 OUString DataSupplier::queryContentIdentifierString( sal_uInt32 nIndex )
55 auto const xTemp(queryContentIdentifier(nIndex));
56 return (xTemp.is()) ? xTemp->getContentIdentifier() : OUString();
59 uno::Reference< ucb::XContentIdentifier > DataSupplier::queryContentIdentifier( sal_uInt32 nIndex )
61 auto const xTemp(queryContent(nIndex));
62 return (xTemp.is()) ? xTemp->getIdentifier() : uno::Reference<ucb::XContentIdentifier>();
65 uno::Reference< ucb::XContent > DataSupplier::queryContent( sal_uInt32 nIndex )
67 if (!getResult(nIndex))
68 return uno::Reference<ucb::XContent>();
70 return maResults[ nIndex ].xContent;
73 bool DataSupplier::getResult( sal_uInt32 nIndex )
75 if ( maResults.size() > nIndex ) // Result already present.
76 return true;
78 getData();
79 return maResults.size() > nIndex;
82 sal_uInt32 DataSupplier::totalCount()
84 getData();
85 return maResults.size();
88 sal_uInt32 DataSupplier::currentCount()
90 return maResults.size();
93 bool DataSupplier::isCountFinal()
95 return mbCountFinal;
98 uno::Reference< sdbc::XRow > DataSupplier::queryPropertyValues( sal_uInt32 nIndex )
100 if ( nIndex < maResults.size() )
102 uno::Reference< sdbc::XRow > xRow = maResults[ nIndex ].xRow;
103 if ( xRow.is() )
105 // Already cached.
106 return xRow;
110 if ( getResult( nIndex ) )
112 uno::Reference< ucb::XContent > xContent( queryContent( nIndex ) );
113 if ( xContent.is() )
117 uno::Reference< ucb::XCommandProcessor > xCmdProc(
118 xContent, uno::UNO_QUERY_THROW );
119 sal_Int32 nCmdId( xCmdProc->createCommandIdentifier() );
120 ucb::Command aCmd;
121 aCmd.Name = "getPropertyValues";
122 aCmd.Handle = -1;
123 aCmd.Argument <<= getResultSet()->getProperties();
124 uno::Any aResult( xCmdProc->execute(
125 aCmd, nCmdId, getResultSet()->getEnvironment() ) );
126 uno::Reference< sdbc::XRow > xRow;
127 if ( aResult >>= xRow )
129 maResults[ nIndex ].xRow = xRow;
130 return xRow;
133 catch ( uno::Exception const & )
138 return uno::Reference< sdbc::XRow >();
141 void DataSupplier::releasePropertyValues( sal_uInt32 nIndex )
143 if ( nIndex < maResults.size() )
144 maResults[ nIndex ].xRow.clear();
147 void DataSupplier::close()
151 void DataSupplier::validate()
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */