1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
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.
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).
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.
27 ************************************************************************/
34 #include <ucbhelper/contentidentifier.hxx>
35 #include <ucbhelper/providerhelper.hxx>
36 #include "odma_datasupplier.hxx"
37 #include "odma_content.hxx"
38 #include "odma_contentprops.hxx"
39 #include "odma_provider.hxx"
41 using namespace com::sun::star::beans
;
42 using namespace com::sun::star::lang
;
43 using namespace com::sun::star::ucb
;
44 using namespace com::sun::star::uno
;
45 using namespace com::sun::star::sdbc
;
52 //=========================================================================
54 // struct ResultListEntry.
56 //=========================================================================
58 struct ResultListEntry
61 Reference
< XContentIdentifier
> xId
;
62 Reference
< XContent
> xContent
;
63 Reference
< XRow
> xRow
;
64 ::rtl::Reference
<ContentProperties
> rData
;
66 ResultListEntry( const ::rtl::Reference
<ContentProperties
>& rEntry
) : rData( rEntry
) {}
69 //=========================================================================
73 //=========================================================================
75 typedef std::vector
< ResultListEntry
* > ResultList
;
77 //=========================================================================
79 // struct DataSupplier_Impl.
81 //=========================================================================
83 struct DataSupplier_Impl
86 ResultList m_aResults
;
87 rtl::Reference
< Content
> m_xContent
;
88 Reference
< XMultiServiceFactory
> m_xSMgr
;
89 // @@@ The data source and an iterator for it
91 // Entry::iterator m_aIterator;
92 sal_Int32 m_nOpenMode
;
93 sal_Bool m_bCountFinal
;
95 DataSupplier_Impl( const Reference
< XMultiServiceFactory
>& rxSMgr
,
96 const rtl::Reference
< Content
>& rContent
,
98 : m_xContent( rContent
), m_xSMgr( rxSMgr
),
99 // m_aFolder( rxSMgr, rContent->getIdentifier()->getContentIdentifier() ),
100 m_nOpenMode( nOpenMode
), m_bCountFinal( sal_False
) {}
101 ~DataSupplier_Impl();
104 //=========================================================================
105 DataSupplier_Impl::~DataSupplier_Impl()
107 ResultList::const_iterator it
= m_aResults
.begin();
108 ResultList::const_iterator end
= m_aResults
.end();
119 //=========================================================================
120 //=========================================================================
122 // DataSupplier Implementation.
124 //=========================================================================
125 //=========================================================================
127 DataSupplier::DataSupplier( const Reference
<XMultiServiceFactory
>& rxSMgr
,
128 const rtl::Reference
< ::odma::Content
>& rContent
,
129 sal_Int32 nOpenMode
)
130 : m_pImpl( new DataSupplier_Impl( rxSMgr
, rContent
, nOpenMode
) )
134 //=========================================================================
136 DataSupplier::~DataSupplier()
141 //=========================================================================
143 ::rtl::OUString
DataSupplier::queryContentIdentifierString( sal_uInt32 nIndex
)
145 osl::Guard
< osl::Mutex
> aGuard( m_pImpl
->m_aMutex
);
147 if ( nIndex
< m_pImpl
->m_aResults
.size() )
149 ::rtl::OUString aId
= m_pImpl
->m_aResults
[ nIndex
]->aId
;
150 if ( aId
.getLength() )
157 if ( getResult( nIndex
) )
160 = m_pImpl
->m_xContent
->getIdentifier()->getContentIdentifier();
162 aId
+= m_pImpl
->m_aResults
[ nIndex
]->rData
->m_sTitle
;
164 m_pImpl
->m_aResults
[ nIndex
]->aId
= aId
;
167 return ::rtl::OUString();
170 //=========================================================================
172 Reference
< XContentIdentifier
> DataSupplier::queryContentIdentifier(
175 osl::Guard
< osl::Mutex
> aGuard( m_pImpl
->m_aMutex
);
177 if ( nIndex
< m_pImpl
->m_aResults
.size() )
179 Reference
< XContentIdentifier
> xId
180 = m_pImpl
->m_aResults
[ nIndex
]->xId
;
188 ::rtl::OUString aId
= queryContentIdentifierString( nIndex
);
189 if ( aId
.getLength() )
191 Reference
< XContentIdentifier
> xId
192 = new ucbhelper::ContentIdentifier( aId
);
193 m_pImpl
->m_aResults
[ nIndex
]->xId
= xId
;
196 return Reference
< XContentIdentifier
>();
199 //=========================================================================
201 Reference
< XContent
> DataSupplier::queryContent( sal_uInt32 nIndex
)
203 osl::Guard
< osl::Mutex
> aGuard( m_pImpl
->m_aMutex
);
205 if ( nIndex
< m_pImpl
->m_aResults
.size() )
207 Reference
< XContent
> xContent
208 = m_pImpl
->m_aResults
[ nIndex
]->xContent
;
216 Reference
< XContentIdentifier
> xId
= queryContentIdentifier( nIndex
);
221 Reference
< XContent
> xContent
222 = m_pImpl
->m_xContent
->getProvider()->queryContent( xId
);
223 m_pImpl
->m_aResults
[ nIndex
]->xContent
= xContent
;
227 catch ( IllegalIdentifierException
& )
231 return Reference
< XContent
>();
234 //=========================================================================
236 sal_Bool
DataSupplier::getResult( sal_uInt32 nIndex
)
238 osl::ClearableGuard
< osl::Mutex
> aGuard( m_pImpl
->m_aMutex
);
240 if ( m_pImpl
->m_aResults
.size() > nIndex
)
242 // Result already present.
246 // Result not (yet) present.
248 if ( m_pImpl
->m_bCountFinal
)
251 // Try to obtain result...
253 sal_uInt32 nOldCount
= m_pImpl
->m_aResults
.size();
254 sal_Bool bFound
= sal_False
;
255 // sal_uInt32 nPos = nOldCount;
257 // @@@ Obtain data and put it into result list...
259 while ( m_pImpl->m_aFolder.next( m_pImpl->m_aIterator ) )
261 m_pImpl->m_aResults.push_back(
262 new ResultListEntry( *m_pImpl->m_aIterator ) );
264 if ( nPos == nIndex )
274 // now query for all documents in the DMS
275 OSL_ENSURE(ContentProvider::getHandle(),"No Handle!");
276 sal_Char
* pQueryId
= new sal_Char
[ODM_QUERYID_MAX
];
277 sal_Char
* lpszDMSList
= new sal_Char
[ODM_DMSID_MAX
];
279 ODMSTATUS odm
= NODMGetDMS(ODMA_ODMA_REGNAME
, lpszDMSList
);
280 lpszDMSList
[strlen(lpszDMSList
)+1] = '\0';
282 const char sQuery
[] = "SELECT ODM_DOCID_LATEST, ODM_NAME";
284 DWORD dwFlags
= ODM_SPECIFIC
;
285 odm
= NODMQueryExecute(ContentProvider::getHandle(), sQuery
, dwFlags
, lpszDMSList
, pQueryId
);
286 if(odm
!= ODM_SUCCESS
) {
288 delete[] lpszDMSList
;
292 sal_uInt16 nCount
= 10;
293 sal_uInt16 nMaxCount
= 10;
294 sal_Char
* lpszDocId
= new sal_Char
[ODM_DOCID_MAX
* nMaxCount
];
295 sal_Char
* lpszDocName
= new sal_Char
[ODM_NAME_MAX
* nMaxCount
];
298 ::rtl::OUString
sContentType(RTL_CONSTASCII_USTRINGPARAM(ODMA_CONTENT_TYPE
));
299 sal_uInt32 nCurrentCount
= 0;
302 if(nCount
>= nMaxCount
)
305 odm
= NODMQueryGetResults(ContentProvider::getHandle(), pQueryId
,lpszDocId
, lpszDocName
, ODM_NAME_MAX
, (WORD
*)&nCount
);
306 nCurrentCount
+= nCount
;
308 if(odm
== ODM_SUCCESS
&& nIndex
< nCurrentCount
)
311 for(sal_uInt16 i
= 0; i
< nCount
; ++i
)
313 ::rtl::Reference
<ContentProperties
> rProps
= new ContentProperties();
314 rProps
->m_sDocumentId
= ::rtl::OString(&lpszDocId
[ODM_DOCID_MAX
*i
]);
315 rProps
->m_sContentType
= sContentType
;
316 m_pImpl
->m_xContent
->getContentProvider()->append(rProps
);
317 m_pImpl
->m_aResults
.push_back( new ResultListEntry(rProps
));
321 while(nCount
> nMaxCount
);
324 // now close the query
325 odm
= NODMQueryClose(ContentProvider::getHandle(), pQueryId
);
327 delete [] lpszDMSList
;
330 delete [] lpszDocName
;
333 m_pImpl
->m_bCountFinal
= sal_True
;
335 rtl::Reference
< ucbhelper::ResultSet
> xResultSet
= getResultSet();
336 if ( xResultSet
.is() )
341 if ( nOldCount
< m_pImpl
->m_aResults
.size() )
342 xResultSet
->rowCountChanged(
343 nOldCount
, m_pImpl
->m_aResults
.size() );
345 if ( m_pImpl
->m_bCountFinal
)
346 xResultSet
->rowCountFinal();
352 //=========================================================================
354 sal_uInt32
DataSupplier::totalCount()
356 osl::ClearableGuard
< osl::Mutex
> aGuard( m_pImpl
->m_aMutex
);
358 if ( m_pImpl
->m_bCountFinal
)
359 return m_pImpl
->m_aResults
.size();
361 sal_uInt32 nOldCount
= m_pImpl
->m_aResults
.size();
363 // @@@ Obtain data and put it into result list...
365 while ( m_pImpl->m_aFolder.next( m_pImpl->m_aIterator ) )
366 m_pImpl->m_aResults.push_back(
367 new ResultListEntry( *m_pImpl->m_aIterator ) );
369 m_pImpl
->m_bCountFinal
= sal_True
;
371 rtl::Reference
< ucbhelper::ResultSet
> xResultSet
= getResultSet();
372 if ( xResultSet
.is() )
377 if ( nOldCount
< m_pImpl
->m_aResults
.size() )
378 xResultSet
->rowCountChanged(
379 nOldCount
, m_pImpl
->m_aResults
.size() );
381 xResultSet
->rowCountFinal();
384 return m_pImpl
->m_aResults
.size();
387 //=========================================================================
389 sal_uInt32
DataSupplier::currentCount()
391 return m_pImpl
->m_aResults
.size();
394 //=========================================================================
396 sal_Bool
DataSupplier::isCountFinal()
398 return m_pImpl
->m_bCountFinal
;
401 //=========================================================================
403 Reference
< XRow
> DataSupplier::queryPropertyValues( sal_uInt32 nIndex
)
405 osl::Guard
< osl::Mutex
> aGuard( m_pImpl
->m_aMutex
);
407 if ( nIndex
< m_pImpl
->m_aResults
.size() )
409 Reference
< XRow
> xRow
= m_pImpl
->m_aResults
[ nIndex
]->xRow
;
417 if ( getResult( nIndex
) )
419 Reference
< XRow
> xRow
= Content::getPropertyValues(
421 getResultSet()->getProperties(),
422 m_pImpl
->m_aResults
[ nIndex
]->rData
,
423 m_pImpl
->m_xContent
->getProvider(),
424 queryContentIdentifierString( nIndex
) );
425 m_pImpl
->m_aResults
[ nIndex
]->xRow
= xRow
;
429 return Reference
< XRow
>();
432 //=========================================================================
434 void DataSupplier::releasePropertyValues( sal_uInt32 nIndex
)
436 osl::Guard
< osl::Mutex
> aGuard( m_pImpl
->m_aMutex
);
438 if ( nIndex
< m_pImpl
->m_aResults
.size() )
439 m_pImpl
->m_aResults
[ nIndex
]->xRow
= Reference
< XRow
>();
442 //=========================================================================
444 void DataSupplier::close()
448 //=========================================================================
450 void DataSupplier::validate()
451 throw( ResultSetException
)
455 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */