Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : /**************************************************************************
31 : : TODO
32 : : **************************************************************************
33 : :
34 : : *************************************************************************/
35 : :
36 : : #include <vector>
37 : : #include <ucbhelper/contentidentifier.hxx>
38 : : #include "hierarchydatasupplier.hxx"
39 : : #include "hierarchyprovider.hxx"
40 : : #include "hierarchycontent.hxx"
41 : :
42 : : using namespace com::sun::star;
43 : : using namespace hierarchy_ucp;
44 : :
45 : : namespace hierarchy_ucp
46 : : {
47 : :
48 : : //=========================================================================
49 : : //
50 : : // struct ResultListEntry.
51 : : //
52 : : //=========================================================================
53 : :
54 : 26 : struct ResultListEntry
55 : : {
56 : : rtl::OUString aId;
57 : : uno::Reference< ucb::XContentIdentifier > xId;
58 : : uno::Reference< ucb::XContent > xContent;
59 : : uno::Reference< sdbc::XRow > xRow;
60 : : HierarchyEntryData aData;
61 : :
62 : 26 : ResultListEntry( const HierarchyEntryData& rEntry ) : aData( rEntry ) {}
63 : : };
64 : :
65 : : //=========================================================================
66 : : //
67 : : // ResultList.
68 : : //
69 : : //=========================================================================
70 : :
71 : : typedef std::vector< ResultListEntry* > ResultList;
72 : :
73 : : //=========================================================================
74 : : //
75 : : // struct DataSupplier_Impl.
76 : : //
77 : : //=========================================================================
78 : :
79 : : struct DataSupplier_Impl
80 : : {
81 : : osl::Mutex m_aMutex;
82 : : ResultList m_aResults;
83 : : rtl::Reference< HierarchyContent > m_xContent;
84 : : uno::Reference< lang::XMultiServiceFactory > m_xSMgr;
85 : : HierarchyEntry m_aFolder;
86 : : HierarchyEntry::iterator m_aIterator;
87 : : sal_Int32 m_nOpenMode;
88 : : sal_Bool m_bCountFinal;
89 : :
90 : 10 : DataSupplier_Impl(
91 : : const uno::Reference< lang::XMultiServiceFactory >& rxSMgr,
92 : : const rtl::Reference< HierarchyContent >& rContent,
93 : : sal_Int32 nOpenMode )
94 : : : m_xContent( rContent ), m_xSMgr( rxSMgr ),
95 : : m_aFolder( rxSMgr,
96 : : static_cast< HierarchyContentProvider * >(
97 : 10 : rContent->getProvider().get() ),
98 [ + - ][ + - ]: 20 : rContent->getIdentifier()->getContentIdentifier() ),
99 [ + - ]: 40 : m_nOpenMode( nOpenMode ), m_bCountFinal( sal_False ) {}
[ + - + - ]
[ + - ]
100 : : ~DataSupplier_Impl();
101 : : };
102 : :
103 : : //=========================================================================
104 [ + - ][ + - ]: 10 : DataSupplier_Impl::~DataSupplier_Impl()
105 : : {
106 [ + - ]: 10 : ResultList::const_iterator it = m_aResults.begin();
107 [ + - ]: 10 : ResultList::const_iterator end = m_aResults.end();
108 : :
109 [ + - ][ + + ]: 36 : while ( it != end )
110 : : {
111 [ + - ][ + - ]: 26 : delete (*it);
112 : 26 : ++it;
113 : : }
114 : 10 : }
115 : :
116 : : }
117 : :
118 : : //=========================================================================
119 : : //=========================================================================
120 : : //
121 : : // HierarchyResultSetDataSupplier Implementation.
122 : : //
123 : : //=========================================================================
124 : : //=========================================================================
125 : :
126 : 10 : HierarchyResultSetDataSupplier::HierarchyResultSetDataSupplier(
127 : : const uno::Reference< lang::XMultiServiceFactory >& rxSMgr,
128 : : const rtl::Reference< HierarchyContent >& rContent,
129 : : sal_Int32 nOpenMode )
130 [ + - ][ + - ]: 10 : : m_pImpl( new DataSupplier_Impl( rxSMgr, rContent, nOpenMode ) )
131 : : {
132 : 10 : }
133 : :
134 : : //=========================================================================
135 : : // virtual
136 : 10 : HierarchyResultSetDataSupplier::~HierarchyResultSetDataSupplier()
137 : : {
138 [ + - ][ + - ]: 10 : delete m_pImpl;
139 [ - + ]: 20 : }
140 : :
141 : : //=========================================================================
142 : : // virtual
143 : 32 : rtl::OUString HierarchyResultSetDataSupplier::queryContentIdentifierString(
144 : : sal_uInt32 nIndex )
145 : : {
146 [ + - ]: 32 : osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
147 : :
148 [ + - ]: 32 : if ( nIndex < m_pImpl->m_aResults.size() )
149 : : {
150 : 32 : rtl::OUString aId = m_pImpl->m_aResults[ nIndex ]->aId;
151 [ + + ]: 32 : if ( !aId.isEmpty() )
152 : : {
153 : : // Already cached.
154 : 32 : return aId;
155 [ + + ]: 32 : }
156 : : }
157 : :
158 [ + - ][ + - ]: 26 : if ( getResult( nIndex ) )
159 : : {
160 : : rtl::OUString aId
161 [ + - ][ + - ]: 26 : = m_pImpl->m_xContent->getIdentifier()->getContentIdentifier();
[ + - ]
162 : :
163 [ + - ]: 26 : if ( ( aId.lastIndexOf( '/' ) + 1 ) != aId.getLength() )
164 : 26 : aId += rtl::OUString("/");
165 : :
166 : 26 : aId += m_pImpl->m_aResults[ nIndex ]->aData.getName();
167 : :
168 : 26 : m_pImpl->m_aResults[ nIndex ]->aId = aId;
169 : 26 : return aId;
170 : : }
171 [ + - ]: 32 : return rtl::OUString();
172 : : }
173 : :
174 : : //=========================================================================
175 : : // virtual
176 : : uno::Reference< ucb::XContentIdentifier >
177 : 0 : HierarchyResultSetDataSupplier::queryContentIdentifier( sal_uInt32 nIndex )
178 : : {
179 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
180 : :
181 [ # # ]: 0 : if ( nIndex < m_pImpl->m_aResults.size() )
182 : : {
183 : : uno::Reference< ucb::XContentIdentifier > xId
184 : 0 : = m_pImpl->m_aResults[ nIndex ]->xId;
185 [ # # ]: 0 : if ( xId.is() )
186 : : {
187 : : // Already cached.
188 : 0 : return xId;
189 [ # # ]: 0 : }
190 : : }
191 : :
192 [ # # ]: 0 : rtl::OUString aId = queryContentIdentifierString( nIndex );
193 [ # # ]: 0 : if ( !aId.isEmpty() )
194 : : {
195 : : uno::Reference< ucb::XContentIdentifier > xId
196 [ # # ][ # # ]: 0 : = new ::ucbhelper::ContentIdentifier( aId );
[ # # ]
197 [ # # ]: 0 : m_pImpl->m_aResults[ nIndex ]->xId = xId;
198 : 0 : return xId;
199 : : }
200 [ # # ]: 0 : return uno::Reference< ucb::XContentIdentifier >();
201 : : }
202 : :
203 : : //=========================================================================
204 : : // virtual
205 : : uno::Reference< ucb::XContent >
206 : 0 : HierarchyResultSetDataSupplier::queryContent( sal_uInt32 nIndex )
207 : : {
208 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
209 : :
210 [ # # ]: 0 : if ( nIndex < m_pImpl->m_aResults.size() )
211 : : {
212 : : uno::Reference< ucb::XContent > xContent
213 : 0 : = m_pImpl->m_aResults[ nIndex ]->xContent;
214 [ # # ]: 0 : if ( xContent.is() )
215 : : {
216 : : // Already cached.
217 : 0 : return xContent;
218 [ # # ]: 0 : }
219 : : }
220 : :
221 : : uno::Reference< ucb::XContentIdentifier > xId
222 [ # # ]: 0 : = queryContentIdentifier( nIndex );
223 [ # # ]: 0 : if ( xId.is() )
224 : : {
225 : : try
226 : : {
227 : : uno::Reference< ucb::XContent > xContent
228 [ # # ]: 0 : = m_pImpl->m_xContent->getProvider()->queryContent( xId );
229 [ # # ]: 0 : m_pImpl->m_aResults[ nIndex ]->xContent = xContent;
230 [ # # ]: 0 : return xContent;
231 : :
232 : : }
233 [ # # ]: 0 : catch ( ucb::IllegalIdentifierException const & )
234 : : {
235 : : }
236 : : }
237 [ # # ]: 0 : return uno::Reference< ucb::XContent >();
238 : : }
239 : :
240 : : //=========================================================================
241 : : // virtual
242 : 54 : sal_Bool HierarchyResultSetDataSupplier::getResult( sal_uInt32 nIndex )
243 : : {
244 [ + - ]: 54 : osl::ClearableGuard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
245 : :
246 [ + + ]: 54 : if ( m_pImpl->m_aResults.size() > nIndex )
247 : : {
248 : : // Result already present.
249 : 52 : return sal_True;
250 : : }
251 : :
252 : : // Result not (yet) present.
253 : :
254 [ - + ]: 2 : if ( m_pImpl->m_bCountFinal )
255 : 0 : return sal_False;
256 : :
257 : : // Try to obtain result...
258 : :
259 : 2 : sal_uInt32 nOldCount = m_pImpl->m_aResults.size();
260 : 2 : sal_Bool bFound = sal_False;
261 : 2 : sal_uInt32 nPos = nOldCount;
262 : :
263 [ + - ][ - + ]: 2 : while ( m_pImpl->m_aFolder.next( m_pImpl->m_aIterator ) )
264 : : {
265 [ # # ]: 0 : const HierarchyEntryData& rResult = *m_pImpl->m_aIterator;
266 [ # # ]: 0 : if ( checkResult( rResult ) )
267 : : {
268 [ # # ][ # # ]: 0 : m_pImpl->m_aResults.push_back( new ResultListEntry( rResult ) );
[ # # ]
269 : :
270 [ # # ]: 0 : if ( nPos == nIndex )
271 : : {
272 : : // Result obtained.
273 : 0 : bFound = sal_True;
274 : 0 : break;
275 : : }
276 : : }
277 : 0 : nPos++;
278 : : }
279 : :
280 [ + - ]: 2 : if ( !bFound )
281 : 2 : m_pImpl->m_bCountFinal = sal_True;
282 : :
283 [ + - ]: 2 : rtl::Reference< ::ucbhelper::ResultSet > xResultSet = getResultSet().get();
284 [ + - ]: 2 : if ( xResultSet.is() )
285 : : {
286 : : // Callbacks follow!
287 [ + - ]: 2 : aGuard.clear();
288 : :
289 [ - + ]: 2 : if ( nOldCount < m_pImpl->m_aResults.size() )
290 : : xResultSet->rowCountChanged(
291 [ # # ]: 0 : nOldCount, m_pImpl->m_aResults.size() );
292 : :
293 [ + - ]: 2 : if ( m_pImpl->m_bCountFinal )
294 [ + - ]: 2 : xResultSet->rowCountFinal();
295 : : }
296 : :
297 [ + - ]: 54 : return bFound;
298 : : }
299 : :
300 : : //=========================================================================
301 : : // virtual
302 : 168 : sal_uInt32 HierarchyResultSetDataSupplier::totalCount()
303 : : {
304 [ + - ]: 168 : osl::ClearableGuard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
305 : :
306 [ + + ]: 168 : if ( m_pImpl->m_bCountFinal )
307 : 160 : return m_pImpl->m_aResults.size();
308 : :
309 : 8 : sal_uInt32 nOldCount = m_pImpl->m_aResults.size();
310 : :
311 [ + - ][ + + ]: 34 : while ( m_pImpl->m_aFolder.next( m_pImpl->m_aIterator ) )
312 : : {
313 [ + - ]: 26 : const HierarchyEntryData& rResult = *m_pImpl->m_aIterator;
314 [ + - ]: 26 : if ( checkResult( rResult ) )
315 [ + - ][ + - ]: 26 : m_pImpl->m_aResults.push_back( new ResultListEntry( rResult ) );
[ + - ]
316 : : }
317 : :
318 : 8 : m_pImpl->m_bCountFinal = sal_True;
319 : :
320 [ + - ]: 8 : rtl::Reference< ::ucbhelper::ResultSet > xResultSet = getResultSet().get();
321 [ + - ]: 8 : if ( xResultSet.is() )
322 : : {
323 : : // Callbacks follow!
324 [ + - ]: 8 : aGuard.clear();
325 : :
326 [ + + ]: 8 : if ( nOldCount < m_pImpl->m_aResults.size() )
327 : : xResultSet->rowCountChanged(
328 [ + - ]: 4 : nOldCount, m_pImpl->m_aResults.size() );
329 : :
330 [ + - ]: 8 : xResultSet->rowCountFinal();
331 : : }
332 : :
333 [ + - ]: 168 : return m_pImpl->m_aResults.size();
334 : : }
335 : :
336 : : //=========================================================================
337 : : // virtual
338 : 0 : sal_uInt32 HierarchyResultSetDataSupplier::currentCount()
339 : : {
340 : 0 : return m_pImpl->m_aResults.size();
341 : : }
342 : :
343 : : //=========================================================================
344 : : // virtual
345 : 0 : sal_Bool HierarchyResultSetDataSupplier::isCountFinal()
346 : : {
347 : 0 : return m_pImpl->m_bCountFinal;
348 : : }
349 : :
350 : : //=========================================================================
351 : : // virtual
352 : : uno::Reference< sdbc::XRow >
353 : 154 : HierarchyResultSetDataSupplier::queryPropertyValues( sal_uInt32 nIndex )
354 : : {
355 [ + - ]: 154 : osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
356 : :
357 [ + - ]: 154 : if ( nIndex < m_pImpl->m_aResults.size() )
358 : : {
359 : : uno::Reference< sdbc::XRow > xRow
360 : 154 : = m_pImpl->m_aResults[ nIndex ]->xRow;
361 [ + + ]: 154 : if ( xRow.is() )
362 : : {
363 : : // Already cached.
364 : 154 : return xRow;
365 [ + + ]: 154 : }
366 : : }
367 : :
368 [ + - ][ + - ]: 26 : if ( getResult( nIndex ) )
369 : : {
370 : : HierarchyContentProperties aData(
371 [ + - ]: 26 : m_pImpl->m_aResults[ nIndex ]->aData );
372 : :
373 : : uno::Reference< sdbc::XRow > xRow
374 : : = HierarchyContent::getPropertyValues(
375 : : m_pImpl->m_xSMgr,
376 [ + - ][ + - ]: 52 : getResultSet()->getProperties(),
377 : : aData,
378 : : static_cast< HierarchyContentProvider * >(
379 : 26 : m_pImpl->m_xContent->getProvider().get() ),
380 [ + - ][ + - ]: 78 : queryContentIdentifierString( nIndex ) );
381 [ + - ]: 26 : m_pImpl->m_aResults[ nIndex ]->xRow = xRow;
382 : 26 : return xRow;
383 : : }
384 : :
385 [ + - ]: 154 : return uno::Reference< sdbc::XRow >();
386 : : }
387 : :
388 : : //=========================================================================
389 : : // virtual
390 : 0 : void HierarchyResultSetDataSupplier::releasePropertyValues( sal_uInt32 nIndex )
391 : : {
392 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
393 : :
394 [ # # ]: 0 : if ( nIndex < m_pImpl->m_aResults.size() )
395 [ # # ][ # # ]: 0 : m_pImpl->m_aResults[ nIndex ]->xRow = uno::Reference< sdbc::XRow >();
396 : 0 : }
397 : :
398 : : //=========================================================================
399 : : // virtual
400 : 0 : void HierarchyResultSetDataSupplier::close()
401 : : {
402 : 0 : }
403 : :
404 : : //=========================================================================
405 : : // virtual
406 : 324 : void HierarchyResultSetDataSupplier::validate()
407 : : throw( ucb::ResultSetException )
408 : : {
409 : 324 : }
410 : :
411 : : //=========================================================================
412 : 26 : sal_Bool HierarchyResultSetDataSupplier::checkResult(
413 : : const HierarchyEntryData& rResult )
414 : : {
415 [ + + - ]: 26 : switch ( m_pImpl->m_nOpenMode )
416 : : {
417 : : case ucb::OpenMode::FOLDERS:
418 [ - + ]: 6 : if ( rResult.getType() == HierarchyEntryData::LINK )
419 : : {
420 : : // Entry is a link.
421 : 0 : return sal_False;
422 : : }
423 : 6 : break;
424 : :
425 : : case ucb::OpenMode::DOCUMENTS:
426 [ - + ]: 20 : if ( rResult.getType() == HierarchyEntryData::FOLDER )
427 : : {
428 : : // Entry is a folder.
429 : 0 : return sal_False;
430 : : }
431 : 20 : break;
432 : :
433 : : case ucb::OpenMode::ALL:
434 : : default:
435 : 0 : break;
436 : : }
437 : :
438 : 26 : return sal_True;
439 : : }
440 : :
441 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|