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