LibreOffice Module ucb (master) 1
tdoc_datasupplier.cxx
Go to the documentation of this file.
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 <optional>
28
29#include <com/sun/star/ucb/IllegalIdentifierException.hpp>
30#include <com/sun/star/ucb/ResultSetException.hpp>
31#include <osl/diagnose.h>
33#include <utility>
34
35#include "tdoc_datasupplier.hxx"
36#include "tdoc_content.hxx"
37
38using namespace com::sun::star;
39using namespace tdoc_ucp;
40
41namespace tdoc_ucp
42{
43
44
45// struct ResultListEntry.
46
47namespace {
48
49
50}
51
52// struct DataSupplier_Impl.
53
54
55}
56
57// DataSupplier Implementation.
58ResultSetDataSupplier::ResultSetDataSupplier(
59 uno::Reference< uno::XComponentContext > xContext,
61: m_xContent(std::move( xContent )), m_xContext(std::move( xContext )),
62 m_bCountFinal( false ), m_bThrowException( false )
63{
64}
65
66// virtual
67ResultSetDataSupplier::~ResultSetDataSupplier()
68{
69}
70
71// virtual
72OUString
74{
75 std::unique_lock aGuard( m_aMutex );
77}
78
79OUString
80ResultSetDataSupplier::queryContentIdentifierStringImpl( std::unique_lock<std::mutex>& /*rGuard*/, sal_uInt32 nIndex )
81{
82 if ( nIndex < m_aResults.size() )
83 {
84 OUString aId = m_aResults[ nIndex ].aURL;
85 if ( !aId.isEmpty() )
86 {
87 // Already cached.
88 return aId;
89 }
90 }
91
92 if ( getResult( nIndex ) )
93 {
94 // Note: getResult fills m_pImpl->m_aResults[ nIndex ]->aURL.
95 return m_aResults[ nIndex ].aURL;
96 }
97 return OUString();
98}
99
100// virtual
101uno::Reference< ucb::XContentIdentifier >
103{
104 std::unique_lock aGuard( m_aMutex );
105 return queryContentIdentifierImpl(aGuard, nIndex);
106}
107
108uno::Reference< ucb::XContentIdentifier >
109ResultSetDataSupplier::queryContentIdentifierImpl( std::unique_lock<std::mutex>& rGuard, sal_uInt32 nIndex )
110{
111 if ( nIndex < m_aResults.size() )
112 {
113 uno::Reference< ucb::XContentIdentifier > xId
114 = m_aResults[ nIndex ].xId;
115 if ( xId.is() )
116 {
117 // Already cached.
118 return xId;
119 }
120 }
121
122 OUString aId = queryContentIdentifierStringImpl( rGuard, nIndex );
123 if ( !aId.isEmpty() )
124 {
125 uno::Reference< ucb::XContentIdentifier > xId
126 = new ::ucbhelper::ContentIdentifier( aId );
127 m_aResults[ nIndex ].xId = xId;
128 return xId;
129 }
130 return uno::Reference< ucb::XContentIdentifier >();
131}
132
133// virtual
134uno::Reference< ucb::XContent >
136{
137 std::unique_lock aGuard( m_aMutex );
138
139 if ( nIndex < m_aResults.size() )
140 {
141 uno::Reference< ucb::XContent > xContent
142 = m_aResults[ nIndex ].xContent;
143 if ( xContent.is() )
144 {
145 // Already cached.
146 return xContent;
147 }
148 }
149
150 uno::Reference< ucb::XContentIdentifier > xId
152 if ( xId.is() )
153 {
154 try
155 {
156 uno::Reference< ucb::XContent > xContent
157 = m_xContent->getProvider()->queryContent( xId );
158 m_aResults[ nIndex ].xContent = xContent;
159 return xContent;
160
161 }
162 catch ( ucb::IllegalIdentifierException const & )
163 {
164 }
165 }
166 return uno::Reference< ucb::XContent >();
167}
168
169// virtual
170bool ResultSetDataSupplier::getResult( sal_uInt32 nIndex )
171{
172 std::unique_lock aGuard( m_aMutex );
173 return getResultImpl(aGuard, nIndex);
174}
175
176bool ResultSetDataSupplier::getResultImpl( std::unique_lock<std::mutex>& rGuard, sal_uInt32 nIndex )
177{
178 if ( m_aResults.size() > nIndex )
179 {
180 // Result already present.
181 return true;
182 }
183
184 // Result not (yet) present.
185
186 if ( m_bCountFinal )
187 return false;
188
189 // Try to obtain result...
190
191 sal_uInt32 nOldCount = m_aResults.size();
192 bool bFound = false;
193
194 if ( queryNamesOfChildren(rGuard) )
195 {
196 for ( sal_uInt32 n = nOldCount;
197 n < sal::static_int_cast<sal_uInt32>(
198 m_xNamesOfChildren->getLength());
199 ++n )
200 {
201 const OUString & rName
202 = m_xNamesOfChildren->getConstArray()[ n ];
203
204 if ( rName.isEmpty() )
205 {
206 OSL_FAIL( "ResultDataSupplier::getResult - Empty name!" );
207 break;
208 }
209
210 // Assemble URL for child.
211 OUString aURL = assembleChildURL( rName );
212
213 m_aResults.emplace_back( aURL );
214
215 if ( n == nIndex )
216 {
217 // Result obtained.
218 bFound = true;
219 break;
220 }
221 }
222 }
223
224 if ( !bFound )
225 m_bCountFinal = true;
226
228 if ( xResultSet.is() )
229 {
230 // Callbacks follow!
231 rGuard.unlock();
232
233 if ( nOldCount < m_aResults.size() )
234 xResultSet->rowCountChanged( nOldCount, m_aResults.size() );
235
236 if ( m_bCountFinal )
237 xResultSet->rowCountFinal();
238
239 rGuard.lock();
240 }
241
242 return bFound;
243}
244
245// virtual
247{
248 std::unique_lock aGuard( m_aMutex );
249
250 if ( m_bCountFinal )
251 return m_aResults.size();
252
253 sal_uInt32 nOldCount = m_aResults.size();
254
255 if ( queryNamesOfChildren(aGuard) )
256 {
257 for ( sal_uInt32 n = nOldCount;
258 n < sal::static_int_cast<sal_uInt32>(
259 m_xNamesOfChildren->getLength());
260 ++n )
261 {
262 const OUString & rName
263 = m_xNamesOfChildren->getConstArray()[ n ];
264
265 if ( rName.isEmpty() )
266 {
267 OSL_FAIL( "ResultDataSupplier::getResult - Empty name!" );
268 break;
269 }
270
271 // Assemble URL for child.
272 OUString aURL = assembleChildURL( rName );
273
274 m_aResults.emplace_back( aURL );
275 }
276 }
277
278 m_bCountFinal = true;
279
281 if ( xResultSet.is() )
282 {
283 // Callbacks follow!
284 aGuard.unlock();
285
286 if ( nOldCount < m_aResults.size() )
287 xResultSet->rowCountChanged( nOldCount, m_aResults.size() );
288
289 xResultSet->rowCountFinal();
290 }
291
292 return m_aResults.size();
293}
294
295// virtual
297{
298 return m_aResults.size();
299}
300
301// virtual
303{
304 return m_bCountFinal;
305}
306
307// virtual
308uno::Reference< sdbc::XRow >
310{
311 std::unique_lock aGuard( m_aMutex );
312
313 if ( nIndex < m_aResults.size() )
314 {
315 uno::Reference< sdbc::XRow > xRow = m_aResults[ nIndex ].xRow;
316 if ( xRow.is() )
317 {
318 // Already cached.
319 return xRow;
320 }
321 }
322
323 if ( getResultImpl( aGuard, nIndex ) )
324 {
325 uno::Reference< sdbc::XRow > xRow = Content::getPropertyValues(
327 getResultSet()->getProperties(),
328 m_xContent->getContentProvider().get(),
330 m_aResults[ nIndex ].xRow = xRow;
331 return xRow;
332 }
333
334 return uno::Reference< sdbc::XRow >();
335}
336
337// virtual
339{
340 std::unique_lock aGuard( m_aMutex );
341
342 if ( nIndex < m_aResults.size() )
343 m_aResults[ nIndex ].xRow.clear();
344}
345
346// virtual
348{
349}
350
351// virtual
353{
354 if ( m_bThrowException )
355 throw ucb::ResultSetException();
356}
357
358bool ResultSetDataSupplier::queryNamesOfChildren(std::unique_lock<std::mutex>& /*rGuard*/)
359{
360 if ( !m_xNamesOfChildren )
361 {
362 uno::Sequence< OUString > aNamesOfChildren;
363
364 if ( !m_xContent->getContentProvider()->queryNamesOfChildren(
365 m_xContent->getIdentifier()->getContentIdentifier(),
366 aNamesOfChildren ) )
367 {
368 OSL_FAIL( "Got no list of children!" );
369 m_bThrowException = true;
370 return false;
371 }
372 else
373 {
374 m_xNamesOfChildren = std::move( aNamesOfChildren );
375 }
376 }
377 return true;
378}
379
380OUString
381ResultSetDataSupplier::assembleChildURL( std::u16string_view aName )
382{
383 OUString aContURL
384 = m_xContent->getIdentifier()->getContentIdentifier();
385 OUString aURL( aContURL );
386
387 sal_Int32 nUrlEnd = aURL.lastIndexOf( '/' );
388 if ( nUrlEnd != aURL.getLength() - 1 )
389 aURL += "/";
390
391 aURL += aName;
392 return aURL;
393}
394
395/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
uno::Reference< ucb::XContent > m_xContent
Reference< XComponentContext > m_xContext
css::uno::Reference< css::sdbc::XRow > getPropertyValues(const css::uno::Sequence< css::beans::Property > &rProperties)
OUString assembleChildURL(std::u16string_view aName)
virtual void releasePropertyValues(sal_uInt32 nIndex) override
virtual OUString queryContentIdentifierString(sal_uInt32 nIndex) override
virtual bool getResult(sal_uInt32 nIndex) override
virtual css::uno::Reference< css::sdbc::XRow > queryPropertyValues(sal_uInt32 nIndex) override
virtual sal_uInt32 totalCount() override
std::vector< ResultListEntry > m_aResults
bool getResultImpl(std::unique_lock< std::mutex > &rGuard, sal_uInt32 nIndex)
bool queryNamesOfChildren(std::unique_lock< std::mutex > &rGuard)
rtl::Reference< Content > m_xContent
OUString queryContentIdentifierStringImpl(std::unique_lock< std::mutex > &rGuard, sal_uInt32 nIndex)
virtual void validate() override
virtual css::uno::Reference< css::ucb::XContent > queryContent(sal_uInt32 nIndex) override
css::uno::Reference< css::ucb::XContentIdentifier > queryContentIdentifierImpl(std::unique_lock< std::mutex > &rGuard, sal_uInt32 nIndex)
virtual css::uno::Reference< css::ucb::XContentIdentifier > queryContentIdentifier(sal_uInt32 nIndex) override
virtual bool isCountFinal() override
std::optional< css::uno::Sequence< OUString > > m_xNamesOfChildren
css::uno::Reference< css::uno::XComponentContext > m_xContext
virtual sal_uInt32 currentCount() override
rtl::Reference< ResultSet > getResultSet() const
URL aURL
sal_Int32 nIndex
OUString aName
sal_Int64 n