Bump version to 5.0-14
[LibreOffice.git] / dbaccess / source / core / dataaccess / ModelImpl.cxx
blob4788df6aa7c429d00f957297f74b9ffe3faacd76
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "commandcontainer.hxx"
21 #include "connection.hxx"
22 #include "core_resource.hrc"
23 #include "core_resource.hxx"
24 #include "databasecontext.hxx"
25 #include "databasedocument.hxx"
26 #include "datasource.hxx"
27 #include "dbastrings.hrc"
28 #include "ModelImpl.hxx"
29 #include "userinformation.hxx"
30 #include "sdbcoretools.hxx"
32 #include <com/sun/star/beans/PropertyBag.hpp>
33 #include <com/sun/star/container/XSet.hpp>
34 #include <com/sun/star/document/MacroExecMode.hpp>
35 #include <com/sun/star/embed/XTransactedObject.hpp>
36 #include <com/sun/star/embed/XTransactionBroadcaster.hpp>
37 #include <com/sun/star/embed/StorageFactory.hpp>
38 #include <com/sun/star/form/XLoadable.hpp>
39 #include <com/sun/star/frame/theGlobalEventBroadcaster.hpp>
40 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
41 #include <com/sun/star/sdb/BooleanComparisonMode.hpp>
42 #include <com/sun/star/script/DocumentScriptLibraryContainer.hpp>
43 #include <com/sun/star/script/DocumentDialogLibraryContainer.hpp>
44 #include <com/sun/star/util/NumberFormatsSupplier.hpp>
46 #include <comphelper/interaction.hxx>
47 #include <comphelper/seqstream.hxx>
48 #include <comphelper/sequence.hxx>
49 #include <connectivity/dbexception.hxx>
50 #include <cppuhelper/exc_hlp.hxx>
51 #include <cppuhelper/typeprovider.hxx>
52 #include <rtl/digest.h>
53 #include <sfx2/signaturestate.hxx>
54 #include <tools/debug.hxx>
55 #include <tools/diagnose_ex.h>
56 #include <osl/diagnose.h>
57 #include <sal/log.hxx>
58 #include <tools/errcode.hxx>
59 #include <tools/urlobj.hxx>
60 #include <unotools/sharedunocomponent.hxx>
62 #include <algorithm>
64 using namespace ::com::sun::star::document;
65 using namespace ::com::sun::star::sdbc;
66 using namespace ::com::sun::star::sdbcx;
67 using namespace ::com::sun::star::sdb;
68 using namespace ::com::sun::star::beans;
69 using namespace ::com::sun::star::uno;
70 using namespace ::com::sun::star::lang;
71 using namespace ::com::sun::star::embed;
72 using namespace ::com::sun::star::container;
73 using namespace ::com::sun::star::util;
74 using namespace ::com::sun::star::io;
75 using namespace ::com::sun::star::ucb;
76 using namespace ::com::sun::star::frame;
77 using namespace ::com::sun::star::view;
78 using namespace ::com::sun::star::task;
79 using namespace ::com::sun::star::reflection;
80 using namespace ::com::sun::star::script;
81 using namespace ::cppu;
82 using namespace ::osl;
83 using namespace ::dbtools;
84 using namespace ::comphelper;
86 namespace dbaccess
89 // VosMutexFacade
90 VosMutexFacade::VosMutexFacade( ::osl::Mutex& _rMutex )
91 :m_rMutex( _rMutex )
95 void VosMutexFacade::acquire()
97 m_rMutex.acquire();
100 void VosMutexFacade::release()
102 m_rMutex.release();
105 bool VosMutexFacade::tryToAcquire()
107 return m_rMutex.tryToAcquire();
110 // DocumentStorageAccess
111 class DocumentStorageAccess : public ::cppu::WeakImplHelper2< XDocumentSubStorageSupplier
112 , XTransactionListener >
114 typedef ::std::map< OUString, Reference< XStorage > > NamedStorages;
116 ::osl::Mutex m_aMutex;
117 /// all sub storages which we ever gave to the outer world
118 NamedStorages m_aExposedStorages;
119 ODatabaseModelImpl* m_pModelImplementation;
120 bool m_bPropagateCommitToRoot;
121 bool m_bDisposingSubStorages;
123 public:
124 DocumentStorageAccess( ODatabaseModelImpl& _rModelImplementation )
125 :m_pModelImplementation( &_rModelImplementation )
126 ,m_bPropagateCommitToRoot( true )
127 ,m_bDisposingSubStorages( false )
131 protected:
132 virtual ~DocumentStorageAccess()
136 public:
137 void dispose();
139 // XDocumentSubStorageSupplier
140 virtual Reference< XStorage > SAL_CALL getDocumentSubStorage( const OUString& aStorageName, ::sal_Int32 _nMode ) throw (RuntimeException, std::exception) SAL_OVERRIDE;
141 virtual Sequence< OUString > SAL_CALL getDocumentSubStoragesNames( ) throw (IOException, RuntimeException, std::exception) SAL_OVERRIDE;
143 // XTransactionListener
144 virtual void SAL_CALL preCommit( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
145 virtual void SAL_CALL commited( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
146 virtual void SAL_CALL preRevert( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
147 virtual void SAL_CALL reverted( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
149 // XEventListener
150 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
152 /// disposes all storages managed by this instance
153 void disposeStorages();
155 /// disposes all known sub storages
156 void commitStorages();
158 /// commits the dedicated "database" storage
159 bool commitEmbeddedStorage( bool _bPreventRootCommits );
161 private:
162 /** opens the sub storage with the given name, in the given mode
164 Reference< XStorage > impl_openSubStorage_nothrow( const OUString& _rStorageName, sal_Int32 _nMode );
166 void impl_suspendCommitPropagation()
168 OSL_ENSURE( m_bPropagateCommitToRoot, "DocumentStorageAccess::impl_suspendCommitPropagation: already suspended" );
169 m_bPropagateCommitToRoot = false;
171 void impl_resumeCommitPropagation()
173 OSL_ENSURE( !m_bPropagateCommitToRoot, "DocumentStorageAccess::impl_resumeCommitPropagation: not suspended" );
174 m_bPropagateCommitToRoot = true;
179 void DocumentStorageAccess::dispose()
181 ::osl::MutexGuard aGuard( m_aMutex );
183 for ( NamedStorages::iterator loop = m_aExposedStorages.begin();
184 loop != m_aExposedStorages.end();
185 ++loop
190 Reference< XTransactionBroadcaster > xBroadcaster( loop->second, UNO_QUERY );
191 if ( xBroadcaster.is() )
192 xBroadcaster->removeTransactionListener( this );
194 catch( const Exception& )
196 DBG_UNHANDLED_EXCEPTION();
200 m_aExposedStorages.clear();
202 m_pModelImplementation = NULL;
205 Reference< XStorage > DocumentStorageAccess::impl_openSubStorage_nothrow( const OUString& _rStorageName, sal_Int32 _nDesiredMode )
207 OSL_ENSURE( !_rStorageName.isEmpty(),"ODatabaseModelImpl::impl_openSubStorage_nothrow: Invalid storage name!" );
209 Reference< XStorage > xStorage;
212 Reference< XStorage > xRootStorage( m_pModelImplementation->getOrCreateRootStorage() );
213 if ( xRootStorage.is() )
215 sal_Int32 nRealMode = m_pModelImplementation->m_bDocumentReadOnly ? ElementModes::READ : _nDesiredMode;
216 if ( nRealMode == ElementModes::READ )
218 if ( xRootStorage.is() && !xRootStorage->hasByName( _rStorageName ) )
219 return xStorage;
222 xStorage = xRootStorage->openStorageElement( _rStorageName, nRealMode );
224 Reference< XTransactionBroadcaster > xBroad( xStorage, UNO_QUERY );
225 if ( xBroad.is() )
226 xBroad->addTransactionListener( this );
229 catch( const Exception& )
231 DBG_UNHANDLED_EXCEPTION();
234 return xStorage;
237 void DocumentStorageAccess::disposeStorages()
239 m_bDisposingSubStorages = true;
241 NamedStorages::iterator aEnd = m_aExposedStorages.end();
242 for ( NamedStorages::iterator aIter = m_aExposedStorages.begin();
243 aIter != aEnd ;
244 ++aIter
249 ::comphelper::disposeComponent( aIter->second );
251 catch( const Exception& )
253 DBG_UNHANDLED_EXCEPTION();
256 m_aExposedStorages.clear();
258 m_bDisposingSubStorages = false;
261 void DocumentStorageAccess::commitStorages()
265 for ( NamedStorages::const_iterator aIter = m_aExposedStorages.begin();
266 aIter != m_aExposedStorages.end();
267 ++aIter
270 tools::stor::commitStorageIfWriteable( aIter->second );
273 catch(const WrappedTargetException&)
275 // WrappedTargetException not allowed to leave
276 throw IOException();
280 bool DocumentStorageAccess::commitEmbeddedStorage( bool _bPreventRootCommits )
282 if ( _bPreventRootCommits )
283 impl_suspendCommitPropagation();
285 bool bSuccess = false;
288 NamedStorages::const_iterator pos = m_aExposedStorages.find( "database" );
289 if ( pos != m_aExposedStorages.end() )
290 bSuccess = tools::stor::commitStorageIfWriteable( pos->second );
292 catch( Exception& )
294 DBG_UNHANDLED_EXCEPTION();
297 if ( _bPreventRootCommits )
298 impl_resumeCommitPropagation();
300 return bSuccess;
304 Reference< XStorage > SAL_CALL DocumentStorageAccess::getDocumentSubStorage( const OUString& aStorageName, ::sal_Int32 _nDesiredMode ) throw (RuntimeException, std::exception)
306 ::osl::MutexGuard aGuard( m_aMutex );
307 NamedStorages::iterator pos = m_aExposedStorages.find( aStorageName );
308 if ( pos == m_aExposedStorages.end() )
310 Reference< XStorage > xResult = impl_openSubStorage_nothrow( aStorageName, _nDesiredMode );
311 pos = m_aExposedStorages.insert( NamedStorages::value_type( aStorageName, xResult ) ).first;
314 return pos->second;
317 Sequence< OUString > SAL_CALL DocumentStorageAccess::getDocumentSubStoragesNames( ) throw (IOException, RuntimeException, std::exception)
319 Reference< XStorage > xRootStor( m_pModelImplementation->getRootStorage() );
320 if ( !xRootStor.is() )
321 return Sequence< OUString >();
323 ::std::vector< OUString > aNames;
325 Sequence< OUString > aElementNames( xRootStor->getElementNames() );
326 for ( sal_Int32 i=0; i<aElementNames.getLength(); ++i )
328 if ( xRootStor->isStorageElement( aElementNames[i] ) )
329 aNames.push_back( aElementNames[i] );
331 return aNames.empty()
332 ? Sequence< OUString >()
333 : Sequence< OUString >( &aNames[0], aNames.size() );
336 void SAL_CALL DocumentStorageAccess::preCommit( const css::lang::EventObject& /*aEvent*/ ) throw (Exception, RuntimeException, std::exception)
338 // not interested in
341 void SAL_CALL DocumentStorageAccess::commited( const css::lang::EventObject& aEvent ) throw (RuntimeException, std::exception)
343 ::osl::MutexGuard aGuard( m_aMutex );
345 if ( m_pModelImplementation )
346 m_pModelImplementation->setModified( true );
348 if ( m_pModelImplementation && m_bPropagateCommitToRoot )
350 Reference< XStorage > xStorage( aEvent.Source, UNO_QUERY );
352 // check if this is the dedicated "database" sub storage
353 NamedStorages::const_iterator pos = m_aExposedStorages.find( "database" );
354 if ( ( pos != m_aExposedStorages.end() )
355 && ( pos->second == xStorage )
358 // if so, also commit the root storage
359 m_pModelImplementation->commitRootStorage();
364 void SAL_CALL DocumentStorageAccess::preRevert( const css::lang::EventObject& /*aEvent*/ ) throw (Exception, RuntimeException, std::exception)
366 // not interested in
369 void SAL_CALL DocumentStorageAccess::reverted( const css::lang::EventObject& /*aEvent*/ ) throw (RuntimeException, std::exception)
371 // not interested in
374 void SAL_CALL DocumentStorageAccess::disposing( const css::lang::EventObject& Source ) throw ( RuntimeException, std::exception )
376 OSL_ENSURE( Reference< XStorage >( Source.Source, UNO_QUERY ).is(), "DocumentStorageAccess::disposing: No storage? What's this?" );
378 if ( m_bDisposingSubStorages )
379 return;
381 for ( NamedStorages::iterator find = m_aExposedStorages.begin();
382 find != m_aExposedStorages.end();
383 ++find
385 if ( find->second == Source.Source )
387 m_aExposedStorages.erase( find );
388 break;
392 // ODatabaseModelImpl
394 ODatabaseModelImpl::ODatabaseModelImpl( const Reference< XComponentContext >& _rxContext, ODatabaseContext& _rDBContext )
395 :m_xModel()
396 ,m_xDataSource()
397 ,m_pStorageAccess( NULL )
398 ,m_aMutex()
399 ,m_aMutexFacade( m_aMutex )
400 ,m_aContainer(4)
401 ,m_aMacroMode( *this )
402 ,m_nImposedMacroExecMode( MacroExecMode::NEVER_EXECUTE )
403 ,m_pDBContext( &_rDBContext )
404 ,m_refCount(0)
405 ,m_aEmbeddedMacros()
406 ,m_bModificationLock( false )
407 ,m_bDocumentInitialized( false )
408 ,m_aContext( _rxContext )
409 ,m_nLoginTimeout(0)
410 ,m_bReadOnly(false)
411 ,m_bPasswordRequired(false)
412 ,m_bSuppressVersionColumns(true)
413 ,m_bModified(false)
414 ,m_bDocumentReadOnly(false)
415 ,m_pSharedConnectionManager(NULL)
416 ,m_nControllerLockCount(0)
418 // some kind of default
419 m_sConnectURL = "jdbc:";
420 m_aTableFilter.realloc(1);
421 m_aTableFilter[0] = "%";
422 impl_construct_nothrow();
425 ODatabaseModelImpl::ODatabaseModelImpl(
426 const OUString& _rRegistrationName,
427 const Reference< XComponentContext >& _rxContext,
428 ODatabaseContext& _rDBContext
430 :m_xModel()
431 ,m_xDataSource()
432 ,m_pStorageAccess( NULL )
433 ,m_aMutex()
434 ,m_aMutexFacade( m_aMutex )
435 ,m_aContainer(4)
436 ,m_aMacroMode( *this )
437 ,m_nImposedMacroExecMode( MacroExecMode::NEVER_EXECUTE )
438 ,m_pDBContext( &_rDBContext )
439 ,m_refCount(0)
440 ,m_aEmbeddedMacros()
441 ,m_bModificationLock( false )
442 ,m_bDocumentInitialized( false )
443 ,m_aContext( _rxContext )
444 ,m_sName(_rRegistrationName)
445 ,m_nLoginTimeout(0)
446 ,m_bReadOnly(false)
447 ,m_bPasswordRequired(false)
448 ,m_bSuppressVersionColumns(true)
449 ,m_bModified(false)
450 ,m_bDocumentReadOnly(false)
451 ,m_pSharedConnectionManager(NULL)
452 ,m_nControllerLockCount(0)
454 impl_construct_nothrow();
457 ODatabaseModelImpl::~ODatabaseModelImpl()
461 void ODatabaseModelImpl::impl_construct_nothrow()
463 // create the property bag to hold the settings (also known as "Info" property)
466 // the set of property value types in the bag is limited:
467 Sequence< Type > aAllowedTypes(6);
468 Type* pAllowedType = aAllowedTypes.getArray();
469 *pAllowedType++ = ::cppu::UnoType<sal_Bool>::get();
470 *pAllowedType++ = ::cppu::UnoType<double>::get();
471 *pAllowedType++ = ::cppu::UnoType<OUString>::get();
472 *pAllowedType++ = ::cppu::UnoType<sal_Int32>::get();
473 *pAllowedType++ = ::cppu::UnoType<sal_Int16>::get();
474 *pAllowedType++ = cppu::UnoType<Sequence< Any >>::get();
476 m_xSettings = PropertyBag::createWithTypes( m_aContext, aAllowedTypes, sal_False/*AllowEmptyPropertyName*/, sal_True/*AutomaticAddition*/ );
478 // insert the default settings
479 Reference< XPropertyContainer > xContainer( m_xSettings, UNO_QUERY_THROW );
480 Reference< XSet > xSettingsSet( m_xSettings, UNO_QUERY_THROW );
481 const AsciiPropertyValue* pSettings = getDefaultDataSourceSettings();
482 for ( ; pSettings->AsciiName; ++pSettings )
484 if ( !pSettings->DefaultValue.hasValue() )
486 Property aProperty(
487 OUString::createFromAscii( pSettings->AsciiName ),
489 pSettings->ValueType,
490 PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT | PropertyAttribute::MAYBEVOID
492 xSettingsSet->insert( makeAny( aProperty ) );
494 else
496 xContainer->addProperty(
497 OUString::createFromAscii( pSettings->AsciiName ),
498 PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
499 pSettings->DefaultValue
504 catch( const Exception& )
506 DBG_UNHANDLED_EXCEPTION();
508 m_pDBContext->appendAtTerminateListener(*this);
511 namespace
513 OUString lcl_getContainerStorageName_throw( ODatabaseModelImpl::ObjectType _eType )
515 const sal_Char* pAsciiName( NULL );
516 switch ( _eType )
518 case ODatabaseModelImpl::E_FORM: pAsciiName = "forms"; break;
519 case ODatabaseModelImpl::E_REPORT: pAsciiName = "reports"; break;
520 case ODatabaseModelImpl::E_QUERY: pAsciiName = "queries"; break;
521 case ODatabaseModelImpl::E_TABLE: pAsciiName = "tables"; break;
522 default:
523 throw RuntimeException();
525 return OUString::createFromAscii( pAsciiName );
528 bool lcl_hasObjectWithMacros_throw( const ODefinitionContainer_Impl& _rObjectDefinitions, const Reference< XStorage >& _rxContainerStorage )
530 bool bSomeDocHasMacros = false;
532 for ( ODefinitionContainer_Impl::const_iterator object = _rObjectDefinitions.begin();
533 ( object != _rObjectDefinitions.end() ) && !bSomeDocHasMacros;
534 ++object
537 #if OSL_DEBUG_LEVEL > 0
538 const OUString& rName( object->first ); (void)rName;
539 #endif
541 const TContentPtr& rDefinition( object->second );
542 const OUString& rPersistentName( rDefinition->m_aProps.sPersistentName );
544 if ( rPersistentName.isEmpty() )
545 { // it's a logical sub folder used to organize the real objects
546 const ODefinitionContainer_Impl& rSubFoldersObjectDefinitions( dynamic_cast< const ODefinitionContainer_Impl& >( *rDefinition.get() ) );
547 bSomeDocHasMacros = lcl_hasObjectWithMacros_throw( rSubFoldersObjectDefinitions, _rxContainerStorage );
548 continue;
551 bSomeDocHasMacros = ODatabaseModelImpl::objectHasMacros( _rxContainerStorage, rPersistentName );
553 return bSomeDocHasMacros;
556 bool lcl_hasObjectsWithMacros_nothrow( ODatabaseModelImpl& _rModel, const ODatabaseModelImpl::ObjectType _eType )
558 bool bSomeDocHasMacros = false;
560 const OContentHelper_Impl& rContainerData( *_rModel.getObjectContainer( _eType ).get() );
561 const ODefinitionContainer_Impl& rObjectDefinitions = dynamic_cast< const ODefinitionContainer_Impl& >( rContainerData );
565 Reference< XStorage > xContainerStorage( _rModel.getStorage( _eType, ElementModes::READWRITE ) );
566 // note the READWRITE here: If the storage already existed before, then the OpenMode will
567 // be ignored, anyway.
568 // If the storage did not yet exist, then it will be created. If the database document
569 // is read-only, the OpenMode will be automatically downgraded to READ. Otherwise,
570 // the storage will in fact be created as READWRITE. While this is not strictly necessary
571 // for this particular use case here, it is required since the storage is *cached*, and
572 // later use cases will need the READWRITE mode.
574 if ( xContainerStorage.is() )
575 bSomeDocHasMacros = lcl_hasObjectWithMacros_throw( rObjectDefinitions, xContainerStorage );
577 catch( const Exception& )
579 DBG_UNHANDLED_EXCEPTION();
580 // be on the safe side: If we can't reliably determine whether there are macros,
581 // assume there actually are. Better this way, than the other way round.
582 bSomeDocHasMacros = true;
585 return bSomeDocHasMacros;
589 bool ODatabaseModelImpl::objectHasMacros( const Reference< XStorage >& _rxContainerStorage, const OUString& _rPersistentName )
591 OSL_PRECOND( _rxContainerStorage.is(), "ODatabaseModelImpl::objectHasMacros: this will crash!" );
593 bool bHasMacros = true;
596 if ( !_rxContainerStorage->hasByName( _rPersistentName ) )
597 return false;
599 Reference< XStorage > xObjectStor( _rxContainerStorage->openStorageElement(
600 _rPersistentName, ElementModes::READ ) );
602 bHasMacros = ::sfx2::DocumentMacroMode::storageHasMacros( xObjectStor );
604 catch( const Exception& )
606 DBG_UNHANDLED_EXCEPTION();
608 return bHasMacros;
611 void ODatabaseModelImpl::reset()
613 m_bReadOnly = false;
614 ::std::vector< TContentPtr > aEmptyContainers( 4 );
615 m_aContainer.swap( aEmptyContainers );
617 if ( m_pStorageAccess )
619 m_pStorageAccess->dispose();
620 m_pStorageAccess->release();
621 m_pStorageAccess = NULL;
625 void SAL_CALL ODatabaseModelImpl::disposing( const ::com::sun::star::lang::EventObject& Source ) throw(RuntimeException)
627 Reference<XConnection> xCon(Source.Source,UNO_QUERY);
628 if ( xCon.is() )
630 bool bStore = false;
631 OWeakConnectionArray::iterator aEnd = m_aConnections.end();
632 for (OWeakConnectionArray::iterator i = m_aConnections.begin(); aEnd != i; ++i)
634 if ( xCon == i->get() )
636 *i = OWeakConnection();
637 bStore = true;
638 break;
642 if ( bStore )
643 commitRootStorage();
645 else
647 OSL_FAIL( "ODatabaseModelImpl::disposing: where does this come from?" );
651 void ODatabaseModelImpl::clearConnections()
653 OWeakConnectionArray aConnections;
654 aConnections.swap( m_aConnections );
656 Reference< XConnection > xConn;
657 OWeakConnectionArray::iterator aEnd = aConnections.end();
658 for ( OWeakConnectionArray::iterator i = aConnections.begin(); aEnd != i; ++i )
660 xConn = *i;
661 if ( xConn.is() )
665 xConn->close();
667 catch(const Exception&)
669 DBG_UNHANDLED_EXCEPTION();
674 m_pSharedConnectionManager = NULL;
675 m_xSharedConnectionManager = NULL;
678 void ODatabaseModelImpl::dispose()
680 // dispose the data source and the model
683 Reference< XDataSource > xDS( m_xDataSource );
684 ::comphelper::disposeComponent( xDS );
686 Reference< XModel > xModel( m_xModel );
687 ::comphelper::disposeComponent( xModel );
689 catch( const Exception& )
691 DBG_UNHANDLED_EXCEPTION();
693 m_xDataSource = WeakReference<XDataSource>();
694 m_xModel = WeakReference< XModel >();
696 ::std::vector<TContentPtr>::iterator aIter = m_aContainer.begin();
697 ::std::vector<TContentPtr>::iterator aEnd = m_aContainer.end();
698 for (;aIter != aEnd ; ++aIter)
700 if ( aIter->get() )
701 (*aIter)->m_pDataSource = NULL;
703 m_aContainer.clear();
705 clearConnections();
707 m_xNumberFormatsSupplier = NULL;
711 bool bCouldStore = commitEmbeddedStorage( true );
712 // "true" means that committing the embedded storage should not trigger committing the root
713 // storage. This is because we are going to commit the root storage ourself, anyway
714 disposeStorages();
715 if ( bCouldStore )
716 commitRootStorage();
718 impl_switchToStorage_throw( NULL );
720 catch( const Exception& )
722 DBG_UNHANDLED_EXCEPTION();
725 if ( m_pStorageAccess )
727 m_pStorageAccess->dispose();
728 m_pStorageAccess->release();
729 m_pStorageAccess = NULL;
733 const Reference< XNumberFormatsSupplier > & ODatabaseModelImpl::getNumberFormatsSupplier()
735 if (!m_xNumberFormatsSupplier.is())
737 // the arguments : the locale of the current user
738 UserInformation aUserInfo;
739 Locale aLocale = aUserInfo.getUserLanguage();
741 m_xNumberFormatsSupplier.set( NumberFormatsSupplier::createWithLocale( m_aContext, aLocale ) );
743 return m_xNumberFormatsSupplier;
746 void ODatabaseModelImpl::setDocFileLocation( const OUString& i_rLoadedFrom )
748 ENSURE_OR_THROW( !i_rLoadedFrom.isEmpty(), "invalid URL" );
749 m_sDocFileLocation = i_rLoadedFrom;
752 void ODatabaseModelImpl::setResource( const OUString& i_rDocumentURL, const Sequence< PropertyValue >& _rArgs )
754 ENSURE_OR_THROW( !i_rDocumentURL.isEmpty(), "invalid URL" );
756 ::comphelper::NamedValueCollection aMediaDescriptor( _rArgs );
757 #if OSL_DEBUG_LEVEL > 0
758 if ( aMediaDescriptor.has( "SalvagedFile" ) )
760 OUString sSalvagedFile( aMediaDescriptor.getOrDefault( "SalvagedFile", OUString() ) );
761 // If SalvagedFile is an empty string, this indicates "the document is being recovered, but i_rDocumentURL already
762 // is the real document URL, not the temporary document location"
763 if ( sSalvagedFile.isEmpty() )
764 sSalvagedFile = i_rDocumentURL;
766 OSL_ENSURE( sSalvagedFile == i_rDocumentURL, "ODatabaseModelImpl::setResource: inconsistency!" );
767 // nowadays, setResource should only be called with the logical URL of the document
769 #endif
771 m_aMediaDescriptor = stripLoadArguments( aMediaDescriptor );
773 impl_switchToLogicalURL( i_rDocumentURL );
776 ::comphelper::NamedValueCollection ODatabaseModelImpl::stripLoadArguments( const ::comphelper::NamedValueCollection& _rArguments )
778 OSL_ENSURE( !_rArguments.has( "Model" ), "ODatabaseModelImpl::stripLoadArguments: this is suspicious (1)!" );
779 OSL_ENSURE( !_rArguments.has( "ViewName" ), "ODatabaseModelImpl::stripLoadArguments: this is suspicious (2)!" );
781 ::comphelper::NamedValueCollection aMutableArgs( _rArguments );
782 aMutableArgs.remove( "Model" );
783 aMutableArgs.remove( "ViewName" );
784 return aMutableArgs;
787 void ODatabaseModelImpl::disposeStorages()
789 getDocumentStorageAccess()->disposeStorages();
792 Reference< XSingleServiceFactory > ODatabaseModelImpl::createStorageFactory() const
794 return StorageFactory::create( m_aContext );
797 void ODatabaseModelImpl::commitRootStorage()
799 Reference< XStorage > xStorage( getOrCreateRootStorage() );
800 bool bSuccess = commitStorageIfWriteable_ignoreErrors( xStorage );
801 SAL_WARN_IF(!bSuccess && xStorage.is(), "dbaccess",
802 "ODatabaseModelImpl::commitRootStorage: could not commit the storage!");
805 Reference< XStorage > ODatabaseModelImpl::getOrCreateRootStorage()
807 if ( !m_xDocumentStorage.is() )
809 Reference< XSingleServiceFactory> xStorageFactory = StorageFactory::create( m_aContext );
810 Any aSource;
811 aSource = m_aMediaDescriptor.get( "Stream" );
812 if ( !aSource.hasValue() )
813 aSource = m_aMediaDescriptor.get( "InputStream" );
814 if ( !aSource.hasValue() && !m_sDocFileLocation.isEmpty() )
815 aSource <<= m_sDocFileLocation;
816 // TODO: shouldn't we also check URL?
818 OSL_ENSURE( aSource.hasValue(), "ODatabaseModelImpl::getOrCreateRootStorage: no source to create the storage from!" );
820 if ( aSource.hasValue() )
822 Sequence< Any > aStorageCreationArgs(2);
823 aStorageCreationArgs[0] = aSource;
824 aStorageCreationArgs[1] <<= ElementModes::READWRITE;
826 Reference< XStorage > xDocumentStorage;
827 OUString sURL;
828 aSource >>= sURL;
829 // Don't try to load a meta-URL as-is.
830 if (!sURL.startsWithIgnoreAsciiCase("vnd.sun.star.pkg:"))
834 xDocumentStorage.set( xStorageFactory->createInstanceWithArguments( aStorageCreationArgs ), UNO_QUERY_THROW );
836 catch( const Exception& )
838 m_bDocumentReadOnly = true;
839 aStorageCreationArgs[1] <<= ElementModes::READ;
842 xDocumentStorage.set( xStorageFactory->createInstanceWithArguments( aStorageCreationArgs ), UNO_QUERY_THROW );
844 catch( const Exception& )
846 DBG_UNHANDLED_EXCEPTION();
851 impl_switchToStorage_throw( xDocumentStorage );
854 return m_xDocumentStorage.getTyped();
857 DocumentStorageAccess* ODatabaseModelImpl::getDocumentStorageAccess()
859 if ( !m_pStorageAccess )
861 m_pStorageAccess = new DocumentStorageAccess( *this );
862 m_pStorageAccess->acquire();
864 return m_pStorageAccess;
867 void ODatabaseModelImpl::modelIsDisposing( const bool _wasInitialized, ResetModelAccess )
869 m_xModel.clear();
871 // Basic libraries and Dialog libraries are a model facet, though held at this impl class.
872 // They automatically dispose themself when the model they belong to is being disposed.
873 // So, to not be tempted to do anything with them, again, we reset them.
874 m_xBasicLibraries.clear();
875 m_xDialogLibraries.clear();
877 m_bDocumentInitialized = _wasInitialized;
880 Reference< XDocumentSubStorageSupplier > ODatabaseModelImpl::getDocumentSubStorageSupplier()
882 return getDocumentStorageAccess();
885 bool ODatabaseModelImpl::commitEmbeddedStorage( bool _bPreventRootCommits )
887 return getDocumentStorageAccess()->commitEmbeddedStorage( _bPreventRootCommits );
890 bool ODatabaseModelImpl::commitStorageIfWriteable_ignoreErrors( const Reference< XStorage >& _rxStorage )
892 bool bSuccess = false;
895 bSuccess = tools::stor::commitStorageIfWriteable( _rxStorage );
897 catch( const Exception& )
899 DBG_UNHANDLED_EXCEPTION();
901 return bSuccess;
904 void ODatabaseModelImpl::setModified( bool _bModified )
906 if ( isModifyLocked() )
907 return;
911 Reference< XModifiable > xModi( m_xModel.get(), UNO_QUERY );
912 if ( xModi.is() )
913 xModi->setModified( _bModified );
914 else
915 m_bModified = _bModified;
917 catch( const Exception& )
919 DBG_UNHANDLED_EXCEPTION();
923 Reference<XDataSource> ODatabaseModelImpl::getOrCreateDataSource()
925 Reference<XDataSource> xDs = m_xDataSource;
926 if ( !xDs.is() )
928 xDs = new ODatabaseSource(this);
929 m_xDataSource = xDs;
931 return xDs;
934 Reference< XModel> ODatabaseModelImpl::getModel_noCreate() const
936 return m_xModel;
939 Reference< XModel > ODatabaseModelImpl::createNewModel_deliverOwnership( bool _bInitialize )
941 Reference< XModel > xModel( m_xModel );
942 OSL_PRECOND( !xModel.is(), "ODatabaseModelImpl::createNewModel_deliverOwnership: not to be called if there already is a model!" );
943 if ( !xModel.is() )
945 bool bHadModelBefore = m_bDocumentInitialized;
947 xModel = ODatabaseDocument::createDatabaseDocument( this, ODatabaseDocument::FactoryAccess() );
948 m_xModel = xModel;
952 Reference< XGlobalEventBroadcaster > xModelCollection = theGlobalEventBroadcaster::get( m_aContext );
953 xModelCollection->insert( makeAny( xModel ) );
955 catch( const Exception& )
957 DBG_UNHANDLED_EXCEPTION();
960 if ( bHadModelBefore )
962 // do an attachResources
963 // In case the document is loaded regularly, this is not necessary, as our loader will do it.
964 // However, in case that the document is implicitly created by asking the data source for the document,
965 // then nobody would call the doc's attachResource. So, we do it here, to ensure it's in a proper
966 // state, fires all events, and so on.
967 // #i105505#
968 xModel->attachResource( xModel->getURL(), m_aMediaDescriptor.getPropertyValues() );
971 if ( _bInitialize )
975 Reference< XLoadable > xLoad( xModel, UNO_QUERY_THROW );
976 xLoad->initNew();
978 catch( RuntimeException& ) { throw; }
979 catch( const Exception& )
981 DBG_UNHANDLED_EXCEPTION();
985 return xModel;
988 void SAL_CALL ODatabaseModelImpl::acquire()
990 osl_atomic_increment(&m_refCount);
993 void SAL_CALL ODatabaseModelImpl::release()
995 if ( osl_atomic_decrement(&m_refCount) == 0 )
997 acquire(); // prevent multiple releases
998 m_pDBContext->removeFromTerminateListener(*this);
999 dispose();
1000 m_pDBContext->storeTransientProperties(*this);
1001 revokeDataSource();
1002 delete this;
1006 void ODatabaseModelImpl::commitStorages()
1008 getDocumentStorageAccess()->commitStorages();
1011 Reference< XStorage > ODatabaseModelImpl::getStorage( const ObjectType _eType, const sal_Int32 _nDesiredMode )
1013 return getDocumentStorageAccess()->getDocumentSubStorage( getObjectContainerStorageName( _eType ), _nDesiredMode );
1016 const AsciiPropertyValue* ODatabaseModelImpl::getDefaultDataSourceSettings()
1018 static const AsciiPropertyValue aKnownSettings[] =
1020 // known JDBC settings
1021 AsciiPropertyValue( "JavaDriverClass", makeAny( OUString() ) ),
1022 AsciiPropertyValue( "JavaDriverClassPath", makeAny( OUString() ) ),
1023 AsciiPropertyValue( "IgnoreCurrency", makeAny( false ) ),
1024 // known settings for file-based drivers
1025 AsciiPropertyValue( "Extension", makeAny( OUString() ) ),
1026 AsciiPropertyValue( "CharSet", makeAny( OUString() ) ),
1027 AsciiPropertyValue( "HeaderLine", makeAny( true ) ),
1028 AsciiPropertyValue( "FieldDelimiter", makeAny( OUString( "," ) ) ),
1029 AsciiPropertyValue( "StringDelimiter", makeAny( OUString( "\"" ) ) ),
1030 AsciiPropertyValue( "DecimalDelimiter", makeAny( OUString( "." ) ) ),
1031 AsciiPropertyValue( "ThousandDelimiter", makeAny( OUString() ) ),
1032 AsciiPropertyValue( "ShowDeleted", makeAny( false ) ),
1033 // known ODBC settings
1034 AsciiPropertyValue( "SystemDriverSettings", makeAny( OUString() ) ),
1035 AsciiPropertyValue( "UseCatalog", makeAny( false ) ),
1036 AsciiPropertyValue( "TypeInfoSettings", makeAny( Sequence< Any >()) ),
1037 // settings related to auto increment handling
1038 AsciiPropertyValue( "AutoIncrementCreation", makeAny( OUString() ) ),
1039 AsciiPropertyValue( "AutoRetrievingStatement", makeAny( OUString() ) ),
1040 AsciiPropertyValue( "IsAutoRetrievingEnabled", makeAny( false ) ),
1041 // known LDAP driver settings
1042 AsciiPropertyValue( "HostName", makeAny( OUString() ) ),
1043 AsciiPropertyValue( "PortNumber", makeAny( (sal_Int32)389 ) ),
1044 AsciiPropertyValue( "BaseDN", makeAny( OUString() ) ),
1045 AsciiPropertyValue( "MaxRowCount", makeAny( (sal_Int32)100 ) ),
1046 // known MySQLNative driver settings
1047 AsciiPropertyValue( "LocalSocket", makeAny( OUString() ) ),
1048 AsciiPropertyValue( "NamedPipe", makeAny( OUString() ) ),
1049 // misc known driver settings
1050 AsciiPropertyValue( "ParameterNameSubstitution", makeAny( false ) ),
1051 AsciiPropertyValue( "AddIndexAppendix", makeAny( true ) ),
1052 AsciiPropertyValue( "IgnoreDriverPrivileges", makeAny( true ) ),
1053 AsciiPropertyValue( "ImplicitCatalogRestriction", ::cppu::UnoType< OUString >::get() ),
1054 AsciiPropertyValue( "ImplicitSchemaRestriction", ::cppu::UnoType< OUString >::get() ),
1055 AsciiPropertyValue( "PrimaryKeySupport", ::cppu::UnoType< sal_Bool >::get() ),
1056 AsciiPropertyValue( "ShowColumnDescription", makeAny( false ) ),
1057 // known SDB level settings
1058 AsciiPropertyValue( "NoNameLengthLimit", makeAny( false ) ),
1059 AsciiPropertyValue( "AppendTableAliasName", makeAny( false ) ),
1060 AsciiPropertyValue( "GenerateASBeforeCorrelationName", makeAny( false ) ),
1061 AsciiPropertyValue( "ColumnAliasInOrderBy", makeAny( true ) ),
1062 AsciiPropertyValue( "EnableSQL92Check", makeAny( false ) ),
1063 AsciiPropertyValue( "BooleanComparisonMode", makeAny( BooleanComparisonMode::EQUAL_INTEGER ) ),
1064 AsciiPropertyValue( "TableTypeFilterMode", makeAny( (sal_Int32)3 ) ),
1065 AsciiPropertyValue( "RespectDriverResultSetType", makeAny( false ) ),
1066 AsciiPropertyValue( "UseSchemaInSelect", makeAny( true ) ),
1067 AsciiPropertyValue( "UseCatalogInSelect", makeAny( true ) ),
1068 AsciiPropertyValue( "EnableOuterJoinEscape", makeAny( true ) ),
1069 AsciiPropertyValue( "PreferDosLikeLineEnds", makeAny( false ) ),
1070 AsciiPropertyValue( "FormsCheckRequiredFields", makeAny( true ) ),
1071 AsciiPropertyValue( "EscapeDateTime", makeAny( true ) ),
1073 // known services to handle database tasks
1074 AsciiPropertyValue( "TableAlterationServiceName", makeAny( OUString() ) ),
1075 AsciiPropertyValue( "TableRenameServiceName", makeAny( OUString() ) ),
1076 AsciiPropertyValue( "ViewAlterationServiceName", makeAny( OUString() ) ),
1077 AsciiPropertyValue( "ViewAccessServiceName", makeAny( OUString() ) ),
1078 AsciiPropertyValue( "CommandDefinitions", makeAny( OUString() ) ),
1079 AsciiPropertyValue( "Forms", makeAny( OUString() ) ),
1080 AsciiPropertyValue( "Reports", makeAny( OUString() ) ),
1081 AsciiPropertyValue( "KeyAlterationServiceName", makeAny( OUString() ) ),
1082 AsciiPropertyValue( "IndexAlterationServiceName", makeAny( OUString() ) ),
1084 AsciiPropertyValue()
1086 return aKnownSettings;
1089 TContentPtr& ODatabaseModelImpl::getObjectContainer( ObjectType _eType )
1091 OSL_PRECOND( _eType >= E_FORM && _eType <= E_TABLE, "ODatabaseModelImpl::getObjectContainer: illegal index!" );
1092 TContentPtr& rContentPtr = m_aContainer[ _eType ];
1094 if ( !rContentPtr.get() )
1096 rContentPtr = TContentPtr( new ODefinitionContainer_Impl );
1097 rContentPtr->m_pDataSource = this;
1098 rContentPtr->m_aProps.aTitle = lcl_getContainerStorageName_throw( _eType );
1100 return rContentPtr;
1103 void ODatabaseModelImpl::revokeDataSource() const
1105 if ( m_pDBContext && !m_sDocumentURL.isEmpty() )
1106 m_pDBContext->revokeDatabaseDocument( *this );
1109 bool ODatabaseModelImpl::adjustMacroMode_AutoReject()
1111 return m_aMacroMode.adjustMacroMode( NULL );
1114 bool ODatabaseModelImpl::checkMacrosOnLoading()
1116 Reference< XInteractionHandler > xInteraction;
1117 xInteraction = m_aMediaDescriptor.getOrDefault( "InteractionHandler", xInteraction );
1118 return m_aMacroMode.checkMacrosOnLoading( xInteraction );
1121 void ODatabaseModelImpl::resetMacroExecutionMode()
1123 m_aMacroMode = ::sfx2::DocumentMacroMode( *this );
1126 Reference< XStorageBasedLibraryContainer > ODatabaseModelImpl::getLibraryContainer( bool _bScript )
1128 Reference< XStorageBasedLibraryContainer >& rxContainer( _bScript ? m_xBasicLibraries : m_xDialogLibraries );
1129 if ( rxContainer.is() )
1130 return rxContainer;
1132 Reference< XStorageBasedDocument > xDocument( getModel_noCreate(), UNO_QUERY_THROW );
1133 // this is only to be called if there already exists a document model - in fact, it is
1134 // to be called by the document model only
1138 Reference< XStorageBasedLibraryContainer > (*Factory)( const Reference< XComponentContext >&, const Reference< XStorageBasedDocument >&)
1139 = _bScript ? &DocumentScriptLibraryContainer::create : &DocumentDialogLibraryContainer::create;
1141 rxContainer.set(
1142 (*Factory)( m_aContext, xDocument ),
1143 UNO_QUERY_THROW
1146 catch( const RuntimeException& )
1148 throw;
1150 catch( const Exception& )
1152 throw WrappedTargetRuntimeException(
1153 OUString(),
1154 xDocument,
1155 ::cppu::getCaughtException()
1158 return rxContainer;
1161 void ODatabaseModelImpl::storeLibraryContainersTo( const Reference< XStorage >& _rxToRootStorage )
1163 if ( m_xBasicLibraries.is() )
1164 m_xBasicLibraries->storeLibrariesToStorage( _rxToRootStorage );
1166 if ( m_xDialogLibraries.is() )
1167 m_xDialogLibraries->storeLibrariesToStorage( _rxToRootStorage );
1170 Reference< XStorage > ODatabaseModelImpl::switchToStorage( const Reference< XStorage >& _rxNewRootStorage )
1172 if ( !_rxNewRootStorage.is() )
1173 throw IllegalArgumentException();
1175 return impl_switchToStorage_throw( _rxNewRootStorage );
1178 namespace
1180 void lcl_modifyListening( ::sfx2::IModifiableDocument& _rDocument,
1181 const Reference< XStorage >& _rxStorage, ::rtl::Reference< ::sfx2::DocumentStorageModifyListener >& _inout_rListener,
1182 comphelper::SolarMutex& _rMutex, bool _bListen )
1184 Reference< XModifiable > xModify( _rxStorage, UNO_QUERY );
1185 OSL_ENSURE( xModify.is() || !_rxStorage.is(), "lcl_modifyListening: storage can't notify us!" );
1187 if ( xModify.is() && !_bListen && _inout_rListener.is() )
1189 xModify->removeModifyListener( _inout_rListener.get() );
1192 if ( _inout_rListener.is() )
1194 _inout_rListener->dispose();
1195 _inout_rListener = NULL;
1198 if ( xModify.is() && _bListen )
1200 _inout_rListener = new ::sfx2::DocumentStorageModifyListener( _rDocument, _rMutex );
1201 xModify->addModifyListener( _inout_rListener.get() );
1206 namespace
1208 static void lcl_rebaseScriptStorage_throw( const Reference< XStorageBasedLibraryContainer >& _rxContainer,
1209 const Reference< XStorage >& _rxNewRootStorage )
1211 if ( _rxContainer.is() )
1213 if ( _rxNewRootStorage.is() )
1214 _rxContainer->setRootStorage( _rxNewRootStorage );
1215 // else
1216 // TODO: what to do here? dispose the container?
1221 Reference< XStorage > ODatabaseModelImpl::impl_switchToStorage_throw( const Reference< XStorage >& _rxNewRootStorage )
1223 // stop listening for modifications at the old storage
1224 lcl_modifyListening( *this, m_xDocumentStorage.getTyped(), m_pStorageModifyListener, m_aMutexFacade, false );
1226 // set new storage
1227 m_xDocumentStorage.reset( _rxNewRootStorage, SharedStorage::TakeOwnership );
1229 // start listening for modifications
1230 lcl_modifyListening( *this, m_xDocumentStorage.getTyped(), m_pStorageModifyListener, m_aMutexFacade, true );
1232 // forward new storage to Basic and Dialog library containers
1233 lcl_rebaseScriptStorage_throw( m_xBasicLibraries, m_xDocumentStorage.getTyped() );
1234 lcl_rebaseScriptStorage_throw( m_xDialogLibraries, m_xDocumentStorage.getTyped() );
1236 m_bReadOnly = !tools::stor::storageIsWritable_nothrow( m_xDocumentStorage.getTyped() );
1237 // TODO: our data source, if it exists, must broadcast the change of its ReadOnly property
1239 return m_xDocumentStorage.getTyped();
1242 void ODatabaseModelImpl::impl_switchToLogicalURL( const OUString& i_rDocumentURL )
1244 if ( i_rDocumentURL == m_sDocumentURL )
1245 return;
1247 const OUString sOldURL( m_sDocumentURL );
1248 // update our name, if necessary
1249 if ( ( m_sName == m_sDocumentURL ) // our name is our old URL
1250 || ( m_sName.isEmpty() ) // we do not have a name, yet (i.e. are not registered at the database context)
1253 INetURLObject aURL( i_rDocumentURL );
1254 if ( aURL.GetProtocol() != INetProtocol::NotValid )
1256 m_sName = i_rDocumentURL;
1257 // TODO: our data source must broadcast the change of the Name property
1261 // remember URL
1262 m_sDocumentURL = i_rDocumentURL;
1264 // update our location, if necessary
1265 if ( m_sDocFileLocation.isEmpty() )
1266 m_sDocFileLocation = m_sDocumentURL;
1268 // register at the database context, or change registration
1269 if ( m_pDBContext )
1271 if ( !sOldURL.isEmpty() )
1272 m_pDBContext->databaseDocumentURLChange( sOldURL, m_sDocumentURL );
1273 else
1274 m_pDBContext->registerDatabaseDocument( *this );
1278 OUString ODatabaseModelImpl::getObjectContainerStorageName( const ObjectType _eType )
1280 return lcl_getContainerStorageName_throw( _eType );
1283 sal_Int16 ODatabaseModelImpl::getCurrentMacroExecMode() const
1285 sal_Int16 nCurrentMode = MacroExecMode::NEVER_EXECUTE;
1288 nCurrentMode = m_aMediaDescriptor.getOrDefault( "MacroExecutionMode", nCurrentMode );
1290 catch( const Exception& )
1292 DBG_UNHANDLED_EXCEPTION();
1294 return nCurrentMode;
1297 bool ODatabaseModelImpl::setCurrentMacroExecMode( sal_uInt16 nMacroMode )
1299 m_aMediaDescriptor.put( "MacroExecutionMode", nMacroMode );
1300 return true;
1303 OUString ODatabaseModelImpl::getDocumentLocation() const
1305 return getURL();
1306 // formerly, we returned getDocFileLocation here, which is the location of the file from which we
1307 // recovered the "real" document.
1308 // However, during CWS autorecovery evolving, we clarified (with MAV/MT) the role of XModel::getURL and
1309 // XStorable::getLocation. In this course, we agreed that for a macro security check, the *document URL*
1310 // (not the recovery file URL) is to be used: The recovery file lies in the backup folder, and by definition,
1311 // this folder is considered to be secure. So, the document URL needs to be used to decide about the security.
1314 Reference< XStorage > ODatabaseModelImpl::getZipStorageToSign()
1316 // we do not support signing the scripting storages, so we're allowed to
1317 // return <NULL/> here.
1318 return Reference< XStorage >();
1321 ODatabaseModelImpl::EmbeddedMacros ODatabaseModelImpl::determineEmbeddedMacros()
1323 if ( !m_aEmbeddedMacros )
1325 if ( ::sfx2::DocumentMacroMode::storageHasMacros( const_cast< ODatabaseModelImpl* >( this )->getOrCreateRootStorage() ) )
1327 m_aEmbeddedMacros.reset( eDocumentWideMacros );
1329 else if ( lcl_hasObjectsWithMacros_nothrow( const_cast< ODatabaseModelImpl& >( *this ), E_FORM )
1330 || lcl_hasObjectsWithMacros_nothrow( const_cast< ODatabaseModelImpl& >( *this ), E_REPORT )
1333 m_aEmbeddedMacros.reset( eSubDocumentMacros );
1335 else
1337 m_aEmbeddedMacros.reset( eNoMacros );
1340 return *m_aEmbeddedMacros;
1343 bool ODatabaseModelImpl::documentStorageHasMacros() const
1345 const_cast< ODatabaseModelImpl* >( this )->determineEmbeddedMacros();
1346 return ( *m_aEmbeddedMacros != eNoMacros );
1349 Reference< XEmbeddedScripts > ODatabaseModelImpl::getEmbeddedDocumentScripts() const
1351 return Reference< XEmbeddedScripts >( getModel_noCreate(), UNO_QUERY );
1354 SignatureState ODatabaseModelImpl::getScriptingSignatureState()
1356 // no support for signatures at the moment
1357 return SignatureState::NOSIGNATURES;
1360 bool ODatabaseModelImpl::hasTrustedScriptingSignature( bool /*bAllowUIToAddAuthor*/ )
1362 // no support for signatures at the moment
1363 return false;
1366 void ODatabaseModelImpl::showBrokenSignatureWarning( const Reference< XInteractionHandler >& /*_rxInteraction*/ ) const
1368 OSL_FAIL( "ODatabaseModelImpl::showBrokenSignatureWarning: signatures can't be broken - we do not support them!" );
1371 void ODatabaseModelImpl::storageIsModified()
1373 setModified( true );
1376 ModelDependentComponent::ModelDependentComponent( const ::rtl::Reference< ODatabaseModelImpl >& _model )
1377 :m_pImpl( _model )
1378 ,m_aMutex( _model->getSharedMutex() )
1382 ModelDependentComponent::~ModelDependentComponent()
1386 } // namespace dbaccess
1388 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */