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