Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : :
21 : : #include "commandcontainer.hxx"
22 : : #include "connection.hxx"
23 : : #include "core_resource.hrc"
24 : : #include "core_resource.hxx"
25 : : #include "databasecontext.hxx"
26 : : #include "databasedocument.hxx"
27 : : #include "datasource.hxx"
28 : : #include "dbastrings.hrc"
29 : : #include "ModelImpl.hxx"
30 : : #include "userinformation.hxx"
31 : : #include "sdbcoretools.hxx"
32 : :
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/sdb/BooleanComparisonMode.hpp>
38 : : #include <com/sun/star/script/DocumentScriptLibraryContainer.hpp>
39 : : #include <com/sun/star/script/DocumentDialogLibraryContainer.hpp>
40 : : #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
41 : : #include <com/sun/star/form/XLoadable.hpp>
42 : :
43 : : #include <comphelper/interaction.hxx>
44 : : #include <comphelper/mediadescriptor.hxx>
45 : : #include <comphelper/seqstream.hxx>
46 : : #include <comphelper/sequence.hxx>
47 : : #include <connectivity/dbexception.hxx>
48 : : #include <cppuhelper/exc_hlp.hxx>
49 : : #include <cppuhelper/typeprovider.hxx>
50 : : #include <rtl/digest.h>
51 : : #include <sfx2/signaturestate.hxx>
52 : : #include <tools/debug.hxx>
53 : : #include <tools/diagnose_ex.h>
54 : : #include <osl/diagnose.h>
55 : : #include <tools/errcode.hxx>
56 : : #include <tools/urlobj.hxx>
57 : : #include <unotools/sharedunocomponent.hxx>
58 : :
59 : : #include <algorithm>
60 : :
61 : : using namespace ::com::sun::star::document;
62 : : using namespace ::com::sun::star::sdbc;
63 : : using namespace ::com::sun::star::sdbcx;
64 : : using namespace ::com::sun::star::sdb;
65 : : using namespace ::com::sun::star::beans;
66 : : using namespace ::com::sun::star::uno;
67 : : using namespace ::com::sun::star::lang;
68 : : using namespace ::com::sun::star::embed;
69 : : using namespace ::com::sun::star::container;
70 : : using namespace ::com::sun::star::util;
71 : : using namespace ::com::sun::star::io;
72 : : using namespace ::com::sun::star::task;
73 : : using namespace ::com::sun::star::ucb;
74 : : using namespace ::com::sun::star::frame;
75 : : using namespace ::com::sun::star::view;
76 : : using namespace ::com::sun::star::task;
77 : : using namespace ::com::sun::star::reflection;
78 : : using namespace ::com::sun::star::script;
79 : : using namespace ::cppu;
80 : : using namespace ::osl;
81 : : using namespace ::dbtools;
82 : : using namespace ::comphelper;
83 : : namespace css = ::com::sun::star;
84 : :
85 : : namespace dbaccess
86 : : {
87 : :
88 : : //============================================================
89 : : //= VosMutexFacade
90 : : //============================================================
91 : 190 : VosMutexFacade::VosMutexFacade( ::osl::Mutex& _rMutex )
92 : 190 : :m_rMutex( _rMutex )
93 : : {
94 : 190 : }
95 : :
96 : 2096 : void SAL_CALL VosMutexFacade::acquire()
97 : : {
98 : 2096 : m_rMutex.acquire();
99 : 2096 : }
100 : :
101 : 0 : sal_Bool SAL_CALL VosMutexFacade::tryToAcquire()
102 : : {
103 : 0 : return m_rMutex.tryToAcquire();
104 : : }
105 : :
106 : 2096 : void SAL_CALL VosMutexFacade::release()
107 : : {
108 : 2096 : m_rMutex.release();
109 : 2096 : }
110 : :
111 : : //============================================================
112 : : //= DocumentStorageAccess
113 : : //============================================================
114 : : DBG_NAME( DocumentStorageAccess )
115 : : class DocumentStorageAccess : public ::cppu::WeakImplHelper2< XDocumentSubStorageSupplier
116 : : , XTransactionListener >
117 : : {
118 : : typedef ::std::map< ::rtl::OUString, Reference< XStorage > > NamedStorages;
119 : :
120 : : ::osl::Mutex m_aMutex;
121 : : /// all sub storages which we ever gave to the outer world
122 : : NamedStorages m_aExposedStorages;
123 : : ODatabaseModelImpl* m_pModelImplementation;
124 : : bool m_bPropagateCommitToRoot;
125 : : bool m_bDisposingSubStorages;
126 : :
127 : : public:
128 : 208 : DocumentStorageAccess( ODatabaseModelImpl& _rModelImplementation )
129 : : :m_pModelImplementation( &_rModelImplementation )
130 : : ,m_bPropagateCommitToRoot( true )
131 [ + - ][ + - ]: 208 : ,m_bDisposingSubStorages( false )
132 : : {
133 : : DBG_CTOR( DocumentStorageAccess, NULL );
134 : 208 : }
135 : :
136 : : protected:
137 : 416 : ~DocumentStorageAccess()
138 [ + - ]: 208 : {
139 : : DBG_DTOR( DocumentStorageAccess, NULL );
140 [ - + ]: 416 : }
141 : :
142 : : public:
143 : : void dispose();
144 : :
145 : : // XDocumentSubStorageSupplier
146 : : virtual Reference< XStorage > SAL_CALL getDocumentSubStorage( const ::rtl::OUString& aStorageName, ::sal_Int32 _nMode ) throw (RuntimeException);
147 : : virtual Sequence< ::rtl::OUString > SAL_CALL getDocumentSubStoragesNames( ) throw (IOException, RuntimeException);
148 : :
149 : : // XTransactionListener
150 : : virtual void SAL_CALL preCommit( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
151 : : virtual void SAL_CALL commited( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException);
152 : : virtual void SAL_CALL preRevert( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException);
153 : : virtual void SAL_CALL reverted( const ::com::sun::star::lang::EventObject& aEvent ) throw (::com::sun::star::uno::RuntimeException);
154 : :
155 : : // XEventListener
156 : : virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
157 : :
158 : : /// disposes all storages managed by this instance
159 : : void disposeStorages();
160 : :
161 : : /// disposes all known sub storages
162 : : void commitStorages() SAL_THROW(( IOException, RuntimeException ));
163 : :
164 : : /// commits the dedicated "database" storage
165 : : bool commitEmbeddedStorage( bool _bPreventRootCommits );
166 : :
167 : : private:
168 : : /** opens the sub storage with the given name, in the given mode
169 : : */
170 : : Reference< XStorage > impl_openSubStorage_nothrow( const ::rtl::OUString& _rStorageName, sal_Int32 _nMode );
171 : :
172 : 194 : void impl_suspendCommitPropagation()
173 : : {
174 : : OSL_ENSURE( m_bPropagateCommitToRoot, "DocumentStorageAccess::impl_suspendCommitPropagation: already suspended" );
175 : 194 : m_bPropagateCommitToRoot = false;
176 : 194 : }
177 : 194 : void impl_resumeCommitPropagation()
178 : : {
179 : : OSL_ENSURE( !m_bPropagateCommitToRoot, "DocumentStorageAccess::impl_resumeCommitPropagation: not suspended" );
180 : 194 : m_bPropagateCommitToRoot = true;
181 : 194 : }
182 : :
183 : : };
184 : :
185 : 208 : void DocumentStorageAccess::dispose()
186 : : {
187 [ + - ]: 208 : ::osl::MutexGuard aGuard( m_aMutex );
188 : :
189 [ - + ]: 416 : for ( NamedStorages::iterator loop = m_aExposedStorages.begin();
190 : 208 : loop != m_aExposedStorages.end();
191 : : ++loop
192 : : )
193 : : {
194 : : try
195 : : {
196 [ # # ]: 0 : Reference< XTransactionBroadcaster > xBroadcaster( loop->second, UNO_QUERY );
197 [ # # ]: 0 : if ( xBroadcaster.is() )
198 [ # # ][ # # ]: 0 : xBroadcaster->removeTransactionListener( this );
[ # # ][ # # ]
199 : : }
200 [ # # ]: 0 : catch( const Exception& )
201 : : {
202 : : DBG_UNHANDLED_EXCEPTION();
203 : : }
204 : : }
205 : :
206 : 208 : m_aExposedStorages.clear();
207 : :
208 [ + - ]: 208 : m_pModelImplementation = NULL;
209 : 208 : }
210 : :
211 : 28 : Reference< XStorage > DocumentStorageAccess::impl_openSubStorage_nothrow( const ::rtl::OUString& _rStorageName, sal_Int32 _nDesiredMode )
212 : : {
213 : : OSL_ENSURE( !_rStorageName.isEmpty(),"ODatabaseModelImpl::impl_openSubStorage_nothrow: Invalid storage name!" );
214 : :
215 : 28 : Reference< XStorage > xStorage;
216 : : try
217 : : {
218 [ + - ]: 28 : Reference< XStorage > xRootStorage( m_pModelImplementation->getOrCreateRootStorage() );
219 [ + - ]: 28 : if ( xRootStorage.is() )
220 : : {
221 [ + - ]: 28 : sal_Int32 nRealMode = m_pModelImplementation->m_bDocumentReadOnly ? ElementModes::READ : _nDesiredMode;
222 [ - + ]: 28 : if ( nRealMode == ElementModes::READ )
223 : : {
224 [ # # ]: 0 : Reference< XNameAccess > xSubStorageNames( xRootStorage, UNO_QUERY );
225 [ # # ][ # # ]: 0 : if ( xSubStorageNames.is() && !xSubStorageNames->hasByName( _rStorageName ) )
[ # # ][ # # ]
[ # # ]
226 [ # # ]: 0 : return xStorage;
227 : : }
228 : :
229 [ + - ][ + - ]: 28 : xStorage = xRootStorage->openStorageElement( _rStorageName, nRealMode );
[ + - ]
230 : :
231 [ + - ]: 28 : Reference< XTransactionBroadcaster > xBroad( xStorage, UNO_QUERY );
232 [ + - ]: 28 : if ( xBroad.is() )
233 [ + - ][ + - ]: 28 : xBroad->addTransactionListener( this );
[ + - ]
234 [ + - ][ # # ]: 28 : }
235 : : }
236 [ # # ]: 0 : catch( const Exception& )
237 : : {
238 : : DBG_UNHANDLED_EXCEPTION();
239 : : }
240 : :
241 : 28 : return xStorage;
242 : : }
243 : :
244 : 380 : void DocumentStorageAccess::disposeStorages()
245 : : {
246 : 380 : m_bDisposingSubStorages = true;
247 : :
248 : 380 : NamedStorages::iterator aEnd = m_aExposedStorages.end();
249 [ + + ]: 408 : for ( NamedStorages::iterator aIter = m_aExposedStorages.begin();
250 : : aIter != aEnd ;
251 : : ++aIter
252 : : )
253 : : {
254 : : try
255 : : {
256 [ + - ]: 28 : ::comphelper::disposeComponent( aIter->second );
257 : : }
258 [ # # ]: 0 : catch( const Exception& )
259 : : {
260 : : DBG_UNHANDLED_EXCEPTION();
261 : : }
262 : : }
263 : 380 : m_aExposedStorages.clear();
264 : :
265 : 380 : m_bDisposingSubStorages = false;
266 [ # # ]: 380 : }
267 : :
268 : 346 : void DocumentStorageAccess::commitStorages() SAL_THROW(( IOException, RuntimeException ))
269 : : {
270 : : try
271 : : {
272 [ - + ]: 692 : for ( NamedStorages::const_iterator aIter = m_aExposedStorages.begin();
273 : 346 : aIter != m_aExposedStorages.end();
274 : : ++aIter
275 : : )
276 : : {
277 [ # # ]: 0 : tools::stor::commitStorageIfWriteable( aIter->second );
278 : : }
279 : : }
280 [ # # ]: 0 : catch(const WrappedTargetException&)
281 : : {
282 : : // WrappedTargetException not allowed to leave
283 [ # # ]: 0 : throw IOException();
284 : : }
285 : 346 : }
286 : :
287 : 540 : bool DocumentStorageAccess::commitEmbeddedStorage( bool _bPreventRootCommits )
288 : : {
289 [ + + ]: 540 : if ( _bPreventRootCommits )
290 : 194 : impl_suspendCommitPropagation();
291 : :
292 : 540 : bool bSuccess = false;
293 : : try
294 : : {
295 [ + - ][ + - ]: 540 : NamedStorages::const_iterator pos = m_aExposedStorages.find( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "database" ) ) );
[ # # ]
296 [ - + ]: 540 : if ( pos != m_aExposedStorages.end() )
297 [ # # ]: 540 : bSuccess = tools::stor::commitStorageIfWriteable( pos->second );
298 : : }
299 : 0 : catch( Exception& )
300 : : {
301 : : DBG_UNHANDLED_EXCEPTION();
302 : : }
303 : :
304 [ + + ]: 540 : if ( _bPreventRootCommits )
305 : 194 : impl_resumeCommitPropagation();
306 : :
307 : 540 : return bSuccess;
308 : :
309 : : }
310 : :
311 : 28 : Reference< XStorage > SAL_CALL DocumentStorageAccess::getDocumentSubStorage( const ::rtl::OUString& aStorageName, ::sal_Int32 _nDesiredMode ) throw (RuntimeException)
312 : : {
313 [ + - ]: 28 : ::osl::MutexGuard aGuard( m_aMutex );
314 [ + - ]: 28 : NamedStorages::iterator pos = m_aExposedStorages.find( aStorageName );
315 [ + - ]: 28 : if ( pos == m_aExposedStorages.end() )
316 : : {
317 [ + - ]: 28 : Reference< XStorage > xResult = impl_openSubStorage_nothrow( aStorageName, _nDesiredMode );
318 [ + - ][ + - ]: 28 : pos = m_aExposedStorages.insert( NamedStorages::value_type( aStorageName, xResult ) ).first;
[ + - ]
319 : : }
320 : :
321 [ + - ]: 28 : return pos->second;
322 : : }
323 : :
324 : 0 : Sequence< ::rtl::OUString > SAL_CALL DocumentStorageAccess::getDocumentSubStoragesNames( ) throw (IOException, RuntimeException)
325 : : {
326 [ # # ]: 0 : Reference< XStorage > xRootStor( m_pModelImplementation->getRootStorage() );
327 [ # # ]: 0 : if ( !xRootStor.is() )
328 [ # # ]: 0 : return Sequence< ::rtl::OUString >();
329 : :
330 [ # # ]: 0 : ::std::vector< ::rtl::OUString > aNames;
331 : :
332 [ # # ]: 0 : Reference< XNameAccess > xNames( xRootStor, UNO_QUERY_THROW );
333 [ # # ][ # # ]: 0 : Sequence< ::rtl::OUString > aElementNames( xNames->getElementNames() );
334 [ # # ]: 0 : for ( sal_Int32 i=0; i<aElementNames.getLength(); ++i )
335 : : {
336 [ # # ][ # # ]: 0 : if ( xRootStor->isStorageElement( aElementNames[i] ) )
[ # # ][ # # ]
337 [ # # ][ # # ]: 0 : aNames.push_back( aElementNames[i] );
338 : : }
339 : 0 : return aNames.empty()
340 : : ? Sequence< ::rtl::OUString >()
341 [ # # ][ # # ]: 0 : : Sequence< ::rtl::OUString >( &aNames[0], aNames.size() );
[ # # ][ # # ]
342 : : }
343 : :
344 : 0 : void SAL_CALL DocumentStorageAccess::preCommit( const css::lang::EventObject& /*aEvent*/ ) throw (Exception, RuntimeException)
345 : : {
346 : : // not interested in
347 : 0 : }
348 : :
349 : 0 : void SAL_CALL DocumentStorageAccess::commited( const css::lang::EventObject& aEvent ) throw (RuntimeException)
350 : : {
351 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
352 : :
353 [ # # ]: 0 : if ( m_pModelImplementation )
354 [ # # ]: 0 : m_pModelImplementation->setModified( sal_True );
355 : :
356 [ # # ][ # # ]: 0 : if ( m_pModelImplementation && m_bPropagateCommitToRoot )
357 : : {
358 [ # # ]: 0 : Reference< XStorage > xStorage( aEvent.Source, UNO_QUERY );
359 : :
360 : : // check if this is the dedicated "database" sub storage
361 [ # # ][ # # ]: 0 : NamedStorages::const_iterator pos = m_aExposedStorages.find( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "database" ) ) );
362 [ # # ][ # # ]: 0 : if ( ( pos != m_aExposedStorages.end() )
[ # # ][ # #
# # # # ]
[ # # ]
363 [ # # ]: 0 : && ( pos->second == xStorage )
364 : : )
365 : : {
366 : : // if so, also commit the root storage
367 [ # # ]: 0 : m_pModelImplementation->commitRootStorage();
368 : 0 : }
369 [ # # ]: 0 : }
370 : 0 : }
371 : :
372 : 0 : void SAL_CALL DocumentStorageAccess::preRevert( const css::lang::EventObject& /*aEvent*/ ) throw (Exception, RuntimeException)
373 : : {
374 : : // not interested in
375 : 0 : }
376 : :
377 : 0 : void SAL_CALL DocumentStorageAccess::reverted( const css::lang::EventObject& /*aEvent*/ ) throw (RuntimeException)
378 : : {
379 : : // not interested in
380 : 0 : }
381 : :
382 : 28 : void SAL_CALL DocumentStorageAccess::disposing( const css::lang::EventObject& Source ) throw ( RuntimeException )
383 : : {
384 : : OSL_ENSURE( Reference< XStorage >( Source.Source, UNO_QUERY ).is(), "DocumentStorageAccess::disposing: No storage? What's this?" );
385 : :
386 [ + - ]: 28 : if ( m_bDisposingSubStorages )
387 : 28 : return;
388 : :
389 [ # # ]: 0 : for ( NamedStorages::iterator find = m_aExposedStorages.begin();
390 : 0 : find != m_aExposedStorages.end();
391 : : ++find
392 : : )
393 [ # # ][ # # ]: 0 : if ( find->second == Source.Source )
394 : : {
395 [ # # ]: 0 : m_aExposedStorages.erase( find );
396 : 0 : break;
397 : : }
398 : : }
399 : :
400 : : //============================================================
401 : : //= ODatabaseModelImpl
402 : : //============================================================
403 : : DBG_NAME(ODatabaseModelImpl)
404 : :
405 : 176 : ODatabaseModelImpl::ODatabaseModelImpl( const Reference< XMultiServiceFactory >& _rxFactory, ODatabaseContext& _rDBContext )
406 : : :m_xModel()
407 : : ,m_xDataSource()
408 : : ,m_pStorageAccess( NULL )
409 : : ,m_aMutex()
410 : : ,m_aMutexFacade( m_aMutex )
411 : : ,m_aContainer(4)
412 : : ,m_aMacroMode( *this )
413 : : ,m_nImposedMacroExecMode( MacroExecMode::NEVER_EXECUTE )
414 : : ,m_pDBContext( &_rDBContext )
415 : : ,m_refCount(0)
416 : : ,m_aEmbeddedMacros()
417 : : ,m_bModificationLock( false )
418 : : ,m_bDocumentInitialized( false )
419 : : ,m_aContext( _rxFactory )
420 : : ,m_nLoginTimeout(0)
421 : : ,m_bReadOnly(sal_False)
422 : : ,m_bPasswordRequired(sal_False)
423 : : ,m_bSuppressVersionColumns(sal_True)
424 : : ,m_bModified(sal_False)
425 : : ,m_bDocumentReadOnly(sal_False)
426 : : ,m_pSharedConnectionManager(NULL)
427 [ + - ][ + - ]: 176 : ,m_nControllerLockCount(0)
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
428 : : {
429 : : // some kind of default
430 : : DBG_CTOR(ODatabaseModelImpl,NULL);
431 [ + - ]: 176 : m_sConnectURL = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("jdbc:"));
432 [ + - ]: 176 : m_aTableFilter.realloc(1);
433 [ + - ][ + - ]: 176 : m_aTableFilter[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("%"));
434 [ + - ]: 176 : impl_construct_nothrow();
435 : 176 : }
436 : :
437 : 14 : ODatabaseModelImpl::ODatabaseModelImpl(
438 : : const ::rtl::OUString& _rRegistrationName,
439 : : const Reference< XMultiServiceFactory >& _rxFactory,
440 : : ODatabaseContext& _rDBContext
441 : : )
442 : : :m_xModel()
443 : : ,m_xDataSource()
444 : : ,m_pStorageAccess( NULL )
445 : : ,m_aMutex()
446 : : ,m_aMutexFacade( m_aMutex )
447 : : ,m_aContainer(4)
448 : : ,m_aMacroMode( *this )
449 : : ,m_nImposedMacroExecMode( MacroExecMode::NEVER_EXECUTE )
450 : : ,m_pDBContext( &_rDBContext )
451 : : ,m_refCount(0)
452 : : ,m_aEmbeddedMacros()
453 : : ,m_bModificationLock( false )
454 : : ,m_bDocumentInitialized( false )
455 : : ,m_aContext( _rxFactory )
456 : : ,m_sName(_rRegistrationName)
457 : : ,m_nLoginTimeout(0)
458 : : ,m_bReadOnly(sal_False)
459 : : ,m_bPasswordRequired(sal_False)
460 : : ,m_bSuppressVersionColumns(sal_True)
461 : : ,m_bModified(sal_False)
462 : : ,m_bDocumentReadOnly(sal_False)
463 : : ,m_pSharedConnectionManager(NULL)
464 [ + - ][ + - ]: 14 : ,m_nControllerLockCount(0)
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
465 : : {
466 : : DBG_CTOR(ODatabaseModelImpl,NULL);
467 [ + - ]: 14 : impl_construct_nothrow();
468 : 14 : }
469 : :
470 [ + - ][ + - ]: 190 : ODatabaseModelImpl::~ODatabaseModelImpl()
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
471 : : {
472 : : DBG_DTOR(ODatabaseModelImpl,NULL);
473 [ - + ]: 380 : }
474 : :
475 : 190 : void ODatabaseModelImpl::impl_construct_nothrow()
476 : : {
477 : : // create the property bag to hold the settings (also known as "Info" property)
478 : : try
479 : : {
480 : : // the set of property value types in the bag is limited:
481 [ + - ]: 190 : Sequence< Type > aAllowedTypes(6);
482 [ + - ]: 190 : Type* pAllowedType = aAllowedTypes.getArray();
483 [ + - ]: 190 : *pAllowedType++ = ::getCppuType( static_cast< sal_Bool* >( NULL ) );
484 [ + - ]: 190 : *pAllowedType++ = ::getCppuType( static_cast< double* >( NULL ) );
485 [ + - ]: 190 : *pAllowedType++ = ::getCppuType( static_cast< ::rtl::OUString* >( NULL ) );
486 [ + - ]: 190 : *pAllowedType++ = ::getCppuType( static_cast< sal_Int32* >( NULL ) );
487 [ + - ]: 190 : *pAllowedType++ = ::getCppuType( static_cast< sal_Int16* >( NULL ) );
488 [ + - ]: 190 : *pAllowedType++ = ::getCppuType( static_cast< Sequence< Any >* >( NULL ) );
489 : :
490 [ + - ]: 190 : Sequence< Any > aInitArgs( 2 );
491 [ + - ]: 190 : aInitArgs[0] <<= NamedValue(
492 : : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AutomaticAddition" ) ),
493 : : makeAny( (sal_Bool)sal_True )
494 [ + - ][ + - ]: 380 : );
[ + - ]
495 [ + - ]: 190 : aInitArgs[1] <<= NamedValue(
496 : : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "AllowedTypes" ) ),
497 : : makeAny( aAllowedTypes )
498 [ + - ][ + - ]: 380 : );
[ + - ]
499 : :
500 [ + - ][ + - ]: 190 : m_xSettings.set( m_aContext.createComponentWithArguments( "com.sun.star.beans.PropertyBag", aInitArgs ), UNO_QUERY_THROW );
501 : :
502 : : // insert the default settings
503 [ + - ]: 190 : Reference< XPropertyContainer > xContainer( m_xSettings, UNO_QUERY_THROW );
504 [ + - ]: 190 : Reference< XSet > xSettingsSet( m_xSettings, UNO_QUERY_THROW );
505 [ + - ]: 190 : const AsciiPropertyValue* pSettings = getDefaultDataSourceSettings();
506 [ + + ]: 10260 : for ( ; pSettings->AsciiName; ++pSettings )
507 : : {
508 [ + + ]: 10070 : if ( !pSettings->DefaultValue.hasValue() )
509 : : {
510 : : Property aProperty(
511 : : ::rtl::OUString::createFromAscii( pSettings->AsciiName ),
512 : : -1,
513 : : pSettings->ValueType,
514 : : PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT | PropertyAttribute::MAYBEVOID
515 : 570 : );
516 [ + - ][ + - ]: 570 : xSettingsSet->insert( makeAny( aProperty ) );
[ + - ]
517 : : }
518 : : else
519 : : {
520 [ + - ]: 9500 : xContainer->addProperty(
521 : : ::rtl::OUString::createFromAscii( pSettings->AsciiName ),
522 : : PropertyAttribute::BOUND | PropertyAttribute::MAYBEDEFAULT,
523 : : pSettings->DefaultValue
524 [ + - ]: 9500 : );
525 : : }
526 [ + - ][ + - ]: 190 : }
[ # # ]
527 : : }
528 : 0 : catch( const Exception& )
529 : : {
530 : : DBG_UNHANDLED_EXCEPTION();
531 : : }
532 : 190 : m_pDBContext->appendAtTerminateListener(*this);
533 : 190 : }
534 : :
535 : : namespace
536 : : {
537 : 768 : ::rtl::OUString lcl_getContainerStorageName_throw( ODatabaseModelImpl::ObjectType _eType )
538 : : {
539 : 768 : const sal_Char* pAsciiName( NULL );
540 [ + + + + : 768 : switch ( _eType )
- ]
541 : : {
542 : 200 : case ODatabaseModelImpl::E_FORM: pAsciiName = "forms"; break;
543 : 200 : case ODatabaseModelImpl::E_REPORT: pAsciiName = "reports"; break;
544 : 184 : case ODatabaseModelImpl::E_QUERY: pAsciiName = "queries"; break;
545 : 184 : case ODatabaseModelImpl::E_TABLE: pAsciiName = "tables"; break;
546 : : default:
547 [ # # ]: 0 : throw RuntimeException();
548 : : }
549 : 768 : return ::rtl::OUString::createFromAscii( pAsciiName );
550 : : }
551 : :
552 : 28 : bool lcl_hasObjectWithMacros_throw( const ODefinitionContainer_Impl& _rObjectDefinitions, const Reference< XStorage >& _rxContainerStorage )
553 : : {
554 : 28 : bool bSomeDocHasMacros = false;
555 : :
556 [ - + ][ # # ]: 84 : for ( ODefinitionContainer_Impl::const_iterator object = _rObjectDefinitions.begin();
[ - + ]
557 [ + - ]: 56 : ( object != _rObjectDefinitions.end() ) && !bSomeDocHasMacros;
558 : : ++object
559 : : )
560 : : {
561 : : #if OSL_DEBUG_LEVEL > 0
562 : : const ::rtl::OUString& rName( object->first ); (void)rName;
563 : : #endif
564 : :
565 : 0 : const TContentPtr& rDefinition( object->second );
566 : 0 : const ::rtl::OUString& rPersistentName( rDefinition->m_aProps.sPersistentName );
567 : :
568 [ # # ]: 0 : if ( rPersistentName.isEmpty() )
569 : : { // it's a logical sub folder used to organize the real objects
570 [ # # ]: 0 : const ODefinitionContainer_Impl& rSubFoldersObjectDefinitions( dynamic_cast< const ODefinitionContainer_Impl& >( *rDefinition.get() ) );
571 [ # # ]: 0 : bSomeDocHasMacros = lcl_hasObjectWithMacros_throw( rSubFoldersObjectDefinitions, _rxContainerStorage );
572 : 0 : continue;
573 : : }
574 : :
575 [ # # ]: 0 : bSomeDocHasMacros = ODatabaseModelImpl::objectHasMacros( _rxContainerStorage, rPersistentName );
576 : : }
577 : 28 : return bSomeDocHasMacros;
578 : : }
579 : :
580 : 28 : bool lcl_hasObjectsWithMacros_nothrow( ODatabaseModelImpl& _rModel, const ODatabaseModelImpl::ObjectType _eType )
581 : : {
582 : 28 : bool bSomeDocHasMacros = false;
583 : :
584 : 28 : const OContentHelper_Impl& rContainerData( *_rModel.getObjectContainer( _eType ).get() );
585 [ + - ]: 28 : const ODefinitionContainer_Impl& rObjectDefinitions = dynamic_cast< const ODefinitionContainer_Impl& >( rContainerData );
586 : :
587 : : try
588 : : {
589 [ + - ]: 28 : Reference< XStorage > xContainerStorage( _rModel.getStorage( _eType, ElementModes::READWRITE ) );
590 : : // note the READWRITE here: If the storage already existed before, then the OpenMode will
591 : : // be ignored, anyway.
592 : : // If the storage did not yet exist, then it will be created. If the database document
593 : : // is read-only, the OpenMode will be automatically downgraded to READ. Otherwise,
594 : : // the storage will in fact be created as READWRITE. While this is not strictly necessary
595 : : // for this particular use case here, it is required since the storage is *cached*, and
596 : : // later use cases will need the READWRITE mode.
597 : :
598 [ + - ]: 28 : if ( xContainerStorage.is() )
599 [ + - ][ # # ]: 28 : bSomeDocHasMacros = lcl_hasObjectWithMacros_throw( rObjectDefinitions, xContainerStorage );
600 : : }
601 : 0 : catch( const Exception& )
602 : : {
603 : : DBG_UNHANDLED_EXCEPTION();
604 : : // be on the safe side: If we can't reliably determine whether there are macros,
605 : : // assume there actually are. Better this way, than the other way round.
606 : 0 : bSomeDocHasMacros = true;
607 : : }
608 : :
609 : 28 : return bSomeDocHasMacros;
610 : : }
611 : : }
612 : :
613 : 0 : bool ODatabaseModelImpl::objectHasMacros( const Reference< XStorage >& _rxContainerStorage, const ::rtl::OUString& _rPersistentName )
614 : : {
615 : : OSL_PRECOND( _rxContainerStorage.is(), "ODatabaseModelImpl::objectHasMacros: this will crash!" );
616 : :
617 : 0 : bool bHasMacros = true;
618 : : try
619 : : {
620 [ # # ][ # # ]: 0 : if ( !_rxContainerStorage->hasByName( _rPersistentName ) )
[ # # ]
621 : 0 : return false;
622 : :
623 [ # # ]: 0 : Reference< XStorage > xObjectStor( _rxContainerStorage->openStorageElement(
624 [ # # ]: 0 : _rPersistentName, ElementModes::READ ) );
625 : :
626 [ # # ][ # # ]: 0 : bHasMacros = ::sfx2::DocumentMacroMode::storageHasMacros( xObjectStor );
627 : : }
628 : 0 : catch( const Exception& )
629 : : {
630 : : DBG_UNHANDLED_EXCEPTION();
631 : : }
632 : 0 : return bHasMacros;
633 : : }
634 : :
635 : 14 : void ODatabaseModelImpl::reset()
636 : : {
637 : 14 : m_bReadOnly = sal_False;
638 [ + - ]: 14 : ::std::vector< TContentPtr > aEmptyContainers( 4 );
639 : 14 : m_aContainer.swap( aEmptyContainers );
640 : :
641 [ + - ]: 14 : if ( m_pStorageAccess )
642 : : {
643 [ + - ]: 14 : m_pStorageAccess->dispose();
644 : 14 : m_pStorageAccess->release();
645 : 14 : m_pStorageAccess = NULL;
646 : 14 : }
647 : 14 : }
648 : :
649 : 48 : void SAL_CALL ODatabaseModelImpl::disposing( const ::com::sun::star::lang::EventObject& Source ) throw(RuntimeException)
650 : : {
651 [ + - ]: 48 : Reference<XConnection> xCon(Source.Source,UNO_QUERY);
652 [ + - ]: 48 : if ( xCon.is() )
653 : : {
654 : 48 : bool bStore = false;
655 : 48 : OWeakConnectionArray::iterator aEnd = m_aConnections.end();
656 [ + - ][ + - ]: 48 : for (OWeakConnectionArray::iterator i = m_aConnections.begin(); aEnd != i; ++i)
657 : : {
658 [ + - ][ + - ]: 48 : if ( xCon == i->get() )
[ + - ]
659 : : {
660 [ + - ][ + - ]: 48 : *i = OWeakConnection();
[ + - ]
661 : 48 : bStore = true;
662 : 48 : break;
663 : : }
664 : : }
665 : :
666 [ + - ]: 48 : if ( bStore )
667 [ + - ]: 48 : commitRootStorage();
668 : : }
669 : : else
670 : : {
671 : : OSL_FAIL( "ODatabaseModelImpl::disposing: where does this come from?" );
672 : 48 : }
673 : 48 : }
674 : :
675 : 208 : void ODatabaseModelImpl::clearConnections()
676 : : {
677 [ + - ]: 208 : OWeakConnectionArray aConnections;
678 : 208 : aConnections.swap( m_aConnections );
679 : :
680 : 208 : Reference< XConnection > xConn;
681 : 208 : OWeakConnectionArray::iterator aEnd = aConnections.end();
682 [ + - ][ + + ]: 268 : for ( OWeakConnectionArray::iterator i = aConnections.begin(); aEnd != i; ++i )
683 : : {
684 [ + - ][ + - ]: 60 : xConn = *i;
[ # # ]
685 [ + + ]: 60 : if ( xConn.is() )
686 : : {
687 : : try
688 : : {
689 [ + - ][ + - ]: 12 : xConn->close();
690 : : }
691 [ # # ]: 0 : catch(const Exception&)
692 : : {
693 : : DBG_UNHANDLED_EXCEPTION();
694 : : }
695 : : }
696 : : }
697 : :
698 : 208 : m_pSharedConnectionManager = NULL;
699 [ + - ]: 208 : m_xSharedConnectionManager = NULL;
700 : 208 : }
701 : :
702 : 194 : void ODatabaseModelImpl::dispose()
703 : : {
704 : : // dispose the data source and the model
705 : : try
706 : : {
707 [ + - ]: 194 : Reference< XDataSource > xDS( m_xDataSource );
708 [ + - ]: 194 : ::comphelper::disposeComponent( xDS );
709 : :
710 [ + - ]: 194 : Reference< XModel > xModel( m_xModel );
711 [ + - ][ # # ]: 194 : ::comphelper::disposeComponent( xModel );
712 : : }
713 [ # # ]: 0 : catch( const Exception& )
714 : : {
715 : : DBG_UNHANDLED_EXCEPTION();
716 : : }
717 [ + - ][ + - ]: 194 : m_xDataSource = WeakReference<XDataSource>();
[ + - ]
718 [ + - ][ + - ]: 194 : m_xModel = WeakReference< XModel >();
[ + - ]
719 : :
720 : 194 : ::std::vector<TContentPtr>::iterator aIter = m_aContainer.begin();
721 : 194 : ::std::vector<TContentPtr>::iterator aEnd = m_aContainer.end();
722 [ + - ][ + + ]: 954 : for (;aIter != aEnd ; ++aIter)
723 : : {
724 [ + + ]: 760 : if ( aIter->get() )
725 : 740 : (*aIter)->m_pDataSource = NULL;
726 : : }
727 : 194 : m_aContainer.clear();
728 : :
729 [ + - ]: 194 : clearConnections();
730 : :
731 [ + - ]: 194 : m_xNumberFormatsSupplier = NULL;
732 : :
733 : : try
734 : : {
735 [ + - ]: 194 : sal_Bool bCouldStore = commitEmbeddedStorage( true );
736 : : // "true" means that committing the embedded storage should not trigger committing the root
737 : : // storage. This is because we are going to commit the root storage ourself, anyway
738 [ + - ]: 194 : disposeStorages();
739 [ - + ]: 194 : if ( bCouldStore )
740 [ # # ]: 0 : commitRootStorage();
741 : :
742 [ + - ][ + - ]: 194 : impl_switchToStorage_throw( NULL );
[ # # ]
743 : : }
744 [ # # ]: 0 : catch( const Exception& )
745 : : {
746 : : DBG_UNHANDLED_EXCEPTION();
747 : : }
748 : :
749 [ + - ]: 194 : if ( m_pStorageAccess )
750 : : {
751 [ + - ]: 194 : m_pStorageAccess->dispose();
752 : 194 : m_pStorageAccess->release();
753 : 194 : m_pStorageAccess = NULL;
754 : : }
755 : 194 : }
756 : :
757 : 552 : const Reference< XNumberFormatsSupplier > & ODatabaseModelImpl::getNumberFormatsSupplier()
758 : : {
759 [ + + ]: 552 : if (!m_xNumberFormatsSupplier.is())
760 : : {
761 : : // the arguments : the locale of the current user
762 [ + - ]: 186 : UserInformation aUserInfo;
763 [ + - ]: 186 : Sequence< Any > aArguments(1);
764 [ + - ][ + - ]: 186 : aArguments.getArray()[0] <<= aUserInfo.getUserLanguage();
765 : :
766 : : m_xNumberFormatsSupplier.set(
767 [ + - ][ + - ]: 186 : m_aContext.createComponentWithArguments( "com.sun.star.util.NumberFormatsSupplier", aArguments ), UNO_QUERY_THROW );
768 [ + - ]: 186 : OSL_ENSURE(m_xNumberFormatsSupplier.is(), "ODatabaseModelImpl::getNumberFormatsSupplier : could not instantiate the formats supplier !");
769 : : }
770 : 552 : return m_xNumberFormatsSupplier;
771 : : }
772 : :
773 : 174 : void ODatabaseModelImpl::setDocFileLocation( const ::rtl::OUString& i_rLoadedFrom )
774 : : {
775 [ - + ][ # # ]: 174 : ENSURE_OR_THROW( !i_rLoadedFrom.isEmpty(), "invalid URL" );
[ # # ][ # # ]
776 : 174 : m_sDocFileLocation = i_rLoadedFrom;
777 : 174 : }
778 : :
779 : 188 : void ODatabaseModelImpl::setResource( const ::rtl::OUString& i_rDocumentURL, const Sequence< PropertyValue >& _rArgs )
780 : : {
781 [ - + ][ # # ]: 188 : ENSURE_OR_THROW( !i_rDocumentURL.isEmpty(), "invalid URL" );
[ # # ][ # # ]
782 : :
783 [ + - ]: 188 : ::comphelper::NamedValueCollection aMediaDescriptor( _rArgs );
784 : : #if OSL_DEBUG_LEVEL > 0
785 : : if ( aMediaDescriptor.has( "SalvagedFile" ) )
786 : : {
787 : : ::rtl::OUString sSalvagedFile( aMediaDescriptor.getOrDefault( "SalvagedFile", ::rtl::OUString() ) );
788 : : // If SalvagedFile is an empty string, this indicates "the document is being recovered, but i_rDocumentURL already
789 : : // is the real document URL, not the temporary document location"
790 : : if ( sSalvagedFile.isEmpty() )
791 : : sSalvagedFile = i_rDocumentURL;
792 : :
793 : : OSL_ENSURE( sSalvagedFile == i_rDocumentURL, "ODatabaseModelImpl::setResource: inconsistency!" );
794 : : // nowadays, setResource should only be called with the logical URL of the document
795 : : }
796 : : #endif
797 : :
798 [ + - ][ + - ]: 188 : m_aMediaDescriptor = stripLoadArguments( aMediaDescriptor );
[ + - ]
799 : :
800 [ + - ][ + - ]: 188 : impl_switchToLogicalURL( i_rDocumentURL );
801 : 188 : }
802 : :
803 : 202 : ::comphelper::NamedValueCollection ODatabaseModelImpl::stripLoadArguments( const ::comphelper::NamedValueCollection& _rArguments )
804 : : {
805 : : OSL_ENSURE( !_rArguments.has( "Model" ), "ODatabaseModelImpl::stripLoadArguments: this is suspicious (1)!" );
806 : : OSL_ENSURE( !_rArguments.has( "ViewName" ), "ODatabaseModelImpl::stripLoadArguments: this is suspicious (2)!" );
807 : :
808 : 202 : ::comphelper::NamedValueCollection aMutableArgs( _rArguments );
809 [ + - ]: 202 : aMutableArgs.remove( "Model" );
810 [ + - ]: 202 : aMutableArgs.remove( "ViewName" );
811 : 202 : return aMutableArgs;
812 : : }
813 : :
814 : 380 : void ODatabaseModelImpl::disposeStorages() SAL_THROW(())
815 : : {
816 : 380 : getDocumentStorageAccess()->disposeStorages();
817 : 380 : }
818 : :
819 : 186 : Reference< XSingleServiceFactory > ODatabaseModelImpl::createStorageFactory() const
820 : : {
821 [ + - ]: 186 : return Reference< XSingleServiceFactory >( m_aContext.createComponent( "com.sun.star.embed.StorageFactory" ), UNO_QUERY_THROW );
822 : : }
823 : :
824 : 48 : void ODatabaseModelImpl::commitRootStorage()
825 : : {
826 [ + - ]: 48 : Reference< XStorage > xStorage( getOrCreateRootStorage() );
827 : : #if OSL_DEBUG_LEVEL > 0
828 : : bool bSuccess =
829 : : #endif
830 [ + - ]: 48 : commitStorageIfWriteable_ignoreErrors( xStorage );
831 : : OSL_ENSURE( bSuccess || !xStorage.is(),
832 : 48 : "ODatabaseModelImpl::commitRootStorage: could commit the storage!" );
833 : 48 : }
834 : :
835 : 268 : Reference< XStorage > ODatabaseModelImpl::getOrCreateRootStorage()
836 : : {
837 [ + + ]: 268 : if ( !m_xDocumentStorage.is() )
838 : : {
839 [ + - ]: 14 : Reference< XSingleServiceFactory> xStorageFactory = createStorageFactory();
840 [ + - ]: 14 : if ( xStorageFactory.is() )
841 : : {
842 : 14 : Any aSource;
843 [ + - ]: 14 : aSource = m_aMediaDescriptor.get( "Stream" );
844 [ + - ]: 14 : if ( !aSource.hasValue() )
845 [ + - ]: 14 : aSource = m_aMediaDescriptor.get( "InputStream" );
846 [ + - ][ + - ]: 14 : if ( !aSource.hasValue() && !m_sDocFileLocation.isEmpty() )
[ + - ]
847 [ + - ]: 14 : aSource <<= m_sDocFileLocation;
848 : : // TODO: shouldn't we also check URL?
849 : :
850 : : OSL_ENSURE( aSource.hasValue(), "ODatabaseModelImpl::getOrCreateRootStorage: no source to create the storage from!" );
851 : :
852 [ + - ]: 14 : if ( aSource.hasValue() )
853 : : {
854 [ + - ]: 14 : Sequence< Any > aStorageCreationArgs(2);
855 [ + - ]: 14 : aStorageCreationArgs[0] = aSource;
856 [ + - ][ + - ]: 14 : aStorageCreationArgs[1] <<= ElementModes::READWRITE;
857 : :
858 : 14 : Reference< XStorage > xDocumentStorage;
859 : : try
860 : : {
861 [ + - ][ + - ]: 14 : xDocumentStorage.set( xStorageFactory->createInstanceWithArguments( aStorageCreationArgs ), UNO_QUERY_THROW );
[ + - ]
862 : : }
863 [ # # # # ]: 0 : catch( const Exception& )
864 : : {
865 : 0 : m_bDocumentReadOnly = sal_True;
866 [ # # # # ]: 0 : aStorageCreationArgs[1] <<= ElementModes::READ;
867 : : try
868 : : {
869 [ # # # # : 0 : xDocumentStorage.set( xStorageFactory->createInstanceWithArguments( aStorageCreationArgs ), UNO_QUERY_THROW );
# # # # ]
870 : : }
871 [ # # ]: 0 : catch( const Exception& )
872 : : {
873 : : DBG_UNHANDLED_EXCEPTION();
874 : : }
875 : : }
876 : :
877 [ + - ][ + - ]: 14 : impl_switchToStorage_throw( xDocumentStorage );
878 : 14 : }
879 : 14 : }
880 : : }
881 : 268 : return m_xDocumentStorage.getTyped();
882 : : }
883 : :
884 : 1294 : DocumentStorageAccess* ODatabaseModelImpl::getDocumentStorageAccess()
885 : : {
886 [ + + ]: 1294 : if ( !m_pStorageAccess )
887 : : {
888 [ + - ]: 208 : m_pStorageAccess = new DocumentStorageAccess( *this );
889 : 208 : m_pStorageAccess->acquire();
890 : : }
891 : 1294 : return m_pStorageAccess;
892 : : }
893 : :
894 : 186 : void ODatabaseModelImpl::modelIsDisposing( const bool _wasInitialized, ResetModelAccess )
895 : : {
896 [ + - ]: 186 : m_xModel = Reference< XModel >();
897 : :
898 : : // Basic libraries and Dialog libraries are a model facet, though held at this impl class.
899 : : // They automatically dispose themself when the model they belong to is being disposed.
900 : : // So, to not be tempted to do anything with them, again, we reset them.
901 : 186 : m_xBasicLibraries.clear();
902 : 186 : m_xDialogLibraries.clear();
903 : :
904 : 186 : m_bDocumentInitialized = _wasInitialized;
905 : 186 : }
906 : :
907 : 0 : Reference< XDocumentSubStorageSupplier > ODatabaseModelImpl::getDocumentSubStorageSupplier()
908 : : {
909 [ # # ]: 0 : return getDocumentStorageAccess();
910 : : }
911 : :
912 : 540 : bool ODatabaseModelImpl::commitEmbeddedStorage( bool _bPreventRootCommits )
913 : : {
914 : 540 : return getDocumentStorageAccess()->commitEmbeddedStorage( _bPreventRootCommits );
915 : : }
916 : :
917 : 48 : bool ODatabaseModelImpl::commitStorageIfWriteable_ignoreErrors( const Reference< XStorage >& _rxStorage ) SAL_THROW(())
918 : : {
919 : 48 : bool bSuccess = false;
920 : : try
921 : : {
922 [ + - ]: 48 : bSuccess = tools::stor::commitStorageIfWriteable( _rxStorage );
923 : : }
924 : 0 : catch( const Exception& )
925 : : {
926 : : DBG_UNHANDLED_EXCEPTION();
927 : : }
928 [ # # ]: 48 : return bSuccess;
929 : : }
930 : :
931 : 2124 : void ODatabaseModelImpl::setModified( sal_Bool _bModified )
932 : : {
933 [ + + ]: 2124 : if ( isModifyLocked() )
934 : 2124 : return;
935 : :
936 : : try
937 : : {
938 [ + - ][ + - ]: 214 : Reference< XModifiable > xModi( m_xModel.get(), UNO_QUERY );
939 [ + + ]: 214 : if ( xModi.is() )
940 [ + - ][ + - ]: 44 : xModi->setModified( _bModified );
941 : : else
942 [ # # ]: 214 : m_bModified = _bModified;
943 : : }
944 : 0 : catch( const Exception& )
945 : : {
946 : : DBG_UNHANDLED_EXCEPTION();
947 : : }
948 : : }
949 : :
950 : 1348 : Reference<XDataSource> ODatabaseModelImpl::getOrCreateDataSource()
951 : : {
952 : 1348 : Reference<XDataSource> xDs = m_xDataSource;
953 [ + + ]: 1348 : if ( !xDs.is() )
954 : : {
955 [ + - ][ + - ]: 404 : xDs = new ODatabaseSource(this);
[ + - ][ + - ]
[ + - ]
956 [ + - ]: 404 : m_xDataSource = xDs;
957 : : }
958 : 1348 : return xDs;
959 : : }
960 : :
961 : 2490 : Reference< XModel> ODatabaseModelImpl::getModel_noCreate() const
962 : : {
963 : 2490 : return m_xModel;
964 : : }
965 : :
966 : 186 : Reference< XModel > ODatabaseModelImpl::createNewModel_deliverOwnership( bool _bInitialize )
967 : : {
968 : 186 : Reference< XModel > xModel( m_xModel );
969 : : OSL_PRECOND( !xModel.is(), "ODatabaseModelImpl::createNewModel_deliverOwnership: not to be called if there already is a model!" );
970 [ + - ]: 186 : if ( !xModel.is() )
971 : : {
972 : 186 : bool bHadModelBefore = m_bDocumentInitialized;
973 : :
974 [ + - ][ + - ]: 186 : xModel = ODatabaseDocument::createDatabaseDocument( this, ODatabaseDocument::FactoryAccess() );
[ + - ][ + - ]
[ + - ]
975 [ + - ]: 186 : m_xModel = xModel;
976 : :
977 : : try
978 : : {
979 : 186 : Reference< XSet > xModelCollection;
980 [ + - ][ + - ]: 186 : if ( m_aContext.createComponent( "com.sun.star.frame.GlobalEventBroadcaster", xModelCollection ) )
981 [ + - ][ + - ]: 186 : xModelCollection->insert( makeAny( xModel ) );
[ + - ][ # # ]
982 : : }
983 [ # # ]: 0 : catch( const Exception& )
984 : : {
985 : : DBG_UNHANDLED_EXCEPTION();
986 : : }
987 : :
988 [ - + ]: 186 : if ( bHadModelBefore )
989 : : {
990 : : // do an attachResources
991 : : // In case the document is loaded regularly, this is not necessary, as our loader will do it.
992 : : // However, in case that the document is implicitly created by asking the data source for the document,
993 : : // then nobody would call the doc's attachResource. So, we do it here, to ensure it's in a proper
994 : : // state, fires all events, and so on.
995 : : // #i105505#
996 [ # # ][ # # ]: 0 : xModel->attachResource( xModel->getURL(), m_aMediaDescriptor.getPropertyValues() );
[ # # ][ # # ]
[ # # ][ # # ]
997 : : }
998 : :
999 [ - + ]: 186 : if ( _bInitialize )
1000 : : {
1001 : : try
1002 : : {
1003 [ # # ]: 0 : Reference< XLoadable > xLoad( xModel, UNO_QUERY_THROW );
1004 [ # # ][ # # ]: 0 : xLoad->initNew();
1005 : : }
1006 [ # # # ]: 0 : catch( RuntimeException& ) { throw; }
1007 [ # # ]: 0 : catch( const Exception& )
1008 : : {
1009 : : DBG_UNHANDLED_EXCEPTION();
1010 : : }
1011 : : }
1012 : : }
1013 : 186 : return xModel;
1014 : : }
1015 : :
1016 : 1564 : oslInterlockedCount SAL_CALL ODatabaseModelImpl::acquire()
1017 : : {
1018 : 1564 : return osl_incrementInterlockedCount(&m_refCount);
1019 : : }
1020 : :
1021 : 1374 : oslInterlockedCount SAL_CALL ODatabaseModelImpl::release()
1022 : : {
1023 [ + + ]: 1374 : if ( osl_decrementInterlockedCount(&m_refCount) == 0 )
1024 : : {
1025 : 190 : acquire(); // prevent multiple releases
1026 : 190 : m_pDBContext->removeFromTerminateListener(*this);
1027 : 190 : dispose();
1028 : 190 : m_pDBContext->storeTransientProperties(*this);
1029 : 190 : revokeDataSource();
1030 [ + - ]: 190 : delete this;
1031 : 190 : return 0;
1032 : : }
1033 : 1374 : return m_refCount;
1034 : : }
1035 : :
1036 : 346 : void ODatabaseModelImpl::commitStorages() SAL_THROW(( IOException, RuntimeException ))
1037 : : {
1038 : 346 : getDocumentStorageAccess()->commitStorages();
1039 : 346 : }
1040 : :
1041 : 28 : Reference< XStorage > ODatabaseModelImpl::getStorage( const ObjectType _eType, const sal_Int32 _nDesiredMode )
1042 : : {
1043 [ + - ]: 28 : return getDocumentStorageAccess()->getDocumentSubStorage( getObjectContainerStorageName( _eType ), _nDesiredMode );
1044 : : }
1045 : :
1046 : 246 : const AsciiPropertyValue* ODatabaseModelImpl::getDefaultDataSourceSettings()
1047 : : {
1048 : : static const AsciiPropertyValue aKnownSettings[] =
1049 : : {
1050 : : // known JDBC settings
1051 : : AsciiPropertyValue( "JavaDriverClass", makeAny( ::rtl::OUString() ) ),
1052 : : AsciiPropertyValue( "JavaDriverClassPath", makeAny( ::rtl::OUString() ) ),
1053 : : AsciiPropertyValue( "IgnoreCurrency", makeAny( (sal_Bool)sal_False ) ),
1054 : : // known settings for file-based drivers
1055 : : AsciiPropertyValue( "Extension", makeAny( ::rtl::OUString() ) ),
1056 : : AsciiPropertyValue( "CharSet", makeAny( ::rtl::OUString() ) ),
1057 : : AsciiPropertyValue( "HeaderLine", makeAny( (sal_Bool)sal_True ) ),
1058 : : AsciiPropertyValue( "FieldDelimiter", makeAny( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "," ) ) ) ),
1059 : : AsciiPropertyValue( "StringDelimiter", makeAny( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "\"" ) ) ) ),
1060 : : AsciiPropertyValue( "DecimalDelimiter", makeAny( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "." ) ) ) ),
1061 : : AsciiPropertyValue( "ThousandDelimiter", makeAny( ::rtl::OUString() ) ),
1062 : : AsciiPropertyValue( "ShowDeleted", makeAny( (sal_Bool)sal_False ) ),
1063 : : // known ODBC settings
1064 : : AsciiPropertyValue( "SystemDriverSettings", makeAny( ::rtl::OUString() ) ),
1065 : : AsciiPropertyValue( "UseCatalog", makeAny( (sal_Bool)sal_False ) ),
1066 : : AsciiPropertyValue( "TypeInfoSettings", makeAny( Sequence< Any >()) ),
1067 : : // settings related to auto increment handling
1068 : : AsciiPropertyValue( "AutoIncrementCreation", makeAny( ::rtl::OUString() ) ),
1069 : : AsciiPropertyValue( "AutoRetrievingStatement", makeAny( ::rtl::OUString() ) ),
1070 : : AsciiPropertyValue( "IsAutoRetrievingEnabled", makeAny( (sal_Bool)sal_False ) ),
1071 : : // known LDAP driver settings
1072 : : AsciiPropertyValue( "HostName", makeAny( ::rtl::OUString() ) ),
1073 : : AsciiPropertyValue( "PortNumber", makeAny( (sal_Int32)389 ) ),
1074 : : AsciiPropertyValue( "BaseDN", makeAny( ::rtl::OUString() ) ),
1075 : : AsciiPropertyValue( "MaxRowCount", makeAny( (sal_Int32)100 ) ),
1076 : : // known MySQLNative driver settings
1077 : : AsciiPropertyValue( "LocalSocket", makeAny( ::rtl::OUString() ) ),
1078 : : AsciiPropertyValue( "NamedPipe", makeAny( ::rtl::OUString() ) ),
1079 : : // misc known driver settings
1080 : : AsciiPropertyValue( "ParameterNameSubstitution", makeAny( (sal_Bool)sal_False ) ),
1081 : : AsciiPropertyValue( "AddIndexAppendix", makeAny( (sal_Bool)sal_True ) ),
1082 : : AsciiPropertyValue( "IgnoreDriverPrivileges", makeAny( (sal_Bool)sal_True ) ),
1083 : 9 : AsciiPropertyValue( "ImplicitCatalogRestriction", ::cppu::UnoType< ::rtl::OUString >::get() ),
1084 : 9 : AsciiPropertyValue( "ImplicitSchemaRestriction", ::cppu::UnoType< ::rtl::OUString >::get() ),
1085 : 9 : AsciiPropertyValue( "PrimaryKeySupport", ::cppu::UnoType< sal_Bool >::get() ),
1086 : : AsciiPropertyValue( "ShowColumnDescription", makeAny( (sal_Bool)sal_False ) ),
1087 : : // known SDB level settings
1088 : : AsciiPropertyValue( "NoNameLengthLimit", makeAny( (sal_Bool)sal_False ) ),
1089 : : AsciiPropertyValue( "AppendTableAliasName", makeAny( (sal_Bool)sal_False ) ),
1090 : : AsciiPropertyValue( "GenerateASBeforeCorrelationName", makeAny( (sal_Bool)sal_True ) ),
1091 : : AsciiPropertyValue( "ColumnAliasInOrderBy", makeAny( (sal_Bool)sal_True ) ),
1092 : : AsciiPropertyValue( "EnableSQL92Check", makeAny( (sal_Bool)sal_False ) ),
1093 : : AsciiPropertyValue( "BooleanComparisonMode", makeAny( BooleanComparisonMode::EQUAL_INTEGER ) ),
1094 : : AsciiPropertyValue( "TableTypeFilterMode", makeAny( (sal_Int32)3 ) ),
1095 : : AsciiPropertyValue( "RespectDriverResultSetType", makeAny( (sal_Bool)sal_False ) ),
1096 : : AsciiPropertyValue( "UseSchemaInSelect", makeAny( (sal_Bool)sal_True ) ),
1097 : : AsciiPropertyValue( "UseCatalogInSelect", makeAny( (sal_Bool)sal_True ) ),
1098 : : AsciiPropertyValue( "EnableOuterJoinEscape", makeAny( (sal_Bool)sal_True ) ),
1099 : : AsciiPropertyValue( "PreferDosLikeLineEnds", makeAny( (sal_Bool)sal_False ) ),
1100 : : AsciiPropertyValue( "FormsCheckRequiredFields", makeAny( (sal_Bool)sal_True ) ),
1101 : : AsciiPropertyValue( "EscapeDateTime", makeAny( (sal_Bool)sal_True ) ),
1102 : :
1103 : : // known services to handle database tasks
1104 : : AsciiPropertyValue( "TableAlterationServiceName", makeAny( ::rtl::OUString() ) ),
1105 : : AsciiPropertyValue( "TableRenameServiceName", makeAny( ::rtl::OUString() ) ),
1106 : : AsciiPropertyValue( "ViewAlterationServiceName", makeAny( ::rtl::OUString() ) ),
1107 : : AsciiPropertyValue( "ViewAccessServiceName", makeAny( ::rtl::OUString() ) ),
1108 : : AsciiPropertyValue( "CommandDefinitions", makeAny( ::rtl::OUString() ) ),
1109 : : AsciiPropertyValue( "Forms", makeAny( ::rtl::OUString() ) ),
1110 : : AsciiPropertyValue( "Reports", makeAny( ::rtl::OUString() ) ),
1111 : : AsciiPropertyValue( "KeyAlterationServiceName", makeAny( ::rtl::OUString() ) ),
1112 : : AsciiPropertyValue( "IndexAlterationServiceName", makeAny( ::rtl::OUString() ) ),
1113 : :
1114 : : AsciiPropertyValue()
1115 [ + + ][ + - ]: 768 : };
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ # # # #
# # ][ + + ]
1116 : 246 : return aKnownSettings;
1117 : : }
1118 : :
1119 : 1352 : TContentPtr& ODatabaseModelImpl::getObjectContainer( ObjectType _eType )
1120 : : {
1121 : : OSL_PRECOND( _eType >= E_FORM && _eType <= E_TABLE, "ODatabaseModelImpl::getObjectContainer: illegal index!" );
1122 : 1352 : TContentPtr& rContentPtr = m_aContainer[ _eType ];
1123 : :
1124 [ + + ]: 1352 : if ( !rContentPtr.get() )
1125 : : {
1126 [ + - ][ + - ]: 740 : rContentPtr = TContentPtr( new ODefinitionContainer_Impl );
1127 : 740 : rContentPtr->m_pDataSource = this;
1128 : 740 : rContentPtr->m_aProps.aTitle = lcl_getContainerStorageName_throw( _eType );
1129 : : }
1130 : 1352 : return rContentPtr;
1131 : : }
1132 : :
1133 : 190 : void ODatabaseModelImpl::revokeDataSource() const
1134 : : {
1135 [ + - ][ + + ]: 190 : if ( m_pDBContext && !m_sDocumentURL.isEmpty() )
[ + + ]
1136 : 186 : m_pDBContext->revokeDatabaseDocument( *this );
1137 : 190 : }
1138 : :
1139 : 0 : bool ODatabaseModelImpl::adjustMacroMode_AutoReject()
1140 : : {
1141 [ # # ]: 0 : return m_aMacroMode.adjustMacroMode( NULL );
1142 : : }
1143 : :
1144 : 0 : bool ODatabaseModelImpl::checkMacrosOnLoading()
1145 : : {
1146 : 0 : Reference< XInteractionHandler > xInteraction;
1147 [ # # ][ # # ]: 0 : xInteraction = m_aMediaDescriptor.getOrDefault( "InteractionHandler", xInteraction );
1148 [ # # ]: 0 : return m_aMacroMode.checkMacrosOnLoading( xInteraction );
1149 : : }
1150 : :
1151 : 186 : void ODatabaseModelImpl::resetMacroExecutionMode()
1152 : : {
1153 [ + - ]: 186 : m_aMacroMode = ::sfx2::DocumentMacroMode( *this );
1154 : 186 : }
1155 : :
1156 : 0 : Reference< XStorageBasedLibraryContainer > ODatabaseModelImpl::getLibraryContainer( bool _bScript )
1157 : : {
1158 [ # # ]: 0 : Reference< XStorageBasedLibraryContainer >& rxContainer( _bScript ? m_xBasicLibraries : m_xDialogLibraries );
1159 [ # # ]: 0 : if ( rxContainer.is() )
1160 : 0 : return rxContainer;
1161 : :
1162 [ # # ][ # # ]: 0 : Reference< XStorageBasedDocument > xDocument( getModel_noCreate(), UNO_QUERY_THROW );
1163 : : // this is only to be called if there already exists a document model - in fact, it is
1164 : : // to be called by the document model only
1165 : :
1166 : : try
1167 : : {
1168 : : Reference< XStorageBasedLibraryContainer > (*Factory)( const Reference< XComponentContext >&, const Reference< XStorageBasedDocument >&)
1169 [ # # ]: 0 : = _bScript ? &DocumentScriptLibraryContainer::create : &DocumentDialogLibraryContainer::create;
1170 : :
1171 : : rxContainer.set(
1172 : : (*Factory)( m_aContext.getUNOContext(), xDocument ),
1173 : : UNO_QUERY_THROW
1174 [ # # ][ # # ]: 0 : );
[ # # ]
1175 : : }
1176 : 0 : catch( const RuntimeException& )
1177 : : {
1178 : 0 : throw;
1179 : : }
1180 [ # # # ]: 0 : catch( const Exception& )
1181 : : {
1182 : : throw WrappedTargetRuntimeException(
1183 : : ::rtl::OUString(),
1184 : : xDocument,
1185 : : ::cppu::getCaughtException()
1186 [ # # # # ]: 0 : );
1187 : : }
1188 : 0 : return rxContainer;
1189 : : }
1190 : :
1191 : 174 : void ODatabaseModelImpl::storeLibraryContainersTo( const Reference< XStorage >& _rxToRootStorage )
1192 : : {
1193 [ - + ]: 174 : if ( m_xBasicLibraries.is() )
1194 : 0 : m_xBasicLibraries->storeLibrariesToStorage( _rxToRootStorage );
1195 : :
1196 [ - + ]: 174 : if ( m_xDialogLibraries.is() )
1197 : 0 : m_xDialogLibraries->storeLibrariesToStorage( _rxToRootStorage );
1198 : 174 : }
1199 : :
1200 : 172 : Reference< XStorage > ODatabaseModelImpl::switchToStorage( const Reference< XStorage >& _rxNewRootStorage )
1201 : : {
1202 [ - + ]: 172 : if ( !_rxNewRootStorage.is() )
1203 [ # # ]: 0 : throw IllegalArgumentException();
1204 : :
1205 : 172 : return impl_switchToStorage_throw( _rxNewRootStorage );
1206 : : }
1207 : :
1208 : : namespace
1209 : : {
1210 : 788 : void lcl_modifyListening( ::sfx2::IModifiableDocument& _rDocument,
1211 : : const Reference< XStorage >& _rxStorage, ::rtl::Reference< ::sfx2::DocumentStorageModifyListener >& _inout_rListener,
1212 : : ::osl::SolarMutex& _rMutex, bool _bListen )
1213 : : {
1214 [ + - ]: 788 : Reference< XModifiable > xModify( _rxStorage, UNO_QUERY );
1215 : : OSL_ENSURE( xModify.is() || !_rxStorage.is(), "lcl_modifyListening: storage can't notify us!" );
1216 : :
1217 [ + + ][ + + ]: 788 : if ( xModify.is() && !_bListen && _inout_rListener.is() )
[ + - ][ + + ]
1218 : : {
1219 [ + - ][ + - ]: 186 : xModify->removeModifyListener( _inout_rListener.get() );
[ + - ][ + - ]
1220 : : }
1221 : :
1222 [ + + ]: 788 : if ( _inout_rListener.is() )
1223 : : {
1224 [ + - ]: 186 : _inout_rListener->dispose();
1225 [ + - ]: 186 : _inout_rListener = NULL;
1226 : : }
1227 : :
1228 [ + + ][ + + ]: 788 : if ( xModify.is() && _bListen )
[ + + ]
1229 : : {
1230 [ + - ][ + - ]: 186 : _inout_rListener = new ::sfx2::DocumentStorageModifyListener( _rDocument, _rMutex );
1231 [ + - ][ + - ]: 186 : xModify->addModifyListener( _inout_rListener.get() );
[ + - ][ + - ]
1232 : 788 : }
1233 : 788 : }
1234 : : }
1235 : :
1236 : : namespace
1237 : : {
1238 : 788 : static void lcl_rebaseScriptStorage_throw( const Reference< XStorageBasedLibraryContainer >& _rxContainer,
1239 : : const Reference< XStorage >& _rxNewRootStorage )
1240 : : {
1241 [ - + ]: 788 : if ( _rxContainer.is() )
1242 : : {
1243 [ # # ]: 0 : if ( _rxNewRootStorage.is() )
1244 : 0 : _rxContainer->setRootStorage( _rxNewRootStorage );
1245 : : // else
1246 : : // TODO: what to do here? dispose the container?
1247 : : }
1248 : 788 : }
1249 : : }
1250 : :
1251 : 394 : Reference< XStorage > ODatabaseModelImpl::impl_switchToStorage_throw( const Reference< XStorage >& _rxNewRootStorage )
1252 : : {
1253 : : // stop listening for modifications at the old storage
1254 : 394 : lcl_modifyListening( *this, m_xDocumentStorage.getTyped(), m_pStorageModifyListener, m_aMutexFacade, false );
1255 : :
1256 : : // set new storage
1257 : 394 : m_xDocumentStorage.reset( _rxNewRootStorage, SharedStorage::TakeOwnership );
1258 : :
1259 : : // start listening for modifications
1260 : 394 : lcl_modifyListening( *this, m_xDocumentStorage.getTyped(), m_pStorageModifyListener, m_aMutexFacade, true );
1261 : :
1262 : : // forward new storage to Basic and Dialog library containers
1263 : 394 : lcl_rebaseScriptStorage_throw( m_xBasicLibraries, m_xDocumentStorage.getTyped() );
1264 : 394 : lcl_rebaseScriptStorage_throw( m_xDialogLibraries, m_xDocumentStorage.getTyped() );
1265 : :
1266 : 394 : m_bReadOnly = !tools::stor::storageIsWritable_nothrow( m_xDocumentStorage.getTyped() );
1267 : : // TODO: our data source, if it exists, must broadcast the change of its ReadOnly property
1268 : :
1269 : 394 : return m_xDocumentStorage.getTyped();
1270 : : }
1271 : :
1272 : 188 : void ODatabaseModelImpl::impl_switchToLogicalURL( const ::rtl::OUString& i_rDocumentURL )
1273 : : {
1274 [ + + ]: 188 : if ( i_rDocumentURL == m_sDocumentURL )
1275 : 188 : return;
1276 : :
1277 : 186 : const ::rtl::OUString sOldURL( m_sDocumentURL );
1278 : : // update our name, if necessary
1279 [ + + ]: 200 : if ( ( m_sName == m_sDocumentURL ) // our name is our old URL
[ + + - + ]
1280 : 14 : || ( m_sName.isEmpty() ) // we do not have a name, yet (i.e. are not registered at the database context)
1281 : : )
1282 : : {
1283 [ + - ]: 172 : INetURLObject aURL( i_rDocumentURL );
1284 [ + - ]: 172 : if ( aURL.GetProtocol() != INET_PROT_NOT_VALID )
1285 : : {
1286 : 172 : m_sName = i_rDocumentURL;
1287 : : // TODO: our data source must broadcast the change of the Name property
1288 [ + - ]: 172 : }
1289 : : }
1290 : :
1291 : : // remember URL
1292 : 186 : m_sDocumentURL = i_rDocumentURL;
1293 : :
1294 : : // update our location, if necessary
1295 [ + + ]: 186 : if ( m_sDocFileLocation.isEmpty() )
1296 : 14 : m_sDocFileLocation = m_sDocumentURL;
1297 : :
1298 : : // register at the database context, or change registration
1299 [ + - ]: 186 : if ( m_pDBContext )
1300 : : {
1301 [ - + ]: 186 : if ( !sOldURL.isEmpty() )
1302 [ # # ]: 0 : m_pDBContext->databaseDocumentURLChange( sOldURL, m_sDocumentURL );
1303 : : else
1304 [ + - ]: 186 : m_pDBContext->registerDatabaseDocument( *this );
1305 : 188 : }
1306 : : }
1307 : :
1308 : 28 : ::rtl::OUString ODatabaseModelImpl::getObjectContainerStorageName( const ObjectType _eType )
1309 : : {
1310 : 28 : return lcl_getContainerStorageName_throw( _eType );
1311 : : }
1312 : :
1313 : 0 : sal_Int16 ODatabaseModelImpl::getCurrentMacroExecMode() const
1314 : : {
1315 : 0 : sal_Int16 nCurrentMode = MacroExecMode::NEVER_EXECUTE;
1316 : : try
1317 : : {
1318 [ # # ]: 0 : nCurrentMode = m_aMediaDescriptor.getOrDefault( "MacroExecutionMode", nCurrentMode );
1319 : : }
1320 [ # # ]: 0 : catch( const Exception& )
1321 : : {
1322 : : DBG_UNHANDLED_EXCEPTION();
1323 : : }
1324 [ # # ]: 0 : return nCurrentMode;
1325 : : }
1326 : :
1327 : 0 : sal_Bool ODatabaseModelImpl::setCurrentMacroExecMode( sal_uInt16 nMacroMode )
1328 : : {
1329 : 0 : m_aMediaDescriptor.put( "MacroExecutionMode", nMacroMode );
1330 : 0 : return sal_True;
1331 : : }
1332 : :
1333 : 0 : ::rtl::OUString ODatabaseModelImpl::getDocumentLocation() const
1334 : : {
1335 : 0 : return getURL();
1336 : : // formerly, we returned getDocFileLocation here, which is the location of the file from which we
1337 : : // recovered the "real" document.
1338 : : // However, during CWS autorecovery evolving, we clarified (with MAV/MT) the role of XModel::getURL and
1339 : : // XStorable::getLocation. In this course, we agreed that for a macro security check, the *document URL*
1340 : : // (not the recovery file URL) is to be used: The recovery file lies in the backup folder, and by definition,
1341 : : // this folder is considered to be secure. So, the document URL needs to be used to decide about the security.
1342 : : }
1343 : :
1344 : 0 : Reference< XStorage > ODatabaseModelImpl::getZipStorageToSign()
1345 : : {
1346 : : // we do not support signing the scripting storages, so we're allowed to
1347 : : // return <NULL/> here.
1348 : 0 : return Reference< XStorage >();
1349 : : }
1350 : :
1351 : 14 : ODatabaseModelImpl::EmbeddedMacros ODatabaseModelImpl::determineEmbeddedMacros()
1352 : : {
1353 [ + - ]: 14 : if ( !m_aEmbeddedMacros )
1354 : : {
1355 [ + - ][ - + ]: 14 : if ( ::sfx2::DocumentMacroMode::storageHasMacros( const_cast< ODatabaseModelImpl* >( this )->getOrCreateRootStorage() ) )
1356 : : {
1357 [ # # ]: 0 : m_aEmbeddedMacros.reset( eDocumentWideMacros );
1358 : : }
1359 [ + - - + ]: 28 : else if ( lcl_hasObjectsWithMacros_nothrow( const_cast< ODatabaseModelImpl& >( *this ), E_FORM )
[ - + ]
1360 : 14 : || lcl_hasObjectsWithMacros_nothrow( const_cast< ODatabaseModelImpl& >( *this ), E_REPORT )
1361 : : )
1362 : : {
1363 [ # # ]: 0 : m_aEmbeddedMacros.reset( eSubDocumentMacros );
1364 : : }
1365 : : else
1366 : : {
1367 [ + - ]: 14 : m_aEmbeddedMacros.reset( eNoMacros );
1368 : : }
1369 : : }
1370 : 14 : return *m_aEmbeddedMacros;
1371 : : }
1372 : :
1373 : 0 : sal_Bool ODatabaseModelImpl::documentStorageHasMacros() const
1374 : : {
1375 : 0 : const_cast< ODatabaseModelImpl* >( this )->determineEmbeddedMacros();
1376 : 0 : return ( *m_aEmbeddedMacros != eNoMacros );
1377 : : }
1378 : :
1379 : 0 : Reference< XEmbeddedScripts > ODatabaseModelImpl::getEmbeddedDocumentScripts() const
1380 : : {
1381 [ # # ]: 0 : return Reference< XEmbeddedScripts >( getModel_noCreate(), UNO_QUERY );
1382 : : }
1383 : :
1384 : 0 : sal_Int16 ODatabaseModelImpl::getScriptingSignatureState()
1385 : : {
1386 : : // no support for signatures at the moment
1387 : 0 : return SIGNATURESTATE_NOSIGNATURES;
1388 : : }
1389 : :
1390 : 0 : sal_Bool ODatabaseModelImpl::hasTrustedScriptingSignature( sal_Bool /*bAllowUIToAddAuthor*/ )
1391 : : {
1392 : : // no support for signatures at the moment
1393 : 0 : return sal_False;
1394 : : }
1395 : :
1396 : 0 : void ODatabaseModelImpl::showBrokenSignatureWarning( const Reference< XInteractionHandler >& /*_rxInteraction*/ ) const
1397 : : {
1398 : : OSL_FAIL( "ODatabaseModelImpl::showBrokenSignatureWarning: signatures can't be broken - we do not support them!" );
1399 : 0 : }
1400 : :
1401 : 1910 : void ODatabaseModelImpl::storageIsModified()
1402 : : {
1403 : 1910 : setModified( sal_True );
1404 : 1910 : }
1405 : :
1406 : 590 : ModelDependentComponent::ModelDependentComponent( const ::rtl::Reference< ODatabaseModelImpl >& _model )
1407 : : :m_pImpl( _model )
1408 [ + - ]: 590 : ,m_aMutex( _model->getSharedMutex() )
1409 : : {
1410 : 590 : }
1411 : :
1412 [ + - ]: 590 : ModelDependentComponent::~ModelDependentComponent()
1413 : : {
1414 [ - + ]: 590 : }
1415 : :
1416 : : } // namespace dbaccess
1417 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|