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/ucb/OpenMode.hpp>
23 #include <com/sun/star/uno/Reference.h>
24 #include <com/sun/star/beans/PropertyAttribute.hpp>
25 #include <com/sun/star/ucb/ListActionType.hpp>
26 #include <com/sun/star/ucb/XSourceInitialization.hpp>
29 #include "ftpresultsetbase.hxx"
30 
31 using namespace ftp;
32 using namespace com::sun::star;
33 
35  const uno::Reference< uno::XComponentContext >& rxContext,
36  const uno::Reference< ucb::XContentProvider >& xProvider,
37  const uno::Sequence< beans::Property >& seq )
38  : m_xContext( rxContext ),
39  m_xProvider( xProvider ),
40  m_nRow( -1 ),
41  m_nWasNull( true ),
42  m_sProperty( seq )
43 {
44 }
45 
47 {
48 }
49 
50 
51 // XInterface
52 
53 void SAL_CALL
55  throw()
56 {
57  OWeakObject::acquire();
58 }
59 
60 
61 void SAL_CALL
63  throw()
64 {
65  OWeakObject::release();
66 }
67 
68 
69 uno::Any SAL_CALL
71 {
73  rType,
74  static_cast< lang::XComponent* >(this),
75  static_cast< sdbc::XRow* >(this),
76  static_cast< sdbc::XResultSet* >(this),
77  static_cast< sdbc::XResultSetMetaDataSupplier* >(this),
78  static_cast< beans::XPropertySet* >(this),
79  static_cast< ucb::XContentAccess* >(this) );
80  return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
81 }
82 
83 
84 // XComponent
85 
86 
87 void SAL_CALL
89  const uno::Reference< lang::XEventListener >& Listener )
90 {
91  osl::MutexGuard aGuard( m_aMutex );
92 
96 
97  m_pDisposeEventListeners->addInterface( Listener );
98 }
99 
100 
101 void SAL_CALL
103  const uno::Reference< lang::XEventListener >& Listener )
104 {
105  osl::MutexGuard aGuard( m_aMutex );
106 
108  m_pDisposeEventListeners->removeInterface( Listener );
109 }
110 
111 
112 void SAL_CALL
114 {
115  osl::MutexGuard aGuard( m_aMutex );
116 
117  lang::EventObject aEvt;
118  aEvt.Source = static_cast< lang::XComponent * >( this );
119 
121  {
122  m_pDisposeEventListeners->disposeAndClear( aEvt );
123  }
124  if( m_pRowCountListeners && m_pRowCountListeners->getLength() )
125  {
126  m_pRowCountListeners->disposeAndClear( aEvt );
127  }
128  if( m_pIsFinalListeners && m_pIsFinalListeners->getLength() )
129  {
130  m_pIsFinalListeners->disposeAndClear( aEvt );
131  }
132 }
133 
134 
135 // XResultSet
136 
137 sal_Bool SAL_CALL
139 {
140  ++m_nRow;
141  return m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size());
142 }
143 
144 
145 sal_Bool SAL_CALL
147 {
148  return m_nRow == -1;
149 }
150 
151 
152 sal_Bool SAL_CALL
154 {
155  return m_nRow >= sal::static_int_cast<sal_Int32>(m_aItems.size()); // Cannot happen, if m_aFolder.isOpen()
156 }
157 
158 
159 sal_Bool SAL_CALL
161 {
162  return m_nRow == 0;
163 }
164 
165 
166 sal_Bool SAL_CALL
168 {
169  if( m_nRow == sal::static_int_cast<sal_Int32>(m_aItems.size()) - 1 )
170  return true;
171  else
172  return false;
173 }
174 
175 
176 void SAL_CALL
178 {
179  m_nRow = -1;
180 }
181 
182 
183 void SAL_CALL
185 {
186  m_nRow = m_aItems.size();
187 }
188 
189 
190 sal_Bool SAL_CALL
192 {
193  m_nRow = -1;
194  return next();
195 }
196 
197 
198 sal_Bool SAL_CALL
200 {
201  m_nRow = m_aItems.size() - 1;
202  return true;
203 }
204 
205 
206 sal_Int32 SAL_CALL
208 {
209  // Test, whether behind last row
210  if( -1 == m_nRow || m_nRow >= sal::static_int_cast<sal_Int32>(m_aItems.size()) )
211  return 0;
212  else
213  return m_nRow+1;
214 }
215 
216 
217 sal_Bool SAL_CALL ResultSetBase::absolute( sal_Int32 row )
218 {
219  if( row >= 0 )
220  m_nRow = row - 1;
221  else
222  {
223  last();
224  m_nRow += ( row + 1 );
225  if( m_nRow < -1 )
226  m_nRow = -1;
227  }
228 
229  return 0<= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size());
230 }
231 
232 
233 sal_Bool SAL_CALL
234 ResultSetBase::relative( sal_Int32 row )
235 {
236  if( isAfterLast() || isBeforeFirst() )
237  throw sdbc::SQLException();
238 
239  if( row > 0 )
240  while( row-- )
241  next();
242  else if( row < 0 )
243  while( row++ && m_nRow > - 1 )
244  previous();
245 
246  return 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size());
247 }
248 
249 
250 sal_Bool SAL_CALL
252 {
253  if( m_nRow > sal::static_int_cast<sal_Int32>(m_aItems.size()) )
254  m_nRow = m_aItems.size(); // Correct Handling of afterLast
255  if( 0 <= m_nRow ) -- m_nRow;
256 
257  return 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size());
258 }
259 
260 
261 void SAL_CALL
263 {
264 }
265 
266 
267 sal_Bool SAL_CALL
269 {
270  return false;
271 }
272 
273 sal_Bool SAL_CALL
275 {
276  return false;
277 }
278 
279 sal_Bool SAL_CALL
281 {
282  return false;
283 }
284 
285 
286 uno::Reference< uno::XInterface > SAL_CALL
288 {
289  return uno::Reference< uno::XInterface >();
290 }
291 
292 
293 // XCloseable
294 
295 void SAL_CALL
297 {
298 }
299 
300 
301 OUString SAL_CALL
303 {
304  if( 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) )
305  return m_aPath[m_nRow];
306  else
307  return OUString();
308 }
309 
310 
311 uno::Reference< ucb::XContentIdentifier > SAL_CALL
313 {
314  if( 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) )
315  {
316  if(!m_aIdents[m_nRow].is()) {
317  OUString url = queryContentIdentifierString();
318  if(!url.isEmpty() )
319  m_aIdents[m_nRow] =
320  uno::Reference< ucb::XContentIdentifier >(
321  new ::ucbhelper::ContentIdentifier(url) );
322  }
323  return m_aIdents[m_nRow];
324  }
325 
326  return uno::Reference<ucb::XContentIdentifier>();
327 }
328 
329 
330 uno::Reference< ucb::XContent > SAL_CALL
332 {
333  if( 0 <= m_nRow && m_nRow < sal::static_int_cast<sal_Int32>(m_aItems.size()) )
334  return m_xProvider->queryContent(queryContentIdentifier());
335  else
336  return uno::Reference< ucb::XContent >();
337 }
338 
339 
341  : public cppu::OWeakObject,
342  public beans::XPropertySetInfo
343 {
344 public:
345 
346  explicit XPropertySetInfoImpl( const uno::Sequence< beans::Property >& aSeq )
347  : m_aSeq( aSeq )
348  {
349  }
350 
351  void SAL_CALL acquire()
352  throw() override
353  {
354  OWeakObject::acquire();
355  }
356 
357 
358  void SAL_CALL release()
359  throw() override
360  {
361  OWeakObject::release();
362  }
363 
364  uno::Any SAL_CALL queryInterface( const uno::Type& rType ) override
365  {
367  rType,
368  static_cast< beans::XPropertySetInfo* >(this) );
369  return aRet.hasValue() ? aRet : OWeakObject::queryInterface( rType );
370  }
371 
372  uno::Sequence< beans::Property > SAL_CALL getProperties() override
373  {
374  return m_aSeq;
375  }
376 
377  beans::Property SAL_CALL getPropertyByName( const OUString& aName ) override
378  {
379  auto pProp = std::find_if(m_aSeq.begin(), m_aSeq.end(),
380  [&aName](const beans::Property& rProp) { return aName == rProp.Name; });
381  if (pProp != m_aSeq.end())
382  return *pProp;
383  throw beans::UnknownPropertyException(aName);
384  }
385 
386  sal_Bool SAL_CALL hasPropertyByName( const OUString& Name ) override
387  {
388  return std::any_of(m_aSeq.begin(), m_aSeq.end(),
389  [&Name](const beans::Property& rProp) { return Name == rProp.Name; });
390  }
391 
392 private:
393 
394  uno::Sequence< beans::Property > m_aSeq;
395 };
396 
397 
398 // XPropertySet
399 uno::Reference< beans::XPropertySetInfo > SAL_CALL
401 {
402  uno::Sequence< beans::Property > seq(2);
403  seq[0].Name = "RowCount";
404  seq[0].Handle = -1;
405  seq[0].Type = cppu::UnoType<sal_Int32>::get();
406  seq[0].Attributes = beans::PropertyAttribute::READONLY;
407 
408  seq[1].Name = "IsRowCountFinal";
409  seq[1].Handle = -1;
410  seq[1].Type = cppu::UnoType<sal_Bool>::get();
411  seq[1].Attributes = beans::PropertyAttribute::READONLY;
412 
413  //t
414  return uno::Reference< beans::XPropertySetInfo > (
415  new XPropertySetInfoImpl( seq ) );
416 }
417 
418 
419 void SAL_CALL ResultSetBase::setPropertyValue(
420  const OUString& aPropertyName, const uno::Any& /*aValue*/ )
421 {
422  if( aPropertyName == "IsRowCountFinal" ||
423  aPropertyName == "RowCount" )
424  return;
425 
426  throw beans::UnknownPropertyException(aPropertyName);
427 }
428 
429 
431  const OUString& PropertyName )
432 {
433  if( PropertyName == "IsRowCountFinal" )
434  {
435  return uno::Any(true);
436  }
437  else if ( PropertyName == "RowCount" )
438  {
439  sal_Int32 count = m_aItems.size();
440  return uno::Any(count);
441  }
442  else
443  throw beans::UnknownPropertyException(PropertyName);
444 }
445 
446 
448  const OUString& aPropertyName,
449  const uno::Reference< beans::XPropertyChangeListener >& xListener )
450 {
451  if( aPropertyName == "IsRowCountFinal" )
452  {
453  osl::MutexGuard aGuard( m_aMutex );
454  if ( ! m_pIsFinalListeners )
455  m_pIsFinalListeners.reset(
457 
458  m_pIsFinalListeners->addInterface( xListener );
459  }
460  else if ( aPropertyName == "RowCount" )
461  {
462  osl::MutexGuard aGuard( m_aMutex );
463  if ( ! m_pRowCountListeners )
464  m_pRowCountListeners.reset(
466  m_pRowCountListeners->addInterface( xListener );
467  }
468  else
469  throw beans::UnknownPropertyException(aPropertyName);
470 }
471 
472 
474  const OUString& aPropertyName,
475  const uno::Reference< beans::XPropertyChangeListener >& aListener )
476 {
477  if( aPropertyName == "IsRowCountFinal" &&
479  {
480  osl::MutexGuard aGuard( m_aMutex );
481  m_pIsFinalListeners->removeInterface( aListener );
482  }
483  else if ( aPropertyName == "RowCount" &&
485  {
486  osl::MutexGuard aGuard( m_aMutex );
487  m_pRowCountListeners->removeInterface( aListener );
488  }
489  else
490  throw beans::UnknownPropertyException(aPropertyName);
491 }
492 
493 
495  const OUString& /*PropertyName*/,
496  const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
497 {
498 }
499 
500 
502  const OUString& /*PropertyName*/,
503  const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
504 {
505 }
506 
507 
508 // XResultSetMetaDataSupplier
509 uno::Reference< sdbc::XResultSetMetaData > SAL_CALL
511 {
513  new ::ucbhelper::ResultSetMetaData( m_xContext, m_sProperty );
514  return uno::Reference< sdbc::XResultSetMetaData >( p );
515 }
516 
517 
518 /* 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()
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
virtual ~ResultSetBase() override
virtual css::uno::Reference< css::ucb::XContent > SAL_CALL queryContent() override
css::uno::Sequence< css::beans::Property > const m_sProperty
virtual void SAL_CALL beforeFirst() override
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)
const uno::Reference< uno::XComponentContext > m_xContext
virtual sal_Int32 SAL_CALL getRow() override