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/.
12 #include <ucbhelper/contentidentifier.hxx>
13 #include <ucbhelper/providerhelper.hxx>
15 #include <com/sun/star/ucb/OpenMode.hpp>
17 #include "cmis_datasupplier.hxx"
18 #include "cmis_content.hxx"
19 #include "cmis_provider.hxx"
21 using namespace com::sun::star
;
27 typedef std::vector
< ResultListEntry
* > ResultList
;
29 DataSupplier::DataSupplier( ChildrenProvider
* pChildrenProvider
, sal_Int32 nOpenMode
)
30 : m_pChildrenProvider( pChildrenProvider
), mnOpenMode(nOpenMode
), mbCountFinal(false)
34 bool DataSupplier::getData()
39 list
< uno::Reference
< ucb::XContent
> > aChildren
= m_pChildrenProvider
->getChildren( );
41 // Loop over the results and filter them
42 for ( list
< uno::Reference
< ucb::XContent
> >::iterator it
= aChildren
.begin();
43 it
!= aChildren
.end(); ++it
)
45 OUString sContentType
= ( *it
)->getContentType( );
46 bool bIsFolder
= sContentType
!= CMIS_FILE_TYPE
;
47 if ( ( mnOpenMode
== ucb::OpenMode::FOLDERS
&& bIsFolder
) ||
48 ( mnOpenMode
== ucb::OpenMode::DOCUMENTS
&& !bIsFolder
) ||
49 ( mnOpenMode
== ucb::OpenMode::ALL
) )
51 maResults
.push_back( new ResultListEntry( *it
) );
59 DataSupplier::~DataSupplier()
61 while ( maResults
.size( ) > 0 )
63 ResultListEntry
* back
= maResults
.back( );
64 maResults
.pop_back( );
69 OUString
DataSupplier::queryContentIdentifierString( sal_uInt32 nIndex
)
71 return queryContentIdentifier( nIndex
)->getContentIdentifier( );
74 uno::Reference
< ucb::XContentIdentifier
> DataSupplier::queryContentIdentifier( sal_uInt32 nIndex
)
76 return queryContent( nIndex
)->getIdentifier( );
79 uno::Reference
< ucb::XContent
> DataSupplier::queryContent( sal_uInt32 nIndex
)
81 if ( nIndex
> maResults
.size() )
84 return maResults
[ nIndex
]->xContent
;
87 bool DataSupplier::getResult( sal_uInt32 nIndex
)
89 if ( maResults
.size() > nIndex
) // Result already present.
92 if ( getData() && maResults
.size() > nIndex
)
98 sal_uInt32
DataSupplier::totalCount()
101 return maResults
.size();
104 sal_uInt32
DataSupplier::currentCount()
106 return maResults
.size();
109 bool DataSupplier::isCountFinal()
114 uno::Reference
< sdbc::XRow
> DataSupplier::queryPropertyValues( sal_uInt32 nIndex
)
116 if ( nIndex
< maResults
.size() )
118 uno::Reference
< sdbc::XRow
> xRow
= maResults
[ nIndex
]->xRow
;
126 if ( getResult( nIndex
) )
128 uno::Reference
< ucb::XContent
> xContent( queryContent( nIndex
) );
133 uno::Reference
< ucb::XCommandProcessor
> xCmdProc(
134 xContent
, uno::UNO_QUERY_THROW
);
135 sal_Int32
nCmdId( xCmdProc
->createCommandIdentifier() );
137 aCmd
.Name
= "getPropertyValues";
139 aCmd
.Argument
<<= getResultSet()->getProperties();
140 uno::Any
aResult( xCmdProc
->execute(
141 aCmd
, nCmdId
, getResultSet()->getEnvironment() ) );
142 uno::Reference
< sdbc::XRow
> xRow
;
143 if ( aResult
>>= xRow
)
145 maResults
[ nIndex
]->xRow
= xRow
;
149 catch ( uno::Exception
const & )
154 return uno::Reference
< sdbc::XRow
>();
157 void DataSupplier::releasePropertyValues( sal_uInt32 nIndex
)
159 if ( nIndex
< maResults
.size() )
160 maResults
[ nIndex
]->xRow
= uno::Reference
< sdbc::XRow
>();
163 void DataSupplier::close()
167 void DataSupplier::validate() throw( ucb::ResultSetException
)
173 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */