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 *************************************************************************/
28 #include <ucbhelper/contentidentifier.hxx>
29 #include "hierarchydatasupplier.hxx"
30 #include "hierarchyprovider.hxx"
31 #include "hierarchycontent.hxx"
33 using namespace com::sun::star
;
34 using namespace hierarchy_ucp
;
36 namespace hierarchy_ucp
41 // struct ResultListEntry.
45 struct ResultListEntry
48 uno::Reference
< ucb::XContentIdentifier
> xId
;
49 uno::Reference
< ucb::XContent
> xContent
;
50 uno::Reference
< sdbc::XRow
> xRow
;
51 HierarchyEntryData aData
;
53 ResultListEntry( const HierarchyEntryData
& rEntry
) : aData( rEntry
) {}
62 typedef std::vector
< ResultListEntry
* > ResultList
;
66 // struct DataSupplier_Impl.
70 struct DataSupplier_Impl
73 ResultList m_aResults
;
74 rtl::Reference
< HierarchyContent
> m_xContent
;
75 uno::Reference
< uno::XComponentContext
> m_xContext
;
76 HierarchyEntry m_aFolder
;
77 HierarchyEntry::iterator m_aIterator
;
78 sal_Int32 m_nOpenMode
;
82 const uno::Reference
< uno::XComponentContext
>& rxContext
,
83 const rtl::Reference
< HierarchyContent
>& rContent
,
85 : m_xContent( rContent
), m_xContext( rxContext
),
87 static_cast< HierarchyContentProvider
* >(
88 rContent
->getProvider().get() ),
89 rContent
->getIdentifier()->getContentIdentifier() ),
90 m_nOpenMode( nOpenMode
), m_bCountFinal( false ) {}
95 DataSupplier_Impl::~DataSupplier_Impl()
97 ResultList::const_iterator it
= m_aResults
.begin();
98 ResultList::const_iterator end
= m_aResults
.end();
112 // HierarchyResultSetDataSupplier Implementation.
117 HierarchyResultSetDataSupplier::HierarchyResultSetDataSupplier(
118 const uno::Reference
< uno::XComponentContext
>& rxContext
,
119 const rtl::Reference
< HierarchyContent
>& rContent
,
120 sal_Int32 nOpenMode
)
121 : m_pImpl( new DataSupplier_Impl( rxContext
, rContent
, nOpenMode
) )
127 HierarchyResultSetDataSupplier::~HierarchyResultSetDataSupplier()
134 OUString
HierarchyResultSetDataSupplier::queryContentIdentifierString(
137 osl::Guard
< osl::Mutex
> aGuard( m_pImpl
->m_aMutex
);
139 if ( nIndex
< m_pImpl
->m_aResults
.size() )
141 OUString aId
= m_pImpl
->m_aResults
[ nIndex
]->aId
;
142 if ( !aId
.isEmpty() )
149 if ( getResult( nIndex
) )
152 = m_pImpl
->m_xContent
->getIdentifier()->getContentIdentifier();
154 if ( ( aId
.lastIndexOf( '/' ) + 1 ) != aId
.getLength() )
157 aId
+= m_pImpl
->m_aResults
[ nIndex
]->aData
.getName();
159 m_pImpl
->m_aResults
[ nIndex
]->aId
= aId
;
167 uno::Reference
< ucb::XContentIdentifier
>
168 HierarchyResultSetDataSupplier::queryContentIdentifier( sal_uInt32 nIndex
)
170 osl::Guard
< osl::Mutex
> aGuard( m_pImpl
->m_aMutex
);
172 if ( nIndex
< m_pImpl
->m_aResults
.size() )
174 uno::Reference
< ucb::XContentIdentifier
> xId
175 = m_pImpl
->m_aResults
[ nIndex
]->xId
;
183 OUString aId
= queryContentIdentifierString( nIndex
);
184 if ( !aId
.isEmpty() )
186 uno::Reference
< ucb::XContentIdentifier
> xId
187 = new ::ucbhelper::ContentIdentifier( aId
);
188 m_pImpl
->m_aResults
[ nIndex
]->xId
= xId
;
191 return uno::Reference
< ucb::XContentIdentifier
>();
196 uno::Reference
< ucb::XContent
>
197 HierarchyResultSetDataSupplier::queryContent( sal_uInt32 nIndex
)
199 osl::Guard
< osl::Mutex
> aGuard( m_pImpl
->m_aMutex
);
201 if ( nIndex
< m_pImpl
->m_aResults
.size() )
203 uno::Reference
< ucb::XContent
> xContent
204 = m_pImpl
->m_aResults
[ nIndex
]->xContent
;
212 uno::Reference
< ucb::XContentIdentifier
> xId
213 = queryContentIdentifier( nIndex
);
218 uno::Reference
< ucb::XContent
> xContent
219 = m_pImpl
->m_xContent
->getProvider()->queryContent( xId
);
220 m_pImpl
->m_aResults
[ nIndex
]->xContent
= xContent
;
224 catch ( ucb::IllegalIdentifierException
const & )
228 return uno::Reference
< ucb::XContent
>();
233 bool HierarchyResultSetDataSupplier::getResult( sal_uInt32 nIndex
)
235 osl::ClearableGuard
< osl::Mutex
> aGuard( m_pImpl
->m_aMutex
);
237 if ( m_pImpl
->m_aResults
.size() > nIndex
)
239 // Result already present.
243 // Result not (yet) present.
245 if ( m_pImpl
->m_bCountFinal
)
248 // Try to obtain result...
250 sal_uInt32 nOldCount
= m_pImpl
->m_aResults
.size();
252 sal_uInt32 nPos
= nOldCount
;
254 while ( m_pImpl
->m_aFolder
.next( m_pImpl
->m_aIterator
) )
256 const HierarchyEntryData
& rResult
= *m_pImpl
->m_aIterator
;
257 if ( checkResult( rResult
) )
259 m_pImpl
->m_aResults
.push_back( new ResultListEntry( rResult
) );
261 if ( nPos
== nIndex
)
272 m_pImpl
->m_bCountFinal
= true;
274 rtl::Reference
< ::ucbhelper::ResultSet
> xResultSet
= getResultSet().get();
275 if ( xResultSet
.is() )
280 if ( nOldCount
< m_pImpl
->m_aResults
.size() )
281 xResultSet
->rowCountChanged(
282 nOldCount
, m_pImpl
->m_aResults
.size() );
284 if ( m_pImpl
->m_bCountFinal
)
285 xResultSet
->rowCountFinal();
293 sal_uInt32
HierarchyResultSetDataSupplier::totalCount()
295 osl::ClearableGuard
< osl::Mutex
> aGuard( m_pImpl
->m_aMutex
);
297 if ( m_pImpl
->m_bCountFinal
)
298 return m_pImpl
->m_aResults
.size();
300 sal_uInt32 nOldCount
= m_pImpl
->m_aResults
.size();
302 while ( m_pImpl
->m_aFolder
.next( m_pImpl
->m_aIterator
) )
304 const HierarchyEntryData
& rResult
= *m_pImpl
->m_aIterator
;
305 if ( checkResult( rResult
) )
306 m_pImpl
->m_aResults
.push_back( new ResultListEntry( rResult
) );
309 m_pImpl
->m_bCountFinal
= true;
311 rtl::Reference
< ::ucbhelper::ResultSet
> xResultSet
= getResultSet().get();
312 if ( xResultSet
.is() )
317 if ( nOldCount
< m_pImpl
->m_aResults
.size() )
318 xResultSet
->rowCountChanged(
319 nOldCount
, m_pImpl
->m_aResults
.size() );
321 xResultSet
->rowCountFinal();
324 return m_pImpl
->m_aResults
.size();
329 sal_uInt32
HierarchyResultSetDataSupplier::currentCount()
331 return m_pImpl
->m_aResults
.size();
336 bool HierarchyResultSetDataSupplier::isCountFinal()
338 return m_pImpl
->m_bCountFinal
;
343 uno::Reference
< sdbc::XRow
>
344 HierarchyResultSetDataSupplier::queryPropertyValues( sal_uInt32 nIndex
)
346 osl::Guard
< osl::Mutex
> aGuard( m_pImpl
->m_aMutex
);
348 if ( nIndex
< m_pImpl
->m_aResults
.size() )
350 uno::Reference
< sdbc::XRow
> xRow
351 = m_pImpl
->m_aResults
[ nIndex
]->xRow
;
359 if ( getResult( nIndex
) )
361 HierarchyContentProperties
aData(
362 m_pImpl
->m_aResults
[ nIndex
]->aData
);
364 uno::Reference
< sdbc::XRow
> xRow
365 = HierarchyContent::getPropertyValues(
367 getResultSet()->getProperties(),
369 static_cast< HierarchyContentProvider
* >(
370 m_pImpl
->m_xContent
->getProvider().get() ),
371 queryContentIdentifierString( nIndex
) );
372 m_pImpl
->m_aResults
[ nIndex
]->xRow
= xRow
;
376 return uno::Reference
< sdbc::XRow
>();
381 void HierarchyResultSetDataSupplier::releasePropertyValues( sal_uInt32 nIndex
)
383 osl::Guard
< osl::Mutex
> aGuard( m_pImpl
->m_aMutex
);
385 if ( nIndex
< m_pImpl
->m_aResults
.size() )
386 m_pImpl
->m_aResults
[ nIndex
]->xRow
= uno::Reference
< sdbc::XRow
>();
391 void HierarchyResultSetDataSupplier::close()
397 void HierarchyResultSetDataSupplier::validate()
398 throw( ucb::ResultSetException
)
403 bool HierarchyResultSetDataSupplier::checkResult(
404 const HierarchyEntryData
& rResult
)
406 switch ( m_pImpl
->m_nOpenMode
)
408 case ucb::OpenMode::FOLDERS
:
409 if ( rResult
.getType() == HierarchyEntryData::LINK
)
416 case ucb::OpenMode::DOCUMENTS
:
417 if ( rResult
.getType() == HierarchyEntryData::FOLDER
)
419 // Entry is a folder.
424 case ucb::OpenMode::ALL
:
432 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */