fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / ucb / source / ucp / webdav / webdavdatasupplier.cxx
blob1114f4def6a9a7687e16c85263f5b4103ec80ba6
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 <osl/diagnose.h>
21 #include <com/sun/star/ucb/OpenMode.hpp>
22 #include <ucbhelper/contentidentifier.hxx>
23 #include <ucbhelper/providerhelper.hxx>
24 #include "webdavdatasupplier.hxx"
25 #include "webdavcontent.hxx"
26 #include "ContentProperties.hxx"
27 #include "DAVSession.hxx"
28 #include "SerfUri.hxx"
30 using namespace com::sun::star;
31 using namespace http_dav_ucp;
33 namespace http_dav_ucp
38 // struct ResultListEntry.
42 struct ResultListEntry
44 OUString aId;
45 uno::Reference< ucb::XContentIdentifier > xId;
46 uno::Reference< ucb::XContent > xContent;
47 uno::Reference< sdbc::XRow > xRow;
48 const ContentProperties* pData;
50 ResultListEntry( const ContentProperties* pEntry ) : pData( pEntry ) {};
51 ~ResultListEntry() { delete pData; }
56 // ResultList.
60 typedef std::vector< ResultListEntry* > ResultList;
64 // struct DataSupplier_Impl.
68 struct DataSupplier_Impl
70 osl::Mutex m_aMutex;
71 ResultList m_aResults;
72 rtl::Reference< Content > m_xContent;
73 uno::Reference< uno::XComponentContext > m_xContext;
74 sal_Int32 m_nOpenMode;
75 bool m_bCountFinal;
76 bool m_bThrowException;
78 DataSupplier_Impl(
79 const uno::Reference< uno::XComponentContext >& rxContext,
80 const rtl::Reference< Content >& rContent,
81 sal_Int32 nOpenMode )
82 : m_xContent( rContent ), m_xContext( rxContext ), m_nOpenMode( nOpenMode ),
83 m_bCountFinal( false ), m_bThrowException( false ) {}
84 ~DataSupplier_Impl();
88 DataSupplier_Impl::~DataSupplier_Impl()
90 ResultList::const_iterator it = m_aResults.begin();
91 ResultList::const_iterator end = m_aResults.end();
93 while ( it != end )
95 delete (*it);
96 ++it;
105 // DataSupplier Implementation.
110 DataSupplier::DataSupplier(
111 const uno::Reference< uno::XComponentContext >& rxContext,
112 const rtl::Reference< Content >& rContent,
113 sal_Int32 nOpenMode )
114 : m_pImpl( new DataSupplier_Impl( rxContext, rContent, nOpenMode ) )
119 // virtual
120 DataSupplier::~DataSupplier()
122 delete m_pImpl;
126 // virtual
127 OUString DataSupplier::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 ]->aId;
134 if ( aId.getLength() )
136 // Already cached.
137 return aId;
141 if ( getResult( nIndex ) )
143 OUString aId = m_pImpl->m_xContent->getResourceAccess().getURL();
145 const ContentProperties& props
146 = *( m_pImpl->m_aResults[ nIndex ]->pData );
148 if ( ( aId.lastIndexOf( '/' ) + 1 ) != aId.getLength() )
149 aId += "/";
151 aId += props.getEscapedTitle();
153 if ( props.isTrailingSlash() )
154 aId += "/";
156 m_pImpl->m_aResults[ nIndex ]->aId = aId;
157 return aId;
159 return OUString();
163 // virtual
164 uno::Reference< ucb::XContentIdentifier >
165 DataSupplier::queryContentIdentifier( sal_uInt32 nIndex )
167 osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
169 if ( nIndex < m_pImpl->m_aResults.size() )
171 uno::Reference< ucb::XContentIdentifier > xId
172 = m_pImpl->m_aResults[ nIndex ]->xId;
173 if ( xId.is() )
175 // Already cached.
176 return xId;
180 OUString aId = queryContentIdentifierString( nIndex );
181 if ( aId.getLength() )
183 uno::Reference< ucb::XContentIdentifier > xId
184 = new ::ucbhelper::ContentIdentifier( aId );
185 m_pImpl->m_aResults[ nIndex ]->xId = xId;
186 return xId;
188 return uno::Reference< ucb::XContentIdentifier >();
192 // virtual
193 uno::Reference< ucb::XContent >
194 DataSupplier::queryContent( sal_uInt32 nIndex )
196 osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
198 if ( nIndex < m_pImpl->m_aResults.size() )
200 uno::Reference< ucb::XContent > xContent
201 = m_pImpl->m_aResults[ nIndex ]->xContent;
202 if ( xContent.is() )
204 // Already cached.
205 return xContent;
209 uno::Reference< ucb::XContentIdentifier > xId
210 = queryContentIdentifier( nIndex );
211 if ( xId.is() )
215 uno::Reference< ucb::XContent > xContent
216 = m_pImpl->m_xContent->getProvider()->queryContent( xId );
217 m_pImpl->m_aResults[ nIndex ]->xContent = xContent;
218 return xContent;
221 catch ( ucb::IllegalIdentifierException& )
225 return uno::Reference< ucb::XContent >();
229 // virtual
230 bool DataSupplier::getResult( sal_uInt32 nIndex )
232 osl::ClearableGuard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
234 if ( m_pImpl->m_aResults.size() > nIndex )
236 // Result already present.
237 return true;
240 // Obtain values...
241 if ( getData() )
243 if ( m_pImpl->m_aResults.size() > nIndex )
245 // Result already present.
246 return true;
250 return false;
254 // virtual
255 sal_uInt32 DataSupplier::totalCount()
257 // Obtain values...
258 getData();
260 return m_pImpl->m_aResults.size();
264 // virtual
265 sal_uInt32 DataSupplier::currentCount()
267 return m_pImpl->m_aResults.size();
271 // virtual
272 bool DataSupplier::isCountFinal()
274 return m_pImpl->m_bCountFinal;
278 // virtual
279 uno::Reference< sdbc::XRow > DataSupplier::queryPropertyValues(
280 sal_uInt32 nIndex )
282 osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
284 if ( nIndex < m_pImpl->m_aResults.size() )
286 uno::Reference< sdbc::XRow > xRow = m_pImpl->m_aResults[ nIndex ]->xRow;
287 if ( xRow.is() )
289 // Already cached.
290 return xRow;
294 if ( getResult( nIndex ) )
296 uno::Reference< sdbc::XRow > xRow
297 = Content::getPropertyValues(
298 m_pImpl->m_xContext,
299 getResultSet()->getProperties(),
300 *(m_pImpl->m_aResults[ nIndex ]->pData),
301 rtl::Reference< ::ucbhelper::ContentProviderImplHelper >(
302 m_pImpl->m_xContent->getProvider().get() ),
303 queryContentIdentifierString( nIndex ) );
304 m_pImpl->m_aResults[ nIndex ]->xRow = xRow;
305 return xRow;
308 return uno::Reference< sdbc::XRow >();
312 // virtual
313 void DataSupplier::releasePropertyValues( sal_uInt32 nIndex )
315 osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
317 if ( nIndex < m_pImpl->m_aResults.size() )
318 m_pImpl->m_aResults[ nIndex ]->xRow = uno::Reference< sdbc::XRow >();
322 // virtual
323 void DataSupplier::close()
328 // virtual
329 void DataSupplier::validate()
330 throw( ucb::ResultSetException )
332 if ( m_pImpl->m_bThrowException )
333 throw ucb::ResultSetException();
336 bool DataSupplier::getData()
338 osl::ClearableGuard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
340 if ( !m_pImpl->m_bCountFinal )
342 std::vector< OUString > propertyNames;
343 ContentProperties::UCBNamesToDAVNames(
344 getResultSet()->getProperties(), propertyNames );
346 // Append "resourcetype", if not already present. It's value is
347 // needed to get a valid ContentProperties::pIsFolder value, which
348 // is needed for OpenMode handling.
350 std::vector< OUString >::const_iterator it
351 = propertyNames.begin();
352 std::vector< OUString >::const_iterator end
353 = propertyNames.end();
355 while ( it != end )
357 if ( (*it).equals( DAVProperties::RESOURCETYPE ) )
358 break;
360 ++it;
363 if ( it == end )
364 propertyNames.push_back( DAVProperties::RESOURCETYPE );
366 std::vector< DAVResource > resources;
369 // propfind depth 1, get property values for parent AND for each
370 // child
371 m_pImpl->m_xContent->getResourceAccess()
372 .PROPFIND( DAVONE,
373 propertyNames,
374 resources,
375 getResultSet()->getEnvironment() );
377 catch ( DAVException & )
379 SAL_WARN( "ucb.ucp.webdav", "PROPFIND : DAVException" );
380 m_pImpl->m_bThrowException = true;
383 if ( !m_pImpl->m_bThrowException )
387 SerfUri aURI(
388 m_pImpl->m_xContent->getResourceAccess().getURL() );
389 OUString aPath = aURI.GetPath();
391 if ( aPath.endsWith("/") )
392 aPath = aPath.copy( 0, aPath.getLength() - 1 );
394 aPath = SerfUri::unescape( aPath );
395 bool bFoundParent = false;
397 for ( sal_uInt32 n = 0; n < resources.size(); ++n )
399 const DAVResource & rRes = resources[ n ];
401 // Filter parent, which is contained somewhere(!) in
402 // the vector.
403 if ( !bFoundParent )
407 SerfUri aCurrURI( rRes.uri );
408 OUString aCurrPath = aCurrURI.GetPath();
409 if ( aCurrPath.endsWith("/") )
410 aCurrPath
411 = aCurrPath.copy(
413 aCurrPath.getLength() - 1 );
415 aCurrPath = SerfUri::unescape( aCurrPath );
416 if ( aPath == aCurrPath )
418 bFoundParent = true;
419 continue;
422 catch ( DAVException const & )
424 // do nothing, ignore error. continue.
428 ContentProperties* pContentProperties
429 = new ContentProperties( rRes );
431 // Check resource against open mode.
432 switch ( m_pImpl->m_nOpenMode )
434 case ucb::OpenMode::FOLDERS:
436 bool bFolder = false;
438 const uno::Any & rValue
439 = pContentProperties->getValue(
440 OUString(
441 "IsFolder" ) );
442 rValue >>= bFolder;
444 if ( !bFolder )
445 continue;
447 break;
450 case ucb::OpenMode::DOCUMENTS:
452 bool bDocument = false;
454 const uno::Any & rValue
455 = pContentProperties->getValue(
456 OUString(
457 "IsDocument" ) );
458 rValue >>= bDocument;
460 if ( !bDocument )
461 continue;
463 break;
466 case ucb::OpenMode::ALL:
467 default:
468 break;
471 m_pImpl->m_aResults.push_back(
472 new ResultListEntry( pContentProperties ) );
475 catch ( DAVException const & )
480 m_pImpl->m_bCountFinal = true;
482 // Callback possible, because listeners may be informed!
483 aGuard.clear();
484 getResultSet()->rowCountFinal();
486 return !m_pImpl->m_bThrowException;
489 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */