1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: myucp_datasupplier.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_dbaccess.hxx"
34 /**************************************************************************
36 **************************************************************************
38 *************************************************************************/
42 #ifndef _UCBHELPER_CONTENTIDENTIFIER_HXX
43 #include <ucbhelper/contentidentifier.hxx>
45 #ifndef _UCBHELPER_PROVIDERHELPER_HXX
46 #include <ucbhelper/providerhelper.hxx>
49 #ifndef DBA_DATASUPPLIER_HXX
50 #include "myucp_datasupplier.hxx"
52 #ifndef DBA_CONTENTHELPER_HXX
53 #include "ContentHelper.hxx"
55 #ifndef _COM_SUN_STAR_CONTAINER_XHIERARCHICALNAMEACCESS_HPP_
56 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
58 #ifndef _TOOLS_DEBUG_HXX
59 #include <tools/debug.hxx>
62 using namespace ::com::sun::star::uno
;
63 using namespace ::com::sun::star::ucb
;
64 using namespace ::com::sun::star::beans
;
65 using namespace ::com::sun::star::lang
;
66 using namespace ::com::sun::star::sdbc
;
67 using namespace ::com::sun::star::io
;
68 using namespace ::com::sun::star::container
;
70 // @@@ Adjust namespace name.
71 using namespace dbaccess
;
73 // @@@ Adjust namespace name.
77 //=========================================================================
79 // struct ResultListEntry.
81 //=========================================================================
83 struct ResultListEntry
86 Reference
< XContentIdentifier
> xId
;
87 ::rtl::Reference
< OContentHelper
> xContent
;
88 Reference
< XRow
> xRow
;
89 const ContentProperties
& rData
;
91 ResultListEntry( const ContentProperties
& rEntry
) : rData( rEntry
) {}
94 //=========================================================================
98 //=========================================================================
100 typedef std::vector
< ResultListEntry
* > ResultList
;
102 //=========================================================================
104 // struct DataSupplier_Impl.
106 //=========================================================================
108 struct DataSupplier_Impl
111 ResultList m_aResults
;
112 rtl::Reference
< ODocumentContainer
> m_xContent
;
113 Reference
< XMultiServiceFactory
> m_xSMgr
;
114 sal_Int32 m_nOpenMode
;
115 sal_Bool m_bCountFinal
;
117 DataSupplier_Impl( const Reference
< XMultiServiceFactory
>& rxSMgr
,
118 const rtl::Reference
< ODocumentContainer
>& rContent
,
119 sal_Int32 nOpenMode
)
120 : m_xContent(rContent
)
122 , m_nOpenMode( nOpenMode
)
123 , m_bCountFinal( sal_False
) {}
124 ~DataSupplier_Impl();
127 //=========================================================================
128 DataSupplier_Impl::~DataSupplier_Impl()
130 ResultList::const_iterator it
= m_aResults
.begin();
131 ResultList::const_iterator end
= m_aResults
.end();
142 //=========================================================================
143 //=========================================================================
145 // DataSupplier Implementation.
147 //=========================================================================
148 //=========================================================================
149 DBG_NAME(DataSupplier
)
151 DataSupplier::DataSupplier( const Reference
< XMultiServiceFactory
>& rxSMgr
,
152 const rtl::Reference
< ODocumentContainer
>& rContent
,
153 sal_Int32 nOpenMode
)
154 : m_pImpl( new DataSupplier_Impl( rxSMgr
, rContent
,nOpenMode
) )
156 DBG_CTOR(DataSupplier
,NULL
);
160 //=========================================================================
162 DataSupplier::~DataSupplier()
165 DBG_DTOR(DataSupplier
,NULL
);
168 //=========================================================================
170 rtl::OUString
DataSupplier::queryContentIdentifierString( sal_uInt32 nIndex
)
172 osl::Guard
< osl::Mutex
> aGuard( m_pImpl
->m_aMutex
);
174 if ( (size_t)nIndex
< m_pImpl
->m_aResults
.size() )
176 rtl::OUString aId
= m_pImpl
->m_aResults
[ nIndex
]->aId
;
177 if ( aId
.getLength() )
184 if ( getResult( nIndex
) )
187 = m_pImpl
->m_xContent
->getIdentifier()->getContentIdentifier();
189 if ( aId
.getLength() )
190 aId
+= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/"));
192 aId
+= m_pImpl
->m_aResults
[ nIndex
]->rData
.aTitle
;
194 m_pImpl
->m_aResults
[ nIndex
]->aId
= aId
;
197 return rtl::OUString();
200 //=========================================================================
202 Reference
< XContentIdentifier
>
203 DataSupplier::queryContentIdentifier( sal_uInt32 nIndex
)
205 osl::Guard
< osl::Mutex
> aGuard( m_pImpl
->m_aMutex
);
207 if ( (size_t)nIndex
< m_pImpl
->m_aResults
.size() )
209 Reference
< XContentIdentifier
> xId
= m_pImpl
->m_aResults
[ nIndex
]->xId
;
217 rtl::OUString aId
= queryContentIdentifierString( nIndex
);
218 if ( aId
.getLength() )
220 Reference
< XContentIdentifier
> xId
= new ::ucbhelper::ContentIdentifier( aId
);
221 m_pImpl
->m_aResults
[ nIndex
]->xId
= xId
;
224 return Reference
< XContentIdentifier
>();
227 //=========================================================================
229 Reference
< XContent
>
230 DataSupplier::queryContent( sal_uInt32 _nIndex
)
232 osl::Guard
< osl::Mutex
> aGuard( m_pImpl
->m_aMutex
);
234 if ( (size_t)_nIndex
< m_pImpl
->m_aResults
.size() )
236 Reference
< XContent
> xContent
= m_pImpl
->m_aResults
[ _nIndex
]->xContent
.get();
244 Reference
< XContentIdentifier
> xId
= queryContentIdentifier( _nIndex
);
249 Reference
< XContent
> xContent
;
250 ::rtl::OUString sName
= xId
->getContentIdentifier();
251 sal_Int32 nIndex
= sName
.lastIndexOf('/') + 1;
252 sName
= sName
.getToken(0,'/',nIndex
);
254 m_pImpl
->m_aResults
[ _nIndex
]->xContent
= m_pImpl
->m_xContent
->getContent(sName
);
256 xContent
= m_pImpl
->m_aResults
[ _nIndex
]->xContent
.get();
260 catch ( IllegalIdentifierException
& )
264 return Reference
< XContent
>();
267 //=========================================================================
269 sal_Bool
DataSupplier::getResult( sal_uInt32 nIndex
)
271 osl::ClearableGuard
< osl::Mutex
> aGuard( m_pImpl
->m_aMutex
);
273 if ( (size_t)nIndex
< m_pImpl
->m_aResults
.size() )
275 // Result already present.
279 // Result not (yet) present.
281 if ( m_pImpl
->m_bCountFinal
)
284 // Try to obtain result...
286 sal_uInt32 nOldCount
= m_pImpl
->m_aResults
.size();
287 sal_Bool bFound
= sal_False
;
288 sal_uInt32 nPos
= nOldCount
;
290 // @@@ Obtain data and put it into result list...
291 Sequence
< ::rtl::OUString
> aSeq
= m_pImpl
->m_xContent
->getElementNames();
292 if ( nIndex
< sal::static_int_cast
< sal_uInt32
>( aSeq
.getLength() ) )
294 const ::rtl::OUString
* pIter
= aSeq
.getConstArray();
295 const ::rtl::OUString
* pEnd
= pIter
+ aSeq
.getLength();
296 for(pIter
= pIter
+ nPos
;pIter
!= pEnd
;++pIter
,++nPos
)
298 m_pImpl
->m_aResults
.push_back(
299 new ResultListEntry( m_pImpl
->m_xContent
->getContent(*pIter
)->getContentProperties() ) );
301 if ( nPos
== nIndex
)
311 m_pImpl
->m_bCountFinal
= sal_True
;
313 rtl::Reference
< ::ucbhelper::ResultSet
> xResultSet
= getResultSet().get();
314 if ( xResultSet
.is() )
319 if ( (size_t)nOldCount
< m_pImpl
->m_aResults
.size() )
320 xResultSet
->rowCountChanged(
321 nOldCount
, m_pImpl
->m_aResults
.size() );
323 if ( m_pImpl
->m_bCountFinal
)
324 xResultSet
->rowCountFinal();
330 //=========================================================================
332 sal_uInt32
DataSupplier::totalCount()
334 osl::ClearableGuard
< osl::Mutex
> aGuard( m_pImpl
->m_aMutex
);
336 if ( m_pImpl
->m_bCountFinal
)
337 return m_pImpl
->m_aResults
.size();
339 sal_uInt32 nOldCount
= m_pImpl
->m_aResults
.size();
341 // @@@ Obtain data and put it into result list...
342 Sequence
< ::rtl::OUString
> aSeq
= m_pImpl
->m_xContent
->getElementNames();
343 const ::rtl::OUString
* pIter
= aSeq
.getConstArray();
344 const ::rtl::OUString
* pEnd
= pIter
+ aSeq
.getLength();
345 for(;pIter
!= pEnd
;++pIter
)
346 m_pImpl
->m_aResults
.push_back(
347 new ResultListEntry( m_pImpl
->m_xContent
->getContent(*pIter
)->getContentProperties() ) );
349 m_pImpl
->m_bCountFinal
= sal_True
;
351 rtl::Reference
< ::ucbhelper::ResultSet
> xResultSet
= getResultSet().get();
352 if ( xResultSet
.is() )
357 if ( (size_t)nOldCount
< m_pImpl
->m_aResults
.size() )
358 xResultSet
->rowCountChanged(
359 nOldCount
, m_pImpl
->m_aResults
.size() );
361 xResultSet
->rowCountFinal();
364 return m_pImpl
->m_aResults
.size();
367 //=========================================================================
369 sal_uInt32
DataSupplier::currentCount()
371 return m_pImpl
->m_aResults
.size();
374 //=========================================================================
376 sal_Bool
DataSupplier::isCountFinal()
378 return m_pImpl
->m_bCountFinal
;
381 //=========================================================================
384 DataSupplier::queryPropertyValues( sal_uInt32 nIndex
)
386 osl::Guard
< osl::Mutex
> aGuard( m_pImpl
->m_aMutex
);
388 if ( (size_t)nIndex
< m_pImpl
->m_aResults
.size() )
390 Reference
< XRow
> xRow
= m_pImpl
->m_aResults
[ nIndex
]->xRow
;
398 if ( getResult( nIndex
) )
400 if ( !m_pImpl
->m_aResults
[ nIndex
]->xContent
.is() )
401 queryContent(nIndex
);
403 Reference
< XRow
> xRow
= m_pImpl
->m_aResults
[ nIndex
]->xContent
->getPropertyValues(getResultSet()->getProperties());
404 m_pImpl
->m_aResults
[ nIndex
]->xRow
= xRow
;
408 return Reference
< XRow
>();
411 //=========================================================================
413 void DataSupplier::releasePropertyValues( sal_uInt32 nIndex
)
415 osl::Guard
< osl::Mutex
> aGuard( m_pImpl
->m_aMutex
);
417 if ( (size_t)nIndex
< m_pImpl
->m_aResults
.size() )
418 m_pImpl
->m_aResults
[ nIndex
]->xRow
= Reference
< XRow
>();
421 //=========================================================================
423 void DataSupplier::close()
427 //=========================================================================
429 void DataSupplier::validate()
430 throw( ResultSetException
)