LCOV - code coverage report
Current view: top level - extensions/source/bibliography - bibload.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 24 265 9.1 %
Date: 2014-04-11 Functions: 7 31 22.6 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10