1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
21 /**************************************************************************
23 **************************************************************************
25 *************************************************************************/
29 #include <com/sun/star/ucb/IllegalIdentifierException.hpp>
30 #include <com/sun/star/ucb/OpenMode.hpp>
31 #include <ucbhelper/contentidentifier.hxx>
32 #include "hierarchydatasupplier.hxx"
33 #include "hierarchyprovider.hxx"
34 #include "hierarchycontent.hxx"
36 using namespace com::sun::star
;
37 using namespace hierarchy_ucp
;
39 namespace hierarchy_ucp
43 // struct ResultListEntry.
47 struct ResultListEntry
50 uno::Reference
< ucb::XContentIdentifier
> xId
;
51 uno::Reference
< ucb::XContent
> xContent
;
52 uno::Reference
< sdbc::XRow
> xRow
;
53 HierarchyEntryData aData
;
55 explicit ResultListEntry( const HierarchyEntryData
& rEntry
) : aData( rEntry
) {}
63 typedef std::vector
< std::unique_ptr
<ResultListEntry
> > ResultList
;
66 // struct DataSupplier_Impl.
69 struct DataSupplier_Impl
72 ResultList m_aResults
;
73 rtl::Reference
< HierarchyContent
> m_xContent
;
74 uno::Reference
< uno::XComponentContext
> m_xContext
;
75 HierarchyEntry m_aFolder
;
76 HierarchyEntry::iterator m_aIterator
;
77 sal_Int32 m_nOpenMode
;
81 const uno::Reference
< uno::XComponentContext
>& rxContext
,
82 const rtl::Reference
< HierarchyContent
>& rContent
,
84 : m_xContent( rContent
), m_xContext( rxContext
),
86 static_cast< HierarchyContentProvider
* >(
87 rContent
->getProvider().get() ),
88 rContent
->getIdentifier()->getContentIdentifier() ),
89 m_nOpenMode( nOpenMode
), m_bCountFinal( false ) {}
96 // HierarchyResultSetDataSupplier Implementation.
99 HierarchyResultSetDataSupplier::HierarchyResultSetDataSupplier(
100 const uno::Reference
< uno::XComponentContext
>& rxContext
,
101 const rtl::Reference
< HierarchyContent
>& rContent
,
102 sal_Int32 nOpenMode
)
103 : m_pImpl( new DataSupplier_Impl( rxContext
, rContent
, nOpenMode
) )
109 HierarchyResultSetDataSupplier::~HierarchyResultSetDataSupplier()
115 OUString
HierarchyResultSetDataSupplier::queryContentIdentifierString(
118 osl::Guard
< osl::Mutex
> aGuard( m_pImpl
->m_aMutex
);
120 if ( nIndex
< m_pImpl
->m_aResults
.size() )
122 OUString aId
= m_pImpl
->m_aResults
[ nIndex
]->aId
;
123 if ( !aId
.isEmpty() )
130 if ( getResult( nIndex
) )
133 = m_pImpl
->m_xContent
->getIdentifier()->getContentIdentifier();
135 if ( ( aId
.lastIndexOf( '/' ) + 1 ) != aId
.getLength() )
138 aId
+= m_pImpl
->m_aResults
[ nIndex
]->aData
.getName();
140 m_pImpl
->m_aResults
[ nIndex
]->aId
= aId
;
148 uno::Reference
< ucb::XContentIdentifier
>
149 HierarchyResultSetDataSupplier::queryContentIdentifier( sal_uInt32 nIndex
)
151 osl::Guard
< osl::Mutex
> aGuard( m_pImpl
->m_aMutex
);
153 if ( nIndex
< m_pImpl
->m_aResults
.size() )
155 uno::Reference
< ucb::XContentIdentifier
> xId
156 = m_pImpl
->m_aResults
[ nIndex
]->xId
;
164 OUString aId
= queryContentIdentifierString( nIndex
);
165 if ( !aId
.isEmpty() )
167 uno::Reference
< ucb::XContentIdentifier
> xId
168 = new ::ucbhelper::ContentIdentifier( aId
);
169 m_pImpl
->m_aResults
[ nIndex
]->xId
= xId
;
172 return uno::Reference
< ucb::XContentIdentifier
>();
177 uno::Reference
< ucb::XContent
>
178 HierarchyResultSetDataSupplier::queryContent( sal_uInt32 nIndex
)
180 osl::Guard
< osl::Mutex
> aGuard( m_pImpl
->m_aMutex
);
182 if ( nIndex
< m_pImpl
->m_aResults
.size() )
184 uno::Reference
< ucb::XContent
> xContent
185 = m_pImpl
->m_aResults
[ nIndex
]->xContent
;
193 uno::Reference
< ucb::XContentIdentifier
> xId
194 = queryContentIdentifier( nIndex
);
199 uno::Reference
< ucb::XContent
> xContent
200 = m_pImpl
->m_xContent
->getProvider()->queryContent( xId
);
201 m_pImpl
->m_aResults
[ nIndex
]->xContent
= xContent
;
205 catch ( ucb::IllegalIdentifierException
const & )
209 return uno::Reference
< ucb::XContent
>();
214 bool HierarchyResultSetDataSupplier::getResult( sal_uInt32 nIndex
)
216 osl::ClearableGuard
< osl::Mutex
> aGuard( m_pImpl
->m_aMutex
);
218 if ( m_pImpl
->m_aResults
.size() > nIndex
)
220 // Result already present.
224 // Result not (yet) present.
226 if ( m_pImpl
->m_bCountFinal
)
229 // Try to obtain result...
231 sal_uInt32 nOldCount
= m_pImpl
->m_aResults
.size();
233 sal_uInt32 nPos
= nOldCount
;
235 while ( m_pImpl
->m_aFolder
.next( m_pImpl
->m_aIterator
) )
237 const HierarchyEntryData
& rResult
= *m_pImpl
->m_aIterator
;
238 if ( checkResult( rResult
) )
240 m_pImpl
->m_aResults
.emplace_back( new ResultListEntry( rResult
) );
242 if ( nPos
== nIndex
)
253 m_pImpl
->m_bCountFinal
= true;
255 rtl::Reference
< ::ucbhelper::ResultSet
> xResultSet
= getResultSet();
256 if ( xResultSet
.is() )
261 if ( nOldCount
< m_pImpl
->m_aResults
.size() )
262 xResultSet
->rowCountChanged(
263 nOldCount
, m_pImpl
->m_aResults
.size() );
265 if ( m_pImpl
->m_bCountFinal
)
266 xResultSet
->rowCountFinal();
274 sal_uInt32
HierarchyResultSetDataSupplier::totalCount()
276 osl::ClearableGuard
< osl::Mutex
> aGuard( m_pImpl
->m_aMutex
);
278 if ( m_pImpl
->m_bCountFinal
)
279 return m_pImpl
->m_aResults
.size();
281 sal_uInt32 nOldCount
= m_pImpl
->m_aResults
.size();
283 while ( m_pImpl
->m_aFolder
.next( m_pImpl
->m_aIterator
) )
285 const HierarchyEntryData
& rResult
= *m_pImpl
->m_aIterator
;
286 if ( checkResult( rResult
) )
287 m_pImpl
->m_aResults
.emplace_back( new ResultListEntry( rResult
) );
290 m_pImpl
->m_bCountFinal
= true;
292 rtl::Reference
< ::ucbhelper::ResultSet
> xResultSet
= getResultSet();
293 if ( xResultSet
.is() )
298 if ( nOldCount
< m_pImpl
->m_aResults
.size() )
299 xResultSet
->rowCountChanged(
300 nOldCount
, m_pImpl
->m_aResults
.size() );
302 xResultSet
->rowCountFinal();
305 return m_pImpl
->m_aResults
.size();
310 sal_uInt32
HierarchyResultSetDataSupplier::currentCount()
312 return m_pImpl
->m_aResults
.size();
317 bool HierarchyResultSetDataSupplier::isCountFinal()
319 return m_pImpl
->m_bCountFinal
;
324 uno::Reference
< sdbc::XRow
>
325 HierarchyResultSetDataSupplier::queryPropertyValues( sal_uInt32 nIndex
)
327 osl::Guard
< osl::Mutex
> aGuard( m_pImpl
->m_aMutex
);
329 if ( nIndex
< m_pImpl
->m_aResults
.size() )
331 uno::Reference
< sdbc::XRow
> xRow
332 = m_pImpl
->m_aResults
[ nIndex
]->xRow
;
340 if ( getResult( nIndex
) )
342 HierarchyContentProperties
aData(
343 m_pImpl
->m_aResults
[ nIndex
]->aData
);
345 uno::Reference
< sdbc::XRow
> xRow
346 = HierarchyContent::getPropertyValues(
348 getResultSet()->getProperties(),
350 static_cast< HierarchyContentProvider
* >(
351 m_pImpl
->m_xContent
->getProvider().get() ),
352 queryContentIdentifierString( nIndex
) );
353 m_pImpl
->m_aResults
[ nIndex
]->xRow
= xRow
;
357 return uno::Reference
< sdbc::XRow
>();
362 void HierarchyResultSetDataSupplier::releasePropertyValues( sal_uInt32 nIndex
)
364 osl::Guard
< osl::Mutex
> aGuard( m_pImpl
->m_aMutex
);
366 if ( nIndex
< m_pImpl
->m_aResults
.size() )
367 m_pImpl
->m_aResults
[ nIndex
]->xRow
.clear();
372 void HierarchyResultSetDataSupplier::close()
378 void HierarchyResultSetDataSupplier::validate()
383 bool HierarchyResultSetDataSupplier::checkResult(
384 const HierarchyEntryData
& rResult
)
386 switch ( m_pImpl
->m_nOpenMode
)
388 case ucb::OpenMode::FOLDERS
:
389 if ( rResult
.getType() == HierarchyEntryData::LINK
)
396 case ucb::OpenMode::DOCUMENTS
:
397 if ( rResult
.getType() == HierarchyEntryData::FOLDER
)
399 // Entry is a folder.
404 case ucb::OpenMode::ALL
:
412 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */