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