merged tag ooo/OOO330_m14
[LibreOffice.git] / extensions / source / bibliography / bibload.cxx
blob91356a0d1074934e88488fa30e54edf44bfbe317
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_extensions.hxx"
32 #include <osl/mutex.hxx>
33 #include <tools/urlobj.hxx>
34 #include <tools/diagnose_ex.h>
35 #include <cppuhelper/weak.hxx>
36 #include <svl/itemprop.hxx>
37 #include <uno/environment.h>
38 #include <svl/urihelper.hxx>
39 #ifndef _TOOLKIT_UNOHLP_HXX
40 #include <toolkit/helper/vclunohelper.hxx>
41 #endif
42 #include <comphelper/processfactory.hxx>
43 #include <cppuhelper/factory.hxx> // helper for factories
44 #include <com/sun/star/sdbc/ResultSetType.hpp>
45 #include <com/sun/star/sdbc/ResultSetConcurrency.hpp>
46 #include <com/sun/star/sdb/XColumn.hpp>
47 #include <com/sun/star/util/XURLTransformer.hpp>
48 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
49 #include <com/sun/star/sdbc/XRowSet.hpp>
50 #include <com/sun/star/sdb/CommandType.hpp>
51 #include <com/sun/star/frame/XFrameLoader.hpp>
52 #include <com/sun/star/lang/XServiceInfo.hpp>
53 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
54 #include <com/sun/star/beans/PropertyAttribute.hpp>
55 #include <com/sun/star/beans/XPropertySet.hpp>
56 #include <com/sun/star/container/XNameAccess.hpp>
57 #include <com/sun/star/text/BibliographyDataField.hpp>
58 #include <com/sun/star/form/XLoadListener.hpp>
59 #include <com/sun/star/frame/XLayoutManager.hpp>
60 #include <toolkit/awt/vclxwindow.hxx>
61 #include <vcl/window.hxx>
62 #include <vcl/edit.hxx>
63 #include <vcl/svapp.hxx>
64 #include <vcl/group.hxx>
65 #include <svtools/svmedit.hxx>
67 #include "bibresid.hxx"
68 #ifndef BIB_HRC
69 #include "bib.hrc"
70 #endif
71 #include "bibcont.hxx"
72 #include "bibbeam.hxx"
73 #include "bibmod.hxx"
74 #include "bibview.hxx"
75 #include "framectr.hxx"
76 #include "datman.hxx"
77 #include <bibconfig.hxx>
78 #include <cppuhelper/implbase4.hxx> // helper for implementations
80 using namespace ::rtl;
81 using namespace ::com::sun::star;
82 using namespace ::com::sun::star::uno;
83 using namespace ::com::sun::star::beans;
84 using namespace ::com::sun::star::lang;
85 using namespace ::com::sun::star::sdb;
86 using namespace ::com::sun::star::sdbc;
87 using namespace ::com::sun::star::form;
88 using namespace ::com::sun::star::container;
89 using namespace ::com::sun::star::frame;
91 #define C2U(cChar) OUString::createFromAscii(cChar)
94 //-----------------------------------------------------------------------------
96 #define PROPERTY_FRAME 1
98 class BibliographyLoader : public cppu::WeakImplHelper4
99 < XServiceInfo, XNameAccess, XPropertySet, XFrameLoader >
101 HdlBibModul m_pBibMod;
102 Reference< XLoadable > m_xDatMan;
103 BibDataManager* m_pDatMan;
104 Reference< XNameAccess > m_xColumns;
105 Reference< XResultSet > m_xCursor;
107 private:
109 void loadView(const Reference< XFrame > & aFrame, const rtl::OUString& aURL,
110 const Sequence< PropertyValue >& aArgs,
111 const Reference< XLoadEventListener > & aListener);
113 BibDataManager* GetDataManager()const;
114 Reference< XNameAccess > GetDataColumns() const;
115 Reference< XResultSet > GetDataCursor() const;
116 Reference< sdb::XColumn > GetIdentifierColumn() const;
118 public:
119 BibliographyLoader();
120 ~BibliographyLoader();
122 // XServiceInfo
123 rtl::OUString SAL_CALL getImplementationName() throw( );
124 sal_Bool SAL_CALL supportsService(const rtl::OUString& ServiceName) throw( );
125 Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames(void) throw( );
126 static rtl::OUString getImplementationName_Static() throw( )
130 return C2U("com.sun.star.extensions.Bibliography");
134 //XNameAccess
135 virtual Any SAL_CALL getByName(const rtl::OUString& aName) throw ( NoSuchElementException, WrappedTargetException, RuntimeException );
136 virtual Sequence< rtl::OUString > SAL_CALL getElementNames(void) throw ( RuntimeException );
137 virtual sal_Bool SAL_CALL hasByName(const rtl::OUString& aName) throw ( RuntimeException );
139 //XElementAccess
140 virtual Type SAL_CALL getElementType(void) throw ( RuntimeException );
141 virtual sal_Bool SAL_CALL hasElements(void) throw ( RuntimeException );
143 //XPropertySet
144 virtual Reference< XPropertySetInfo > SAL_CALL getPropertySetInfo(void) throw ( RuntimeException );
145 virtual void SAL_CALL setPropertyValue(const rtl::OUString& PropertyName, const Any& aValue) throw( UnknownPropertyException, PropertyVetoException, IllegalArgumentException, WrappedTargetException, RuntimeException );
146 virtual Any SAL_CALL getPropertyValue(const rtl::OUString& PropertyName) throw ( UnknownPropertyException, WrappedTargetException, RuntimeException );
147 virtual void SAL_CALL addPropertyChangeListener(const rtl::OUString& PropertyName, const Reference< XPropertyChangeListener > & aListener) throw( UnknownPropertyException, WrappedTargetException, RuntimeException );
148 virtual void SAL_CALL removePropertyChangeListener(const rtl::OUString& PropertyName, const Reference< XPropertyChangeListener > & aListener) throw( UnknownPropertyException, WrappedTargetException, RuntimeException );
149 virtual void SAL_CALL addVetoableChangeListener(const rtl::OUString& PropertyName, const Reference< XVetoableChangeListener > & aListener) throw( UnknownPropertyException, WrappedTargetException, RuntimeException );
150 virtual void SAL_CALL removeVetoableChangeListener(const rtl::OUString& PropertyName, const Reference< XVetoableChangeListener > & aListener) throw( UnknownPropertyException, WrappedTargetException, RuntimeException );
152 static Sequence<rtl::OUString> SAL_CALL getSupportedServiceNames_Static(void) throw( );
154 friend Reference< XInterface > SAL_CALL BibliographyLoader_CreateInstance( const Reference< XMultiServiceFactory > & rSMgr ) throw( Exception );
156 // XLoader
157 virtual void SAL_CALL load(const Reference< XFrame > & aFrame, const rtl::OUString& aURL,
158 const Sequence< PropertyValue >& aArgs,
159 const Reference< XLoadEventListener > & aListener) throw (::com::sun::star::uno::RuntimeException);
160 virtual void SAL_CALL cancel(void) throw (::com::sun::star::uno::RuntimeException);
163 BibliographyLoader::BibliographyLoader() :
164 m_pBibMod(0),
165 m_pDatMan(0)
169 BibliographyLoader::~BibliographyLoader()
171 Reference< lang::XComponent > xComp(m_xCursor, UNO_QUERY);
172 if (xComp.is())
173 xComp->dispose();
174 if(m_pBibMod)
175 CloseBibModul(m_pBibMod);
179 Reference< XInterface > SAL_CALL BibliographyLoader_CreateInstance( const Reference< XMultiServiceFactory > & /*rSMgr*/ ) throw( Exception )
181 return *(new BibliographyLoader);
185 // XServiceInfo
186 rtl::OUString BibliographyLoader::getImplementationName() throw( )
189 return getImplementationName_Static();
192 // XServiceInfo
193 sal_Bool BibliographyLoader::supportsService(const rtl::OUString& ServiceName) throw( )
195 Sequence< rtl::OUString > aSNL = getSupportedServiceNames();
196 const rtl::OUString * pArray = aSNL.getConstArray();
197 for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
198 if( pArray[i] == ServiceName )
199 return sal_True;
200 return sal_False;
203 // XServiceInfo
204 Sequence< rtl::OUString > BibliographyLoader::getSupportedServiceNames(void) throw( )
206 return getSupportedServiceNames_Static();
209 // ORegistryServiceManager_Static
210 Sequence< rtl::OUString > BibliographyLoader::getSupportedServiceNames_Static(void) throw( )
212 Sequence< rtl::OUString > aSNS( 2 );
213 aSNS.getArray()[0] = C2U("com.sun.star.frame.FrameLoader");
215 aSNS.getArray()[1] = C2U("com.sun.star.frame.Bibliography");
217 return aSNS;
220 extern "C"
222 void SAL_CALL component_getImplementationEnvironment(
223 const sal_Char ** ppEnvTypeName, uno_Environment ** /*ppEnv*/ )
225 *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
228 sal_Bool SAL_CALL component_writeInfo( void * //pServiceManager
229 , registry::XRegistryKey * pRegistryKey )
233 rtl::OUString sKey = rtl::OUString::createFromAscii("/");
234 sKey += BibliographyLoader::getImplementationName_Static();
235 //creates the impl key: /com.sun.star.extensions.Bibliography
236 Reference< registry::XRegistryKey > xImplKey = pRegistryKey->createKey(sKey);
239 //sKey += rtl::OUString::createFromAscii("/UNO/SERVICES");
240 Reference< registry::XRegistryKey > xNewKey = xImplKey->createKey( C2U("/UNO/SERVICES") );
241 Sequence< rtl::OUString > aServices = BibliographyLoader::getSupportedServiceNames_Static();
242 for( INT32 i = 0; i < aServices.getLength(); i++ )
243 xNewKey->createKey( aServices.getConstArray()[i]);
244 xNewKey = xImplKey->createKey( C2U("/UNO/Loader"));
246 Reference< registry::XRegistryKey > xPatternKey = xImplKey->createKey( C2U("/Loader/Pattern" ));
247 xPatternKey->setAsciiValue( C2U( ".component:Bibliography/*" ) );
249 return sal_True;
251 catch (Exception &)
253 return sal_False;
258 void * SAL_CALL component_getFactory(
259 const sal_Char * pImplName, XMultiServiceFactory * pServiceManager, void * /*pRegistryKey*/ )
261 void * pRet = 0;
262 if (!BibliographyLoader::getImplementationName_Static().compareToAscii( pImplName ) )
264 // create the factory
265 Reference< XSingleServiceFactory > xFactory =
266 cppu::createSingleFactory(
267 pServiceManager,
268 BibliographyLoader::getImplementationName_Static(),
269 BibliographyLoader_CreateInstance,
270 BibliographyLoader::getSupportedServiceNames_Static() );
271 // acquire, because we return an interface pointer instead of a reference
272 xFactory->acquire();
273 pRet = xFactory.get();
275 return pRet;
279 // -----------------------------------------------------------------------
280 void BibliographyLoader::cancel(void) throw (::com::sun::star::uno::RuntimeException)
286 // -----------------------------------------------------------------------
287 void BibliographyLoader::load(const Reference< XFrame > & rFrame, const rtl::OUString& rURL,
288 const Sequence< PropertyValue >& rArgs,
289 const Reference< XLoadEventListener > & rListener) throw (::com::sun::star::uno::RuntimeException)
293 vos::OGuard aGuard(Application::GetSolarMutex());
294 m_pBibMod = OpenBibModul();
296 String aURLStr( rURL );
297 String aPartName = aURLStr.GetToken( 1, '/' );
298 Reference<XPropertySet> xPrSet(rFrame, UNO_QUERY);
299 if(xPrSet.is())
301 Any aTitle;
302 aTitle <<= OUString(String(BibResId(RID_BIB_STR_FRAME_TITLE)));
303 xPrSet->setPropertyValue(C2U("Title"), aTitle);
305 if(aPartName.EqualsAscii("View") || aPartName.EqualsAscii("View1"))
307 loadView(rFrame, rURL, rArgs, rListener);
311 // -----------------------------------------------------------------------
312 void BibliographyLoader::loadView(const Reference< XFrame > & rFrame, const rtl::OUString& /*rURL*/,
313 const Sequence< PropertyValue >& /*rArgs*/,
314 const Reference< XLoadEventListener > & rListener)
316 vos::OGuard aGuard(Application::GetSolarMutex());
318 if(!m_pBibMod)
319 m_pBibMod = OpenBibModul();
322 //create the menu
323 ResMgr* pResMgr = (*m_pBibMod)->GetResMgr();
324 INetURLObject aEntry( URIHelper::SmartRelToAbs(pResMgr->GetFileName()) );
325 String aMenuRes( RTL_CONSTASCII_USTRINGPARAM( "private:resource/" ));
326 aMenuRes += ( aEntry.GetName() += '/' );
327 aMenuRes+=String::CreateFromInt32(RID_MAIN_MENU);
329 util::URL aURL;
330 aURL.Complete = aMenuRes;
332 Reference< XMultiServiceFactory > xMgr = comphelper::getProcessServiceFactory();
333 Reference< util::XURLTransformer > xTrans ( xMgr->createInstance( C2U("com.sun.star.util.URLTransformer") ), UNO_QUERY );
334 if( xTrans.is() )
336 // Datei laden
337 xTrans->parseStrict( aURL );
339 Reference< XDispatchProvider > xProv( rFrame, UNO_QUERY );
340 if ( xProv.is() )
342 Reference< XDispatch > aDisp = xProv->queryDispatch( aURL, C2U("_menubar"), 12 );
343 if ( aDisp.is() )
344 aDisp->dispatch( aURL, Sequence<PropertyValue>() );
348 m_pDatMan = (*m_pBibMod)->createDataManager();
349 m_xDatMan = m_pDatMan;
350 BibDBDescriptor aBibDesc = BibModul::GetConfig()->GetBibliographyURL();
352 if(!aBibDesc.sDataSource.getLength())
354 DBChangeDialogConfig_Impl aConfig;
355 const Sequence<OUString> aSources = aConfig.GetDataSourceNames();
356 if(aSources.getLength())
357 aBibDesc.sDataSource = aSources.getConstArray()[0];
360 Reference< XForm > xForm = m_pDatMan->createDatabaseForm( aBibDesc );
362 Reference< awt::XWindow > aWindow = rFrame->getContainerWindow();
363 VCLXWindow* pParentComponent = VCLXWindow::GetImplementation(aWindow);
365 Window* pParent = VCLUnoHelper::GetWindow( aWindow );
367 BibBookContainer *pMyWindow = new BibBookContainer( pParent, m_pDatMan );
368 pMyWindow->Show();
370 ::bib::BibView* pView = new ::bib::BibView( pMyWindow, m_pDatMan, WB_VSCROLL | WB_HSCROLL | WB_3DLOOK );
371 pView->Show();
372 m_pDatMan->SetView( pView );
374 ::bib::BibBeamer* pBeamer = new ::bib::BibBeamer( pMyWindow, m_pDatMan );
375 pBeamer->Show();
376 pMyWindow->createTopFrame(pBeamer);
378 pMyWindow->createBottomFrame(pView);
380 Reference< awt::XWindow > xWin ( pMyWindow->GetComponentInterface(), UNO_QUERY );
382 Reference< XController > xCtrRef( new BibFrameController_Impl( xWin, m_pDatMan ) );
384 xCtrRef->attachFrame(rFrame);
385 rFrame->setComponent( xWin, xCtrRef);
386 pBeamer->SetXController(xCtrRef);
389 // not earlier because SetFocus() is triggered in setVisible()
390 pParentComponent->setVisible(sal_True);
392 m_xDatMan->load();
393 // #100312# ----------
394 m_pDatMan->RegisterInterceptor(pBeamer);
396 if ( rListener.is() )
397 rListener->loadFinished( this );
399 // attach menu bar
400 Reference< XPropertySet > xPropSet( rFrame, UNO_QUERY );
401 Reference< ::com::sun::star::frame::XLayoutManager > xLayoutManager;
402 if ( xPropSet.is() )
406 Any a = xPropSet->getPropertyValue( OUString( RTL_CONSTASCII_USTRINGPARAM( "LayoutManager" )));
407 a >>= xLayoutManager;
409 catch ( uno::Exception& )
414 if ( xLayoutManager.is() )
415 xLayoutManager->createElement( OUString( RTL_CONSTASCII_USTRINGPARAM( "private:resource/menubar/menubar" )));
417 /* -----------------06.12.99 14:37-------------------
419 --------------------------------------------------*/
420 BibDataManager* BibliographyLoader::GetDataManager()const
422 if(!m_pDatMan)
424 if(!m_pBibMod)
425 const_cast< BibliographyLoader* >( this )->m_pBibMod = OpenBibModul();
426 const_cast< BibliographyLoader* >( this )->m_pDatMan = (*m_pBibMod)->createDataManager();
427 const_cast< BibliographyLoader* >( this )->m_xDatMan = m_pDatMan;
429 return m_pDatMan;
431 /* -----------------06.12.99 14:39-------------------
433 --------------------------------------------------*/
434 Reference< XNameAccess > BibliographyLoader::GetDataColumns() const
436 if (!m_xColumns.is())
438 Reference< XMultiServiceFactory > xMgr = comphelper::getProcessServiceFactory();
439 Reference< XRowSet > xRowSet(xMgr->createInstance(C2U("com.sun.star.sdb.RowSet")), UNO_QUERY);
440 Reference< XPropertySet > xResultSetProps(xRowSet, UNO_QUERY);
441 DBG_ASSERT(xResultSetProps.is() , "BibliographyLoader::GetDataCursor : invalid row set (no XResultSet or no XPropertySet) !");
443 BibDBDescriptor aBibDesc = BibModul::GetConfig()->GetBibliographyURL();
445 Any aBibUrlAny; aBibUrlAny <<= aBibDesc.sDataSource;
446 xResultSetProps->setPropertyValue(C2U("DataSourceName"), aBibUrlAny);
447 Any aCommandType; aCommandType <<= aBibDesc.nCommandType;
448 xResultSetProps->setPropertyValue(C2U("CommandType"), aCommandType);
449 Any aTableName; aTableName <<= aBibDesc.sTableOrQuery;
450 xResultSetProps->setPropertyValue(C2U("Command"), aTableName);
451 Any aResultSetType; aResultSetType <<= (sal_Int32)(ResultSetType::SCROLL_INSENSITIVE);
452 xResultSetProps->setPropertyValue(C2U("ResultSetType"), aResultSetType);
453 Any aResultSetCurrency; aResultSetCurrency <<= (sal_Int32)(ResultSetConcurrency::UPDATABLE);
454 xResultSetProps->setPropertyValue(C2U("ResultSetConcurrency"), aResultSetCurrency);
456 sal_Bool bSuccess = sal_False;
459 xRowSet->execute();
460 bSuccess = sal_True;
462 catch(const SQLException&)
464 DBG_UNHANDLED_EXCEPTION();
466 catch(const Exception& )
468 DBG_UNHANDLED_EXCEPTION();
469 bSuccess = sal_False;
472 if (!bSuccess)
474 Reference< XComponent > xSetComp(xRowSet, UNO_QUERY);
475 if (xSetComp.is())
476 xSetComp->dispose();
477 xRowSet = NULL;
479 else
480 ((BibliographyLoader*)this)->m_xCursor = xRowSet.get();
482 Reference< sdbcx::XColumnsSupplier > xSupplyCols(m_xCursor, UNO_QUERY);
483 if (xSupplyCols.is())
484 ((BibliographyLoader*)this)->m_xColumns = xSupplyCols->getColumns();
487 return m_xColumns;
489 /* -----------------17.12.99 12:29-------------------
491 --------------------------------------------------*/
492 Reference< sdb::XColumn > BibliographyLoader::GetIdentifierColumn() const
494 BibDataManager* pDatMan = GetDataManager();
495 Reference< XNameAccess > xColumns = GetDataColumns();
496 rtl::OUString sIdentifierColumnName = pDatMan->GetIdentifierMapping();
498 Reference< sdb::XColumn > xReturn;
499 if (xColumns.is() && xColumns->hasByName(sIdentifierColumnName))
501 xReturn = Reference< XColumn > (*(Reference< XInterface > *)
502 xColumns->getByName(sIdentifierColumnName).getValue(), UNO_QUERY);
504 return xReturn;
507 /* -----------------06.12.99 15:05-------------------
509 --------------------------------------------------*/
510 Reference< XResultSet > BibliographyLoader::GetDataCursor() const
512 if (!m_xCursor.is())
513 GetDataColumns();
514 if (m_xCursor.is())
515 m_xCursor->first();
516 return m_xCursor;
519 /*-- 17.11.99 12:51:38---------------------------------------------------
521 -----------------------------------------------------------------------*/
522 rtl::OUString lcl_AddProperty(Reference< XNameAccess > xColumns,
523 const Mapping* pMapping, const String& rColumnName)
525 String sColumnName(rColumnName);
526 if(pMapping)
528 for(sal_uInt16 nEntry = 0; nEntry < COLUMN_COUNT; nEntry++)
530 if(pMapping->aColumnPairs[nEntry].sLogicalColumnName == OUString(rColumnName))
532 sColumnName = pMapping->aColumnPairs[nEntry].sRealColumnName;
533 break;
537 rtl::OUString uColumnName(sColumnName);
538 rtl::OUString uRet;
539 Reference< sdb::XColumn > xCol;
540 if (xColumns->hasByName(uColumnName))
541 xCol = Reference< sdb::XColumn > (*(Reference< XInterface > *)xColumns->getByName(uColumnName).getValue(), UNO_QUERY);
542 if (xCol.is())
543 uRet = xCol->getString();
544 return uRet;
546 //-----------------------------------------------------------------------------
547 Any BibliographyLoader::getByName(const rtl::OUString& rName) throw
548 ( NoSuchElementException, WrappedTargetException, RuntimeException )
550 Any aRet;
553 BibDataManager* pDatMan = ((BibliographyLoader*)this)->GetDataManager();
554 Reference< XResultSet > xCursor = GetDataCursor();
555 Reference< sdbcx::XColumnsSupplier > xSupplyCols(xCursor, UNO_QUERY);
556 Reference< XNameAccess > xColumns;
557 if (!xSupplyCols.is())
558 return aRet;
559 xColumns = xSupplyCols->getColumns();
560 DBG_ASSERT(xSupplyCols.is(), "BibliographyLoader::getByName : invalid columns returned by the data cursor (may be the result set is not alive ?) !");
561 if (!xColumns.is())
562 return aRet;
564 String sIdentifierMapping = pDatMan->GetIdentifierMapping();
565 rtl::OUString sId = sIdentifierMapping;
566 Reference< sdb::XColumn > xColumn;
567 if (xColumns->hasByName(sId))
568 xColumn = Reference< sdb::XColumn > (*(Reference< XInterface > *)xColumns->getByName(sId).getValue(), UNO_QUERY);
569 if (xColumn.is())
573 if ((rName == xColumn->getString()) && !xColumn->wasNull())
575 Sequence<PropertyValue> aPropSequ(COLUMN_COUNT);
576 PropertyValue* pValues = aPropSequ.getArray();
577 BibConfig* pConfig = BibModul::GetConfig();
578 BibDBDescriptor aBibDesc = BibModul::GetConfig()->GetBibliographyURL();
579 const Mapping* pMapping = pConfig->GetMapping(aBibDesc);
580 for(sal_uInt16 nEntry = 0; nEntry < COLUMN_COUNT; nEntry++)
582 const String sColName = pConfig->GetDefColumnName(
583 nEntry);
584 pValues[nEntry].Name = sColName;
585 pValues[nEntry].Value <<= lcl_AddProperty(xColumns, pMapping, sColName);
587 aRet.setValue(&aPropSequ, ::getCppuType((Sequence<PropertyValue>*)0));
589 break;
592 while(xCursor->next());
595 catch(const Exception&)
597 DBG_UNHANDLED_EXCEPTION();
599 return aRet;
601 /*-- 17.11.99 12:51:39---------------------------------------------------
603 -----------------------------------------------------------------------*/
604 Sequence< rtl::OUString > BibliographyLoader::getElementNames(void) throw ( RuntimeException )
606 Sequence< rtl::OUString > aRet(10);
607 int nRealNameCount = 0;
610 Reference< XResultSet > xCursor(GetDataCursor());
611 Reference< sdb::XColumn > xIdColumn(GetIdentifierColumn());
612 if (xIdColumn.is()) // implies xCursor.is()
616 rtl::OUString sTemp = xIdColumn->getString();
617 if (sTemp.getLength() && !xIdColumn->wasNull())
619 int nLen = aRet.getLength();
620 if(nLen == nRealNameCount)
621 aRet.realloc(nLen + 10);
622 rtl::OUString* pArray = aRet.getArray();
623 pArray[nRealNameCount] = sTemp;
624 nRealNameCount++;
627 while (xCursor->next());
630 catch(const Exception&)
632 DBG_UNHANDLED_EXCEPTION();
635 aRet.realloc(nRealNameCount);
636 return aRet;
638 /*-- 17.11.99 12:51:39---------------------------------------------------
640 -----------------------------------------------------------------------*/
641 sal_Bool BibliographyLoader::hasByName(const rtl::OUString& rName) throw ( RuntimeException )
643 sal_Bool bRet = sal_False;
646 Reference< XResultSet > xCursor = GetDataCursor();
647 Reference< sdb::XColumn > xIdColumn = GetIdentifierColumn();
649 if (xIdColumn.is()) // implies xCursor.is()
653 rtl::OUString sCurrentId = xIdColumn->getString();
654 if (!xIdColumn->wasNull() && (rName.compareTo(sCurrentId) == COMPARE_EQUAL))
656 bRet = sal_True;
657 break;
660 while(xCursor->next());
663 catch(const Exception&)
665 DBG_UNHANDLED_EXCEPTION();
667 return bRet;
669 /*-- 17.11.99 12:51:39---------------------------------------------------
671 -----------------------------------------------------------------------*/
672 Type BibliographyLoader::getElementType(void) throw ( RuntimeException )
674 return ::getCppuType((Sequence<PropertyValue>*)0);
676 /*-- 17.11.99 12:51:40---------------------------------------------------
678 -----------------------------------------------------------------------*/
679 sal_Bool BibliographyLoader::hasElements(void) throw ( RuntimeException )
681 Reference< XResultSet > xCursor = GetDataCursor();
682 Reference< XNameAccess > xColumns = GetDataColumns();
683 return xColumns.is() && (xColumns->getElementNames().getLength() != 0);
686 /*-- 07.12.99 14:28:39---------------------------------------------------
688 -----------------------------------------------------------------------*/
689 Reference< XPropertySetInfo > BibliographyLoader::getPropertySetInfo(void) throw
690 ( RuntimeException )
692 static SfxItemPropertyMapEntry aBibProps_Impl[] =
694 { MAP_CHAR_LEN("BibliographyDataFieldNames"), 0, &::getCppuType((Sequence<PropertyValue>*)0), PropertyAttribute::READONLY, 0},
695 {0,0,0,0,0,0}
697 static Reference< XPropertySetInfo > xRet =
698 SfxItemPropertySet(aBibProps_Impl).getPropertySetInfo();
699 return xRet;
701 /*-- 07.12.99 14:28:39---------------------------------------------------
703 -----------------------------------------------------------------------*/
704 void BibliographyLoader::setPropertyValue(const rtl::OUString& /*PropertyName*/,
705 const Any& /*aValue*/)
706 throw( UnknownPropertyException, PropertyVetoException,
707 IllegalArgumentException, WrappedTargetException, RuntimeException)
709 throw UnknownPropertyException();
710 //no changeable properties
712 /*-- 07.12.99 14:28:39---------------------------------------------------
714 -----------------------------------------------------------------------*/
715 Any BibliographyLoader::getPropertyValue(const rtl::OUString& rPropertyName)
716 throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
718 Any aRet;
719 static const sal_uInt16 aInternalMapping[] =
721 IDENTIFIER_POS , // BibliographyDataField_IDENTIFIER
722 AUTHORITYTYPE_POS , // BibliographyDataField_BIBILIOGRAPHIC_TYPE
723 ADDRESS_POS , // BibliographyDataField_ADDRESS
724 ANNOTE_POS , // BibliographyDataField_ANNOTE
725 AUTHOR_POS , // BibliographyDataField_AUTHOR
726 BOOKTITLE_POS , // BibliographyDataField_BOOKTITLE
727 CHAPTER_POS , // BibliographyDataField_CHAPTER
728 EDITION_POS , // BibliographyDataField_EDITION
729 EDITOR_POS , // BibliographyDataField_EDITOR
730 HOWPUBLISHED_POS , // BibliographyDataField_HOWPUBLISHED
731 INSTITUTION_POS , // BibliographyDataField_INSTITUTION
732 JOURNAL_POS , // BibliographyDataField_JOURNAL
733 MONTH_POS , // BibliographyDataField_MONTH
734 NOTE_POS , // BibliographyDataField_NOTE
735 NUMBER_POS , // BibliographyDataField_NUMBER
736 ORGANIZATIONS_POS , // BibliographyDataField_ORGANIZATIONS
737 PAGES_POS , // BibliographyDataField_PAGES
738 PUBLISHER_POS , // BibliographyDataField_PUBLISHER
739 SCHOOL_POS , // BibliographyDataField_SCHOOL
740 SERIES_POS , // BibliographyDataField_SERIES
741 TITLE_POS , // BibliographyDataField_TITLE
742 REPORTTYPE_POS , // BibliographyDataField_REPORT_TYPE
743 VOLUME_POS , // BibliographyDataField_VOLUME
744 YEAR_POS , // BibliographyDataField_YEAR
745 URL_POS , // BibliographyDataField_URL
746 CUSTOM1_POS , // BibliographyDataField_CUSTOM1
747 CUSTOM2_POS , // BibliographyDataField_CUSTOM2
748 CUSTOM3_POS , // BibliographyDataField_CUSTOM3
749 CUSTOM4_POS , // BibliographyDataField_CUSTOM4
750 CUSTOM5_POS , // BibliographyDataField_CUSTOM5
751 ISBN_POS //BibliographyDataField_ISBN
753 if(C2U("BibliographyDataFieldNames") == rPropertyName)
755 Sequence<PropertyValue> aSeq(COLUMN_COUNT);
756 PropertyValue* pArray = aSeq.getArray();
757 BibConfig* pConfig = BibModul::GetConfig();
758 for(sal_uInt16 i = 0; i <= text::BibliographyDataField::ISBN ; i++)
760 pArray[i].Name = pConfig->GetDefColumnName(aInternalMapping[i]);
761 pArray[i].Value <<= (sal_Int16) i;
763 aRet.setValue(&aSeq, ::getCppuType((Sequence<PropertyValue>*)0));
765 else
766 throw UnknownPropertyException();
767 return aRet;
769 /*-- 07.12.99 14:28:40---------------------------------------------------
771 -----------------------------------------------------------------------*/
772 void BibliographyLoader::addPropertyChangeListener(
773 const rtl::OUString& /*PropertyName*/, const Reference< XPropertyChangeListener > & /*aListener*/)
774 throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
776 //no bound properties
778 /*-- 07.12.99 14:28:40---------------------------------------------------
780 -----------------------------------------------------------------------*/
781 void BibliographyLoader::removePropertyChangeListener(
782 const rtl::OUString& /*PropertyName*/, const Reference< XPropertyChangeListener > & /*aListener*/)
783 throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
785 //no bound properties
787 /*-- 07.12.99 14:28:40---------------------------------------------------
789 -----------------------------------------------------------------------*/
790 void BibliographyLoader::addVetoableChangeListener(
791 const rtl::OUString& /*PropertyName*/, const Reference< XVetoableChangeListener > & /*aListener*/)
792 throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
794 //no vetoable properties
796 /*-- 07.12.99 14:28:40---------------------------------------------------
798 -----------------------------------------------------------------------*/
799 void BibliographyLoader::removeVetoableChangeListener(
800 const rtl::OUString& /*PropertyName*/, const Reference< XVetoableChangeListener > & /*aListener*/)
801 throw( UnknownPropertyException, WrappedTargetException, RuntimeException )
803 //no vetoable properties