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 <osl/mutex.hxx>
21 : #include <tools/diagnose_ex.h>
22 : #include <cppuhelper/weak.hxx>
23 : #include <svl/itemprop.hxx>
24 : #include <uno/environment.h>
25 : #include <svl/urihelper.hxx>
26 : #include <toolkit/helper/vclunohelper.hxx>
27 : #include <comphelper/processfactory.hxx>
28 : #include <cppuhelper/factory.hxx> // helper for factories
29 : #include <com/sun/star/sdbc/ResultSetType.hpp>
30 : #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
31 : #include <com/sun/star/sdb/XColumn.hpp>
32 : #include <com/sun/star/util/XURLTransformer.hpp>
33 : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
34 : #include <com/sun/star/sdbc/XRowSet.hpp>
35 : #include <com/sun/star/sdb/CommandType.hpp>
36 : #include <com/sun/star/frame/XFrameLoader.hpp>
37 : #include <com/sun/star/lang/XServiceInfo.hpp>
38 : #include <com/sun/star/lang/XSingleServiceFactory.hpp>
39 : #include <com/sun/star/beans/PropertyAttribute.hpp>
40 : #include <com/sun/star/beans/XPropertySet.hpp>
41 : #include <com/sun/star/container/XNameAccess.hpp>
42 : #include <com/sun/star/text/BibliographyDataField.hpp>
43 : #include <com/sun/star/form/XLoadListener.hpp>
44 : #include <com/sun/star/frame/XLayoutManager.hpp>
45 : #include <com/sun/star/uno/XAggregation.hpp>
46 : #include <toolkit/awt/vclxwindow.hxx>
47 : #include <vcl/window.hxx>
48 : #include <vcl/edit.hxx>
49 : #include <vcl/svapp.hxx>
50 : #include <vcl/group.hxx>
51 : #include <svtools/svmedit.hxx>
52 :
53 : #include "bibresid.hxx"
54 : #include "bib.hrc"
55 : #include "bibcont.hxx"
56 : #include "bibbeam.hxx"
57 : #include "bibmod.hxx"
58 : #include "bibview.hxx"
59 : #include "framectr.hxx"
60 : #include "datman.hxx"
61 : #include <bibconfig.hxx>
62 : #include <cppuhelper/implbase4.hxx> // helper for implementations
63 :
64 : using namespace ::rtl;
65 : using namespace ::com::sun::star;
66 : using namespace ::com::sun::star::uno;
67 : using namespace ::com::sun::star::beans;
68 : using namespace ::com::sun::star::lang;
69 : using namespace ::com::sun::star::sdb;
70 : using namespace ::com::sun::star::sdbc;
71 : using namespace ::com::sun::star::form;
72 : using namespace ::com::sun::star::container;
73 : using namespace ::com::sun::star::frame;
74 :
75 : #define C2U(cChar) OUString::createFromAscii(cChar)
76 :
77 :
78 : //-----------------------------------------------------------------------------
79 :
80 : #define PROPERTY_FRAME 1
81 :
82 : class BibliographyLoader : public cppu::WeakImplHelper4
83 : < XServiceInfo, XNameAccess, XPropertySet, XFrameLoader >
84 : {
85 : HdlBibModul m_pBibMod;
86 : Reference< XLoadable > m_xDatMan;
87 : BibDataManager* m_pDatMan;
88 : Reference< XNameAccess > m_xColumns;
89 : Reference< XResultSet > m_xCursor;
90 :
91 : private:
92 :
93 : void loadView(const Reference< XFrame > & aFrame, const rtl::OUString& aURL,
94 : const Sequence< PropertyValue >& aArgs,
95 : const Reference< XLoadEventListener > & aListener);
96 :
97 : BibDataManager* GetDataManager()const;
98 : Reference< XNameAccess > GetDataColumns() const;
99 : Reference< XResultSet > GetDataCursor() const;
100 : Reference< sdb::XColumn > GetIdentifierColumn() const;
101 :
102 : public:
103 : BibliographyLoader();
104 : ~BibliographyLoader();
105 :
106 : // XServiceInfo
107 : rtl::OUString SAL_CALL getImplementationName() throw( );
108 : sal_Bool SAL_CALL supportsService(const rtl::OUString& ServiceName) throw( );
109 : Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames(void) throw( );
110 0 : static rtl::OUString getImplementationName_Static() throw( )
111 :
112 : {
113 : //!
114 0 : return C2U("com.sun.star.extensions.Bibliography");
115 : //!
116 : }
117 :
118 : //XNameAccess
119 : virtual Any SAL_CALL getByName(const rtl::OUString& aName) throw ( NoSuchElementException, WrappedTargetException, RuntimeException );
120 : virtual Sequence< rtl::OUString > SAL_CALL getElementNames(void) throw ( RuntimeException );
121 : virtual sal_Bool SAL_CALL hasByName(const rtl::OUString& aName) throw ( RuntimeException );
122 :
123 : //XElementAccess
124 : virtual Type SAL_CALL getElementType(void) throw ( RuntimeException );
125 : virtual sal_Bool SAL_CALL hasElements(void) throw ( RuntimeException );
126 :
127 : //XPropertySet
128 : virtual Reference< XPropertySetInfo > SAL_CALL getPropertySetInfo(void) throw ( RuntimeException );
129 : virtual void SAL_CALL setPropertyValue(const rtl::OUString& PropertyName, const Any& aValue) throw( UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException );
130 : virtual Any SAL_CALL getPropertyValue(const rtl::OUString& PropertyName) throw ( UnknownPropertyException, WrappedTargetException, RuntimeException );
131 : virtual void SAL_CALL addPropertyChangeListener(const rtl::OUString& PropertyName, const Reference< XPropertyChangeListener > & aListener) throw( UnknownPropertyException, WrappedTargetException, RuntimeException );
132 : virtual void SAL_CALL removePropertyChangeListener(const rtl::OUString& PropertyName, const Reference< XPropertyChangeListener > & aListener) throw( UnknownPropertyException, WrappedTargetException, RuntimeException );
133 : virtual void SAL_CALL addVetoableChangeListener(const rtl::OUString& PropertyName, const Reference< XVetoableChangeListener > & aListener) throw( UnknownPropertyException, WrappedTargetException, RuntimeException );
134 : virtual void SAL_CALL removeVetoableChangeListener(const rtl::OUString& PropertyName, const Reference< XVetoableChangeListener > & aListener) throw( UnknownPropertyException, WrappedTargetException, RuntimeException );
135 :
136 : static Sequence<rtl::OUString> SAL_CALL getSupportedServiceNames_Static(void) throw( );
137 :
138 : friend Reference< XInterface > SAL_CALL BibliographyLoader_CreateInstance( const Reference< XMultiServiceFactory > & rSMgr ) throw( Exception );
139 :
140 : // XLoader
141 : virtual void SAL_CALL load(const Reference< XFrame > & aFrame, const rtl::OUString& aURL,
142 : const Sequence< PropertyValue >& aArgs,
143 : const Reference< XLoadEventListener > & aListener) throw (::com::sun::star::uno::RuntimeException);
144 : virtual void SAL_CALL cancel(void) throw (::com::sun::star::uno::RuntimeException);
145 : };
146 :
147 0 : BibliographyLoader::BibliographyLoader() :
148 : m_pBibMod(0),
149 0 : m_pDatMan(0)
150 : {
151 0 : }
152 :
153 0 : BibliographyLoader::~BibliographyLoader()
154 : {
155 0 : Reference< lang::XComponent > xComp(m_xCursor, UNO_QUERY);
156 0 : if (xComp.is())
157 0 : xComp->dispose();
158 0 : if(m_pBibMod)
159 0 : CloseBibModul(m_pBibMod);
160 0 : }
161 :
162 :
163 0 : Reference< XInterface > SAL_CALL BibliographyLoader_CreateInstance( const Reference< XMultiServiceFactory > & /*rSMgr*/ ) throw( Exception )
164 : {
165 0 : return *(new BibliographyLoader);
166 : }
167 :
168 :
169 : // XServiceInfo
170 0 : rtl::OUString BibliographyLoader::getImplementationName() throw( )
171 :
172 : {
173 0 : return getImplementationName_Static();
174 : }
175 :
176 : // XServiceInfo
177 0 : sal_Bool BibliographyLoader::supportsService(const rtl::OUString& ServiceName) throw( )
178 : {
179 0 : Sequence< rtl::OUString > aSNL = getSupportedServiceNames();
180 0 : const rtl::OUString * pArray = aSNL.getConstArray();
181 0 : for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
182 0 : if( pArray[i] == ServiceName )
183 0 : return sal_True;
184 0 : return sal_False;
185 : }
186 :
187 : // XServiceInfo
188 0 : Sequence< rtl::OUString > BibliographyLoader::getSupportedServiceNames(void) throw( )
189 : {
190 0 : return getSupportedServiceNames_Static();
191 : }
192 :
193 : // ORegistryServiceManager_Static
194 0 : Sequence< rtl::OUString > BibliographyLoader::getSupportedServiceNames_Static(void) throw( )
195 : {
196 0 : Sequence< rtl::OUString > aSNS( 2 );
197 0 : aSNS.getArray()[0] = C2U("com.sun.star.frame.FrameLoader");
198 : //!
199 0 : aSNS.getArray()[1] = C2U("com.sun.star.frame.Bibliography");
200 : //!
201 0 : return aSNS;
202 : }
203 :
204 : extern "C"
205 : {
206 0 : SAL_DLLPUBLIC_EXPORT void * SAL_CALL bib_component_getFactory(
207 : const sal_Char * pImplName, XMultiServiceFactory * pServiceManager, void * /*pRegistryKey*/ )
208 : {
209 0 : void * pRet = 0;
210 0 : if (!BibliographyLoader::getImplementationName_Static().compareToAscii( pImplName ) )
211 : {
212 : // create the factory
213 : Reference< XSingleServiceFactory > xFactory =
214 : cppu::createSingleFactory(
215 : pServiceManager,
216 : BibliographyLoader::getImplementationName_Static(),
217 : BibliographyLoader_CreateInstance,
218 0 : BibliographyLoader::getSupportedServiceNames_Static() );
219 : // acquire, because we return an interface pointer instead of a reference
220 0 : xFactory->acquire();
221 0 : pRet = xFactory.get();
222 : }
223 0 : return pRet;
224 : }
225 :
226 : }
227 : // -----------------------------------------------------------------------
228 0 : void BibliographyLoader::cancel(void) throw (::com::sun::star::uno::RuntimeException)
229 : {
230 : //!
231 : //!
232 0 : }
233 :
234 0 : void BibliographyLoader::load(const Reference< XFrame > & rFrame, const rtl::OUString& rURL,
235 : const Sequence< PropertyValue >& rArgs,
236 : const Reference< XLoadEventListener > & rListener) throw (::com::sun::star::uno::RuntimeException)
237 : {
238 :
239 0 : SolarMutexGuard aGuard;
240 :
241 0 : m_pBibMod = OpenBibModul();
242 :
243 0 : String aURLStr( rURL );
244 0 : String aPartName = aURLStr.GetToken( 1, '/' );
245 0 : Reference<XPropertySet> xPrSet(rFrame, UNO_QUERY);
246 0 : if(xPrSet.is())
247 : {
248 0 : Any aTitle;
249 0 : aTitle <<= OUString(String(BibResId(RID_BIB_STR_FRAME_TITLE)));
250 0 : xPrSet->setPropertyValue(C2U("Title"), aTitle);
251 : }
252 0 : if(aPartName.EqualsAscii("View") || aPartName.EqualsAscii("View1"))
253 : {
254 0 : loadView(rFrame, rURL, rArgs, rListener);
255 0 : }
256 0 : }
257 :
258 : // -----------------------------------------------------------------------
259 0 : void BibliographyLoader::loadView(const Reference< XFrame > & rFrame, const rtl::OUString& /*rURL*/,
260 : const Sequence< PropertyValue >& /*rArgs*/,
261 : const Reference< XLoadEventListener > & rListener)
262 : {
263 0 : SolarMutexGuard aGuard;
264 : //!
265 0 : if(!m_pBibMod)
266 0 : m_pBibMod = OpenBibModul();
267 :
268 0 : m_pDatMan = (*m_pBibMod)->createDataManager();
269 0 : m_xDatMan = m_pDatMan;
270 0 : BibDBDescriptor aBibDesc = BibModul::GetConfig()->GetBibliographyURL();
271 :
272 0 : if(aBibDesc.sDataSource.isEmpty())
273 : {
274 0 : DBChangeDialogConfig_Impl aConfig;
275 0 : const Sequence<OUString> aSources = aConfig.GetDataSourceNames();
276 0 : if(aSources.getLength())
277 0 : aBibDesc.sDataSource = aSources.getConstArray()[0];
278 : }
279 :
280 0 : Reference< XForm > xForm = m_pDatMan->createDatabaseForm( aBibDesc );
281 :
282 0 : Reference< awt::XWindow > aWindow = rFrame->getContainerWindow();
283 0 : VCLXWindow* pParentComponent = VCLXWindow::GetImplementation(aWindow);
284 :
285 0 : Window* pParent = VCLUnoHelper::GetWindow( aWindow );
286 :
287 0 : BibBookContainer *pMyWindow = new BibBookContainer( pParent );
288 0 : pMyWindow->Show();
289 :
290 0 : ::bib::BibView* pView = new ::bib::BibView( pMyWindow, m_pDatMan, WB_VSCROLL | WB_HSCROLL | WB_3DLOOK );
291 0 : pView->Show();
292 0 : m_pDatMan->SetView( pView );
293 :
294 0 : ::bib::BibBeamer* pBeamer = new ::bib::BibBeamer( pMyWindow, m_pDatMan );
295 0 : pBeamer->Show();
296 0 : pMyWindow->createTopFrame(pBeamer);
297 :
298 0 : pMyWindow->createBottomFrame(pView);
299 :
300 0 : Reference< awt::XWindow > xWin ( pMyWindow->GetComponentInterface(), UNO_QUERY );
301 :
302 0 : Reference< XController > xCtrRef( new BibFrameController_Impl( xWin, m_pDatMan ) );
303 :
304 0 : xCtrRef->attachFrame(rFrame);
305 0 : rFrame->setComponent( xWin, xCtrRef);
306 0 : pBeamer->SetXController(xCtrRef);
307 : //!
308 :
309 : // not earlier because SetFocus() is triggered in setVisible()
310 0 : pParentComponent->setVisible(sal_True);
311 :
312 0 : m_xDatMan->load();
313 : // #100312# ----------
314 0 : m_pDatMan->RegisterInterceptor(pBeamer);
315 :
316 0 : if ( rListener.is() )
317 0 : rListener->loadFinished( this );
318 :
319 : // attach menu bar
320 0 : Reference< XPropertySet > xPropSet( rFrame, UNO_QUERY );
321 0 : Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
322 0 : if ( xPropSet.is() )
323 : {
324 : try
325 : {
326 0 : Any a = xPropSet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" )));
327 0 : a >>= xLayoutManager;
328 : }
329 0 : catch ( const uno::Exception& )
330 : {
331 : }
332 : }
333 :
334 0 : if ( xLayoutManager.is() )
335 0 : xLayoutManager->createElement( OUString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/menubar/menubar" )));
336 0 : }
337 :
338 0 : BibDataManager* BibliographyLoader::GetDataManager()const
339 : {
340 0 : if(!m_pDatMan)
341 : {
342 0 : if(!m_pBibMod)
343 0 : const_cast< BibliographyLoader* >( this )->m_pBibMod = OpenBibModul();
344 0 : const_cast< BibliographyLoader* >( this )->m_pDatMan = (*m_pBibMod)->createDataManager();
345 0 : const_cast< BibliographyLoader* >( this )->m_xDatMan = m_pDatMan;
346 : }
347 0 : return m_pDatMan;
348 : }
349 :
350 0 : Reference< XNameAccess > BibliographyLoader::GetDataColumns() const
351 : {
352 0 : if (!m_xColumns.is())
353 : {
354 0 : Reference< XMultiServiceFactory > xMgr = comphelper::getProcessServiceFactory();
355 0 : Reference< XRowSet > xRowSet(xMgr->createInstance(C2U("com.sun.star.sdb.RowSet")), UNO_QUERY);
356 0 : Reference< XPropertySet > xResultSetProps(xRowSet, UNO_QUERY);
357 : DBG_ASSERT(xResultSetProps.is() , "BibliographyLoader::GetDataCursor : invalid row set (no XResultSet or no XPropertySet) !");
358 :
359 0 : BibDBDescriptor aBibDesc = BibModul::GetConfig()->GetBibliographyURL();
360 :
361 0 : Any aBibUrlAny; aBibUrlAny <<= aBibDesc.sDataSource;
362 0 : xResultSetProps->setPropertyValue(C2U("DataSourceName"), aBibUrlAny);
363 0 : Any aCommandType; aCommandType <<= aBibDesc.nCommandType;
364 0 : xResultSetProps->setPropertyValue(C2U("CommandType"), aCommandType);
365 0 : Any aTableName; aTableName <<= aBibDesc.sTableOrQuery;
366 0 : xResultSetProps->setPropertyValue(C2U("Command"), aTableName);
367 0 : Any aResultSetType; aResultSetType <<= (sal_Int32)(ResultSetType::SCROLL_INSENSITIVE);
368 0 : xResultSetProps->setPropertyValue(C2U("ResultSetType"), aResultSetType);
369 0 : Any aResultSetCurrency; aResultSetCurrency <<= (sal_Int32)(ResultSetConcurrency::UPDATABLE);
370 0 : xResultSetProps->setPropertyValue(C2U("ResultSetConcurrency"), aResultSetCurrency);
371 :
372 0 : sal_Bool bSuccess = sal_False;
373 : try
374 : {
375 0 : xRowSet->execute();
376 0 : bSuccess = sal_True;
377 : }
378 0 : catch(const SQLException&)
379 : {
380 : DBG_UNHANDLED_EXCEPTION();
381 : }
382 0 : catch(const Exception& )
383 : {
384 : DBG_UNHANDLED_EXCEPTION();
385 0 : bSuccess = sal_False;
386 : }
387 :
388 0 : if (!bSuccess)
389 : {
390 0 : Reference< XComponent > xSetComp(xRowSet, UNO_QUERY);
391 0 : if (xSetComp.is())
392 0 : xSetComp->dispose();
393 0 : xRowSet = NULL;
394 : }
395 : else
396 0 : ((BibliographyLoader*)this)->m_xCursor = xRowSet.get();
397 :
398 0 : Reference< sdbcx::XColumnsSupplier > xSupplyCols(m_xCursor, UNO_QUERY);
399 0 : if (xSupplyCols.is())
400 0 : ((BibliographyLoader*)this)->m_xColumns = xSupplyCols->getColumns();
401 : }
402 :
403 0 : return m_xColumns;
404 : }
405 :
406 0 : Reference< sdb::XColumn > BibliographyLoader::GetIdentifierColumn() const
407 : {
408 0 : BibDataManager* pDatMan = GetDataManager();
409 0 : Reference< XNameAccess > xColumns = GetDataColumns();
410 0 : rtl::OUString sIdentifierColumnName = pDatMan->GetIdentifierMapping();
411 :
412 0 : Reference< sdb::XColumn > xReturn;
413 0 : if (xColumns.is() && xColumns->hasByName(sIdentifierColumnName))
414 : {
415 : xReturn = Reference< XColumn > (*(Reference< XInterface > *)
416 0 : xColumns->getByName(sIdentifierColumnName).getValue(), UNO_QUERY);
417 : }
418 0 : return xReturn;
419 : }
420 :
421 0 : Reference< XResultSet > BibliographyLoader::GetDataCursor() const
422 : {
423 0 : if (!m_xCursor.is())
424 0 : GetDataColumns();
425 0 : if (m_xCursor.is())
426 0 : m_xCursor->first();
427 0 : return m_xCursor;
428 : }
429 :
430 0 : static rtl::OUString lcl_AddProperty(Reference< XNameAccess > xColumns,
431 : const Mapping* pMapping, const String& rColumnName)
432 : {
433 0 : String sColumnName(rColumnName);
434 0 : if(pMapping)
435 : {
436 0 : for(sal_uInt16 nEntry = 0; nEntry < COLUMN_COUNT; nEntry++)
437 : {
438 0 : if(pMapping->aColumnPairs[nEntry].sLogicalColumnName == OUString(rColumnName))
439 : {
440 0 : sColumnName = pMapping->aColumnPairs[nEntry].sRealColumnName;
441 0 : break;
442 : }
443 : }
444 : }
445 0 : rtl::OUString uColumnName(sColumnName);
446 0 : rtl::OUString uRet;
447 0 : Reference< sdb::XColumn > xCol;
448 0 : if (xColumns->hasByName(uColumnName))
449 0 : xCol = Reference< sdb::XColumn > (*(Reference< XInterface > *)xColumns->getByName(uColumnName).getValue(), UNO_QUERY);
450 0 : if (xCol.is())
451 0 : uRet = xCol->getString();
452 0 : return uRet;
453 : }
454 : //-----------------------------------------------------------------------------
455 0 : Any BibliographyLoader::getByName(const rtl::OUString& rName) throw
456 : ( NoSuchElementException, WrappedTargetException, RuntimeException )
457 : {
458 0 : Any aRet;
459 : try
460 : {
461 0 : BibDataManager* pDatMan = ((BibliographyLoader*)this)->GetDataManager();
462 0 : Reference< XResultSet > xCursor = GetDataCursor();
463 0 : Reference< sdbcx::XColumnsSupplier > xSupplyCols(xCursor, UNO_QUERY);
464 0 : Reference< XNameAccess > xColumns;
465 0 : if (!xSupplyCols.is())
466 : return aRet;
467 0 : xColumns = xSupplyCols->getColumns();
468 : DBG_ASSERT(xSupplyCols.is(), "BibliographyLoader::getByName : invalid columns returned by the data cursor (may be the result set is not alive ?) !");
469 0 : if (!xColumns.is())
470 : return aRet;
471 :
472 0 : String sIdentifierMapping = pDatMan->GetIdentifierMapping();
473 0 : rtl::OUString sId = sIdentifierMapping;
474 0 : Reference< sdb::XColumn > xColumn;
475 0 : if (xColumns->hasByName(sId))
476 0 : xColumn = Reference< sdb::XColumn > (*(Reference< XInterface > *)xColumns->getByName(sId).getValue(), UNO_QUERY);
477 0 : if (xColumn.is())
478 : {
479 0 : do
480 : {
481 0 : if ((rName == xColumn->getString()) && !xColumn->wasNull())
482 : {
483 0 : Sequence<PropertyValue> aPropSequ(COLUMN_COUNT);
484 0 : PropertyValue* pValues = aPropSequ.getArray();
485 0 : BibConfig* pConfig = BibModul::GetConfig();
486 0 : BibDBDescriptor aBibDesc = BibModul::GetConfig()->GetBibliographyURL();
487 0 : const Mapping* pMapping = pConfig->GetMapping(aBibDesc);
488 0 : for(sal_uInt16 nEntry = 0; nEntry < COLUMN_COUNT; nEntry++)
489 : {
490 : const String sColName = pConfig->GetDefColumnName(
491 0 : nEntry);
492 0 : pValues[nEntry].Name = sColName;
493 0 : pValues[nEntry].Value <<= lcl_AddProperty(xColumns, pMapping, sColName);
494 0 : }
495 0 : aRet.setValue(&aPropSequ, ::getCppuType((Sequence<PropertyValue>*)0));
496 :
497 0 : break;
498 : }
499 : }
500 0 : while(xCursor->next());
501 0 : }
502 : }
503 0 : catch(const Exception&)
504 : {
505 : DBG_UNHANDLED_EXCEPTION();
506 : }
507 0 : return aRet;
508 : }
509 :
510 0 : Sequence< rtl::OUString > BibliographyLoader::getElementNames(void) throw ( RuntimeException )
511 : {
512 0 : Sequence< rtl::OUString > aRet(10);
513 0 : int nRealNameCount = 0;
514 : try
515 : {
516 0 : Reference< XResultSet > xCursor(GetDataCursor());
517 0 : Reference< sdb::XColumn > xIdColumn(GetIdentifierColumn());
518 0 : if (xIdColumn.is()) // implies xCursor.is()
519 : {
520 0 : do
521 : {
522 0 : rtl::OUString sTemp = xIdColumn->getString();
523 0 : if (!sTemp.isEmpty() && !xIdColumn->wasNull())
524 : {
525 0 : int nLen = aRet.getLength();
526 0 : if(nLen == nRealNameCount)
527 0 : aRet.realloc(nLen + 10);
528 0 : rtl::OUString* pArray = aRet.getArray();
529 0 : pArray[nRealNameCount] = sTemp;
530 0 : nRealNameCount++;
531 0 : }
532 : }
533 0 : while (xCursor->next());
534 0 : }
535 : }
536 0 : catch(const Exception&)
537 : {
538 : DBG_UNHANDLED_EXCEPTION();
539 : }
540 :
541 0 : aRet.realloc(nRealNameCount);
542 0 : return aRet;
543 : }
544 :
545 0 : sal_Bool BibliographyLoader::hasByName(const rtl::OUString& rName) throw ( RuntimeException )
546 : {
547 0 : sal_Bool bRet = sal_False;
548 : try
549 : {
550 0 : Reference< XResultSet > xCursor = GetDataCursor();
551 0 : Reference< sdb::XColumn > xIdColumn = GetIdentifierColumn();
552 :
553 0 : if (xIdColumn.is()) // implies xCursor.is()
554 : {
555 0 : do
556 : {
557 0 : rtl::OUString sCurrentId = xIdColumn->getString();
558 0 : if (!xIdColumn->wasNull() && (rName.compareTo(sCurrentId) == COMPARE_EQUAL))
559 : {
560 0 : bRet = sal_True;
561 : break;
562 0 : }
563 : }
564 0 : while(xCursor->next());
565 0 : }
566 : }
567 0 : catch(const Exception&)
568 : {
569 : DBG_UNHANDLED_EXCEPTION();
570 : }
571 0 : return bRet;
572 : }
573 :
574 0 : Type BibliographyLoader::getElementType(void) throw ( RuntimeException )
575 : {
576 0 : return ::getCppuType((Sequence<PropertyValue>*)0);
577 : }
578 :
579 0 : sal_Bool BibliographyLoader::hasElements(void) throw ( RuntimeException )
580 : {
581 0 : Reference< XResultSet > xCursor = GetDataCursor();
582 0 : Reference< XNameAccess > xColumns = GetDataColumns();
583 0 : return xColumns.is() && (xColumns->getElementNames().getLength() != 0);
584 : }
585 :
586 0 : Reference< XPropertySetInfo > BibliographyLoader::getPropertySetInfo(void) throw
587 : ( RuntimeException )
588 : {
589 : static SfxItemPropertyMapEntry aBibProps_Impl[] =
590 : {
591 0 : { MAP_CHAR_LEN("BibliographyDataFieldNames"), 0, &::getCppuType((Sequence<PropertyValue>*)0), PropertyAttribute::READONLY, 0},
592 : {0,0,0,0,0,0}
593 0 : };
594 : static Reference< XPropertySetInfo > xRet =
595 0 : SfxItemPropertySet(aBibProps_Impl).getPropertySetInfo();
596 0 : return xRet;
597 : }
598 :
599 0 : void BibliographyLoader::setPropertyValue(const rtl::OUString& /*PropertyName*/,
600 : const Any& /*aValue*/)
601 : throw( UnknownPropertyException, PropertyVetoException,
602 : IllegalArgumentException, WrappedTargetException, RuntimeException)
603 : {
604 0 : throw UnknownPropertyException();
605 : //no changeable properties
606 : }
607 :
608 0 : Any BibliographyLoader::getPropertyValue(const rtl::OUString& rPropertyName)
609 : throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
610 : {
611 0 : Any aRet;
612 : static const sal_uInt16 aInternalMapping[] =
613 : {
614 : IDENTIFIER_POS , // BibliographyDataField_IDENTIFIER
615 : AUTHORITYTYPE_POS , // BibliographyDataField_BIBILIOGRAPHIC_TYPE
616 : ADDRESS_POS , // BibliographyDataField_ADDRESS
617 : ANNOTE_POS , // BibliographyDataField_ANNOTE
618 : AUTHOR_POS , // BibliographyDataField_AUTHOR
619 : BOOKTITLE_POS , // BibliographyDataField_BOOKTITLE
620 : CHAPTER_POS , // BibliographyDataField_CHAPTER
621 : EDITION_POS , // BibliographyDataField_EDITION
622 : EDITOR_POS , // BibliographyDataField_EDITOR
623 : HOWPUBLISHED_POS , // BibliographyDataField_HOWPUBLISHED
624 : INSTITUTION_POS , // BibliographyDataField_INSTITUTION
625 : JOURNAL_POS , // BibliographyDataField_JOURNAL
626 : MONTH_POS , // BibliographyDataField_MONTH
627 : NOTE_POS , // BibliographyDataField_NOTE
628 : NUMBER_POS , // BibliographyDataField_NUMBER
629 : ORGANIZATIONS_POS , // BibliographyDataField_ORGANIZATIONS
630 : PAGES_POS , // BibliographyDataField_PAGES
631 : PUBLISHER_POS , // BibliographyDataField_PUBLISHER
632 : SCHOOL_POS , // BibliographyDataField_SCHOOL
633 : SERIES_POS , // BibliographyDataField_SERIES
634 : TITLE_POS , // BibliographyDataField_TITLE
635 : REPORTTYPE_POS , // BibliographyDataField_REPORT_TYPE
636 : VOLUME_POS , // BibliographyDataField_VOLUME
637 : YEAR_POS , // BibliographyDataField_YEAR
638 : URL_POS , // BibliographyDataField_URL
639 : CUSTOM1_POS , // BibliographyDataField_CUSTOM1
640 : CUSTOM2_POS , // BibliographyDataField_CUSTOM2
641 : CUSTOM3_POS , // BibliographyDataField_CUSTOM3
642 : CUSTOM4_POS , // BibliographyDataField_CUSTOM4
643 : CUSTOM5_POS , // BibliographyDataField_CUSTOM5
644 : ISBN_POS //BibliographyDataField_ISBN
645 : };
646 0 : if(C2U("BibliographyDataFieldNames") == rPropertyName)
647 : {
648 0 : Sequence<PropertyValue> aSeq(COLUMN_COUNT);
649 0 : PropertyValue* pArray = aSeq.getArray();
650 0 : BibConfig* pConfig = BibModul::GetConfig();
651 0 : for(sal_uInt16 i = 0; i <= text::BibliographyDataField::ISBN ; i++)
652 : {
653 0 : pArray[i].Name = pConfig->GetDefColumnName(aInternalMapping[i]);
654 0 : pArray[i].Value <<= (sal_Int16) i;
655 : }
656 0 : aRet.setValue(&aSeq, ::getCppuType((Sequence<PropertyValue>*)0));
657 : }
658 : else
659 0 : throw UnknownPropertyException();
660 0 : return aRet;
661 : }
662 :
663 0 : void BibliographyLoader::addPropertyChangeListener(
664 : const rtl::OUString& /*PropertyName*/, const Reference< XPropertyChangeListener > & /*aListener*/)
665 : throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
666 : {
667 : //no bound properties
668 0 : }
669 :
670 0 : void BibliographyLoader::removePropertyChangeListener(
671 : const rtl::OUString& /*PropertyName*/, const Reference< XPropertyChangeListener > & /*aListener*/)
672 : throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
673 : {
674 : //no bound properties
675 0 : }
676 :
677 0 : void BibliographyLoader::addVetoableChangeListener(
678 : const rtl::OUString& /*PropertyName*/, const Reference< XVetoableChangeListener > & /*aListener*/)
679 : throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
680 : {
681 : //no vetoable properties
682 0 : }
683 :
684 0 : void BibliographyLoader::removeVetoableChangeListener(
685 : const rtl::OUString& /*PropertyName*/, const Reference< XVetoableChangeListener > & /*aListener*/)
686 : throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
687 : {
688 : //no vetoable properties
689 0 : }
690 :
691 :
692 :
693 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|