Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
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 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
20 : : #include <vector>
21 : :
22 : : #include <ucbhelper/contentidentifier.hxx>
23 : : #include <ucbhelper/providerhelper.hxx>
24 : :
25 : : #include "myucp_datasupplier.hxx"
26 : : #include "ContentHelper.hxx"
27 : : #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
28 : : #include <tools/debug.hxx>
29 : :
30 : : using namespace ::com::sun::star::uno;
31 : : using namespace ::com::sun::star::ucb;
32 : : using namespace ::com::sun::star::beans;
33 : : using namespace ::com::sun::star::lang;
34 : : using namespace ::com::sun::star::sdbc;
35 : : using namespace ::com::sun::star::io;
36 : : using namespace ::com::sun::star::container;
37 : :
38 : : // @@@ Adjust namespace name.
39 : : using namespace dbaccess;
40 : :
41 : : // @@@ Adjust namespace name.
42 : : namespace dbaccess
43 : : {
44 : :
45 : : //=========================================================================
46 : : //
47 : : // struct ResultListEntry.
48 : : //
49 : : //=========================================================================
50 : :
51 : 0 : struct ResultListEntry
52 : : {
53 : : rtl::OUString aId;
54 : : Reference< XContentIdentifier > xId;
55 : : ::rtl::Reference< OContentHelper > xContent;
56 : : Reference< XRow > xRow;
57 : : const ContentProperties& rData;
58 : :
59 : 0 : ResultListEntry( const ContentProperties& rEntry ) : rData( rEntry ) {}
60 : : };
61 : :
62 : : //=========================================================================
63 : : //
64 : : // ResultList.
65 : : //
66 : : //=========================================================================
67 : :
68 : : typedef std::vector< ResultListEntry* > ResultList;
69 : :
70 : : //=========================================================================
71 : : //
72 : : // struct DataSupplier_Impl.
73 : : //
74 : : //=========================================================================
75 : :
76 : : struct DataSupplier_Impl
77 : : {
78 : : osl::Mutex m_aMutex;
79 : : ResultList m_aResults;
80 : : rtl::Reference< ODocumentContainer > m_xContent;
81 : : Reference< XMultiServiceFactory > m_xSMgr;
82 : : sal_Int32 m_nOpenMode;
83 : : sal_Bool m_bCountFinal;
84 : :
85 : 0 : DataSupplier_Impl( const Reference< XMultiServiceFactory >& rxSMgr,
86 : : const rtl::Reference< ODocumentContainer >& rContent,
87 : : sal_Int32 nOpenMode )
88 : : : m_xContent(rContent)
89 : : , m_xSMgr( rxSMgr )
90 : : , m_nOpenMode( nOpenMode )
91 [ # # ]: 0 : , m_bCountFinal( sal_False ) {}
92 : : ~DataSupplier_Impl();
93 : : };
94 : :
95 : : //=========================================================================
96 : 0 : DataSupplier_Impl::~DataSupplier_Impl()
97 : : {
98 [ # # ]: 0 : ResultList::const_iterator it = m_aResults.begin();
99 [ # # ]: 0 : ResultList::const_iterator end = m_aResults.end();
100 : :
101 [ # # ][ # # ]: 0 : while ( it != end )
102 : : {
103 [ # # ][ # # ]: 0 : delete (*it);
104 : 0 : ++it;
105 : : }
106 : 0 : }
107 : :
108 : : }
109 : :
110 : : //=========================================================================
111 : : //
112 : : // DataSupplier Implementation.
113 : : //
114 : : //=========================================================================
115 : : DBG_NAME(DataSupplier)
116 : :
117 : 0 : DataSupplier::DataSupplier( const Reference< XMultiServiceFactory >& rxSMgr,
118 : : const rtl::Reference< ODocumentContainer >& rContent,
119 : : sal_Int32 nOpenMode )
120 [ # # ][ # # ]: 0 : : m_pImpl( new DataSupplier_Impl( rxSMgr, rContent,nOpenMode ) )
121 : : {
122 : : DBG_CTOR(DataSupplier,NULL);
123 : :
124 : 0 : }
125 : :
126 [ # # ]: 0 : DataSupplier::~DataSupplier()
127 : : {
128 : :
129 : : DBG_DTOR(DataSupplier,NULL);
130 [ # # ]: 0 : }
131 : :
132 : 0 : rtl::OUString DataSupplier::queryContentIdentifierString( sal_uInt32 nIndex )
133 : : {
134 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
135 : :
136 [ # # ]: 0 : if ( (size_t)nIndex < m_pImpl->m_aResults.size() )
137 : : {
138 : 0 : rtl::OUString aId = m_pImpl->m_aResults[ nIndex ]->aId;
139 [ # # ]: 0 : if ( !aId.isEmpty() )
140 : : {
141 : : // Already cached.
142 : 0 : return aId;
143 [ # # ]: 0 : }
144 : : }
145 : :
146 [ # # ][ # # ]: 0 : if ( getResult( nIndex ) )
147 : : {
148 : : rtl::OUString aId
149 [ # # ][ # # ]: 0 : = m_pImpl->m_xContent->getIdentifier()->getContentIdentifier();
[ # # ]
150 : :
151 [ # # ]: 0 : if ( !aId.isEmpty() )
152 [ # # ]: 0 : aId += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/"));
153 : :
154 : 0 : aId += m_pImpl->m_aResults[ nIndex ]->rData.aTitle;
155 : :
156 : 0 : m_pImpl->m_aResults[ nIndex ]->aId = aId;
157 : 0 : return aId;
158 : : }
159 [ # # ]: 0 : return rtl::OUString();
160 : : }
161 : :
162 : : Reference< XContentIdentifier >
163 : 0 : DataSupplier::queryContentIdentifier( sal_uInt32 nIndex )
164 : : {
165 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
166 : :
167 [ # # ]: 0 : if ( (size_t)nIndex < m_pImpl->m_aResults.size() )
168 : : {
169 : 0 : Reference< XContentIdentifier > xId = m_pImpl->m_aResults[ nIndex ]->xId;
170 [ # # ]: 0 : if ( xId.is() )
171 : : {
172 : : // Already cached.
173 : 0 : return xId;
174 [ # # ]: 0 : }
175 : : }
176 : :
177 [ # # ]: 0 : rtl::OUString aId = queryContentIdentifierString( nIndex );
178 [ # # ]: 0 : if ( !aId.isEmpty() )
179 : : {
180 [ # # ][ # # ]: 0 : Reference< XContentIdentifier > xId = new ::ucbhelper::ContentIdentifier( aId );
[ # # ]
181 [ # # ]: 0 : m_pImpl->m_aResults[ nIndex ]->xId = xId;
182 : 0 : return xId;
183 : : }
184 [ # # ]: 0 : return Reference< XContentIdentifier >();
185 : : }
186 : :
187 : : Reference< XContent >
188 : 0 : DataSupplier::queryContent( sal_uInt32 _nIndex )
189 : : {
190 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
191 : :
192 [ # # ]: 0 : if ( (size_t)_nIndex < m_pImpl->m_aResults.size() )
193 : : {
194 [ # # ][ # # ]: 0 : Reference< XContent > xContent = m_pImpl->m_aResults[ _nIndex ]->xContent.get();
195 [ # # ]: 0 : if ( xContent.is() )
196 : : {
197 : : // Already cached.
198 : 0 : return xContent;
199 [ # # ]: 0 : }
200 : : }
201 : :
202 [ # # ]: 0 : Reference< XContentIdentifier > xId = queryContentIdentifier( _nIndex );
203 [ # # ]: 0 : if ( xId.is() )
204 : : {
205 : : try
206 : : {
207 : 0 : Reference< XContent > xContent;
208 [ # # ][ # # ]: 0 : ::rtl::OUString sName = xId->getContentIdentifier();
209 : 0 : sal_Int32 nIndex = sName.lastIndexOf('/') + 1;
210 : 0 : sName = sName.getToken(0,'/',nIndex);
211 : :
212 [ # # ][ # # ]: 0 : m_pImpl->m_aResults[ _nIndex ]->xContent = m_pImpl->m_xContent->getContent(sName);
213 : :
214 [ # # ][ # # ]: 0 : xContent = m_pImpl->m_aResults[ _nIndex ]->xContent.get();
215 [ # # ]: 0 : return xContent;
216 : :
217 : : }
218 [ # # ]: 0 : catch ( IllegalIdentifierException& )
219 : : {
220 : : }
221 : : }
222 [ # # ]: 0 : return Reference< XContent >();
223 : : }
224 : :
225 : 0 : sal_Bool DataSupplier::getResult( sal_uInt32 nIndex )
226 : : {
227 [ # # ]: 0 : osl::ClearableGuard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
228 : :
229 [ # # ]: 0 : if ( (size_t)nIndex < m_pImpl->m_aResults.size() )
230 : : {
231 : : // Result already present.
232 : 0 : return sal_True;
233 : : }
234 : :
235 : : // Result not (yet) present.
236 : :
237 [ # # ]: 0 : if ( m_pImpl->m_bCountFinal )
238 : 0 : return sal_False;
239 : :
240 : : // Try to obtain result...
241 : :
242 : 0 : sal_uInt32 nOldCount = m_pImpl->m_aResults.size();
243 : 0 : sal_Bool bFound = sal_False;
244 : 0 : sal_uInt32 nPos = nOldCount;
245 : :
246 : : // @@@ Obtain data and put it into result list...
247 [ # # ]: 0 : Sequence< ::rtl::OUString> aSeq = m_pImpl->m_xContent->getElementNames();
248 [ # # ]: 0 : if ( nIndex < sal::static_int_cast< sal_uInt32 >( aSeq.getLength() ) )
249 : : {
250 : 0 : const ::rtl::OUString* pIter = aSeq.getConstArray();
251 : 0 : const ::rtl::OUString* pEnd = pIter + aSeq.getLength();
252 [ # # ]: 0 : for(pIter = pIter + nPos;pIter != pEnd;++pIter,++nPos)
253 : : {
254 : 0 : m_pImpl->m_aResults.push_back(
255 [ # # ][ # # ]: 0 : new ResultListEntry( m_pImpl->m_xContent->getContent(*pIter)->getContentProperties() ) );
[ # # ]
[ # # # # ]
256 : :
257 [ # # ]: 0 : if ( nPos == nIndex )
258 : : {
259 : : // Result obtained.
260 : 0 : bFound = sal_True;
261 : 0 : break;
262 : : }
263 : : }
264 : : }
265 : :
266 [ # # ]: 0 : if ( !bFound )
267 : 0 : m_pImpl->m_bCountFinal = sal_True;
268 : :
269 [ # # ]: 0 : rtl::Reference< ::ucbhelper::ResultSet > xResultSet = getResultSet().get();
270 [ # # ]: 0 : if ( xResultSet.is() )
271 : : {
272 : : // Callbacks follow!
273 [ # # ]: 0 : aGuard.clear();
274 : :
275 [ # # ]: 0 : if ( (size_t)nOldCount < m_pImpl->m_aResults.size() )
276 : : xResultSet->rowCountChanged(
277 [ # # ]: 0 : nOldCount, m_pImpl->m_aResults.size() );
278 : :
279 [ # # ]: 0 : if ( m_pImpl->m_bCountFinal )
280 [ # # ]: 0 : xResultSet->rowCountFinal();
281 : : }
282 : :
283 [ # # ][ # # ]: 0 : return bFound;
284 : : }
285 : :
286 : 0 : sal_uInt32 DataSupplier::totalCount()
287 : : {
288 [ # # ]: 0 : osl::ClearableGuard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
289 : :
290 [ # # ]: 0 : if ( m_pImpl->m_bCountFinal )
291 : 0 : return m_pImpl->m_aResults.size();
292 : :
293 : 0 : sal_uInt32 nOldCount = m_pImpl->m_aResults.size();
294 : :
295 : : // @@@ Obtain data and put it into result list...
296 [ # # ]: 0 : Sequence< ::rtl::OUString> aSeq = m_pImpl->m_xContent->getElementNames();
297 : 0 : const ::rtl::OUString* pIter = aSeq.getConstArray();
298 : 0 : const ::rtl::OUString* pEnd = pIter + aSeq.getLength();
299 [ # # ]: 0 : for(;pIter != pEnd;++pIter)
300 : 0 : m_pImpl->m_aResults.push_back(
301 [ # # ][ # # ]: 0 : new ResultListEntry( m_pImpl->m_xContent->getContent(*pIter)->getContentProperties() ) );
[ # # ]
[ # # # # ]
302 : :
303 : 0 : m_pImpl->m_bCountFinal = sal_True;
304 : :
305 [ # # ]: 0 : rtl::Reference< ::ucbhelper::ResultSet > xResultSet = getResultSet().get();
306 [ # # ]: 0 : if ( xResultSet.is() )
307 : : {
308 : : // Callbacks follow!
309 [ # # ]: 0 : aGuard.clear();
310 : :
311 [ # # ]: 0 : if ( (size_t)nOldCount < m_pImpl->m_aResults.size() )
312 : : xResultSet->rowCountChanged(
313 [ # # ]: 0 : nOldCount, m_pImpl->m_aResults.size() );
314 : :
315 [ # # ]: 0 : xResultSet->rowCountFinal();
316 : : }
317 : :
318 [ # # ][ # # ]: 0 : return m_pImpl->m_aResults.size();
319 : : }
320 : :
321 : 0 : sal_uInt32 DataSupplier::currentCount()
322 : : {
323 : 0 : return m_pImpl->m_aResults.size();
324 : : }
325 : :
326 : 0 : sal_Bool DataSupplier::isCountFinal()
327 : : {
328 : 0 : return m_pImpl->m_bCountFinal;
329 : : }
330 : :
331 : : Reference< XRow >
332 : 0 : DataSupplier::queryPropertyValues( sal_uInt32 nIndex )
333 : : {
334 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
335 : :
336 [ # # ]: 0 : if ( (size_t)nIndex < m_pImpl->m_aResults.size() )
337 : : {
338 : 0 : Reference< XRow > xRow = m_pImpl->m_aResults[ nIndex ]->xRow;
339 [ # # ]: 0 : if ( xRow.is() )
340 : : {
341 : : // Already cached.
342 : 0 : return xRow;
343 [ # # ]: 0 : }
344 : : }
345 : :
346 [ # # ][ # # ]: 0 : if ( getResult( nIndex ) )
347 : : {
348 [ # # ]: 0 : if ( !m_pImpl->m_aResults[ nIndex ]->xContent.is() )
349 [ # # ]: 0 : queryContent(nIndex);
350 : :
351 [ # # ][ # # ]: 0 : Reference< XRow > xRow = m_pImpl->m_aResults[ nIndex ]->xContent->getPropertyValues(getResultSet()->getProperties());
[ # # ]
352 [ # # ]: 0 : m_pImpl->m_aResults[ nIndex ]->xRow = xRow;
353 : 0 : return xRow;
354 : : }
355 : :
356 [ # # ]: 0 : return Reference< XRow >();
357 : : }
358 : :
359 : 0 : void DataSupplier::releasePropertyValues( sal_uInt32 nIndex )
360 : : {
361 [ # # ]: 0 : osl::Guard< osl::Mutex > aGuard( m_pImpl->m_aMutex );
362 : :
363 [ # # ]: 0 : if ( (size_t)nIndex < m_pImpl->m_aResults.size() )
364 [ # # ][ # # ]: 0 : m_pImpl->m_aResults[ nIndex ]->xRow = Reference< XRow >();
365 : 0 : }
366 : :
367 : 0 : void DataSupplier::close()
368 : : {
369 : 0 : }
370 : :
371 : 0 : void DataSupplier::validate()
372 : : throw( ResultSetException )
373 : : {
374 : 0 : }
375 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|