nss: upgrade to release 3.73
[LibreOffice.git] / ucb / source / ucp / ftp / ftpresultsetbase.cxx
blobcb3d017af7d3cb47c46b404ccf4edc755f0aac4b
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 "ftpresultsetbase.hxx"
28 using namespace ftp;
29 using namespace com::sun::star;
31 ResultSetBase::ResultSetBase(
32 const uno::Reference< uno::XComponentContext >& rxContext,
33 const uno::Reference< ucb::XContentProvider >& xProvider,
34 const uno::Sequence< beans::Property >& seq )
35 : m_xContext( rxContext ),
36 m_xProvider( xProvider ),
37 m_nRow( -1 ),
38 m_nWasNull( true ),
39 m_sProperty( seq )
43 ResultSetBase::~ResultSetBase()
48 // XInterface
50 void SAL_CALL
51 ResultSetBase::acquire()
52 throw()
54 OWeakObject::acquire();
58 void SAL_CALL
59 ResultSetBase::release()
60 throw()
62 OWeakObject::release();
66 uno::Any SAL_CALL
67 ResultSetBase::queryInterface( const uno::Type& rType )
69 uno::Any aRet = cppu::queryInterface(
70 rType,
71 static_cast< lang::XComponent* >(this),
72 static_cast< sdbc::XRow* >(this),
73 static_cast< sdbc::XResultSet* >(this),
74 static_cast< sdbc::XResultSetMetaDataSupplier* >(this),
75 static_cast< beans::XPropertySet* >(this),
76 static_cast< ucb::XContentAccess* >(this) );
77 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
81 // XComponent
84 void SAL_CALL
85 ResultSetBase::addEventListener(
86 const uno::Reference< lang::XEventListener >& Listener )
88 osl::MutexGuard aGuard( m_aMutex );
90 if ( ! m_pDisposeEventListeners )
91 m_pDisposeEventListeners.reset(
92 new comphelper::OInterfaceContainerHelper2( m_aMutex ) );
94 m_pDisposeEventListeners->addInterface( Listener );
98 void SAL_CALL
99 ResultSetBase::removeEventListener(
100 const uno::Reference< lang::XEventListener >& Listener )
102 osl::MutexGuard aGuard( m_aMutex );
104 if ( m_pDisposeEventListeners )
105 m_pDisposeEventListeners->removeInterface( Listener );
109 void SAL_CALL
110 ResultSetBase::dispose()
112 osl::MutexGuard aGuard( m_aMutex );
114 lang::EventObject aEvt;
115 aEvt.Source = static_cast< lang::XComponent * >( this );
117 if ( m_pDisposeEventListeners && m_pDisposeEventListeners->getLength() )
119 m_pDisposeEventListeners->disposeAndClear( aEvt );
121 if( m_pRowCountListeners && m_pRowCountListeners->getLength() )
123 m_pRowCountListeners->disposeAndClear( aEvt );
125 if( m_pIsFinalListeners && m_pIsFinalListeners->getLength() )
127 m_pIsFinalListeners->disposeAndClear( aEvt );
132 // XResultSet
134 sal_Bool SAL_CALL
135 ResultSetBase::next()
137 ++m_nRow;
138 return m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size());
142 sal_Bool SAL_CALL
143 ResultSetBase::isBeforeFirst()
145 return m_nRow == -1;
149 sal_Bool SAL_CALL
150 ResultSetBase::isAfterLast()
152 return m_nRow >= sal::static_int_cast<sal_Int32>(m_aItems.size()); // Cannot happen, if m_aFolder.isOpen()
156 sal_Bool SAL_CALL
157 ResultSetBase::isFirst()
159 return m_nRow == 0;
163 sal_Bool SAL_CALL
164 ResultSetBase::isLast()
166 if( m_nRow == sal::static_int_cast<sal_Int32>(m_aItems.size()) - 1 )
167 return true;
168 else
169 return false;
173 void SAL_CALL
174 ResultSetBase::beforeFirst()
176 m_nRow = -1;
180 void SAL_CALL
181 ResultSetBase::afterLast()
183 m_nRow = m_aItems.size();
187 sal_Bool SAL_CALL
188 ResultSetBase::first()
190 m_nRow = -1;
191 return next();
195 sal_Bool SAL_CALL
196 ResultSetBase::last()
198 m_nRow = m_aItems.size() - 1;
199 return true;
203 sal_Int32 SAL_CALL
204 ResultSetBase::getRow()
206 // Test, whether behind last row
207 if( -1 == m_nRow || m_nRow >= sal::static_int_cast<sal_Int32>(m_aItems.size()) )
208 return 0;
209 else
210 return m_nRow+1;
214 sal_Bool SAL_CALL ResultSetBase::absolute( sal_Int32 row )
216 if( row >= 0 )
217 m_nRow = row - 1;
218 else
220 last();
221 m_nRow += ( row + 1 );
222 if( m_nRow < -1 )
223 m_nRow = -1;
226 return 0<= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size());
230 sal_Bool SAL_CALL
231 ResultSetBase::relative( sal_Int32 row )
233 if( isAfterLast() || isBeforeFirst() )
234 throw sdbc::SQLException();
236 if( row > 0 )
237 while( row-- )
238 next();
239 else if( row < 0 )
240 while( row++ && m_nRow > - 1 )
241 previous();
243 return 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size());
247 sal_Bool SAL_CALL
248 ResultSetBase::previous()
250 if( m_nRow > sal::static_int_cast<sal_Int32>(m_aItems.size()) )
251 m_nRow = m_aItems.size(); // Correct Handling of afterLast
252 if( 0 <= m_nRow ) -- m_nRow;
254 return 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size());
258 void SAL_CALL
259 ResultSetBase::refreshRow()
264 sal_Bool SAL_CALL
265 ResultSetBase::rowUpdated()
267 return false;
270 sal_Bool SAL_CALL
271 ResultSetBase::rowInserted()
273 return false;
276 sal_Bool SAL_CALL
277 ResultSetBase::rowDeleted()
279 return false;
283 uno::Reference< uno::XInterface > SAL_CALL
284 ResultSetBase::getStatement()
286 return uno::Reference< uno::XInterface >();
290 // XCloseable
292 void SAL_CALL
293 ResultSetBase::close()
298 OUString SAL_CALL
299 ResultSetBase::queryContentIdentifierString()
301 if( 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) )
302 return m_aPath[m_nRow];
303 else
304 return OUString();
308 uno::Reference< ucb::XContentIdentifier > SAL_CALL
309 ResultSetBase::queryContentIdentifier()
311 if( 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) )
313 if(!m_aIdents[m_nRow].is()) {
314 OUString url = queryContentIdentifierString();
315 if(!url.isEmpty() )
316 m_aIdents[m_nRow] =
317 uno::Reference< ucb::XContentIdentifier >(
318 new ::ucbhelper::ContentIdentifier(url) );
320 return m_aIdents[m_nRow];
323 return uno::Reference<ucb::XContentIdentifier>();
327 uno::Reference< ucb::XContent > SAL_CALL
328 ResultSetBase::queryContent()
330 if( 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) )
331 return m_xProvider->queryContent(queryContentIdentifier());
332 else
333 return uno::Reference< ucb::XContent >();
336 namespace {
338 class XPropertySetInfoImpl
339 : public cppu::OWeakObject,
340 public beans::XPropertySetInfo
342 public:
344 explicit XPropertySetInfoImpl( const uno::Sequence< beans::Property >& aSeq )
345 : m_aSeq( aSeq )
349 void SAL_CALL acquire()
350 throw() override
352 OWeakObject::acquire();
356 void SAL_CALL release()
357 throw() override
359 OWeakObject::release();
362 uno::Any SAL_CALL queryInterface( const uno::Type& rType ) override
364 uno::Any aRet = cppu::queryInterface(
365 rType,
366 static_cast< beans::XPropertySetInfo* >(this) );
367 return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
370 uno::Sequence< beans::Property > SAL_CALL getProperties() override
372 return m_aSeq;
375 beans::Property SAL_CALL getPropertyByName( const OUString& aName ) override
377 auto pProp = std::find_if(m_aSeq.begin(), m_aSeq.end(),
378 [&aName](const beans::Property& rProp) { return aName == rProp.Name; });
379 if (pProp != m_aSeq.end())
380 return *pProp;
381 throw beans::UnknownPropertyException(aName);
384 sal_Bool SAL_CALL hasPropertyByName( const OUString& Name ) override
386 return std::any_of(m_aSeq.begin(), m_aSeq.end(),
387 [&Name](const beans::Property& rProp) { return Name == rProp.Name; });
390 private:
392 uno::Sequence< beans::Property > m_aSeq;
397 // XPropertySet
398 uno::Reference< beans::XPropertySetInfo > SAL_CALL
399 ResultSetBase::getPropertySetInfo()
401 uno::Sequence< beans::Property > seq(2);
402 seq[0].Name = "RowCount";
403 seq[0].Handle = -1;
404 seq[0].Type = cppu::UnoType<sal_Int32>::get();
405 seq[0].Attributes = beans::PropertyAttribute::READONLY;
407 seq[1].Name = "IsRowCountFinal";
408 seq[1].Handle = -1;
409 seq[1].Type = cppu::UnoType<sal_Bool>::get();
410 seq[1].Attributes = beans::PropertyAttribute::READONLY;
413 return uno::Reference< beans::XPropertySetInfo > (
414 new XPropertySetInfoImpl( seq ) );
418 void SAL_CALL ResultSetBase::setPropertyValue(
419 const OUString& aPropertyName, const uno::Any& /*aValue*/ )
421 if( aPropertyName == "IsRowCountFinal" ||
422 aPropertyName == "RowCount" )
423 return;
425 throw beans::UnknownPropertyException(aPropertyName);
429 uno::Any SAL_CALL ResultSetBase::getPropertyValue(
430 const OUString& PropertyName )
432 if( PropertyName == "IsRowCountFinal" )
434 return uno::Any(true);
436 else if ( PropertyName == "RowCount" )
438 sal_Int32 count = m_aItems.size();
439 return uno::Any(count);
441 else
442 throw beans::UnknownPropertyException(PropertyName);
446 void SAL_CALL ResultSetBase::addPropertyChangeListener(
447 const OUString& aPropertyName,
448 const uno::Reference< beans::XPropertyChangeListener >& xListener )
450 if( aPropertyName == "IsRowCountFinal" )
452 osl::MutexGuard aGuard( m_aMutex );
453 if ( ! m_pIsFinalListeners )
454 m_pIsFinalListeners.reset(
455 new comphelper::OInterfaceContainerHelper2( m_aMutex ) );
457 m_pIsFinalListeners->addInterface( xListener );
459 else if ( aPropertyName == "RowCount" )
461 osl::MutexGuard aGuard( m_aMutex );
462 if ( ! m_pRowCountListeners )
463 m_pRowCountListeners.reset(
464 new comphelper::OInterfaceContainerHelper2( m_aMutex ) );
465 m_pRowCountListeners->addInterface( xListener );
467 else
468 throw beans::UnknownPropertyException(aPropertyName);
472 void SAL_CALL ResultSetBase::removePropertyChangeListener(
473 const OUString& aPropertyName,
474 const uno::Reference< beans::XPropertyChangeListener >& aListener )
476 if( aPropertyName == "IsRowCountFinal" &&
477 m_pIsFinalListeners )
479 osl::MutexGuard aGuard( m_aMutex );
480 m_pIsFinalListeners->removeInterface( aListener );
482 else if ( aPropertyName == "RowCount" &&
483 m_pRowCountListeners )
485 osl::MutexGuard aGuard( m_aMutex );
486 m_pRowCountListeners->removeInterface( aListener );
488 else
489 throw beans::UnknownPropertyException(aPropertyName);
493 void SAL_CALL ResultSetBase::addVetoableChangeListener(
494 const OUString& /*PropertyName*/,
495 const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
500 void SAL_CALL ResultSetBase::removeVetoableChangeListener(
501 const OUString& /*PropertyName*/,
502 const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
507 // XResultSetMetaDataSupplier
508 uno::Reference< sdbc::XResultSetMetaData > SAL_CALL
509 ResultSetBase::getMetaData()
511 ::ucbhelper::ResultSetMetaData* p =
512 new ::ucbhelper::ResultSetMetaData( m_xContext, m_sProperty );
513 return uno::Reference< sdbc::XResultSetMetaData >( p );
517 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */