Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / ucb / source / ucp / ftp / ftpresultsetbase.cxx
blob84beb5c700ca3d7ab3a45522f416b81d889a6545
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 <ucbhelper/contentidentifier.hxx>
21 #include <com/sun/star/sdbc/SQLException.hpp>
22 #include <com/sun/star/uno/Reference.h>
23 #include <com/sun/star/beans/PropertyAttribute.hpp>
24 #include <ucbhelper/resultsetmetadata.hxx>
25 #include <cppuhelper/queryinterface.hxx>
26 #include <utility>
27 #include "ftpresultsetbase.hxx"
29 using namespace ftp;
30 using namespace com::sun::star;
32 ResultSetBase::ResultSetBase(
33 uno::Reference< uno::XComponentContext > xContext,
34 uno::Reference< ucb::XContentProvider > xProvider,
35 const uno::Sequence< beans::Property >& seq )
36 : m_xContext(std::move( xContext )),
37 m_xProvider(std::move( xProvider )),
38 m_nRow( -1 ),
39 m_nWasNull( true ),
40 m_sProperty( seq )
44 ResultSetBase::~ResultSetBase()
49 // XInterface
51 void SAL_CALL
52 ResultSetBase::acquire()
53 noexcept
55 OWeakObject::acquire();
59 void SAL_CALL
60 ResultSetBase::release()
61 noexcept
63 OWeakObject::release();
67 uno::Any SAL_CALL
68 ResultSetBase::queryInterface( const uno::Type& rType )
70 uno::Any aRet = cppu::queryInterface(
71 rType,
72 static_cast< lang::XComponent* >(this),
73 static_cast< sdbc::XRow* >(this),
74 static_cast< sdbc::XResultSet* >(this),
75 static_cast< sdbc::XResultSetMetaDataSupplier* >(this),
76 static_cast< beans::XPropertySet* >(this),
77 static_cast< ucb::XContentAccess* >(this) );
78 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
82 // XComponent
85 void SAL_CALL
86 ResultSetBase::addEventListener(
87 const uno::Reference< lang::XEventListener >& Listener )
89 osl::MutexGuard aGuard( m_aMutex );
91 if ( ! m_pDisposeEventListeners )
92 m_pDisposeEventListeners.reset(
93 new comphelper::OInterfaceContainerHelper3<lang::XEventListener>( m_aMutex ) );
95 m_pDisposeEventListeners->addInterface( Listener );
99 void SAL_CALL
100 ResultSetBase::removeEventListener(
101 const uno::Reference< lang::XEventListener >& Listener )
103 osl::MutexGuard aGuard( m_aMutex );
105 if ( m_pDisposeEventListeners )
106 m_pDisposeEventListeners->removeInterface( Listener );
110 void SAL_CALL
111 ResultSetBase::dispose()
113 osl::MutexGuard aGuard( m_aMutex );
115 lang::EventObject aEvt;
116 aEvt.Source = static_cast< lang::XComponent * >( this );
118 if ( m_pDisposeEventListeners && m_pDisposeEventListeners->getLength() )
120 m_pDisposeEventListeners->disposeAndClear( aEvt );
122 if( m_pRowCountListeners && m_pRowCountListeners->getLength() )
124 m_pRowCountListeners->disposeAndClear( aEvt );
126 if( m_pIsFinalListeners && m_pIsFinalListeners->getLength() )
128 m_pIsFinalListeners->disposeAndClear( aEvt );
133 // XResultSet
135 sal_Bool SAL_CALL
136 ResultSetBase::next()
138 ++m_nRow;
139 return m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size());
143 sal_Bool SAL_CALL
144 ResultSetBase::isBeforeFirst()
146 return m_nRow == -1;
150 sal_Bool SAL_CALL
151 ResultSetBase::isAfterLast()
153 return m_nRow >= sal::static_int_cast<sal_Int32>(m_aItems.size()); // Cannot happen, if m_aFolder.isOpen()
157 sal_Bool SAL_CALL
158 ResultSetBase::isFirst()
160 return m_nRow == 0;
164 sal_Bool SAL_CALL
165 ResultSetBase::isLast()
167 if( m_nRow == sal::static_int_cast<sal_Int32>(m_aItems.size()) - 1 )
168 return true;
169 else
170 return false;
174 void SAL_CALL
175 ResultSetBase::beforeFirst()
177 m_nRow = -1;
181 void SAL_CALL
182 ResultSetBase::afterLast()
184 m_nRow = m_aItems.size();
188 sal_Bool SAL_CALL
189 ResultSetBase::first()
191 m_nRow = -1;
192 return next();
196 sal_Bool SAL_CALL
197 ResultSetBase::last()
199 m_nRow = m_aItems.size() - 1;
200 return true;
204 sal_Int32 SAL_CALL
205 ResultSetBase::getRow()
207 // Test, whether behind last row
208 if( -1 == m_nRow || m_nRow >= sal::static_int_cast<sal_Int32>(m_aItems.size()) )
209 return 0;
210 else
211 return m_nRow+1;
215 sal_Bool SAL_CALL ResultSetBase::absolute( sal_Int32 row )
217 if( row >= 0 )
218 m_nRow = row - 1;
219 else
221 last();
222 m_nRow += ( row + 1 );
223 if( m_nRow < -1 )
224 m_nRow = -1;
227 return 0<= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size());
231 sal_Bool SAL_CALL
232 ResultSetBase::relative( sal_Int32 row )
234 if( isAfterLast() || isBeforeFirst() )
235 throw sdbc::SQLException();
237 if( row > 0 )
238 while( row-- )
239 next();
240 else if( row < 0 )
241 while( row++ && m_nRow > - 1 )
242 previous();
244 return 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size());
248 sal_Bool SAL_CALL
249 ResultSetBase::previous()
251 if( m_nRow > sal::static_int_cast<sal_Int32>(m_aItems.size()) )
252 m_nRow = m_aItems.size(); // Correct Handling of afterLast
253 if( 0 <= m_nRow ) -- m_nRow;
255 return 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size());
259 void SAL_CALL
260 ResultSetBase::refreshRow()
265 sal_Bool SAL_CALL
266 ResultSetBase::rowUpdated()
268 return false;
271 sal_Bool SAL_CALL
272 ResultSetBase::rowInserted()
274 return false;
277 sal_Bool SAL_CALL
278 ResultSetBase::rowDeleted()
280 return false;
284 uno::Reference< uno::XInterface > SAL_CALL
285 ResultSetBase::getStatement()
287 return uno::Reference< uno::XInterface >();
291 // XCloseable
293 void SAL_CALL
294 ResultSetBase::close()
299 OUString SAL_CALL
300 ResultSetBase::queryContentIdentifierString()
302 if( 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) )
303 return m_aPath[m_nRow];
304 else
305 return OUString();
309 uno::Reference< ucb::XContentIdentifier > SAL_CALL
310 ResultSetBase::queryContentIdentifier()
312 if( 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) )
314 if(!m_aIdents[m_nRow].is()) {
315 OUString url = queryContentIdentifierString();
316 if(!url.isEmpty() )
317 m_aIdents[m_nRow] =
318 uno::Reference< ucb::XContentIdentifier >(
319 new ::ucbhelper::ContentIdentifier(url) );
321 return m_aIdents[m_nRow];
324 return uno::Reference<ucb::XContentIdentifier>();
328 uno::Reference< ucb::XContent > SAL_CALL
329 ResultSetBase::queryContent()
331 if( 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) )
332 return m_xProvider->queryContent(queryContentIdentifier());
333 else
334 return uno::Reference< ucb::XContent >();
337 namespace {
339 class XPropertySetInfoImpl
340 : public cppu::OWeakObject,
341 public beans::XPropertySetInfo
343 public:
345 explicit XPropertySetInfoImpl( const uno::Sequence< beans::Property >& aSeq )
346 : m_aSeq( aSeq )
350 void SAL_CALL acquire()
351 noexcept override
353 OWeakObject::acquire();
357 void SAL_CALL release()
358 noexcept override
360 OWeakObject::release();
363 uno::Any SAL_CALL queryInterface( const uno::Type& rType ) override
365 uno::Any aRet = cppu::queryInterface(
366 rType,
367 static_cast< beans::XPropertySetInfo* >(this) );
368 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
371 uno::Sequence< beans::Property > SAL_CALL getProperties() override
373 return m_aSeq;
376 beans::Property SAL_CALL getPropertyByName( const OUString& aName ) override
378 auto pProp = std::find_if(std::cbegin(m_aSeq), std::cend(m_aSeq),
379 [&aName](const beans::Property& rProp) { return aName == rProp.Name; });
380 if (pProp != std::cend(m_aSeq))
381 return *pProp;
382 throw beans::UnknownPropertyException(aName);
385 sal_Bool SAL_CALL hasPropertyByName( const OUString& Name ) override
387 return std::any_of(std::cbegin(m_aSeq), std::cend(m_aSeq),
388 [&Name](const beans::Property& rProp) { return Name == rProp.Name; });
391 private:
393 uno::Sequence< beans::Property > m_aSeq;
398 // XPropertySet
399 uno::Reference< beans::XPropertySetInfo > SAL_CALL
400 ResultSetBase::getPropertySetInfo()
402 uno::Sequence< beans::Property > seq
404 { "RowCount", -1, cppu::UnoType<sal_Int32>::get(), beans::PropertyAttribute::READONLY },
405 { "IsRowCountFinal", -1, cppu::UnoType<sal_Bool>::get(), beans::PropertyAttribute::READONLY }
408 return uno::Reference< beans::XPropertySetInfo > (
409 new XPropertySetInfoImpl( seq ) );
413 void SAL_CALL ResultSetBase::setPropertyValue(
414 const OUString& aPropertyName, const uno::Any& /*aValue*/ )
416 if( aPropertyName == "IsRowCountFinal" ||
417 aPropertyName == "RowCount" )
418 return;
420 throw beans::UnknownPropertyException(aPropertyName);
424 uno::Any SAL_CALL ResultSetBase::getPropertyValue(
425 const OUString& PropertyName )
427 if( PropertyName == "IsRowCountFinal" )
429 return uno::Any(true);
431 else if ( PropertyName == "RowCount" )
433 sal_Int32 count = m_aItems.size();
434 return uno::Any(count);
436 else
437 throw beans::UnknownPropertyException(PropertyName);
441 void SAL_CALL ResultSetBase::addPropertyChangeListener(
442 const OUString& aPropertyName,
443 const uno::Reference< beans::XPropertyChangeListener >& xListener )
445 if( aPropertyName == "IsRowCountFinal" )
447 osl::MutexGuard aGuard( m_aMutex );
448 if ( ! m_pIsFinalListeners )
449 m_pIsFinalListeners.reset(
450 new comphelper::OInterfaceContainerHelper3<beans::XPropertyChangeListener>( m_aMutex ) );
452 m_pIsFinalListeners->addInterface( xListener );
454 else if ( aPropertyName == "RowCount" )
456 osl::MutexGuard aGuard( m_aMutex );
457 if ( ! m_pRowCountListeners )
458 m_pRowCountListeners.reset(
459 new comphelper::OInterfaceContainerHelper3<beans::XPropertyChangeListener>( m_aMutex ) );
460 m_pRowCountListeners->addInterface( xListener );
462 else
463 throw beans::UnknownPropertyException(aPropertyName);
467 void SAL_CALL ResultSetBase::removePropertyChangeListener(
468 const OUString& aPropertyName,
469 const uno::Reference< beans::XPropertyChangeListener >& aListener )
471 if( aPropertyName == "IsRowCountFinal" &&
472 m_pIsFinalListeners )
474 osl::MutexGuard aGuard( m_aMutex );
475 m_pIsFinalListeners->removeInterface( aListener );
477 else if ( aPropertyName == "RowCount" &&
478 m_pRowCountListeners )
480 osl::MutexGuard aGuard( m_aMutex );
481 m_pRowCountListeners->removeInterface( aListener );
483 else
484 throw beans::UnknownPropertyException(aPropertyName);
488 void SAL_CALL ResultSetBase::addVetoableChangeListener(
489 const OUString& /*PropertyName*/,
490 const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
495 void SAL_CALL ResultSetBase::removeVetoableChangeListener(
496 const OUString& /*PropertyName*/,
497 const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
502 // XResultSetMetaDataSupplier
503 uno::Reference< sdbc::XResultSetMetaData > SAL_CALL
504 ResultSetBase::getMetaData()
506 return new ::ucbhelper::ResultSetMetaData( m_xContext, m_sProperty );
510 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */