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