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: odma_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_ucb.hxx"
34 /**************************************************************************
36 **************************************************************************
38 *************************************************************************/
41 #include <ucbhelper/contentidentifier.hxx>
42 #include <ucbhelper/providerhelper.hxx>
43 #include "odma_datasupplier.hxx"
44 #include "odma_content.hxx"
45 #include "odma_contentprops.hxx"
46 #include "odma_provider.hxx"
48 using namespace com::sun::star::beans
;
49 using namespace com::sun::star::lang
;
50 using namespace com::sun::star::ucb
;
51 using namespace com::sun::star::uno
;
52 using namespace com::sun::star::sdbc
;
59 //=========================================================================
61 // struct ResultListEntry.
63 //=========================================================================
65 struct ResultListEntry
68 Reference
< XContentIdentifier
> xId
;
69 Reference
< XContent
> xContent
;
70 Reference
< XRow
> xRow
;
71 ::rtl::Reference
<ContentProperties
> rData
;
73 ResultListEntry( const ::rtl::Reference
<ContentProperties
>& rEntry
) : rData( rEntry
) {}
76 //=========================================================================
80 //=========================================================================
82 typedef std::vector
< ResultListEntry
* > ResultList
;
84 //=========================================================================
86 // struct DataSupplier_Impl.
88 //=========================================================================
90 struct DataSupplier_Impl
93 ResultList m_aResults
;
94 rtl::Reference
< Content
> m_xContent
;
95 Reference
< XMultiServiceFactory
> m_xSMgr
;
96 // @@@ The data source and an iterator for it
98 // Entry::iterator m_aIterator;
99 sal_Int32 m_nOpenMode
;
100 sal_Bool m_bCountFinal
;
102 DataSupplier_Impl( const Reference
< XMultiServiceFactory
>& rxSMgr
,
103 const rtl::Reference
< Content
>& rContent
,
104 sal_Int32 nOpenMode
)
105 : m_xContent( rContent
), m_xSMgr( rxSMgr
),
106 // m_aFolder( rxSMgr, rContent->getIdentifier()->getContentIdentifier() ),
107 m_nOpenMode( nOpenMode
), m_bCountFinal( sal_False
) {}
108 ~DataSupplier_Impl();
111 //=========================================================================
112 DataSupplier_Impl::~DataSupplier_Impl()
114 ResultList::const_iterator it
= m_aResults
.begin();
115 ResultList::const_iterator end
= m_aResults
.end();
126 //=========================================================================
127 //=========================================================================
129 // DataSupplier Implementation.
131 //=========================================================================
132 //=========================================================================
134 DataSupplier::DataSupplier( const Reference
<XMultiServiceFactory
>& rxSMgr
,
135 const rtl::Reference
< ::odma::Content
>& rContent
,
136 sal_Int32 nOpenMode
)
137 : m_pImpl( new DataSupplier_Impl( rxSMgr
, rContent
, nOpenMode
) )
141 //=========================================================================
143 DataSupplier::~DataSupplier()
148 //=========================================================================
150 ::rtl::OUString
DataSupplier::queryContentIdentifierString( sal_uInt32 nIndex
)
152 osl::Guard
< osl::Mutex
> aGuard( m_pImpl
->m_aMutex
);
154 if ( nIndex
< m_pImpl
->m_aResults
.size() )
156 ::rtl::OUString aId
= m_pImpl
->m_aResults
[ nIndex
]->aId
;
157 if ( aId
.getLength() )
164 if ( getResult( nIndex
) )
167 = m_pImpl
->m_xContent
->getIdentifier()->getContentIdentifier();
169 aId
+= m_pImpl
->m_aResults
[ nIndex
]->rData
->m_sTitle
;
171 m_pImpl
->m_aResults
[ nIndex
]->aId
= aId
;
174 return ::rtl::OUString();
177 //=========================================================================
179 Reference
< XContentIdentifier
> DataSupplier::queryContentIdentifier(
182 osl::Guard
< osl::Mutex
> aGuard( m_pImpl
->m_aMutex
);
184 if ( nIndex
< m_pImpl
->m_aResults
.size() )
186 Reference
< XContentIdentifier
> xId
187 = m_pImpl
->m_aResults
[ nIndex
]->xId
;
195 ::rtl::OUString aId
= queryContentIdentifierString( nIndex
);
196 if ( aId
.getLength() )
198 Reference
< XContentIdentifier
> xId
199 = new ucbhelper::ContentIdentifier( aId
);
200 m_pImpl
->m_aResults
[ nIndex
]->xId
= xId
;
203 return Reference
< XContentIdentifier
>();
206 //=========================================================================
208 Reference
< XContent
> DataSupplier::queryContent( sal_uInt32 nIndex
)
210 osl::Guard
< osl::Mutex
> aGuard( m_pImpl
->m_aMutex
);
212 if ( nIndex
< m_pImpl
->m_aResults
.size() )
214 Reference
< XContent
> xContent
215 = m_pImpl
->m_aResults
[ nIndex
]->xContent
;
223 Reference
< XContentIdentifier
> xId
= queryContentIdentifier( nIndex
);
228 Reference
< XContent
> xContent
229 = m_pImpl
->m_xContent
->getProvider()->queryContent( xId
);
230 m_pImpl
->m_aResults
[ nIndex
]->xContent
= xContent
;
234 catch ( IllegalIdentifierException
& )
238 return Reference
< XContent
>();
241 //=========================================================================
243 sal_Bool
DataSupplier::getResult( sal_uInt32 nIndex
)
245 osl::ClearableGuard
< osl::Mutex
> aGuard( m_pImpl
->m_aMutex
);
247 if ( m_pImpl
->m_aResults
.size() > nIndex
)
249 // Result already present.
253 // Result not (yet) present.
255 if ( m_pImpl
->m_bCountFinal
)
258 // Try to obtain result...
260 sal_uInt32 nOldCount
= m_pImpl
->m_aResults
.size();
261 sal_Bool bFound
= sal_False
;
262 // sal_uInt32 nPos = nOldCount;
264 // @@@ Obtain data and put it into result list...
266 while ( m_pImpl->m_aFolder.next( m_pImpl->m_aIterator ) )
268 m_pImpl->m_aResults.push_back(
269 new ResultListEntry( *m_pImpl->m_aIterator ) );
271 if ( nPos == nIndex )
281 // now query for all documents in the DMS
282 OSL_ENSURE(ContentProvider::getHandle(),"No Handle!");
283 sal_Char
* pQueryId
= new sal_Char
[ODM_QUERYID_MAX
];
284 sal_Char
* lpszDMSList
= new sal_Char
[ODM_DMSID_MAX
];
286 ODMSTATUS odm
= NODMGetDMS(ODMA_ODMA_REGNAME
, lpszDMSList
);
287 lpszDMSList
[strlen(lpszDMSList
)+1] = '\0';
289 ::rtl::OString
sQuery("SELECT ODM_DOCID_LATEST, ODM_NAME");
291 DWORD dwFlags
= ODM_SPECIFIC
;
292 odm
= NODMQueryExecute(ContentProvider::getHandle(), sQuery
,dwFlags
, lpszDMSList
, pQueryId
);
293 if(odm
!= ODM_SUCCESS
)
296 sal_uInt16 nCount
= 10;
297 sal_uInt16 nMaxCount
= 10;
298 sal_Char
* lpszDocId
= new sal_Char
[ODM_DOCID_MAX
* nMaxCount
];
299 sal_Char
* lpszDocName
= new sal_Char
[ODM_NAME_MAX
* nMaxCount
];
302 ::rtl::OUString
sContentType(RTL_CONSTASCII_USTRINGPARAM(ODMA_CONTENT_TYPE
));
303 sal_uInt32 nCurrentCount
= 0;
306 if(nCount
>= nMaxCount
)
309 odm
= NODMQueryGetResults(ContentProvider::getHandle(), pQueryId
,lpszDocId
, lpszDocName
, ODM_NAME_MAX
, (WORD
*)&nCount
);
310 nCurrentCount
+= nCount
;
312 if(odm
== ODM_SUCCESS
&& nIndex
< nCurrentCount
)
315 for(sal_uInt16 i
= 0; i
< nCount
; ++i
)
317 ::rtl::Reference
<ContentProperties
> rProps
= new ContentProperties();
318 rProps
->m_sDocumentId
= ::rtl::OString(&lpszDocId
[ODM_DOCID_MAX
*i
]);
319 rProps
->m_sContentType
= sContentType
;
320 m_pImpl
->m_xContent
->getContentProvider()->append(rProps
);
321 m_pImpl
->m_aResults
.push_back( new ResultListEntry(rProps
));
325 while(nCount
> nMaxCount
);
328 // now close the query
329 odm
= NODMQueryClose(ContentProvider::getHandle(), pQueryId
);
337 m_pImpl
->m_bCountFinal
= sal_True
;
339 rtl::Reference
< ucbhelper::ResultSet
> xResultSet
= getResultSet();
340 if ( xResultSet
.is() )
345 if ( nOldCount
< m_pImpl
->m_aResults
.size() )
346 xResultSet
->rowCountChanged(
347 nOldCount
, m_pImpl
->m_aResults
.size() );
349 if ( m_pImpl
->m_bCountFinal
)
350 xResultSet
->rowCountFinal();
356 //=========================================================================
358 sal_uInt32
DataSupplier::totalCount()
360 osl::ClearableGuard
< osl::Mutex
> aGuard( m_pImpl
->m_aMutex
);
362 if ( m_pImpl
->m_bCountFinal
)
363 return m_pImpl
->m_aResults
.size();
365 sal_uInt32 nOldCount
= m_pImpl
->m_aResults
.size();
367 // @@@ Obtain data and put it into result list...
369 while ( m_pImpl->m_aFolder.next( m_pImpl->m_aIterator ) )
370 m_pImpl->m_aResults.push_back(
371 new ResultListEntry( *m_pImpl->m_aIterator ) );
373 m_pImpl
->m_bCountFinal
= sal_True
;
375 rtl::Reference
< ucbhelper::ResultSet
> xResultSet
= getResultSet();
376 if ( xResultSet
.is() )
381 if ( nOldCount
< m_pImpl
->m_aResults
.size() )
382 xResultSet
->rowCountChanged(
383 nOldCount
, m_pImpl
->m_aResults
.size() );
385 xResultSet
->rowCountFinal();
388 return m_pImpl
->m_aResults
.size();
391 //=========================================================================
393 sal_uInt32
DataSupplier::currentCount()
395 return m_pImpl
->m_aResults
.size();
398 //=========================================================================
400 sal_Bool
DataSupplier::isCountFinal()
402 return m_pImpl
->m_bCountFinal
;
405 //=========================================================================
407 Reference
< XRow
> DataSupplier::queryPropertyValues( sal_uInt32 nIndex
)
409 osl::Guard
< osl::Mutex
> aGuard( m_pImpl
->m_aMutex
);
411 if ( nIndex
< m_pImpl
->m_aResults
.size() )
413 Reference
< XRow
> xRow
= m_pImpl
->m_aResults
[ nIndex
]->xRow
;
421 if ( getResult( nIndex
) )
423 Reference
< XRow
> xRow
= Content::getPropertyValues(
425 getResultSet()->getProperties(),
426 m_pImpl
->m_aResults
[ nIndex
]->rData
,
427 m_pImpl
->m_xContent
->getProvider(),
428 queryContentIdentifierString( nIndex
) );
429 m_pImpl
->m_aResults
[ nIndex
]->xRow
= xRow
;
433 return Reference
< XRow
>();
436 //=========================================================================
438 void DataSupplier::releasePropertyValues( sal_uInt32 nIndex
)
440 osl::Guard
< osl::Mutex
> aGuard( m_pImpl
->m_aMutex
);
442 if ( nIndex
< m_pImpl
->m_aResults
.size() )
443 m_pImpl
->m_aResults
[ nIndex
]->xRow
= Reference
< XRow
>();
446 //=========================================================================
448 void DataSupplier::close()
452 //=========================================================================
454 void DataSupplier::validate()
455 throw( ResultSetException
)