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

Generated by: LCOV version 1.10