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 <vector>
28 
29 #include <com/sun/star/ucb/IllegalIdentifierException.hpp>
30 #include <com/sun/star/ucb/OpenMode.hpp>
33 #include "hierarchyprovider.hxx"
34 #include "hierarchycontent.hxx"
35 
36 using namespace com::sun::star;
37 using namespace hierarchy_ucp;
38 
39 namespace hierarchy_ucp
40 {
41 
42 
43 // struct ResultListEntry.
44 
45 
47 {
48  OUString aId;
49  uno::Reference< ucb::XContentIdentifier > xId;
50  uno::Reference< ucb::XContent > xContent;
51  uno::Reference< sdbc::XRow > xRow;
53 
54  explicit ResultListEntry( const HierarchyEntryData& rEntry ) : aData( rEntry ) {}
55 };
56 
57 
58 // ResultList.
59 
60 
61 typedef std::vector< std::unique_ptr<ResultListEntry> > ResultList;
62 
63 
64 // struct DataSupplier_Impl.
65 
66 
68 {
69  osl::Mutex m_aMutex;
70  ResultList m_aResults;
72  uno::Reference< uno::XComponentContext > m_xContext;
75  sal_Int32 const m_nOpenMode;
77 
79  const uno::Reference< uno::XComponentContext >& rxContext,
80  const rtl::Reference< HierarchyContent >& rContent,
81  sal_Int32 nOpenMode )
82  : m_xContent( rContent ), m_xContext( rxContext ),
83  m_aFolder( rxContext,
84  static_cast< HierarchyContentProvider * >(
85  rContent->getProvider().get() ),
86  rContent->getIdentifier()->getContentIdentifier() ),
87  m_nOpenMode( nOpenMode ), m_bCountFinal( false ) {}
88 };
89 
90 
91 }
92 
93 
94 // HierarchyResultSetDataSupplier Implementation.
95 
96 
97 HierarchyResultSetDataSupplier::HierarchyResultSetDataSupplier(
98  const uno::Reference< uno::XComponentContext >& rxContext,
99  const rtl::Reference< HierarchyContent >& rContent,
100  sal_Int32 nOpenMode )
101 : m_pImpl( new DataSupplier_Impl( rxContext, rContent, nOpenMode ) )
102 {
103 }
104 
105 
106 // virtual
108 {
109 }
110 
111 
112 // virtual
114  sal_uInt32 nIndex )
115 {
116  osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
117 
118  if ( nIndex < m_pImpl->m_aResults.size() )
119  {
120  OUString aId = m_pImpl->m_aResults[ nIndex ]->aId;
121  if ( !aId.isEmpty() )
122  {
123  // Already cached.
124  return aId;
125  }
126  }
127 
128  if ( getResult( nIndex ) )
129  {
130  OUString aId
131  = m_pImpl->m_xContent->getIdentifier()->getContentIdentifier();
132 
133  if ( ( aId.lastIndexOf( '/' ) + 1 ) != aId.getLength() )
134  aId += "/";
135 
136  aId += m_pImpl->m_aResults[ nIndex ]->aData.getName();
137 
138  m_pImpl->m_aResults[ nIndex ]->aId = aId;
139  return aId;
140  }
141  return OUString();
142 }
143 
144 
145 // virtual
146 uno::Reference< ucb::XContentIdentifier >
148 {
149  osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
150 
151  if ( nIndex < m_pImpl->m_aResults.size() )
152  {
153  uno::Reference< ucb::XContentIdentifier > xId
154  = m_pImpl->m_aResults[ nIndex ]->xId;
155  if ( xId.is() )
156  {
157  // Already cached.
158  return xId;
159  }
160  }
161 
162  OUString aId = queryContentIdentifierString( nIndex );
163  if ( !aId.isEmpty() )
164  {
165  uno::Reference< ucb::XContentIdentifier > xId
166  = new ::ucbhelper::ContentIdentifier( aId );
167  m_pImpl->m_aResults[ nIndex ]->xId = xId;
168  return xId;
169  }
170  return uno::Reference< ucb::XContentIdentifier >();
171 }
172 
173 
174 // virtual
175 uno::Reference< ucb::XContent >
177 {
178  osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
179 
180  if ( nIndex < m_pImpl->m_aResults.size() )
181  {
182  uno::Reference< ucb::XContent > xContent
183  = m_pImpl->m_aResults[ nIndex ]->xContent;
184  if ( xContent.is() )
185  {
186  // Already cached.
187  return xContent;
188  }
189  }
190 
191  uno::Reference< ucb::XContentIdentifier > xId
192  = queryContentIdentifier( nIndex );
193  if ( xId.is() )
194  {
195  try
196  {
197  uno::Reference< ucb::XContent > xContent
198  = m_pImpl->m_xContent->getProvider()->queryContent( xId );
199  m_pImpl->m_aResults[ nIndex ]->xContent = xContent;
200  return xContent;
201 
202  }
203  catch ( ucb::IllegalIdentifierException const & )
204  {
205  }
206  }
207  return uno::Reference< ucb::XContent >();
208 }
209 
210 
211 // virtual
213 {
214  osl::ClearableGuard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
215 
216  if ( m_pImpl->m_aResults.size() > nIndex )
217  {
218  // Result already present.
219  return true;
220  }
221 
222  // Result not (yet) present.
223 
224  if ( m_pImpl->m_bCountFinal )
225  return false;
226 
227  // Try to obtain result...
228 
229  sal_uInt32 nOldCount = m_pImpl->m_aResults.size();
230  bool bFound = false;
231  sal_uInt32 nPos = nOldCount;
232 
233  while ( m_pImpl->m_aFolder.next( m_pImpl->m_aIterator ) )
234  {
235  const HierarchyEntryData& rResult = *m_pImpl->m_aIterator;
236  if ( checkResult( rResult ) )
237  {
238  m_pImpl->m_aResults.emplace_back( new ResultListEntry( rResult ) );
239 
240  if ( nPos == nIndex )
241  {
242  // Result obtained.
243  bFound = true;
244  break;
245  }
246  }
247  nPos++;
248  }
249 
250  if ( !bFound )
251  m_pImpl->m_bCountFinal = true;
252 
254  if ( xResultSet.is() )
255  {
256  // Callbacks follow!
257  aGuard.clear();
258 
259  if ( nOldCount < m_pImpl->m_aResults.size() )
260  xResultSet->rowCountChanged(
261  nOldCount, m_pImpl->m_aResults.size() );
262 
263  if ( m_pImpl->m_bCountFinal )
264  xResultSet->rowCountFinal();
265  }
266 
267  return bFound;
268 }
269 
270 
271 // virtual
273 {
274  osl::ClearableGuard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
275 
276  if ( m_pImpl->m_bCountFinal )
277  return m_pImpl->m_aResults.size();
278 
279  sal_uInt32 nOldCount = m_pImpl->m_aResults.size();
280 
281  while ( m_pImpl->m_aFolder.next( m_pImpl->m_aIterator ) )
282  {
283  const HierarchyEntryData& rResult = *m_pImpl->m_aIterator;
284  if ( checkResult( rResult ) )
285  m_pImpl->m_aResults.emplace_back( new ResultListEntry( rResult ) );
286  }
287 
288  m_pImpl->m_bCountFinal = true;
289 
291  if ( xResultSet.is() )
292  {
293  // Callbacks follow!
294  aGuard.clear();
295 
296  if ( nOldCount < m_pImpl->m_aResults.size() )
297  xResultSet->rowCountChanged(
298  nOldCount, m_pImpl->m_aResults.size() );
299 
300  xResultSet->rowCountFinal();
301  }
302 
303  return m_pImpl->m_aResults.size();
304 }
305 
306 
307 // virtual
309 {
310  return m_pImpl->m_aResults.size();
311 }
312 
313 
314 // virtual
316 {
317  return m_pImpl->m_bCountFinal;
318 }
319 
320 
321 // virtual
322 uno::Reference< sdbc::XRow >
324 {
325  osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
326 
327  if ( nIndex < m_pImpl->m_aResults.size() )
328  {
329  uno::Reference< sdbc::XRow > xRow
330  = m_pImpl->m_aResults[ nIndex ]->xRow;
331  if ( xRow.is() )
332  {
333  // Already cached.
334  return xRow;
335  }
336  }
337 
338  if ( getResult( nIndex ) )
339  {
341  m_pImpl->m_aResults[ nIndex ]->aData );
342 
343  uno::Reference< sdbc::XRow > xRow
345  m_pImpl->m_xContext,
346  getResultSet()->getProperties(),
347  aData,
348  static_cast< HierarchyContentProvider * >(
349  m_pImpl->m_xContent->getProvider().get() ),
350  queryContentIdentifierString( nIndex ) );
351  m_pImpl->m_aResults[ nIndex ]->xRow = xRow;
352  return xRow;
353  }
354 
355  return uno::Reference< sdbc::XRow >();
356 }
357 
358 
359 // virtual
361 {
362  osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
363 
364  if ( nIndex < m_pImpl->m_aResults.size() )
365  m_pImpl->m_aResults[ nIndex ]->xRow.clear();
366 }
367 
368 
369 // virtual
371 {
372 }
373 
374 
375 // virtual
377 {
378 }
379 
380 
382  const HierarchyEntryData& rResult )
383 {
384  switch ( m_pImpl->m_nOpenMode )
385  {
386  case ucb::OpenMode::FOLDERS:
387  if ( rResult.getType() == HierarchyEntryData::LINK )
388  {
389  // Entry is a link.
390  return false;
391  }
392  break;
393 
394  case ucb::OpenMode::DOCUMENTS:
395  if ( rResult.getType() == HierarchyEntryData::FOLDER )
396  {
397  // Entry is a folder.
398  return false;
399  }
400  break;
401 
402  case ucb::OpenMode::ALL:
403  default:
404  break;
405  }
406 
407  return true;
408 }
409 
410 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
uno::Reference< ucb::XContentIdentifier > xId
const char aData[]
virtual OUString queryContentIdentifierString(sal_uInt32 nIndex) override
uno::Reference< uno::XComponentContext > m_xContext
HierarchyEntry::iterator const m_aIterator
ResultListEntry(const HierarchyEntryData &rEntry)
virtual void releasePropertyValues(sal_uInt32 nIndex) override
virtual css::uno::Reference< css::ucb::XContent > queryContent(sal_uInt32 nIndex) override
virtual bool getResult(sal_uInt32 nIndex) override
std::unique_ptr< DataSupplier_Impl > m_pImpl
css::uno::Reference< css::sdbc::XRow > getPropertyValues(const css::uno::Sequence< css::beans::Property > &rProperties)
rtl::Reference< HierarchyContent > m_xContent
uno::Reference< sdbc::XRow > xRow
virtual css::uno::Reference< css::sdbc::XRow > queryPropertyValues(sal_uInt32 nIndex) override
std::vector< std::unique_ptr< ResultListEntry > > ResultList
rtl::Reference< ResultSet > getResultSet() const
virtual css::uno::Reference< css::ucb::XContentIdentifier > queryContentIdentifier(sal_uInt32 nIndex) override
bool checkResult(const HierarchyEntryData &rResult)
DataSupplier_Impl(const uno::Reference< uno::XComponentContext > &rxContext, const rtl::Reference< HierarchyContent > &rContent, sal_Int32 nOpenMode)
DESKTOP_DEPLOYMENTMISC_DLLPUBLIC OUString getIdentifier(css::uno::Reference< css::deployment::XPackage > const &package)
sal_Int32 nPos
uno::Reference< ucb::XContent > xContent