fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / dbaccess / source / core / dataaccess / myucp_datasupplier.cxx
blobaedd0ba27a6a8b66c7e42e3c4f587b239a39183e
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 .
20 #include <vector>
22 #include <ucbhelper/contentidentifier.hxx>
23 #include <ucbhelper/providerhelper.hxx>
25 #include "myucp_datasupplier.hxx"
26 #include "ContentHelper.hxx"
27 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
28 #include <tools/debug.hxx>
30 using namespace ::com::sun::star::uno;
31 using namespace ::com::sun::star::ucb;
32 using namespace ::com::sun::star::beans;
33 using namespace ::com::sun::star::lang;
34 using namespace ::com::sun::star::sdbc;
35 using namespace ::com::sun::star::io;
36 using namespace ::com::sun::star::container;
38 // @@@ Adjust namespace name.
39 using namespace dbaccess;
41 // @@@ Adjust namespace name.
42 namespace dbaccess
45 // struct ResultListEntry.
46 struct ResultListEntry
48 OUString aId;
49 Reference< XContentIdentifier > xId;
50 ::rtl::Reference< OContentHelper > xContent;
51 Reference< XRow > xRow;
52 const ContentProperties& rData;
54 ResultListEntry( const ContentProperties& rEntry ) : rData( rEntry ) {}
57 // ResultList.
58 typedef std::vector< ResultListEntry* > ResultList;
60 // struct DataSupplier_Impl.
61 struct DataSupplier_Impl
63 osl::Mutex m_aMutex;
64 ResultList m_aResults;
65 rtl::Reference< ODocumentContainer > m_xContent;
66 sal_Int32 m_nOpenMode;
67 bool m_bCountFinal;
69 DataSupplier_Impl( const rtl::Reference< ODocumentContainer >& rContent,
70 sal_Int32 nOpenMode )
71 : m_xContent(rContent)
72 , m_nOpenMode( nOpenMode )
73 , m_bCountFinal( false ) {}
74 ~DataSupplier_Impl();
77 DataSupplier_Impl::~DataSupplier_Impl()
79 ResultList::const_iterator it = m_aResults.begin();
80 ResultList::const_iterator end = m_aResults.end();
82 while ( it != end )
84 delete (*it);
85 ++it;
91 // DataSupplier Implementation.
93 DataSupplier::DataSupplier( const rtl::Reference< ODocumentContainer >& rContent,
94 sal_Int32 nOpenMode )
95 : m_pImpl( new DataSupplier_Impl( rContent,nOpenMode ) )
100 DataSupplier::~DataSupplier()
105 OUString DataSupplier::queryContentIdentifierString( sal_uInt32 nIndex )
107 osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
109 if ( (size_t)nIndex < m_pImpl->m_aResults.size() )
111 OUString aId = m_pImpl->m_aResults[ nIndex ]->aId;
112 if ( !aId.isEmpty() )
114 // Already cached.
115 return aId;
119 if ( getResult( nIndex ) )
121 OUString aId = m_pImpl->m_xContent->getIdentifier()->getContentIdentifier();
123 if ( !aId.isEmpty() )
124 aId += "/";
126 aId += m_pImpl->m_aResults[ nIndex ]->rData.aTitle;
128 m_pImpl->m_aResults[ nIndex ]->aId = aId;
129 return aId;
131 return OUString();
134 Reference< XContentIdentifier >
135 DataSupplier::queryContentIdentifier( sal_uInt32 nIndex )
137 osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
139 if ( (size_t)nIndex < m_pImpl->m_aResults.size() )
141 Reference< XContentIdentifier > xId = m_pImpl->m_aResults[ nIndex ]->xId;
142 if ( xId.is() )
144 // Already cached.
145 return xId;
149 OUString aId = queryContentIdentifierString( nIndex );
150 if ( !aId.isEmpty() )
152 Reference< XContentIdentifier > xId = new ::ucbhelper::ContentIdentifier( aId );
153 m_pImpl->m_aResults[ nIndex ]->xId = xId;
154 return xId;
156 return Reference< XContentIdentifier >();
159 Reference< XContent >
160 DataSupplier::queryContent( sal_uInt32 _nIndex )
162 osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
164 if ( (size_t)_nIndex < m_pImpl->m_aResults.size() )
166 Reference< XContent > xContent = m_pImpl->m_aResults[ _nIndex ]->xContent.get();
167 if ( xContent.is() )
169 // Already cached.
170 return xContent;
174 Reference< XContentIdentifier > xId = queryContentIdentifier( _nIndex );
175 if ( xId.is() )
179 Reference< XContent > xContent;
180 OUString sName = xId->getContentIdentifier();
181 sal_Int32 nIndex = sName.lastIndexOf('/') + 1;
182 sName = sName.getToken(0,'/',nIndex);
184 m_pImpl->m_aResults[ _nIndex ]->xContent = m_pImpl->m_xContent->getContent(sName);
186 xContent = m_pImpl->m_aResults[ _nIndex ]->xContent.get();
187 return xContent;
190 catch ( IllegalIdentifierException& )
194 return Reference< XContent >();
197 bool DataSupplier::getResult( sal_uInt32 nIndex )
199 osl::ClearableGuard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
201 if ( (size_t)nIndex < m_pImpl->m_aResults.size() )
203 // Result already present.
204 return true;
207 // Result not (yet) present.
209 if ( m_pImpl->m_bCountFinal )
210 return false;
212 // Try to obtain result...
214 sal_uInt32 nOldCount = m_pImpl->m_aResults.size();
215 bool bFound = false;
216 sal_uInt32 nPos = nOldCount;
218 // @@@ Obtain data and put it into result list...
219 Sequence< OUString> aSeq = m_pImpl->m_xContent->getElementNames();
220 if ( nIndex < sal::static_int_cast< sal_uInt32 >( aSeq.getLength() ) )
222 const OUString* pIter = aSeq.getConstArray();
223 const OUString* pEnd = pIter + aSeq.getLength();
224 for(pIter = pIter + nPos;pIter != pEnd;++pIter,++nPos)
226 m_pImpl->m_aResults.push_back(
227 new ResultListEntry( m_pImpl->m_xContent->getContent(*pIter)->getContentProperties() ) );
229 if ( nPos == nIndex )
231 // Result obtained.
232 bFound = true;
233 break;
238 if ( !bFound )
239 m_pImpl->m_bCountFinal = true;
241 rtl::Reference< ::ucbhelper::ResultSet > xResultSet = getResultSet().get();
242 if ( xResultSet.is() )
244 // Callbacks follow!
245 aGuard.clear();
247 if ( (size_t)nOldCount < m_pImpl->m_aResults.size() )
248 xResultSet->rowCountChanged(
249 nOldCount, m_pImpl->m_aResults.size() );
251 if ( m_pImpl->m_bCountFinal )
252 xResultSet->rowCountFinal();
255 return bFound;
258 sal_uInt32 DataSupplier::totalCount()
260 osl::ClearableGuard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
262 if ( m_pImpl->m_bCountFinal )
263 return m_pImpl->m_aResults.size();
265 sal_uInt32 nOldCount = m_pImpl->m_aResults.size();
267 // @@@ Obtain data and put it into result list...
268 Sequence< OUString> aSeq = m_pImpl->m_xContent->getElementNames();
269 const OUString* pIter = aSeq.getConstArray();
270 const OUString* pEnd = pIter + aSeq.getLength();
271 for(;pIter != pEnd;++pIter)
272 m_pImpl->m_aResults.push_back(
273 new ResultListEntry( m_pImpl->m_xContent->getContent(*pIter)->getContentProperties() ) );
275 m_pImpl->m_bCountFinal = true;
277 rtl::Reference< ::ucbhelper::ResultSet > xResultSet = getResultSet().get();
278 if ( xResultSet.is() )
280 // Callbacks follow!
281 aGuard.clear();
283 if ( (size_t)nOldCount < m_pImpl->m_aResults.size() )
284 xResultSet->rowCountChanged(
285 nOldCount, m_pImpl->m_aResults.size() );
287 xResultSet->rowCountFinal();
290 return m_pImpl->m_aResults.size();
293 sal_uInt32 DataSupplier::currentCount()
295 return m_pImpl->m_aResults.size();
298 bool DataSupplier::isCountFinal()
300 return m_pImpl->m_bCountFinal;
303 Reference< XRow >
304 DataSupplier::queryPropertyValues( sal_uInt32 nIndex )
306 osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
308 if ( (size_t)nIndex < m_pImpl->m_aResults.size() )
310 Reference< XRow > xRow = m_pImpl->m_aResults[ nIndex ]->xRow;
311 if ( xRow.is() )
313 // Already cached.
314 return xRow;
318 if ( getResult( nIndex ) )
320 if ( !m_pImpl->m_aResults[ nIndex ]->xContent.is() )
321 queryContent(nIndex);
323 Reference< XRow > xRow = m_pImpl->m_aResults[ nIndex ]->xContent->getPropertyValues(getResultSet()->getProperties());
324 m_pImpl->m_aResults[ nIndex ]->xRow = xRow;
325 return xRow;
328 return Reference< XRow >();
331 void DataSupplier::releasePropertyValues( sal_uInt32 nIndex )
333 osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
335 if ( (size_t)nIndex < m_pImpl->m_aResults.size() )
336 m_pImpl->m_aResults[ nIndex ]->xRow.clear();
339 void DataSupplier::close()
343 void DataSupplier::validate()
344 throw( ResultSetException )
348 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */