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