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( ChildrenProvider* pChildrenProvider, sal_Int32 nOpenMode )
32 0 : : m_pChildrenProvider( pChildrenProvider ), mnOpenMode(nOpenMode), mbCountFinal(false)
33 : {
34 0 : }
35 :
36 0 : bool DataSupplier::getData()
37 : {
38 0 : if ( mbCountFinal )
39 0 : return true;
40 :
41 0 : list< uno::Reference< ucb::XContent > > aChildren = m_pChildrenProvider->getChildren( );
42 :
43 : // Loop over the results and filter them
44 0 : for ( list< uno::Reference< ucb::XContent > >::iterator it = aChildren.begin();
45 0 : it != aChildren.end(); ++it )
46 : {
47 0 : rtl::OUString sContentType = ( *it )->getContentType( );
48 0 : bool bIsFolder = sContentType != CMIS_FILE_TYPE;
49 0 : if ( ( mnOpenMode == ucb::OpenMode::FOLDERS && bIsFolder ) ||
50 0 : ( mnOpenMode == ucb::OpenMode::DOCUMENTS && !bIsFolder ) ||
51 : ( mnOpenMode == ucb::OpenMode::ALL ) )
52 : {
53 0 : maResults.push_back( new ResultListEntry( *it ) );
54 : }
55 0 : }
56 0 : mbCountFinal = sal_True;
57 :
58 0 : return true;
59 : }
60 :
61 0 : DataSupplier::~DataSupplier()
62 : {
63 0 : while ( maResults.size( ) > 0 )
64 : {
65 0 : ResultListEntry* back = maResults.back( );
66 0 : maResults.pop_back( );
67 0 : delete( back );
68 : }
69 0 : }
70 :
71 0 : ::rtl::OUString DataSupplier::queryContentIdentifierString( sal_uInt32 nIndex )
72 : {
73 0 : return queryContentIdentifier( nIndex )->getContentIdentifier( );
74 : }
75 :
76 0 : uno::Reference< ucb::XContentIdentifier > DataSupplier::queryContentIdentifier( sal_uInt32 nIndex )
77 : {
78 0 : return queryContent( nIndex )->getIdentifier( );
79 : }
80 :
81 0 : uno::Reference< ucb::XContent > DataSupplier::queryContent( sal_uInt32 nIndex )
82 : {
83 0 : if ( nIndex > maResults.size() )
84 0 : getData( );
85 :
86 0 : return maResults[ nIndex ]->xContent;
87 : }
88 :
89 0 : sal_Bool DataSupplier::getResult( sal_uInt32 nIndex )
90 : {
91 0 : if ( maResults.size() > nIndex ) // Result already present.
92 0 : return sal_True;
93 :
94 0 : if ( getData() && maResults.size() > nIndex )
95 0 : return sal_True;
96 :
97 0 : return sal_False;
98 : }
99 :
100 0 : sal_uInt32 DataSupplier::totalCount()
101 : {
102 0 : getData();
103 0 : return maResults.size();
104 : }
105 :
106 0 : sal_uInt32 DataSupplier::currentCount()
107 : {
108 0 : return maResults.size();
109 : }
110 :
111 0 : sal_Bool DataSupplier::isCountFinal()
112 : {
113 0 : return mbCountFinal;
114 : }
115 :
116 0 : uno::Reference< sdbc::XRow > DataSupplier::queryPropertyValues( sal_uInt32 nIndex )
117 : {
118 0 : if ( nIndex < maResults.size() )
119 : {
120 0 : uno::Reference< sdbc::XRow > xRow = maResults[ nIndex ]->xRow;
121 0 : if ( xRow.is() )
122 : {
123 : // Already cached.
124 0 : return xRow;
125 0 : }
126 : }
127 :
128 0 : if ( getResult( nIndex ) )
129 : {
130 0 : uno::Reference< ucb::XContent > xContent( queryContent( nIndex ) );
131 0 : if ( xContent.is() )
132 : {
133 : try
134 : {
135 : uno::Reference< ucb::XCommandProcessor > xCmdProc(
136 0 : xContent, uno::UNO_QUERY_THROW );
137 0 : sal_Int32 nCmdId( xCmdProc->createCommandIdentifier() );
138 0 : ucb::Command aCmd;
139 0 : aCmd.Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("getPropertyValues"));
140 0 : aCmd.Handle = -1;
141 0 : aCmd.Argument <<= getResultSet()->getProperties();
142 0 : uno::Any aResult( xCmdProc->execute(
143 0 : aCmd, nCmdId, getResultSet()->getEnvironment() ) );
144 0 : uno::Reference< sdbc::XRow > xRow;
145 0 : if ( aResult >>= xRow )
146 : {
147 0 : maResults[ nIndex ]->xRow = xRow;
148 0 : return xRow;
149 0 : }
150 : }
151 0 : catch ( uno::Exception const & )
152 : {
153 : }
154 0 : }
155 : }
156 0 : return uno::Reference< sdbc::XRow >();
157 : }
158 :
159 0 : void DataSupplier::releasePropertyValues( sal_uInt32 nIndex )
160 : {
161 0 : if ( nIndex < maResults.size() )
162 0 : maResults[ nIndex ]->xRow = uno::Reference< sdbc::XRow >();
163 0 : }
164 :
165 0 : void DataSupplier::close()
166 : {
167 0 : }
168 :
169 0 : void DataSupplier::validate() throw( ucb::ResultSetException )
170 : {
171 0 : }
172 :
173 0 : }
174 :
175 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|