Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * Copyright 2012 LibreOffice contributors.
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 : :
10 : : #include <vector>
11 : :
12 : : #include <ucbhelper/contentidentifier.hxx>
13 : : #include <ucbhelper/providerhelper.hxx>
14 : :
15 : : #include <com/sun/star/ucb/OpenMode.hpp>
16 : :
17 : : #include "cmis_datasupplier.hxx"
18 : : #include "cmis_content.hxx"
19 : : #include "cmis_provider.hxx"
20 : :
21 : : #define STD_TO_OUSTR( str ) rtl::OUString( str.c_str(), str.length( ), RTL_TEXTENCODING_UTF8 )
22 : :
23 : : using namespace com::sun::star;
24 : : using namespace std;
25 : :
26 : : namespace cmis
27 : : {
28 : :
29 : : typedef std::vector< ResultListEntry* > ResultList;
30 : :
31 : 0 : DataSupplier::DataSupplier( const uno::Reference< lang::XMultiServiceFactory >& rxSMgr,
32 : : ChildrenProvider* pChildrenProvider, sal_Int32 nOpenMode )
33 : 0 : : m_pChildrenProvider( pChildrenProvider ), m_xSMgr(rxSMgr), mnOpenMode(nOpenMode), mbCountFinal(false)
34 : : {
35 : 0 : }
36 : :
37 : 0 : bool DataSupplier::getData()
38 : : {
39 : 0 : if ( mbCountFinal )
40 : 0 : return true;
41 : :
42 : 0 : list< uno::Reference< ucb::XContent > > aChildren = m_pChildrenProvider->getChildren( );
43 : :
44 : : // Loop over the results and filter them
45 : 0 : for ( list< uno::Reference< ucb::XContent > >::iterator it = aChildren.begin();
46 : 0 : it != aChildren.end(); ++it )
47 : : {
48 : 0 : rtl::OUString sContentType = ( *it )->getContentType( );
49 : 0 : bool bIsFolder = sContentType != CMIS_FILE_TYPE;
50 : 0 : if ( ( mnOpenMode == ucb::OpenMode::FOLDERS && bIsFolder ) ||
51 : 0 : ( mnOpenMode == ucb::OpenMode::DOCUMENTS && !bIsFolder ) ||
52 : : ( mnOpenMode == ucb::OpenMode::ALL ) )
53 : : {
54 : 0 : maResults.push_back( new ResultListEntry( *it ) );
55 : : }
56 : 0 : }
57 : 0 : mbCountFinal = sal_True;
58 : :
59 : 0 : return true;
60 : : }
61 : :
62 : 0 : DataSupplier::~DataSupplier()
63 : : {
64 : 0 : while ( maResults.size( ) > 0 )
65 : : {
66 : 0 : ResultListEntry* back = maResults.back( );
67 : 0 : maResults.pop_back( );
68 : 0 : delete( back );
69 : : }
70 : 0 : }
71 : :
72 : 0 : ::rtl::OUString DataSupplier::queryContentIdentifierString( sal_uInt32 nIndex )
73 : : {
74 : 0 : return queryContentIdentifier( nIndex )->getContentIdentifier( );
75 : : }
76 : :
77 : 0 : uno::Reference< ucb::XContentIdentifier > DataSupplier::queryContentIdentifier( sal_uInt32 nIndex )
78 : : {
79 : 0 : return queryContent( nIndex )->getIdentifier( );
80 : : }
81 : :
82 : 0 : uno::Reference< ucb::XContent > DataSupplier::queryContent( sal_uInt32 nIndex )
83 : : {
84 : 0 : if ( nIndex > maResults.size() )
85 : 0 : getData( );
86 : :
87 : 0 : return maResults[ nIndex ]->xContent;
88 : : }
89 : :
90 : 0 : sal_Bool DataSupplier::getResult( sal_uInt32 nIndex )
91 : : {
92 : 0 : if ( maResults.size() > nIndex ) // Result already present.
93 : 0 : return sal_True;
94 : :
95 : 0 : if ( getData() && maResults.size() > nIndex )
96 : 0 : return sal_True;
97 : :
98 : 0 : return sal_False;
99 : : }
100 : :
101 : 0 : sal_uInt32 DataSupplier::totalCount()
102 : : {
103 : 0 : getData();
104 : 0 : return maResults.size();
105 : : }
106 : :
107 : 0 : sal_uInt32 DataSupplier::currentCount()
108 : : {
109 : 0 : return maResults.size();
110 : : }
111 : :
112 : 0 : sal_Bool DataSupplier::isCountFinal()
113 : : {
114 : 0 : return mbCountFinal;
115 : : }
116 : :
117 : 0 : uno::Reference< sdbc::XRow > DataSupplier::queryPropertyValues( sal_uInt32 nIndex )
118 : : {
119 : 0 : if ( nIndex < maResults.size() )
120 : : {
121 : 0 : uno::Reference< sdbc::XRow > xRow = maResults[ nIndex ]->xRow;
122 : 0 : if ( xRow.is() )
123 : : {
124 : : // Already cached.
125 : 0 : return xRow;
126 : 0 : }
127 : : }
128 : :
129 : 0 : if ( getResult( nIndex ) )
130 : : {
131 : 0 : uno::Reference< ucb::XContent > xContent( queryContent( nIndex ) );
132 : 0 : if ( xContent.is() )
133 : : {
134 : : try
135 : : {
136 : : uno::Reference< ucb::XCommandProcessor > xCmdProc(
137 : 0 : xContent, uno::UNO_QUERY_THROW );
138 : 0 : sal_Int32 nCmdId( xCmdProc->createCommandIdentifier() );
139 : 0 : ucb::Command aCmd;
140 : 0 : aCmd.Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("getPropertyValues"));
141 : 0 : aCmd.Handle = -1;
142 : 0 : aCmd.Argument <<= getResultSet()->getProperties();
143 : 0 : uno::Any aResult( xCmdProc->execute(
144 : 0 : aCmd, nCmdId, getResultSet()->getEnvironment() ) );
145 : 0 : uno::Reference< sdbc::XRow > xRow;
146 : 0 : if ( aResult >>= xRow )
147 : : {
148 : 0 : maResults[ nIndex ]->xRow = xRow;
149 : 0 : return xRow;
150 : 0 : }
151 : : }
152 : 0 : catch ( uno::Exception const & )
153 : : {
154 : : }
155 : 0 : }
156 : : }
157 : 0 : return uno::Reference< sdbc::XRow >();
158 : : }
159 : :
160 : 0 : void DataSupplier::releasePropertyValues( sal_uInt32 nIndex )
161 : : {
162 : 0 : if ( nIndex < maResults.size() )
163 : 0 : maResults[ nIndex ]->xRow = uno::Reference< sdbc::XRow >();
164 : 0 : }
165 : :
166 : 0 : void DataSupplier::close()
167 : : {
168 : 0 : }
169 : :
170 : 0 : void DataSupplier::validate() throw( ucb::ResultSetException )
171 : : {
172 : 0 : }
173 : :
174 : 0 : }
175 : :
176 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|