LibreOffice Module ucb (master) 1
hierarchydatasupplier.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 <com/sun/star/ucb/IllegalIdentifierException.hpp>
28#include <com/sun/star/ucb/OpenMode.hpp>
31#include "hierarchyprovider.hxx"
32#include "hierarchycontent.hxx"
33
34using namespace com::sun::star;
35using namespace hierarchy_ucp;
36
37
38
39HierarchyResultSetDataSupplier::HierarchyResultSetDataSupplier(
40 const uno::Reference< uno::XComponentContext >& rxContext,
42 sal_Int32 nOpenMode )
43: m_xContent( rContent ), m_xContext( rxContext ),
44 m_aFolder( rxContext,
45 static_cast< HierarchyContentProvider * >(
46 rContent->getProvider().get() ),
47 rContent->getIdentifier()->getContentIdentifier() ),
48 m_nOpenMode( nOpenMode ), m_bCountFinal( false )
49{
50}
51
52
53// virtual
55{
56}
57
58
59// virtual
61 sal_uInt32 nIndex )
62{
63 std::unique_lock aGuard( m_aMutex );
65}
66
68 std::unique_lock<std::mutex>& rGuard,
69 sal_uInt32 nIndex )
70{
71 if ( nIndex < m_aResults.size() )
72 {
73 OUString aId = m_aResults[ nIndex ]->aId;
74 if ( !aId.isEmpty() )
75 {
76 // Already cached.
77 return aId;
78 }
79 }
80
81 if ( getResultImpl( rGuard, nIndex ) )
82 {
83 OUString aId
84 = m_xContent->getIdentifier()->getContentIdentifier();
85
86 if ( ( aId.lastIndexOf( '/' ) + 1 ) != aId.getLength() )
87 aId += "/";
88
89 aId += m_aResults[ nIndex ]->aData.getName();
90
91 m_aResults[ nIndex ]->aId = aId;
92 return aId;
93 }
94 return OUString();
95}
96
97
98// virtual
99uno::Reference< ucb::XContentIdentifier >
101{
102 std::unique_lock aGuard( m_aMutex );
103
104 if ( nIndex < m_aResults.size() )
105 {
106 uno::Reference< ucb::XContentIdentifier > xId
107 = m_aResults[ nIndex ]->xId;
108 if ( xId.is() )
109 {
110 // Already cached.
111 return xId;
112 }
113 }
114
115 OUString aId = queryContentIdentifierStringImpl( aGuard, nIndex );
116 if ( !aId.isEmpty() )
117 {
118 uno::Reference< ucb::XContentIdentifier > xId
119 = new ::ucbhelper::ContentIdentifier( aId );
120 m_aResults[ nIndex ]->xId = xId;
121 return xId;
122 }
123 return uno::Reference< ucb::XContentIdentifier >();
124}
125
126
127// virtual
128uno::Reference< ucb::XContent >
130{
131 std::unique_lock aGuard( m_aMutex );
132
133 if ( nIndex < m_aResults.size() )
134 {
135 uno::Reference< ucb::XContent > xContent
136 = m_aResults[ nIndex ]->xContent;
137 if ( xContent.is() )
138 {
139 // Already cached.
140 return xContent;
141 }
142 }
143
144 uno::Reference< ucb::XContentIdentifier > xId
146 if ( xId.is() )
147 {
148 try
149 {
150 uno::Reference< ucb::XContent > xContent
151 = m_xContent->getProvider()->queryContent( xId );
152 m_aResults[ nIndex ]->xContent = xContent;
153 return xContent;
154
155 }
156 catch ( ucb::IllegalIdentifierException const & )
157 {
158 }
159 }
160 return uno::Reference< ucb::XContent >();
161}
162
163
164// virtual
166{
167 std::unique_lock aGuard( m_aMutex );
168 return getResultImpl(aGuard, nIndex);
169}
170
171bool HierarchyResultSetDataSupplier::getResultImpl( std::unique_lock<std::mutex>& rGuard, sal_uInt32 nIndex )
172{
173 if ( m_aResults.size() > nIndex )
174 {
175 // Result already present.
176 return true;
177 }
178
179 // Result not (yet) present.
180
181 if ( m_bCountFinal )
182 return false;
183
184 // Try to obtain result...
185
186 sal_uInt32 nOldCount = m_aResults.size();
187 bool bFound = false;
188 sal_uInt32 nPos = nOldCount;
189
190 while ( m_aFolder.next( m_aIterator ) )
191 {
192 const HierarchyEntryData& rResult = *m_aIterator;
193 if ( checkResult( rResult ) )
194 {
195 m_aResults.emplace_back( new ResultListEntry( rResult ) );
196
197 if ( nPos == nIndex )
198 {
199 // Result obtained.
200 bFound = true;
201 break;
202 }
203 }
204 nPos++;
205 }
206
207 if ( !bFound )
208 m_bCountFinal = true;
209
211 if ( xResultSet.is() )
212 {
213 // Callbacks follow!
214 rGuard.unlock();
215
216 if ( nOldCount < m_aResults.size() )
217 xResultSet->rowCountChanged(
218 nOldCount, m_aResults.size() );
219
220 if ( m_bCountFinal )
221 xResultSet->rowCountFinal();
222
223 rGuard.lock();
224 }
225
226 return bFound;
227}
228
229
230// virtual
232{
233 std::unique_lock aGuard( m_aMutex );
234
235 if ( m_bCountFinal )
236 return m_aResults.size();
237
238 sal_uInt32 nOldCount = m_aResults.size();
239
240 while ( m_aFolder.next( m_aIterator ) )
241 {
242 const HierarchyEntryData& rResult = *m_aIterator;
243 if ( checkResult( rResult ) )
244 m_aResults.emplace_back( new ResultListEntry( rResult ) );
245 }
246
247 m_bCountFinal = true;
248
250 if ( xResultSet.is() )
251 {
252 // Callbacks follow!
253 aGuard.unlock();
254
255 if ( nOldCount < m_aResults.size() )
256 xResultSet->rowCountChanged(
257 nOldCount, m_aResults.size() );
258
259 xResultSet->rowCountFinal();
260 }
261
262 return m_aResults.size();
263}
264
265
266// virtual
268{
269 return m_aResults.size();
270}
271
272
273// virtual
275{
276 return m_bCountFinal;
277}
278
279
280// virtual
281uno::Reference< sdbc::XRow >
283{
284 std::unique_lock aGuard( m_aMutex );
285
286 if ( nIndex < m_aResults.size() )
287 {
288 uno::Reference< sdbc::XRow > xRow
289 = m_aResults[ nIndex ]->xRow;
290 if ( xRow.is() )
291 {
292 // Already cached.
293 return xRow;
294 }
295 }
296
297 if ( getResultImpl( aGuard, nIndex ) )
298 {
300 m_aResults[ nIndex ]->aData );
301
302 uno::Reference< sdbc::XRow > xRow
305 getResultSet()->getProperties(),
306 aData,
307 static_cast< HierarchyContentProvider * >(
308 m_xContent->getProvider().get() ),
310 m_aResults[ nIndex ]->xRow = xRow;
311 return xRow;
312 }
313
314 return uno::Reference< sdbc::XRow >();
315}
316
317
318// virtual
320{
321 std::unique_lock aGuard( m_aMutex );
322
323 if ( nIndex < m_aResults.size() )
324 m_aResults[ nIndex ]->xRow.clear();
325}
326
327
328// virtual
330{
331}
332
333
334// virtual
336{
337}
338
339
341 const HierarchyEntryData& rResult )
342{
343 switch ( m_nOpenMode )
344 {
345 case ucb::OpenMode::FOLDERS:
346 if ( rResult.getType() == HierarchyEntryData::LINK )
347 {
348 // Entry is a link.
349 return false;
350 }
351 break;
352
353 case ucb::OpenMode::DOCUMENTS:
354 if ( rResult.getType() == HierarchyEntryData::FOLDER )
355 {
356 // Entry is a folder.
357 return false;
358 }
359 break;
360
361 case ucb::OpenMode::ALL:
362 default:
363 break;
364 }
365
366 return true;
367}
368
369/* 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)
virtual css::uno::Reference< css::sdbc::XRow > queryPropertyValues(sal_uInt32 nIndex) override
virtual void releasePropertyValues(sal_uInt32 nIndex) override
bool getResultImpl(std::unique_lock< std::mutex > &, sal_uInt32 nIndex)
virtual css::uno::Reference< css::ucb::XContent > queryContent(sal_uInt32 nIndex) override
rtl::Reference< HierarchyContent > m_xContent
bool checkResult(const HierarchyEntryData &rResult)
OUString queryContentIdentifierStringImpl(std::unique_lock< std::mutex > &, sal_uInt32 nIndex)
virtual OUString queryContentIdentifierString(sal_uInt32 nIndex) final override
css::uno::Reference< css::uno::XComponentContext > m_xContext
virtual bool getResult(sal_uInt32 nIndex) final override
virtual css::uno::Reference< css::ucb::XContentIdentifier > queryContentIdentifier(sal_uInt32 nIndex) override
rtl::Reference< ResultSet > getResultSet() const
sal_Int32 nIndex
sal_uInt16 nPos
constexpr OUStringLiteral aData
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC OUString getIdentifier(css::uno::Reference< css::deployment::XPackage > const &package)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)