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