fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / ucb / source / ucp / tdoc / tdoc_datasupplier.cxx
blob2869de6c6e51e3f0fdaf26647182b8e070a2d442
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 /**************************************************************************
22 TODO
23 **************************************************************************
25 *************************************************************************/
27 #include <vector>
29 #include "osl/diagnose.h"
30 #include "ucbhelper/contentidentifier.hxx"
32 #include "tdoc_datasupplier.hxx"
33 #include "tdoc_content.hxx"
35 using namespace com::sun::star;
36 using namespace tdoc_ucp;
38 namespace tdoc_ucp
43 // struct ResultListEntry.
47 struct ResultListEntry
49 OUString aURL;
50 uno::Reference< ucb::XContentIdentifier > xId;
51 uno::Reference< ucb::XContent > xContent;
52 uno::Reference< sdbc::XRow > xRow;
54 ResultListEntry( const OUString& rURL ) : aURL( rURL ) {}
59 // ResultList.
63 typedef std::vector< ResultListEntry* > ResultList;
67 // struct DataSupplier_Impl.
71 struct DataSupplier_Impl
73 osl::Mutex m_aMutex;
74 ResultList m_aResults;
75 rtl::Reference< Content > m_xContent;
76 uno::Reference< uno::XComponentContext > m_xContext;
77 uno::Sequence< OUString > * m_pNamesOfChildren;
78 sal_Int32 m_nOpenMode;
79 bool m_bCountFinal;
80 bool m_bThrowException;
82 DataSupplier_Impl(
83 const uno::Reference< uno::XComponentContext >& rxContext,
84 const rtl::Reference< Content >& rContent,
85 sal_Int32 nOpenMode )
86 : m_xContent( rContent ), m_xContext( rxContext ),
87 m_pNamesOfChildren( 0 ), m_nOpenMode( nOpenMode ),
88 m_bCountFinal( false ), m_bThrowException( false )
90 ~DataSupplier_Impl();
94 DataSupplier_Impl::~DataSupplier_Impl()
96 ResultList::const_iterator it = m_aResults.begin();
97 ResultList::const_iterator end = m_aResults.end();
99 while ( it != end )
101 delete (*it);
102 ++it;
105 delete m_pNamesOfChildren;
110 // DataSupplier Implementation.
111 ResultSetDataSupplier::ResultSetDataSupplier(
112 const uno::Reference< uno::XComponentContext >& rxContext,
113 const rtl::Reference< Content >& rContent,
114 sal_Int32 nOpenMode )
115 : m_pImpl( new DataSupplier_Impl( rxContext, rContent, nOpenMode ) )
119 // virtual
120 ResultSetDataSupplier::~ResultSetDataSupplier()
122 delete m_pImpl;
125 // virtual
126 OUString
127 ResultSetDataSupplier::queryContentIdentifierString( sal_uInt32 nIndex )
129 osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
131 if ( nIndex < m_pImpl->m_aResults.size() )
133 OUString aId = m_pImpl->m_aResults[ nIndex ]->aURL;
134 if ( !aId.isEmpty() )
136 // Already cached.
137 return aId;
141 if ( getResult( nIndex ) )
143 // Note: getResult fills m_pImpl->m_aResults[ nIndex ]->aURL.
144 return m_pImpl->m_aResults[ nIndex ]->aURL;
146 return OUString();
149 // virtual
150 uno::Reference< ucb::XContentIdentifier >
151 ResultSetDataSupplier::queryContentIdentifier( sal_uInt32 nIndex )
153 osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
155 if ( nIndex < m_pImpl->m_aResults.size() )
157 uno::Reference< ucb::XContentIdentifier > xId
158 = m_pImpl->m_aResults[ nIndex ]->xId;
159 if ( xId.is() )
161 // Already cached.
162 return xId;
166 OUString aId = queryContentIdentifierString( nIndex );
167 if ( !aId.isEmpty() )
169 uno::Reference< ucb::XContentIdentifier > xId
170 = new ::ucbhelper::ContentIdentifier( aId );
171 m_pImpl->m_aResults[ nIndex ]->xId = xId;
172 return xId;
174 return uno::Reference< ucb::XContentIdentifier >();
177 // virtual
178 uno::Reference< ucb::XContent >
179 ResultSetDataSupplier::queryContent( sal_uInt32 nIndex )
181 osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
183 if ( nIndex < m_pImpl->m_aResults.size() )
185 uno::Reference< ucb::XContent > xContent
186 = m_pImpl->m_aResults[ nIndex ]->xContent;
187 if ( xContent.is() )
189 // Already cached.
190 return xContent;
194 uno::Reference< ucb::XContentIdentifier > xId
195 = queryContentIdentifier( nIndex );
196 if ( xId.is() )
200 uno::Reference< ucb::XContent > xContent
201 = m_pImpl->m_xContent->getProvider()->queryContent( xId );
202 m_pImpl->m_aResults[ nIndex ]->xContent = xContent;
203 return xContent;
206 catch ( ucb::IllegalIdentifierException const & )
210 return uno::Reference< ucb::XContent >();
213 // virtual
214 bool ResultSetDataSupplier::getResult( sal_uInt32 nIndex )
216 osl::ClearableGuard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
218 if ( m_pImpl->m_aResults.size() > nIndex )
220 // Result already present.
221 return true;
224 // Result not (yet) present.
226 if ( m_pImpl->m_bCountFinal )
227 return false;
229 // Try to obtain result...
231 sal_uInt32 nOldCount = m_pImpl->m_aResults.size();
232 bool bFound = false;
234 if ( queryNamesOfChildren() )
236 for ( sal_uInt32 n = nOldCount;
237 n < sal::static_int_cast<sal_uInt32>(
238 m_pImpl->m_pNamesOfChildren->getLength());
239 ++n )
241 const OUString & rName
242 = m_pImpl->m_pNamesOfChildren->getConstArray()[ n ];
244 if ( rName.isEmpty() )
246 OSL_FAIL( "ResultDataSupplier::getResult - Empty name!" );
247 break;
250 // Assemble URL for child.
251 OUString aURL = assembleChildURL( rName );
253 m_pImpl->m_aResults.push_back( new ResultListEntry( aURL ) );
255 if ( n == nIndex )
257 // Result obtained.
258 bFound = true;
259 break;
264 if ( !bFound )
265 m_pImpl->m_bCountFinal = true;
267 rtl::Reference< ::ucbhelper::ResultSet > xResultSet = getResultSet().get();
268 if ( xResultSet.is() )
270 // Callbacks follow!
271 aGuard.clear();
273 if ( nOldCount < m_pImpl->m_aResults.size() )
274 xResultSet->rowCountChanged( nOldCount, m_pImpl->m_aResults.size() );
276 if ( m_pImpl->m_bCountFinal )
277 xResultSet->rowCountFinal();
280 return bFound;
283 // virtual
284 sal_uInt32 ResultSetDataSupplier::totalCount()
286 osl::ClearableGuard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
288 if ( m_pImpl->m_bCountFinal )
289 return m_pImpl->m_aResults.size();
291 sal_uInt32 nOldCount = m_pImpl->m_aResults.size();
293 if ( queryNamesOfChildren() )
295 for ( sal_uInt32 n = nOldCount;
296 n < sal::static_int_cast<sal_uInt32>(
297 m_pImpl->m_pNamesOfChildren->getLength());
298 ++n )
300 const OUString & rName
301 = m_pImpl->m_pNamesOfChildren->getConstArray()[ n ];
303 if ( rName.isEmpty() )
305 OSL_FAIL( "ResultDataSupplier::getResult - Empty name!" );
306 break;
309 // Assemble URL for child.
310 OUString aURL = assembleChildURL( rName );
312 m_pImpl->m_aResults.push_back( new ResultListEntry( aURL ) );
316 m_pImpl->m_bCountFinal = true;
318 rtl::Reference< ::ucbhelper::ResultSet > xResultSet = getResultSet().get();
319 if ( xResultSet.is() )
321 // Callbacks follow!
322 aGuard.clear();
324 if ( nOldCount < m_pImpl->m_aResults.size() )
325 xResultSet->rowCountChanged( nOldCount, m_pImpl->m_aResults.size() );
327 xResultSet->rowCountFinal();
330 return m_pImpl->m_aResults.size();
333 // virtual
334 sal_uInt32 ResultSetDataSupplier::currentCount()
336 return m_pImpl->m_aResults.size();
339 // virtual
340 bool ResultSetDataSupplier::isCountFinal()
342 return m_pImpl->m_bCountFinal;
345 // virtual
346 uno::Reference< sdbc::XRow >
347 ResultSetDataSupplier::queryPropertyValues( sal_uInt32 nIndex )
349 osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
351 if ( nIndex < m_pImpl->m_aResults.size() )
353 uno::Reference< sdbc::XRow > xRow = m_pImpl->m_aResults[ nIndex ]->xRow;
354 if ( xRow.is() )
356 // Already cached.
357 return xRow;
361 if ( getResult( nIndex ) )
363 uno::Reference< sdbc::XRow > xRow = Content::getPropertyValues(
364 m_pImpl->m_xContext,
365 getResultSet()->getProperties(),
366 m_pImpl->m_xContent->getContentProvider().get(),
367 queryContentIdentifierString( nIndex ) );
368 m_pImpl->m_aResults[ nIndex ]->xRow = xRow;
369 return xRow;
372 return uno::Reference< sdbc::XRow >();
375 // virtual
376 void ResultSetDataSupplier::releasePropertyValues( sal_uInt32 nIndex )
378 osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
380 if ( nIndex < m_pImpl->m_aResults.size() )
381 m_pImpl->m_aResults[ nIndex ]->xRow = uno::Reference< sdbc::XRow >();
384 // virtual
385 void ResultSetDataSupplier::close()
389 // virtual
390 void ResultSetDataSupplier::validate()
391 throw( ucb::ResultSetException )
393 if ( m_pImpl->m_bThrowException )
394 throw ucb::ResultSetException();
397 bool ResultSetDataSupplier::queryNamesOfChildren()
399 osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
401 if ( m_pImpl->m_pNamesOfChildren == 0 )
403 uno::Sequence< OUString > * pNamesOfChildren
404 = new uno::Sequence< OUString >();
406 if ( !m_pImpl->m_xContent->getContentProvider()->queryNamesOfChildren(
407 m_pImpl->m_xContent->getIdentifier()->getContentIdentifier(),
408 *pNamesOfChildren ) )
410 OSL_FAIL( "Got no list of children!" );
411 delete pNamesOfChildren;
412 m_pImpl->m_bThrowException = true;
413 return false;
415 else
417 m_pImpl->m_pNamesOfChildren = pNamesOfChildren;
420 return true;
423 OUString
424 ResultSetDataSupplier::assembleChildURL( const OUString& aName )
426 OUString aContURL
427 = m_pImpl->m_xContent->getIdentifier()->getContentIdentifier();
428 OUString aURL( aContURL );
430 sal_Int32 nUrlEnd = aURL.lastIndexOf( '/' );
431 if ( nUrlEnd != aURL.getLength() - 1 )
432 aURL += "/";
434 aURL += aName;
435 return aURL;
438 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */