LibreOffice Module ucb (master)  1
ftpresultsetbase.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
21 #include <com/sun/star/sdbc/SQLException.hpp>
22 #include <com/sun/star/uno/Reference.h>
23 #include <com/sun/star/beans/PropertyAttribute.hpp>
26 #include "ftpresultsetbase.hxx"
27 
28 using namespace ftp;
29 using namespace com::sun::star;
30 
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 )
40 {
41 }
42 
44 {
45 }
46 
47 
48 // XInterface
49 
50 void SAL_CALL
52  throw()
53 {
54  OWeakObject::acquire();
55 }
56 
57 
58 void SAL_CALL
60  throw()
61 {
62  OWeakObject::release();
63 }
64 
65 
66 uno::Any SAL_CALL
68 {
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 );
78 }
79 
80 
81 // XComponent
82 
83 
84 void SAL_CALL
86  const uno::Reference< lang::XEventListener >& Listener )
87 {
88  osl::MutexGuard aGuard( m_aMutex );
89 
93 
94  m_pDisposeEventListeners->addInterface( Listener );
95 }
96 
97 
98 void SAL_CALL
100  const uno::Reference< lang::XEventListener >& Listener )
101 {
102  osl::MutexGuard aGuard( m_aMutex );
103 
105  m_pDisposeEventListeners->removeInterface( Listener );
106 }
107 
108 
109 void SAL_CALL
111 {
112  osl::MutexGuard aGuard( m_aMutex );
113 
114  lang::EventObject aEvt;
115  aEvt.Source = static_cast< lang::XComponent * >( this );
116 
118  {
119  m_pDisposeEventListeners->disposeAndClear( aEvt );
120  }
121  if( m_pRowCountListeners && m_pRowCountListeners->getLength() )
122  {
123  m_pRowCountListeners->disposeAndClear( aEvt );
124  }
125  if( m_pIsFinalListeners && m_pIsFinalListeners->getLength() )
126  {
127  m_pIsFinalListeners->disposeAndClear( aEvt );
128  }
129 }
130 
131 
132 // XResultSet
133 
134 sal_Bool SAL_CALL
136 {
137  ++m_nRow;
138  return m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size());
139 }
140 
141 
142 sal_Bool SAL_CALL
144 {
145  return m_nRow == -1;
146 }
147 
148 
149 sal_Bool SAL_CALL
151 {
152  return m_nRow >= sal::static_int_cast<sal_Int32>(m_aItems.size()); // Cannot happen, if m_aFolder.isOpen()
153 }
154 
155 
156 sal_Bool SAL_CALL
158 {
159  return m_nRow == 0;
160 }
161 
162 
163 sal_Bool SAL_CALL
165 {
166  if( m_nRow == sal::static_int_cast<sal_Int32>(m_aItems.size()) - 1 )
167  return true;
168  else
169  return false;
170 }
171 
172 
173 void SAL_CALL
175 {
176  m_nRow = -1;
177 }
178 
179 
180 void SAL_CALL
182 {
183  m_nRow = m_aItems.size();
184 }
185 
186 
187 sal_Bool SAL_CALL
189 {
190  m_nRow = -1;
191  return next();
192 }
193 
194 
195 sal_Bool SAL_CALL
197 {
198  m_nRow = m_aItems.size() - 1;
199  return true;
200 }
201 
202 
203 sal_Int32 SAL_CALL
205 {
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;
211 }
212 
213 
214 sal_Bool SAL_CALL ResultSetBase::absolute( sal_Int32 row )
215 {
216  if( row >= 0 )
217  m_nRow = row - 1;
218  else
219  {
220  last();
221  m_nRow += ( row + 1 );
222  if( m_nRow < -1 )
223  m_nRow = -1;
224  }
225 
226  return 0<= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size());
227 }
228 
229 
230 sal_Bool SAL_CALL
231 ResultSetBase::relative( sal_Int32 row )
232 {
233  if( isAfterLast() || isBeforeFirst() )
234  throw sdbc::SQLException();
235 
236  if( row > 0 )
237  while( row-- )
238  next();
239  else if( row < 0 )
240  while( row++ && m_nRow > - 1 )
241  previous();
242 
243  return 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size());
244 }
245 
246 
247 sal_Bool SAL_CALL
249 {
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;
253 
254  return 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size());
255 }
256 
257 
258 void SAL_CALL
260 {
261 }
262 
263 
264 sal_Bool SAL_CALL
266 {
267  return false;
268 }
269 
270 sal_Bool SAL_CALL
272 {
273  return false;
274 }
275 
276 sal_Bool SAL_CALL
278 {
279  return false;
280 }
281 
282 
283 uno::Reference< uno::XInterface > SAL_CALL
285 {
286  return uno::Reference< uno::XInterface >();
287 }
288 
289 
290 // XCloseable
291 
292 void SAL_CALL
294 {
295 }
296 
297 
298 OUString SAL_CALL
300 {
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();
305 }
306 
307 
308 uno::Reference< ucb::XContentIdentifier > SAL_CALL
310 {
311  if( 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) )
312  {
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) );
319  }
320  return m_aIdents[m_nRow];
321  }
322 
323  return uno::Reference<ucb::XContentIdentifier>();
324 }
325 
326 
327 uno::Reference< ucb::XContent > SAL_CALL
329 {
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 >();
334 }
335 
336 namespace {
337 
338 class XPropertySetInfoImpl
339  : public cppu::OWeakObject,
340  public beans::XPropertySetInfo
341 {
342 public:
343 
344  explicit XPropertySetInfoImpl( const uno::Sequence< beans::Property >& aSeq )
345  : m_aSeq( aSeq )
346  {
347  }
348 
349  void SAL_CALL acquire()
350  throw() override
351  {
352  OWeakObject::acquire();
353  }
354 
355 
356  void SAL_CALL release()
357  throw() override
358  {
359  OWeakObject::release();
360  }
361 
362  uno::Any SAL_CALL queryInterface( const uno::Type& rType ) override
363  {
365  rType,
366  static_cast< beans::XPropertySetInfo* >(this) );
367  return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
368  }
369 
370  uno::Sequence< beans::Property > SAL_CALL getProperties() override
371  {
372  return m_aSeq;
373  }
374 
375  beans::Property SAL_CALL getPropertyByName( const OUString& aName ) override
376  {
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);
382  }
383 
384  sal_Bool SAL_CALL hasPropertyByName( const OUString& Name ) override
385  {
386  return std::any_of(m_aSeq.begin(), m_aSeq.end(),
387  [&Name](const beans::Property& rProp) { return Name == rProp.Name; });
388  }
389 
390 private:
391 
392  uno::Sequence< beans::Property > m_aSeq;
393 };
394 
395 }
396 
397 // XPropertySet
398 uno::Reference< beans::XPropertySetInfo > SAL_CALL
400 {
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;
406 
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;
411 
412  //t
413  return uno::Reference< beans::XPropertySetInfo > (
414  new XPropertySetInfoImpl( seq ) );
415 }
416 
417 
418 void SAL_CALL ResultSetBase::setPropertyValue(
419  const OUString& aPropertyName, const uno::Any& /*aValue*/ )
420 {
421  if( aPropertyName == "IsRowCountFinal" ||
422  aPropertyName == "RowCount" )
423  return;
424 
425  throw beans::UnknownPropertyException(aPropertyName);
426 }
427 
428 
430  const OUString& PropertyName )
431 {
432  if( PropertyName == "IsRowCountFinal" )
433  {
434  return uno::Any(true);
435  }
436  else if ( PropertyName == "RowCount" )
437  {
438  sal_Int32 count = m_aItems.size();
439  return uno::Any(count);
440  }
441  else
442  throw beans::UnknownPropertyException(PropertyName);
443 }
444 
445 
447  const OUString& aPropertyName,
448  const uno::Reference< beans::XPropertyChangeListener >& xListener )
449 {
450  if( aPropertyName == "IsRowCountFinal" )
451  {
452  osl::MutexGuard aGuard( m_aMutex );
453  if ( ! m_pIsFinalListeners )
454  m_pIsFinalListeners.reset(
456 
457  m_pIsFinalListeners->addInterface( xListener );
458  }
459  else if ( aPropertyName == "RowCount" )
460  {
461  osl::MutexGuard aGuard( m_aMutex );
462  if ( ! m_pRowCountListeners )
463  m_pRowCountListeners.reset(
465  m_pRowCountListeners->addInterface( xListener );
466  }
467  else
468  throw beans::UnknownPropertyException(aPropertyName);
469 }
470 
471 
473  const OUString& aPropertyName,
474  const uno::Reference< beans::XPropertyChangeListener >& aListener )
475 {
476  if( aPropertyName == "IsRowCountFinal" &&
478  {
479  osl::MutexGuard aGuard( m_aMutex );
480  m_pIsFinalListeners->removeInterface( aListener );
481  }
482  else if ( aPropertyName == "RowCount" &&
484  {
485  osl::MutexGuard aGuard( m_aMutex );
486  m_pRowCountListeners->removeInterface( aListener );
487  }
488  else
489  throw beans::UnknownPropertyException(aPropertyName);
490 }
491 
492 
494  const OUString& /*PropertyName*/,
495  const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
496 {
497 }
498 
499 
501  const OUString& /*PropertyName*/,
502  const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
503 {
504 }
505 
506 
507 // XResultSetMetaDataSupplier
508 uno::Reference< sdbc::XResultSetMetaData > SAL_CALL
510 {
512  new ::ucbhelper::ResultSetMetaData( m_xContext, m_sProperty );
513  return uno::Reference< sdbc::XResultSetMetaData >( p );
514 }
515 
516 
517 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual sal_Bool SAL_CALL absolute(sal_Int32 row) override
virtual void SAL_CALL addVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
virtual void SAL_CALL refreshRow() override
const size_t count(pCandidateA->getBorderLines().size())
bool hasValue()
Sequence< Any > m_aSeq
std::unique_ptr< comphelper::OInterfaceContainerHelper2 > m_pDisposeEventListeners
virtual css::uno::Reference< css::sdbc::XResultSetMetaData > SAL_CALL getMetaData() override
virtual sal_Bool SAL_CALL isLast() override
virtual sal_Bool SAL_CALL previous() override
virtual sal_Bool SAL_CALL isAfterLast() override
virtual css::uno::Reference< css::ucb::XContentIdentifier > SAL_CALL queryContentIdentifier() override
virtual OUString SAL_CALL queryContentIdentifierString() override
std::vector< OUString > m_aPath
virtual void SAL_CALL removeVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
virtual void SAL_CALL setPropertyValue(const OUString &aPropertyName, const css::uno::Any &aValue) override
virtual void SAL_CALL acquire() override
virtual sal_Bool SAL_CALL rowInserted() override
virtual sal_Bool SAL_CALL last() override
virtual sal_Bool SAL_CALL isBeforeFirst() override
virtual sal_Bool SAL_CALL first() override
std::unique_ptr< comphelper::OInterfaceContainerHelper2 > m_pIsFinalListeners
virtual sal_Bool SAL_CALL rowUpdated() override
std::unique_ptr< comphelper::OInterfaceContainerHelper2 > m_pRowCountListeners
virtual sal_Bool SAL_CALL next() override
ResultSetBase(const css::uno::Reference< css::uno::XComponentContext > &rxContext, const css::uno::Reference< css::ucb::XContentProvider > &xProvider, const css::uno::Sequence< css::beans::Property > &seq)
virtual void SAL_CALL dispose() override
unsigned char sal_Bool
virtual sal_Bool SAL_CALL rowDeleted() override
virtual void SAL_CALL close() override
Definition of ftpcontentprovider.
css::uno::Type const & get()
virtual void SAL_CALL release() override
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &PropertyName) override
virtual void SAL_CALL removePropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &aListener) override
css::uno::Reference< css::uno::XComponentContext > m_xContext
virtual sal_Bool SAL_CALL isFirst() override
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
virtual sal_Bool SAL_CALL relative(sal_Int32 rows) override
virtual css::uno::Any SAL_CALL queryInterface(const css::uno::Type &aType) override
virtual void SAL_CALL removeEventListener(const css::uno::Reference< css::lang::XEventListener > &aListener) override
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getStatement() override
virtual void SAL_CALL addPropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
css::uno::Reference< css::ucb::XContentProvider > m_xProvider
virtual void SAL_CALL afterLast() override
virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener > &xListener) override
void * p
virtual ~ResultSetBase() override
virtual css::uno::Reference< css::ucb::XContent > SAL_CALL queryContent() override
css::uno::Sequence< css::beans::Property > const m_sProperty
Reference< XComponentContext > m_xContext
virtual void SAL_CALL beforeFirst() override
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)
virtual sal_Int32 SAL_CALL getRow() override