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 "core_resource.hxx"
22 : : #include "core_resource.hrc"
23 : : #include "datasource.hxx"
24 : : #include "databasedocument.hxx"
25 : : #include "dbastrings.hrc"
26 : : #include "module_dba.hxx"
27 : : #include "documenteventexecutor.hxx"
28 : : #include "databasecontext.hxx"
29 : : #include "documentcontainer.hxx"
30 : : #include "sdbcoretools.hxx"
31 : : #include "recovery/dbdocrecovery.hxx"
32 : :
33 : : #include <com/sun/star/beans/Optional.hpp>
34 : : #include <com/sun/star/document/XExporter.hpp>
35 : : #include <com/sun/star/document/XFilter.hpp>
36 : : #include <com/sun/star/document/XImporter.hpp>
37 : : #include <com/sun/star/embed/EntryInitModes.hpp>
38 : : #include <com/sun/star/embed/XEmbedPersist.hpp>
39 : : #include <com/sun/star/embed/XTransactedObject.hpp>
40 : : #include <com/sun/star/embed/XTransactionBroadcaster.hpp>
41 : : #include <com/sun/star/io/XActiveDataSource.hpp>
42 : : #include <com/sun/star/io/XSeekable.hpp>
43 : : #include <com/sun/star/io/XOutputStream.hpp>
44 : : #include <com/sun/star/io/XTruncate.hpp>
45 : : #include <com/sun/star/script/provider/XScriptProviderFactory.hpp>
46 : : #include <com/sun/star/task/ErrorCodeIOException.hpp>
47 : : #include <com/sun/star/task/XStatusIndicator.hpp>
48 : : #include <com/sun/star/task/XStatusIndicatorFactory.hpp>
49 : : #include <com/sun/star/ucb/SimpleFileAccess.hpp>
50 : : #include <com/sun/star/ucb/XSimpleFileAccess2.hpp>
51 : : #include <com/sun/star/ui/XUIConfigurationStorage.hpp>
52 : : #include <com/sun/star/view/XSelectionSupplier.hpp>
53 : : #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
54 : : #include <com/sun/star/ucb/XContent.hpp>
55 : : #include <com/sun/star/sdb/application/XDatabaseDocumentUI.hpp>
56 : :
57 : : #include <com/sun/star/script/XStorageBasedLibraryContainer.hpp>
58 : : #include <com/sun/star/awt/XControl.hpp>
59 : : #include <com/sun/star/awt/XDialogProvider.hpp>
60 : : #include <com/sun/star/document/XGraphicObjectResolver.hpp>
61 : :
62 : :
63 : : #include <comphelper/documentconstants.hxx>
64 : : #include <comphelper/enumhelper.hxx>
65 : : #include <comphelper/genericpropertyset.hxx>
66 : : #include <comphelper/interaction.hxx>
67 : : #include <comphelper/mediadescriptor.hxx>
68 : : #include <comphelper/namedvaluecollection.hxx>
69 : : #include <comphelper/numberedcollection.hxx>
70 : : #include <comphelper/property.hxx>
71 : : #include <comphelper/storagehelper.hxx>
72 : :
73 : : #include <connectivity/dbtools.hxx>
74 : :
75 : : #include <cppuhelper/exc_hlp.hxx>
76 : : #include <framework/titlehelper.hxx>
77 : : #include <unotools/saveopt.hxx>
78 : : #include <tools/debug.hxx>
79 : : #include <tools/diagnose_ex.h>
80 : : #include <osl/diagnose.h>
81 : : #include <tools/errcode.hxx>
82 : :
83 : : #include <boost/bind.hpp>
84 : :
85 : : #include <algorithm>
86 : : #include <functional>
87 : : #include <list>
88 : :
89 : : #include <svtools/grfmgr.hxx>
90 : : #define MAP_LEN(x) x, sizeof(x) - 1
91 : :
92 : : using namespace ::com::sun::star::uno;
93 : : using namespace ::com::sun::star::beans;
94 : : using namespace ::com::sun::star::frame;
95 : : using namespace ::com::sun::star::lang;
96 : : using namespace ::com::sun::star::container;
97 : : using namespace ::com::sun::star::document;
98 : : using namespace ::com::sun::star::io;
99 : : using namespace ::com::sun::star::util;
100 : : using namespace ::com::sun::star::embed;
101 : : using namespace ::com::sun::star::task;
102 : : using namespace ::com::sun::star::view;
103 : : using namespace ::com::sun::star::sdbc;
104 : : using namespace ::com::sun::star;
105 : : using namespace ::com::sun::star::xml::sax;
106 : : using namespace ::com::sun::star::script;
107 : : using namespace ::com::sun::star::script::provider;
108 : : using namespace ::com::sun::star::ui;
109 : : using namespace ::cppu;
110 : : using namespace ::osl;
111 : :
112 : : using ::com::sun::star::awt::XWindow;
113 : : using ::com::sun::star::ucb::XContent;
114 : : using ::com::sun::star::sdb::application::XDatabaseDocumentUI;
115 : :
116 : : namespace dbaccess
117 : : {
118 : :
119 : : //============================================================
120 : : //= ViewMonitor
121 : : //============================================================
122 : :
123 : 0 : bool ViewMonitor::onControllerConnected( const Reference< XController >& _rxController )
124 : : {
125 : 0 : bool bFirstControllerEver = ( m_bEverHadController == false );
126 : 0 : m_bEverHadController = true;
127 : :
128 : 0 : m_xLastConnectedController = _rxController;
129 : 0 : m_bLastIsFirstEverController = bFirstControllerEver;
130 : :
131 : 0 : return bFirstControllerEver;
132 : : }
133 : :
134 : 0 : bool ViewMonitor::onSetCurrentController( const Reference< XController >& _rxController )
135 : : {
136 : : // we interpret this as "loading the document (including UI) is finished",
137 : : // if and only if this is the controller which was last connected, and it was the
138 : : // first controller ever connected
139 [ # # ][ # # ]: 0 : bool bLoadFinished = ( _rxController == m_xLastConnectedController ) && m_bLastIsFirstEverController;
140 : :
141 : : // notify the respective events
142 [ # # ]: 0 : if ( bLoadFinished )
143 [ # # ][ # # ]: 0 : m_rEventNotifier.notifyDocumentEventAsync( m_bIsNewDocument ? "OnNew" : "OnLoad" );
[ # # ]
144 : :
145 : 0 : return bLoadFinished;
146 : : }
147 : :
148 : : //============================================================
149 : : //= ODatabaseDocument
150 : : //============================================================
151 : : DBG_NAME(ODatabaseDocument)
152 : :
153 : 32 : extern "C" void SAL_CALL createRegistryInfo_ODatabaseDocument()
154 : : {
155 [ + - ][ + - ]: 32 : static ::dba::OAutoRegistration< ODatabaseDocument > aAutoRegistration;
[ + - ][ # # ]
156 : 32 : }
157 : :
158 : 186 : ODatabaseDocument::ODatabaseDocument(const ::rtl::Reference<ODatabaseModelImpl>& _pImpl )
159 : : :ModelDependentComponent( _pImpl )
160 [ + - ]: 186 : ,ODatabaseDocument_OfficeDocument( getMutex() )
161 [ + - ]: 186 : ,m_aModifyListeners( getMutex() )
162 [ + - ]: 186 : ,m_aCloseListener( getMutex() )
163 [ + - ]: 186 : ,m_aStorageListeners( getMutex() )
164 [ + - ]: 372 : ,m_pEventContainer( new DocumentEvents( *this, getMutex(), _pImpl->getDocumentEvents() ) )
165 : : ,m_pEventExecutor( NULL ) // initialized below, ref-count-protected
166 [ + - ]: 186 : ,m_aEventNotifier( *this, getMutex() )
167 : : ,m_aViewMonitor( m_aEventNotifier )
168 : : ,m_eInitState( NotInitialized )
169 : : ,m_bClosing( false )
170 : : ,m_bAllowDocumentScripting( false )
171 [ + - ][ + - ]: 1488 : ,m_bHasBeenRecovered( false )
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
172 : : {
173 : : DBG_CTOR(ODatabaseDocument,NULL);
174 : : OSL_TRACE( "DD: ctor: %p: %p", this, m_pImpl.get() );
175 : :
176 [ + - ]: 186 : osl_incrementInterlockedCount( &m_refCount );
177 : : {
178 [ + - ]: 186 : impl_reparent_nothrow( m_xForms );
179 [ + - ]: 186 : impl_reparent_nothrow( m_xReports );
180 [ + - ]: 186 : impl_reparent_nothrow( m_pImpl->m_xTableDefinitions );
181 [ + - ]: 186 : impl_reparent_nothrow( m_pImpl->m_xCommandDefinitions );
182 : :
183 [ + - ][ + - ]: 186 : m_pEventExecutor = new DocumentEventExecutor( m_pImpl->m_aContext, this );
[ + - ]
184 : : }
185 [ + - ]: 186 : osl_decrementInterlockedCount( &m_refCount );
186 : :
187 : : // if there previously was a document instance for the same Impl which was already initialized,
188 : : // then consider ourself initialized, too.
189 : : // #i94840#
190 [ - + ]: 186 : if ( m_pImpl->hadInitializedDocument() )
191 : : {
192 : : // Note we set our init-state to "Initializing", not "Initialized". We're created from inside the ModelImpl,
193 : : // which is expected to call attachResource in case there was a previous incarnation of the document,
194 : : // so we can properly finish our initialization then.
195 : 0 : impl_setInitializing();
196 : :
197 [ # # ]: 0 : if ( !m_pImpl->getURL().isEmpty() )
198 : : {
199 : : // if the previous incarnation of the DatabaseDocument already had an URL, then creating this incarnation
200 : : // here is effectively loading the document.
201 : : // #i105505#
202 : 0 : m_aViewMonitor.onLoadedDocument();
203 : : }
204 : : }
205 : 186 : }
206 : :
207 [ + - ][ + - ]: 186 : ODatabaseDocument::~ODatabaseDocument()
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
208 : : {
209 : : OSL_TRACE( "DD: dtor: %p: %p", this, m_pImpl.get() );
210 : : DBG_DTOR(ODatabaseDocument,NULL);
211 [ + - ][ - + ]: 186 : if ( !ODatabaseDocument_OfficeDocument::rBHelper.bInDispose && !ODatabaseDocument_OfficeDocument::rBHelper.bDisposed )
212 : : {
213 : 0 : acquire();
214 [ # # ]: 0 : dispose();
215 : : }
216 : :
217 [ + - ][ + - ]: 186 : delete m_pEventContainer, m_pEventContainer = NULL;
218 [ - + ]: 372 : }
219 : :
220 : 20312 : Any SAL_CALL ODatabaseDocument::queryInterface( const Type& _rType ) throw (RuntimeException)
221 : : {
222 : : // strip XEmbeddedScripts and XScriptInvocationContext if we have any form/report
223 : : // which already contains macros. In this case, the database document itself is not
224 : : // allowed to contain macros, too.
225 [ + + + - : 41872 : if ( !m_bAllowDocumentScripting
- + ][ - + ]
226 [ + - ]: 10780 : && ( _rType.equals( XEmbeddedScripts::static_type() )
227 [ + - ]: 10780 : || _rType.equals( XScriptInvocationContext::static_type() )
228 : : )
229 : : )
230 : 0 : return Any();
231 : :
232 [ + - ]: 20312 : Any aReturn = ODatabaseDocument_OfficeDocument::queryInterface(_rType);
233 [ + + ]: 20312 : if (!aReturn.hasValue())
234 [ + - ]: 4764 : aReturn = ODatabaseDocument_Title::queryInterface(_rType);
235 : 20312 : return aReturn;
236 : : }
237 : :
238 : 53993 : void SAL_CALL ODatabaseDocument::acquire( ) throw ()
239 : : {
240 : 53993 : ODatabaseDocument_OfficeDocument::acquire();
241 : 53994 : }
242 : :
243 : 53993 : void SAL_CALL ODatabaseDocument::release( ) throw ()
244 : : {
245 : 53993 : ODatabaseDocument_OfficeDocument::release();
246 : 53994 : }
247 : :
248 : 0 : Sequence< Type > SAL_CALL ODatabaseDocument::getTypes( ) throw (RuntimeException)
249 : : {
250 : : Sequence< Type > aTypes = ::comphelper::concatSequences(
251 : : ODatabaseDocument_OfficeDocument::getTypes(),
252 : : ODatabaseDocument_Title::getTypes()
253 [ # # ][ # # ]: 0 : );
[ # # ][ # # ]
254 : :
255 : : // strip XEmbeddedScripts and XScriptInvocationContext if we have any form/report
256 : : // which already contains macros. In this case, the database document itself is not
257 : : // allowed to contain macros, too.
258 [ # # ]: 0 : if ( !m_bAllowDocumentScripting )
259 : : {
260 [ # # ]: 0 : Sequence< Type > aStrippedTypes( aTypes.getLength() );
261 [ # # ]: 0 : Type* pStripTo( aStrippedTypes.getArray() );
262 : :
263 : : // strip XEmbeddedScripts, and immediately re-assign to aTypes
264 : : aTypes = Sequence< Type >(
265 : : pStripTo,
266 : : ::std::remove_copy_if(
267 : : aTypes.getConstArray(),
268 : 0 : aTypes.getConstArray() + aTypes.getLength(),
269 : : pStripTo,
270 [ # # ]: 0 : ::std::bind2nd( ::std::equal_to< Type >(), XEmbeddedScripts::static_type() )
271 [ # # # # ]: 0 : ) - pStripTo
272 [ # # ][ # # ]: 0 : );
[ # # ]
273 : :
274 : : // strip XScriptInvocationContext, and immediately re-assign to aTypes
275 : : aTypes = Sequence< Type >(
276 : : pStripTo,
277 : : ::std::remove_copy_if(
278 : : aTypes.getConstArray(),
279 : 0 : aTypes.getConstArray() + aTypes.getLength(),
280 : : pStripTo,
281 [ # # ]: 0 : ::std::bind2nd( ::std::equal_to< Type >(), XScriptInvocationContext::static_type() )
282 [ # # # # ]: 0 : ) - pStripTo
283 [ # # ][ # # ]: 0 : );
[ # # # # ]
284 : : }
285 : :
286 : 0 : return aTypes;
287 : : }
288 : :
289 : 0 : Sequence< sal_Int8 > SAL_CALL ODatabaseDocument::getImplementationId( ) throw (RuntimeException)
290 : : {
291 : : static ::cppu::OImplementationId * pId = 0;
292 [ # # ]: 0 : if (! pId)
293 : : {
294 [ # # ][ # # ]: 0 : ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
295 [ # # ]: 0 : if (! pId)
296 : : {
297 [ # # ][ # # ]: 0 : static ::cppu::OImplementationId aId;
298 : 0 : pId = &aId;
299 [ # # ]: 0 : }
300 : : }
301 : 0 : return pId->getImplementationId();
302 : : }
303 : :
304 : : // local functions
305 : : namespace
306 : : {
307 : 536 : Reference< XStatusIndicator > lcl_extractStatusIndicator( const ::comphelper::NamedValueCollection& _rArguments )
308 : : {
309 : 536 : Reference< XStatusIndicator > xStatusIndicator;
310 [ + - ]: 536 : return _rArguments.getOrDefault( "StatusIndicator", xStatusIndicator );
311 : : }
312 : :
313 : 348 : static void lcl_triggerStatusIndicator_throw( const ::comphelper::NamedValueCollection& _rArguments, DocumentGuard& _rGuard, const bool _bStart )
314 : : {
315 [ + - ]: 348 : Reference< XStatusIndicator > xStatusIndicator( lcl_extractStatusIndicator( _rArguments ) );
316 [ + - ]: 348 : if ( !xStatusIndicator.is() )
317 : 348 : return;
318 : :
319 [ # # ]: 0 : _rGuard.clear();
320 : : try
321 : : {
322 [ # # ]: 0 : if ( _bStart )
323 [ # # ][ # # ]: 0 : xStatusIndicator->start( ::rtl::OUString(), (sal_Int32)1000000 );
[ # # ]
324 : : else
325 [ # # ][ # # ]: 0 : xStatusIndicator->end();
326 : : }
327 [ # # ]: 0 : catch( const Exception& )
328 : : {
329 : : DBG_UNHANDLED_EXCEPTION();
330 : : }
331 [ # # ][ - + ]: 348 : _rGuard.reset();
332 : : // note that |reset| can throw a DisposedException
333 : : }
334 : :
335 : 174 : static void lcl_extractStatusIndicator( const ::comphelper::NamedValueCollection& _rArguments, Sequence< Any >& _rCallArgs )
336 : : {
337 [ + - ]: 174 : Reference< XStatusIndicator > xStatusIndicator( lcl_extractStatusIndicator( _rArguments ) );
338 [ + - ]: 174 : if ( !xStatusIndicator.is() )
339 : 174 : return;
340 : :
341 : 0 : sal_Int32 nLength = _rCallArgs.getLength();
342 [ # # ]: 0 : _rCallArgs.realloc( nLength + 1 );
343 [ # # ][ # # ]: 174 : _rCallArgs[ nLength ] <<= xStatusIndicator;
[ - + ]
344 : : }
345 : :
346 : 14 : static void lcl_extractAndStartStatusIndicator( const ::comphelper::NamedValueCollection& _rArguments, Reference< XStatusIndicator >& _rxStatusIndicator,
347 : : Sequence< Any >& _rCallArgs )
348 : : {
349 [ + - ]: 14 : _rxStatusIndicator = lcl_extractStatusIndicator( _rArguments );
350 [ + - ]: 14 : if ( !_rxStatusIndicator.is() )
351 : 14 : return;
352 : :
353 : : try
354 : : {
355 [ # # ][ # # ]: 0 : _rxStatusIndicator->start( ::rtl::OUString(), (sal_Int32)1000000 );
[ # # ]
356 : :
357 : 0 : sal_Int32 nLength = _rCallArgs.getLength();
358 [ # # ]: 0 : _rCallArgs.realloc( nLength + 1 );
359 [ # # ][ # # ]: 0 : _rCallArgs[ nLength ] <<= _rxStatusIndicator;
360 : : }
361 : 0 : catch( const Exception& )
362 : : {
363 : : DBG_UNHANDLED_EXCEPTION();
364 : : }
365 : : }
366 : :
367 : 174 : static Sequence< PropertyValue > lcl_appendFileNameToDescriptor( const ::comphelper::NamedValueCollection& _rDescriptor, const ::rtl::OUString _rURL )
368 : : {
369 [ + - ]: 174 : ::comphelper::NamedValueCollection aMutableDescriptor( _rDescriptor );
370 [ + - ]: 174 : if ( !_rURL.isEmpty() )
371 : : {
372 [ + - ]: 174 : aMutableDescriptor.put( "FileName", _rURL );
373 [ + - ]: 174 : aMutableDescriptor.put( "URL", _rURL );
374 : : }
375 [ + - ][ + - ]: 174 : return aMutableDescriptor.getPropertyValues();
376 : : }
377 : : }
378 : :
379 : 40 : static rtl::OUString sPictures( RTL_CONSTASCII_USTRINGPARAM("Pictures") );
380 : :
381 : : // base documents seem to have a different behaviour to other documents, the
382 : : // root storage contents at least seem to be re-used over different saves, thus if there is a
383 : : // top level Picture directory it is never cleared.
384 : : // If we delete the 'Pictures' directory then the dialog library storage which does store
385 : : // any embed images will not work properly. ( this is due to the fact it will
386 : : // try to load the dialog which will try and access the embed images, if those images are not cached in
387 : : // memory it will try to read them from the Picture directory which is now gone, so... we have to use this
388 : : // inglorious hack below which basically will
389 : : // a) create a temp storage
390 : : // b) introspect any dialogs for any embed graphics and grab the associate URL(s)
391 : : // c) populate the temp storage with the associated embed images ( will be stored in a 'Pictures' folder )
392 : : // d) delete the 'Picture' element from the root storage
393 : : // e) copy the Pictures element of the temp storage to the root storage
394 : : //
395 : : // this assumes that we don't use the Pictures folder in the root of the base
396 : : // document for anything, I believe this is a valid assumption ( as much as
397 : : // I could check anyway )
398 : :
399 : 0 : void lcl_uglyHackToStoreDialogeEmbedImages( const Reference< XStorageBasedLibraryContainer >& xDlgCont, const Reference< XStorage >& xStorage, const Reference< XModel >& rxModel, const ::comphelper::ComponentContext& aContext ) throw ( RuntimeException )
400 : : {
401 [ # # ][ # # ]: 0 : Sequence< rtl::OUString > sLibraries = xDlgCont->getElementNames();
402 [ # # ][ # # ]: 0 : Reference< XStorage > xTmpPic = xStorage->openStorageElement( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("tempPictures") ), ElementModes::READWRITE );
[ # # ]
403 : :
404 [ # # ]: 0 : std::vector< rtl::OUString > vEmbedImgUrls;
405 [ # # ]: 0 : for ( sal_Int32 i=0; i < sLibraries.getLength(); ++i )
406 : : {
407 [ # # ]: 0 : rtl::OUString sLibrary( sLibraries[ i ] );
408 [ # # ][ # # ]: 0 : xDlgCont->loadLibrary( sLibrary );
409 : 0 : Reference< XNameContainer > xLib;
410 [ # # ][ # # ]: 0 : xDlgCont->getByName( sLibrary ) >>= xLib;
[ # # ]
411 [ # # ]: 0 : if ( xLib.is() )
412 : : {
413 [ # # ][ # # ]: 0 : Sequence< rtl::OUString > sDialogs = xLib->getElementNames();
414 : 0 : sal_Int32 nDialogs( sDialogs.getLength() );
415 [ # # ]: 0 : for ( sal_Int32 j=0; j < nDialogs; ++j )
416 : : {
417 : 0 : Reference < ::com::sun::star::awt::XDialogProvider > xDlgPrv;
418 [ # # ]: 0 : Sequence< Any > aArgs(1);
419 [ # # ][ # # ]: 0 : aArgs[ 0 ] <<= rxModel;
420 [ # # ][ # # ]: 0 : xDlgPrv.set( aContext.createComponentWithArguments( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.DialogProvider")) , aArgs), UNO_QUERY );
[ # # ]
421 [ # # ]: 0 : rtl::OUString sDialogUrl = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("vnd.sun.star.script:") );
422 [ # # ][ # # ]: 0 : sDialogUrl = sDialogUrl.concat( sLibraries[ i ] ).concat( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("." ) ) ).concat ( sDialogs[ j ] ).concat( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("?location=document") ) );
[ # # ][ # # ]
423 : :
424 [ # # ][ # # ]: 0 : Reference< ::com::sun::star::awt::XControl > xDialog( xDlgPrv->createDialog( sDialogUrl ), UNO_QUERY );
[ # # ]
425 [ # # ][ # # ]: 0 : Reference< XInterface > xModel( xDialog->getModel() );
426 [ # # ]: 0 : GraphicObject::InspectForGraphicObjectImageURL( xModel, vEmbedImgUrls );
427 [ # # ][ # # ]: 0 : }
428 : : }
429 : 0 : }
430 : : // if we have any image urls, make sure we copy the associated images into tempPictures
431 [ # # ]: 0 : if ( !vEmbedImgUrls.empty() )
432 : : {
433 : : // Export the images to the storage
434 [ # # ]: 0 : Sequence< Any > aArgs( 1 );
435 [ # # ][ # # ]: 0 : aArgs[ 0 ] <<= xTmpPic;
436 : : Reference< XGraphicObjectResolver > xGraphicResolver(
437 [ # # ][ # # ]: 0 : aContext.createComponentWithArguments( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.Svx.GraphicExportHelper" ) ), aArgs ), UNO_QUERY );
[ # # ]
438 : 0 : std::vector< rtl::OUString >::iterator it = vEmbedImgUrls.begin();
439 : 0 : std::vector< rtl::OUString >::iterator it_end = vEmbedImgUrls.end();
440 [ # # ]: 0 : if ( xGraphicResolver.is() )
441 : : {
442 [ # # ][ # # ]: 0 : for ( sal_Int32 count = 0; it != it_end; ++it, ++count )
443 [ # # ][ # # ]: 0 : xGraphicResolver->resolveGraphicObjectURL( *it );
444 : : }
445 : :
446 : : // delete old 'Pictures' storage and copy the contents of tempPictures into xStorage
447 [ # # ][ # # ]: 0 : xStorage->removeElement( sPictures );
448 [ # # ][ # # ]: 0 : xTmpPic->copyElementTo( sPictures, xStorage, sPictures );
[ # # ]
449 : : }
450 : : else
451 : : {
452 : : // clean up an existing Pictures dir
453 [ # # ][ # # ]: 0 : if ( xStorage->isStorageElement( sPictures ) )
[ # # ]
454 [ # # ][ # # ]: 0 : xStorage->removeElement( sPictures );
455 [ # # ]: 0 : }
456 : 0 : }
457 : :
458 : 186 : void ODatabaseDocument::impl_setInitialized()
459 : : {
460 : 186 : m_eInitState = Initialized;
461 : :
462 : : // start event notifications
463 : 186 : m_aEventNotifier.onDocumentInitialized();
464 : 186 : }
465 : :
466 : 14 : void ODatabaseDocument::impl_reset_nothrow()
467 : : {
468 : : try
469 : : {
470 [ + - ]: 14 : m_pImpl->clearConnections();
471 [ + - ]: 14 : m_pImpl->disposeStorages();
472 [ + - ]: 14 : m_pImpl->resetRootStroage();
473 : :
474 [ + - ]: 14 : clearObjectContainer( m_xForms );
475 [ + - ]: 14 : clearObjectContainer( m_xReports );
476 [ + - ]: 14 : clearObjectContainer( m_pImpl->m_xTableDefinitions );
477 [ + - ]: 14 : clearObjectContainer( m_pImpl->m_xCommandDefinitions );
478 : :
479 : 14 : m_eInitState = NotInitialized;
480 : :
481 [ + - ]: 14 : m_pImpl->reset();
482 : : }
483 : 0 : catch(const Exception&)
484 : : {
485 : : DBG_UNHANDLED_EXCEPTION();
486 : : }
487 : 14 : m_pImpl->m_bDocumentReadOnly = sal_False;
488 [ # # ]: 14 : }
489 : :
490 : 14 : void ODatabaseDocument::impl_import_nolck_throw( const ::comphelper::ComponentContext _rContext, const Reference< XInterface >& _rxTargetComponent,
491 : : const ::comphelper::NamedValueCollection& _rResource )
492 : : {
493 [ + - ]: 14 : Sequence< Any > aFilterCreationArgs;
494 : 14 : Reference< XStatusIndicator > xStatusIndicator;
495 [ + - ]: 14 : lcl_extractAndStartStatusIndicator( _rResource, xStatusIndicator, aFilterCreationArgs );
496 : :
497 : : /** property map for import info set */
498 : : comphelper::PropertyMapEntry aExportInfoMap[] =
499 : : {
500 [ + - ]: 14 : { MAP_LEN( "BaseURI"), 0,&::getCppuType( (::rtl::OUString *)0 ),beans::PropertyAttribute::MAYBEVOID, 0 },
501 [ + - ]: 14 : { MAP_LEN( "StreamName"), 0,&::getCppuType( (::rtl::OUString *)0 ),beans::PropertyAttribute::MAYBEVOID, 0 },
502 : : { NULL, 0, 0, NULL, 0, 0 }
503 : 42 : };
504 [ + - ]: 14 : uno::Reference< beans::XPropertySet > xInfoSet( comphelper::GenericPropertySet_CreateInstance( new comphelper::PropertySetInfo( aExportInfoMap ) ) );
505 [ + - ][ + - ]: 14 : xInfoSet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("BaseURI")), uno::makeAny(_rResource.getOrDefault("URL",::rtl::OUString())));
[ + - ][ + - ]
[ + - ]
506 [ + - ][ + - ]: 14 : xInfoSet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("StreamName")), uno::makeAny(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("content.xml"))));
[ + - ][ + - ]
[ + - ]
507 : :
508 : 14 : const sal_Int32 nCount = aFilterCreationArgs.getLength();
509 [ + - ]: 14 : aFilterCreationArgs.realloc(nCount + 1);
510 [ + - ][ + - ]: 14 : aFilterCreationArgs[nCount] <<= xInfoSet;
511 : :
512 : : Reference< XImporter > xImporter(
513 : : _rContext.createComponentWithArguments( "com.sun.star.comp.sdb.DBFilter", aFilterCreationArgs ),
514 [ + - ][ + - ]: 14 : UNO_QUERY_THROW );
515 : :
516 [ + - ]: 14 : Reference< XComponent > xComponent( _rxTargetComponent, UNO_QUERY_THROW );
517 [ + - ][ + - ]: 14 : xImporter->setTargetDocument( xComponent );
518 : :
519 [ + - ]: 14 : Reference< XFilter > xFilter( xImporter, UNO_QUERY_THROW );
520 [ + - ][ + - ]: 14 : Sequence< PropertyValue > aFilterArgs( ODatabaseModelImpl::stripLoadArguments( _rResource ).getPropertyValues() );
[ + - ]
521 [ + - ][ + - ]: 14 : xFilter->filter( aFilterArgs );
522 : :
523 [ - + ]: 14 : if ( xStatusIndicator.is() )
524 [ # # ][ # # ]: 14 : xStatusIndicator->end();
[ + - ][ + - ]
525 : 14 : }
526 : :
527 : 0 : void SAL_CALL ODatabaseDocument::initNew( ) throw (DoubleInitializationException, IOException, Exception, RuntimeException)
528 : : {
529 : : // SYNCHRONIZED ->
530 [ # # ]: 0 : DocumentGuard aGuard( *this, DocumentGuard::InitMethod );
531 : :
532 [ # # ]: 0 : impl_reset_nothrow();
533 : :
534 : 0 : impl_setInitializing();
535 : :
536 : : // create a temporary storage
537 : : Reference< XStorage > xTempStor( ::comphelper::OStorageHelper::GetTemporaryStorage(
538 [ # # ][ # # ]: 0 : m_pImpl->m_aContext.getLegacyServiceFactory() ) );
539 : :
540 : : // store therein
541 [ # # ][ # # ]: 0 : impl_storeToStorage_throw( xTempStor, Sequence< PropertyValue >(), aGuard );
[ # # ]
542 : :
543 : : // let the impl know we're now based on this storage
544 [ # # ]: 0 : m_pImpl->switchToStorage( xTempStor );
545 : :
546 : : // for the newly created document, allow document-wide scripting
547 : 0 : m_bAllowDocumentScripting = true;
548 : :
549 [ # # ]: 0 : impl_setInitialized();
550 : :
551 [ # # ][ # # ]: 0 : m_aEventNotifier.notifyDocumentEventAsync( "OnTitleChanged" );
552 : :
553 [ # # ]: 0 : impl_setModified_nothrow( sal_False, aGuard );
554 : : // <- SYNCHRONIZED
555 : :
556 [ # # ][ # # ]: 0 : m_aEventNotifier.notifyDocumentEvent( "OnCreate" );
557 : :
558 [ # # ][ # # ]: 0 : impl_notifyStorageChange_nolck_nothrow( xTempStor );
559 : 0 : }
560 : :
561 : 14 : void SAL_CALL ODatabaseDocument::load( const Sequence< PropertyValue >& _Arguments ) throw (DoubleInitializationException, IOException, Exception, RuntimeException)
562 : : {
563 : : // SYNCHRONIZED ->
564 [ + - ]: 14 : DocumentGuard aGuard( *this, DocumentGuard::InitMethod );
565 : :
566 [ + - ]: 14 : impl_reset_nothrow();
567 : :
568 [ + - ]: 14 : ::comphelper::NamedValueCollection aResource( _Arguments );
569 [ + - ][ - + ]: 14 : if ( aResource.has( "FileName" ) && !aResource.has( "URL" ) )
[ # # ][ # # ]
[ - + ]
570 : : // FileName is the compatibility name for URL, so we might have clients passing
571 : : // a FileName only. However, some of our code works with the URL only, so ensure
572 : : // we have one.
573 [ # # ][ # # ]: 0 : aResource.put( "URL", aResource.get( "FileName" ) );
574 [ + - ][ + - ]: 14 : if ( aResource.has( "URL" ) && !aResource.has( "FileName" ) )
[ + - ][ + - ]
[ + - ]
575 : : // similar ... just in case there is legacy code which expects a FileName only
576 [ + - ][ + - ]: 14 : aResource.put( "FileName", aResource.get( "URL" ) );
577 : :
578 : : // now that somebody (perhaps) told us an macro execution mode, remember it as
579 : : // ImposedMacroExecMode
580 : : m_pImpl->setImposedMacroExecMode(
581 [ + - ]: 14 : aResource.getOrDefault( "MacroExecutionMode", m_pImpl->getImposedMacroExecMode() ) );
582 : :
583 : 14 : impl_setInitializing();
584 : : try
585 : : {
586 [ + - ]: 14 : aGuard.clear();
587 [ + - ][ + - ]: 14 : impl_import_nolck_throw( m_pImpl->m_aContext, *this, aResource );
[ + - ][ + - ]
588 [ + - ]: 14 : aGuard.reset();
589 : : }
590 [ # # ]: 0 : catch( const Exception& )
591 : : {
592 [ # # ]: 0 : impl_reset_nothrow();
593 : 0 : throw;
594 : : }
595 : : // tell our view monitor that the document has been loaded - this way it will fire the proper
596 : : // event (OnLoad instead of OnCreate) later on
597 : 14 : m_aViewMonitor.onLoadedDocument();
598 : :
599 : : // note that we do *not* call impl_setInitialized() here: The initialization is only complete
600 : : // when the XModel::attachResource has been called, not sooner.
601 : :
602 [ + - ][ + - ]: 14 : impl_setModified_nothrow( sal_False, aGuard );
[ + - ]
603 : : // <- SYNCHRONIZED
604 : 14 : }
605 : :
606 : : namespace
607 : : {
608 : 0 : bool lcl_hasAnyModifiedSubComponent_throw( const Reference< XController >& i_rController )
609 : : {
610 [ # # ]: 0 : Reference< XDatabaseDocumentUI > xDatabaseUI( i_rController, UNO_QUERY_THROW );
611 : :
612 [ # # ][ # # ]: 0 : Sequence< Reference< XComponent > > aComponents( xDatabaseUI->getSubComponents() );
613 : 0 : const Reference< XComponent >* component = aComponents.getConstArray();
614 : 0 : const Reference< XComponent >* componentsEnd = aComponents.getConstArray() + aComponents.getLength();
615 : :
616 : 0 : bool isAnyModified = false;
617 [ # # ]: 0 : for ( ; component != componentsEnd; ++component )
618 : : {
619 [ # # ]: 0 : Reference< XModifiable > xModify( *component, UNO_QUERY );
620 [ # # ]: 0 : if ( xModify.is() )
621 : : {
622 [ # # ][ # # ]: 0 : isAnyModified = xModify->isModified();
623 : 0 : continue;
624 : : }
625 : :
626 : : // TODO: clarify: anything else to care for? Both the sub componbents with and without model
627 : : // should support the XModifiable interface, so I think nothing more is needed here.
628 : : OSL_FAIL( "lcl_hasAnyModifiedSubComponent_throw: anything left to do here?" );
629 [ # # ]: 0 : }
630 : :
631 [ # # ]: 0 : return isAnyModified;
632 : : }
633 : : }
634 : :
635 : 0 : ::sal_Bool SAL_CALL ODatabaseDocument::wasModifiedSinceLastSave() throw ( RuntimeException )
636 : : {
637 [ # # ]: 0 : DocumentGuard aGuard( *this );
638 : :
639 : : // The implementation here is somewhat sloppy, in that it returns whether *any* part of the whole
640 : : // database document, including opened sub components, is modified. This is more than what is requested:
641 : : // We need to return <TRUE/> if the doc itself, or any of the opened sub components, has been modified
642 : : // since the last call to any of the save* methods, or since the document has been loaded/created.
643 : : // However, the API definition explicitly allows to be that sloppy ...
644 : :
645 [ # # ][ # # ]: 0 : if ( isModified() )
646 : 0 : return sal_True;
647 : :
648 : : // auto recovery is an "UI feature", it is to restore the UI the user knows. Thus,
649 : : // we ask our connected controllers, not simply our existing form/report definitions.
650 : : // (There is some information which even cannot be obtained without asking the controller.
651 : : // For instance, newly created, but not yet saved, forms/reports are acessible via the
652 : : // controller only, but not via the model.)
653 : :
654 : : try
655 : : {
656 [ # # ][ # # ]: 0 : for ( Controllers::const_iterator ctrl = m_aControllers.begin();
[ # # ]
657 [ # # ]: 0 : ctrl != m_aControllers.end();
658 : : ++ctrl
659 : : )
660 : : {
661 [ # # ][ # # ]: 0 : if ( lcl_hasAnyModifiedSubComponent_throw( *ctrl ) )
662 : 0 : return sal_True;
663 : : }
664 : : }
665 [ # # ]: 0 : catch( const Exception& )
666 : : {
667 : : DBG_UNHANDLED_EXCEPTION();
668 : : }
669 : :
670 [ # # ]: 0 : return sal_False;
671 : : }
672 : :
673 : 0 : void SAL_CALL ODatabaseDocument::storeToRecoveryFile( const ::rtl::OUString& i_TargetLocation, const Sequence< PropertyValue >& i_MediaDescriptor ) throw ( RuntimeException, IOException, WrappedTargetException )
674 : : {
675 [ # # ]: 0 : DocumentGuard aGuard( *this );
676 [ # # ]: 0 : ModifyLock aLock( *this );
677 : :
678 : : try
679 : : {
680 : : // create a storage for the target location
681 [ # # ]: 0 : Reference< XStorage > xTargetStorage( impl_createStorageFor_throw( i_TargetLocation ) );
682 : :
683 : : // first store the document as a whole into this storage
684 [ # # ]: 0 : impl_storeToStorage_throw( xTargetStorage, i_MediaDescriptor, aGuard );
685 : :
686 : : // save the sub components which need saving
687 [ # # ]: 0 : DatabaseDocumentRecovery aDocRecovery( m_pImpl->m_aContext);
688 [ # # ]: 0 : aDocRecovery.saveModifiedSubComponents( xTargetStorage, m_aControllers );
689 : :
690 : : // commit the root storage
691 [ # # ][ # # ]: 0 : tools::stor::commitStorageIfWriteable( xTargetStorage );
692 : : }
693 [ # # ]: 0 : catch( const Exception& )
694 : : {
695 [ # # ]: 0 : Any aError = ::cppu::getCaughtException();
696 [ # # # # : 0 : if ( aError.isExtractableTo( ::cppu::UnoType< IOException >::get() )
# # # # #
# ]
697 [ # # ]: 0 : || aError.isExtractableTo( ::cppu::UnoType< RuntimeException >::get() )
698 : 0 : || aError.isExtractableTo( ::cppu::UnoType< WrappedTargetException >::get() )
699 : : )
700 : : {
701 : : // allowed to leave
702 : 0 : throw;
703 : : }
704 : :
705 [ # # # # ]: 0 : throw WrappedTargetException( ::rtl::OUString(), *this, aError );
706 [ # # ][ # # ]: 0 : }
707 : 0 : }
708 : :
709 : 0 : void SAL_CALL ODatabaseDocument::recoverFromFile( const ::rtl::OUString& i_SourceLocation, const ::rtl::OUString& i_SalvagedFile, const Sequence< PropertyValue >& i_MediaDescriptor ) throw ( RuntimeException, IOException, WrappedTargetException )
710 : : {
711 [ # # ]: 0 : DocumentGuard aGuard( *this, DocumentGuard::InitMethod );
712 : :
713 [ # # ]: 0 : if ( i_SourceLocation.isEmpty() )
714 [ # # ][ # # ]: 0 : throw IllegalArgumentException( ::rtl::OUString(), *this, 1 );
715 : :
716 : : try
717 : : {
718 : : // load the document itself, by simply delegating to our "load" method
719 : :
720 : : // our load implementation expects the SalvagedFile and URL to be in the media descriptor
721 [ # # ]: 0 : ::comphelper::NamedValueCollection aMediaDescriptor( i_MediaDescriptor );
722 [ # # ]: 0 : aMediaDescriptor.put( "SalvagedFile", i_SalvagedFile );
723 [ # # ]: 0 : aMediaDescriptor.put( "URL", i_SourceLocation );
724 : :
725 [ # # ]: 0 : aGuard.clear(); // (load has an own guarding scheme)
726 [ # # ][ # # ]: 0 : load( aMediaDescriptor.getPropertyValues() );
[ # # ]
727 : :
728 : : // Without a controller, we are unable to recover the sub components, as they're always tied to a controller.
729 : : // So, everything else is done when the first controller is connected.
730 : 0 : m_bHasBeenRecovered = true;
731 : :
732 : : // tell the impl that we've been loaded from the given location
733 [ # # ]: 0 : m_pImpl->setDocFileLocation( i_SourceLocation );
734 : :
735 : : // by definition (of XDocumentRecovery), we're responsible for delivering a fully-initialized document,
736 : : // which includes an attachResource call.
737 [ # # ]: 0 : const ::rtl::OUString sLogicalDocumentURL( i_SalvagedFile.isEmpty() ? i_SourceLocation : i_SalvagedFile );
738 [ # # ][ # # ]: 0 : impl_attachResource( sLogicalDocumentURL, aMediaDescriptor.getPropertyValues(), aGuard );
[ # # ][ # # ]
739 : : // <- SYNCHRONIZED
740 : : }
741 [ # # ]: 0 : catch( const Exception& )
742 : : {
743 [ # # ]: 0 : Any aError = ::cppu::getCaughtException();
744 [ # # # # : 0 : if ( aError.isExtractableTo( ::cppu::UnoType< IOException >::get() )
# # # # #
# ]
745 [ # # ]: 0 : || aError.isExtractableTo( ::cppu::UnoType< RuntimeException >::get() )
746 : 0 : || aError.isExtractableTo( ::cppu::UnoType< WrappedTargetException >::get() )
747 : : )
748 : : {
749 : : // allowed to leave
750 : 0 : throw;
751 : : }
752 : :
753 [ # # # # ]: 0 : throw WrappedTargetException( ::rtl::OUString(), *this, aError );
754 [ # # ]: 0 : }
755 : 0 : }
756 : :
757 : : // XModel
758 : 14 : sal_Bool SAL_CALL ODatabaseDocument::attachResource( const ::rtl::OUString& _rURL, const Sequence< PropertyValue >& _rArguments ) throw (RuntimeException)
759 : : {
760 [ + - ]: 14 : DocumentGuard aGuard( *this, DocumentGuard::MethodUsedDuringInit );
761 [ + - ][ + - ]: 14 : return impl_attachResource( _rURL, _rArguments, aGuard );
762 : : }
763 : :
764 : 14 : sal_Bool ODatabaseDocument::impl_attachResource( const ::rtl::OUString& i_rLogicalDocumentURL,
765 : : const Sequence< PropertyValue >& i_rMediaDescriptor, DocumentGuard& _rDocGuard )
766 : : {
767 [ + - ][ - + : 14 : if ( ( i_rLogicalDocumentURL == getURL() )
# # # # ]
[ + - ]
[ - + # # ]
768 : 0 : && ( i_rMediaDescriptor.getLength() == 1 )
769 : 0 : && ( i_rMediaDescriptor[0].Name.compareToAscii( "BreakMacroSignature" ) == 0 )
770 : : )
771 : : {
772 : : // this is a BAD hack of the Basic importer code ... there should be a dedicated API for this,
773 : : // not this bad mis-using of existing interfaces
774 : 0 : return sal_False;
775 : : // (we do not support macro signatures, so we can ignore this call)
776 : : }
777 : :
778 : : // if no URL has been provided, the caller was lazy enough to not call our getURL - which is not allowed anymore,
779 : : // now since getURL and getLocation both return the same, so calling one of those should be simple.
780 : 14 : ::rtl::OUString sDocumentURL( i_rLogicalDocumentURL );
781 : : OSL_ENSURE( !sDocumentURL.isEmpty(), "ODatabaseDocument::impl_attachResource: invalid URL!" );
782 [ - + ]: 14 : if ( sDocumentURL.isEmpty() )
783 [ # # ]: 0 : sDocumentURL = getURL();
784 : :
785 [ + - ]: 14 : m_pImpl->setResource( sDocumentURL, i_rMediaDescriptor );
786 : :
787 [ + - ]: 14 : if ( impl_isInitializing() )
788 : : { // this means we've just been loaded, and this is the attachResource call which follows
789 : : // the load call.
790 [ + - ]: 14 : impl_setInitialized();
791 : :
792 : : // determine whether the document as a whole, or sub documents, have macros. Especially the latter
793 : : // controls the availability of our XEmbeddedScripts and XScriptInvocationContext interfaces, and we
794 : : // should know this before anybody actually uses the object.
795 [ + - ]: 14 : m_bAllowDocumentScripting = ( m_pImpl->determineEmbeddedMacros() != ODatabaseModelImpl::eSubDocumentMacros );
796 : :
797 [ + - ]: 14 : _rDocGuard.clear();
798 : : // <- SYNCHRONIZED
799 [ + - ][ + - ]: 14 : m_aEventNotifier.notifyDocumentEvent( "OnLoadFinished" );
800 : : }
801 : :
802 : 14 : return sal_True;
803 : : }
804 : :
805 : 224 : ::rtl::OUString SAL_CALL ODatabaseDocument::getURL( ) throw (RuntimeException)
806 : : {
807 [ + - ]: 224 : DocumentGuard aGuard( *this, DocumentGuard::MethodWithoutInit );
808 [ + - ]: 224 : return m_pImpl->getURL();
809 : : }
810 : :
811 : 4 : Sequence< PropertyValue > SAL_CALL ODatabaseDocument::getArgs( ) throw (RuntimeException)
812 : : {
813 [ + - ]: 4 : DocumentGuard aGuard( *this, DocumentGuard::MethodWithoutInit );
814 [ + - ][ + - ]: 4 : return m_pImpl->getMediaDescriptor().getPropertyValues();
815 : : }
816 : :
817 : 0 : void SAL_CALL ODatabaseDocument::connectController( const Reference< XController >& _xController ) throw (RuntimeException)
818 : : {
819 [ # # ]: 0 : DocumentGuard aGuard( *this );
820 : :
821 : : #if OSL_DEBUG_LEVEL > 0
822 : : for ( Controllers::const_iterator controller = m_aControllers.begin();
823 : : controller != m_aControllers.end();
824 : : ++controller
825 : : )
826 : : {
827 : : OSL_ENSURE( *controller != _xController, "ODatabaseDocument::connectController: this controller is already connected!" );
828 : : }
829 : : #endif
830 : :
831 [ # # ]: 0 : m_aControllers.push_back( _xController );
832 : :
833 [ # # ][ # # ]: 0 : m_aEventNotifier.notifyDocumentEventAsync( "OnViewCreated", Reference< XController2 >( _xController, UNO_QUERY ) );
834 : :
835 [ # # ]: 0 : bool bFirstControllerEver = m_aViewMonitor.onControllerConnected( _xController );
836 [ # # ]: 0 : if ( !bFirstControllerEver )
837 : 0 : return;
838 : :
839 : : // check/adjust our macro mode.
840 [ # # ][ # # ]: 0 : m_pImpl->checkMacrosOnLoading();
[ # # ]
841 : : }
842 : :
843 : 0 : void SAL_CALL ODatabaseDocument::disconnectController( const Reference< XController >& _xController ) throw (RuntimeException)
844 : : {
845 : 0 : bool bNotifyViewClosed = false;
846 : 0 : bool bLastControllerGone = false;
847 : 0 : bool bIsClosing = false;
848 : :
849 : : // SYNCHRONIZED ->
850 : : {
851 [ # # ]: 0 : DocumentGuard aGuard( *this );
852 : :
853 [ # # ]: 0 : Controllers::iterator pos = ::std::find( m_aControllers.begin(), m_aControllers.end(), _xController );
854 : : OSL_ENSURE( pos != m_aControllers.end(), "ODatabaseDocument::disconnectController: don't know this controller!" );
855 [ # # ][ # # ]: 0 : if ( pos != m_aControllers.end() )
856 : : {
857 [ # # ]: 0 : m_aControllers.erase( pos );
858 : 0 : bNotifyViewClosed = true;
859 : : }
860 : :
861 [ # # ][ # # ]: 0 : if ( m_xCurrentController == _xController )
862 [ # # ]: 0 : m_xCurrentController = NULL;
863 : :
864 : 0 : bLastControllerGone = m_aControllers.empty();
865 [ # # ]: 0 : bIsClosing = m_bClosing;
866 : : }
867 : : // <- SYNCHRONIZED
868 : :
869 [ # # ]: 0 : if ( bNotifyViewClosed )
870 [ # # ][ # # ]: 0 : m_aEventNotifier.notifyDocumentEvent( "OnViewClosed", Reference< XController2 >( _xController, UNO_QUERY ) );
[ # # ]
871 : :
872 [ # # ][ # # ]: 0 : if ( bLastControllerGone && !bIsClosing )
873 : : {
874 : : // if this was the last view, close the document as a whole
875 : : // #i51157#
876 : : try
877 : : {
878 [ # # ]: 0 : close( sal_True );
879 : : }
880 : 0 : catch( const CloseVetoException& )
881 : : {
882 : : // okay, somebody vetoed and took ownership
883 : : }
884 : : }
885 : 0 : }
886 : :
887 : 0 : void SAL_CALL ODatabaseDocument::lockControllers( ) throw (RuntimeException)
888 : : {
889 [ # # ]: 0 : DocumentGuard aGuard( *this );
890 : :
891 [ # # ]: 0 : ++m_pImpl->m_nControllerLockCount;
892 : 0 : }
893 : :
894 : 0 : void SAL_CALL ODatabaseDocument::unlockControllers( ) throw (RuntimeException)
895 : : {
896 [ # # ]: 0 : DocumentGuard aGuard( *this );
897 : :
898 [ # # ]: 0 : --m_pImpl->m_nControllerLockCount;
899 : 0 : }
900 : :
901 : 0 : sal_Bool SAL_CALL ODatabaseDocument::hasControllersLocked( ) throw (RuntimeException)
902 : : {
903 [ # # ]: 0 : DocumentGuard aGuard( *this );
904 : :
905 [ # # ]: 0 : return m_pImpl->m_nControllerLockCount != 0;
906 : : }
907 : :
908 : 4 : Reference< XController > SAL_CALL ODatabaseDocument::getCurrentController() throw (RuntimeException)
909 : : {
910 [ + - ]: 4 : DocumentGuard aGuard( *this );
911 : :
912 [ - + ][ + - ]: 4 : return m_xCurrentController.is() ? m_xCurrentController : ( m_aControllers.empty() ? Reference< XController >() : *m_aControllers.begin() );
[ - + ][ + - ]
913 : : }
914 : :
915 : 0 : void SAL_CALL ODatabaseDocument::setCurrentController( const Reference< XController >& _xController ) throw (NoSuchElementException, RuntimeException)
916 : : {
917 [ # # ]: 0 : DocumentGuard aGuard( *this );
918 : :
919 [ # # ]: 0 : m_xCurrentController = _xController;
920 : :
921 [ # # ][ # # ]: 0 : if ( !m_aViewMonitor.onSetCurrentController( _xController ) )
922 : : return;
923 : :
924 : : // check if there are sub components to recover from our document storage
925 : 0 : bool bAttemptRecovery = m_bHasBeenRecovered;
926 [ # # ][ # # ]: 0 : if ( !bAttemptRecovery && m_pImpl->getMediaDescriptor().has( "ForceRecovery" ) )
[ # # ][ # # ]
927 : : // do not use getOrDefault, it will throw for invalid types, which is not desired here
928 [ # # ]: 0 : m_pImpl->getMediaDescriptor().get( "ForceRecovery" ) >>= bAttemptRecovery;
929 : :
930 [ # # ]: 0 : if ( !bAttemptRecovery )
931 : : return;
932 : :
933 : : try
934 : : {
935 [ # # ]: 0 : DatabaseDocumentRecovery aDocRecovery( m_pImpl->m_aContext );
936 [ # # ][ # # ]: 0 : aDocRecovery.recoverSubDocuments( m_pImpl->getRootStorage(), _xController );
[ # # ][ # # ]
937 : : }
938 [ # # ]: 0 : catch( const Exception& )
939 : : {
940 : : DBG_UNHANDLED_EXCEPTION();
941 [ # # ][ # # ]: 0 : }
942 : : }
943 : :
944 : 0 : Reference< XInterface > SAL_CALL ODatabaseDocument::getCurrentSelection( ) throw (RuntimeException)
945 : : {
946 [ # # ]: 0 : DocumentGuard aGuard( *this );
947 : :
948 : 0 : Reference< XInterface > xRet;
949 [ # # ][ # # ]: 0 : Reference< XSelectionSupplier > xDocView( getCurrentController(), UNO_QUERY );
950 [ # # ]: 0 : if ( xDocView.is() )
951 [ # # ][ # # ]: 0 : xRet.set(xDocView->getSelection(),UNO_QUERY);
[ # # ]
952 : :
953 [ # # ]: 0 : return xRet;
954 : : }
955 : :
956 : : // XStorable
957 : 0 : sal_Bool SAL_CALL ODatabaseDocument::hasLocation( ) throw (RuntimeException)
958 : : {
959 : 0 : return !getLocation().isEmpty();
960 : : }
961 : :
962 : 2 : ::rtl::OUString SAL_CALL ODatabaseDocument::getLocation( ) throw (RuntimeException)
963 : : {
964 [ + - ]: 2 : DocumentGuard aGuard( *this, DocumentGuard::MethodWithoutInit );
965 [ + - ]: 2 : return m_pImpl->getURL();
966 : : // both XStorable::getLocation and XModel::getURL have to return the URL of the document, *not*
967 : : // the location of the file which the docunment was possibly recovered from (which would be getDocFileLocation)
968 : : }
969 : :
970 : 0 : sal_Bool SAL_CALL ODatabaseDocument::isReadonly( ) throw (RuntimeException)
971 : : {
972 [ # # ]: 0 : DocumentGuard aGuard( *this, DocumentGuard::MethodWithoutInit );
973 [ # # ]: 0 : return m_pImpl->m_bDocumentReadOnly;
974 : : }
975 : :
976 : 2 : void SAL_CALL ODatabaseDocument::store( ) throw (IOException, RuntimeException)
977 : : {
978 [ + - ]: 2 : DocumentGuard aGuard( *this );
979 : :
980 : 2 : ::rtl::OUString sDocumentURL( m_pImpl->getURL() );
981 [ + - ]: 2 : if ( !sDocumentURL.isEmpty() )
982 : : {
983 [ + - ]: 2 : if ( m_pImpl->getDocFileLocation() == m_pImpl->getURL() )
984 [ - + ]: 2 : if ( m_pImpl->m_bDocumentReadOnly )
985 [ # # ]: 0 : throw IOException();
986 : :
987 [ + - ]: 2 : impl_storeAs_throw( m_pImpl->getURL(), m_pImpl->getMediaDescriptor(), SAVE, aGuard );
988 : 2 : return;
989 : : }
990 : :
991 : : // if we have no URL, but did survive the DocumentGuard above, then we've been inited via XLoadable::initNew,
992 : : // i.e. we're based on a temporary storage
993 : : OSL_ENSURE( m_pImpl->getDocFileLocation().isEmpty(), "ODatabaseDocument::store: unexpected URL inconsistency!" );
994 : :
995 : : try
996 : : {
997 [ # # ][ # # ]: 0 : impl_storeToStorage_throw( m_pImpl->getRootStorage(), m_pImpl->getMediaDescriptor().getPropertyValues(), aGuard );
[ # # ][ # # ]
998 : : }
999 [ # # # # ]: 0 : catch( const Exception& )
1000 : : {
1001 [ # # ]: 0 : Any aError = ::cppu::getCaughtException();
1002 [ # # # # : 0 : if ( aError.isExtractableTo( ::cppu::UnoType< IOException >::get() )
# # # # ]
1003 [ # # ]: 0 : || aError.isExtractableTo( ::cppu::UnoType< RuntimeException >::get() )
1004 : : )
1005 : : {
1006 : : // allowed to leave
1007 : 0 : throw;
1008 : : }
1009 [ # # ]: 0 : impl_throwIOExceptionCausedBySave_throw( aError, ::rtl::OUString() );
1010 [ + - ][ + - ]: 2 : }
[ - + ]
1011 : : }
1012 : :
1013 : 0 : void ODatabaseDocument::impl_throwIOExceptionCausedBySave_throw( const Any& i_rError, const ::rtl::OUString& i_rTargetURL ) const
1014 : : {
1015 [ # # ]: 0 : ::rtl::OUString sErrorMessage = extractExceptionMessage( m_pImpl->m_aContext, i_rError );
1016 : : sErrorMessage = ResourceManager::loadString(
1017 : : RID_STR_ERROR_WHILE_SAVING,
1018 : : "$location$", i_rTargetURL,
1019 : : "$message$", sErrorMessage
1020 [ # # ]: 0 : );
1021 [ # # ][ # # ]: 0 : throw IOException( sErrorMessage, *const_cast< ODatabaseDocument* >( this ) );
1022 : : }
1023 : :
1024 : 174 : void ODatabaseDocument::impl_storeAs_throw( const ::rtl::OUString& _rURL, const ::comphelper::NamedValueCollection& _rArguments,
1025 : : const StoreType _eType, DocumentGuard& _rGuard ) throw ( IOException, RuntimeException )
1026 : : {
1027 : : OSL_PRECOND( ( _eType == SAVE ) || ( _eType == SAVE_AS ),
1028 : : "ODatabaseDocument::impl_storeAs_throw: you introduced a new type which cannot be handled here!" );
1029 : :
1030 : : // if we're in the process of initializing the document (which effectively means it is an implicit
1031 : : // initialization triggered in storeAsURL), the we do not notify events, since to an observer, the SaveAs
1032 : : // should not be noticable
1033 : 174 : bool bIsInitializationProcess = impl_isInitializing();
1034 : :
1035 [ + + ]: 174 : if ( !bIsInitializationProcess )
1036 : : {
1037 [ + - ]: 2 : _rGuard.clear();
1038 [ + - ][ + - ]: 2 : m_aEventNotifier.notifyDocumentEvent( _eType == SAVE ? "OnSave" : "OnSaveAs", NULL, makeAny( _rURL ) );
[ + - ][ + - ]
1039 [ + - ]: 2 : _rGuard.reset();
1040 : : }
1041 : :
1042 : 174 : Reference< XStorage > xNewRootStorage;
1043 : : // will be non-NULL if our storage changed
1044 : :
1045 : : try
1046 : : {
1047 [ + - ]: 174 : ModifyLock aLock( *this );
1048 : : // ignore all changes of our "modified" state during storing
1049 : :
1050 : 174 : sal_Bool bLocationChanged = ( _rURL != m_pImpl->getDocFileLocation() );
1051 [ + + ]: 174 : if ( bLocationChanged )
1052 : : {
1053 : : // create storage for target URL
1054 [ + - ]: 172 : Reference< XStorage > xTargetStorage( impl_createStorageFor_throw( _rURL ) );
1055 : :
1056 [ - + ]: 172 : if ( m_pImpl->isEmbeddedDatabase() )
1057 [ # # ]: 0 : m_pImpl->clearConnections();
1058 : :
1059 : : // commit everything
1060 [ + - ]: 172 : m_pImpl->commitEmbeddedStorage();
1061 [ + - ]: 172 : m_pImpl->commitStorages();
1062 : :
1063 : : // copy own storage to target storage
1064 [ + - ]: 172 : Reference< XStorage > xCurrentStorage( m_pImpl->getRootStorage() );
1065 [ - + ]: 172 : if ( xCurrentStorage.is() )
1066 [ # # ][ # # ]: 0 : xCurrentStorage->copyToStorage( xTargetStorage );
1067 : :
1068 [ + - ]: 172 : m_pImpl->disposeStorages();
1069 : :
1070 : : // each and every document definition obtained via m_xForms and m_xReports depends
1071 : : // on the sub storages which we just disposed. So, dispose the forms/reports collections, too.
1072 : : // This ensures that they're re-created when needed.
1073 [ + - ]: 172 : clearObjectContainer( m_xForms );
1074 [ + - ]: 172 : clearObjectContainer( m_xReports );
1075 : :
1076 [ + - ][ + - ]: 172 : xNewRootStorage = m_pImpl->switchToStorage( xTargetStorage );
1077 : :
1078 : 172 : m_pImpl->m_bDocumentReadOnly = sal_False;
1079 : : }
1080 : :
1081 : : // store to current storage
1082 [ + - ][ + - ]: 174 : Reference< XStorage > xCurrentStorage( m_pImpl->getOrCreateRootStorage(), UNO_QUERY_THROW );
1083 [ + - ]: 174 : Sequence< PropertyValue > aMediaDescriptor( lcl_appendFileNameToDescriptor( _rArguments, _rURL ) );
1084 [ + - ]: 174 : impl_storeToStorage_throw( xCurrentStorage, aMediaDescriptor, _rGuard );
1085 : :
1086 : : // success - tell our impl
1087 [ + - ]: 174 : m_pImpl->setDocFileLocation( _rURL );
1088 [ + - ]: 174 : m_pImpl->setResource( _rURL, aMediaDescriptor );
1089 : :
1090 : : // if we are in an initialization process, then this is finished, now that we stored the document
1091 [ + + ]: 174 : if ( bIsInitializationProcess )
1092 [ + - ][ + - ]: 174 : impl_setInitialized();
[ + - ]
1093 : : }
1094 [ # # # # ]: 0 : catch( const Exception& )
1095 : : {
1096 [ # # ]: 0 : Any aError = ::cppu::getCaughtException();
1097 : :
1098 : : // notify the failure
1099 [ # # ]: 0 : if ( !bIsInitializationProcess )
1100 [ # # # # : 0 : m_aEventNotifier.notifyDocumentEventAsync( _eType == SAVE ? "OnSaveFailed" : "OnSaveAsFailed", NULL, makeAny( _rURL ) );
# # # # ]
1101 : :
1102 [ # # # # : 0 : if ( aError.isExtractableTo( ::cppu::UnoType< IOException >::get() )
# # # # ]
1103 [ # # ]: 0 : || aError.isExtractableTo( ::cppu::UnoType< RuntimeException >::get() )
1104 : : )
1105 : : {
1106 : : // allowed to leave
1107 : 0 : throw;
1108 : : }
1109 : :
1110 [ # # ]: 0 : impl_throwIOExceptionCausedBySave_throw( aError, _rURL );
1111 : : }
1112 : :
1113 : : // notify the document event
1114 [ + + ]: 174 : if ( !bIsInitializationProcess )
1115 [ + - ][ + - ]: 2 : m_aEventNotifier.notifyDocumentEventAsync( _eType == SAVE ? "OnSaveDone" : "OnSaveAsDone", NULL, makeAny( _rURL ) );
[ + - ][ + - ]
1116 : :
1117 : : // reset our "modified" flag, and clear the guard
1118 [ + - ]: 174 : impl_setModified_nothrow( sal_False, _rGuard );
1119 : : // <- SYNCHRONIZED
1120 : :
1121 : : // notify storage listeners
1122 [ + + ]: 174 : if ( xNewRootStorage.is() )
1123 [ + - ]: 174 : impl_notifyStorageChange_nolck_nothrow( xNewRootStorage );
1124 : 174 : }
1125 : :
1126 : 172 : Reference< XStorage > ODatabaseDocument::impl_createStorageFor_throw( const ::rtl::OUString& _rURL ) const
1127 : : {
1128 [ + - ][ + - ]: 172 : Reference< ucb::XSimpleFileAccess2 > xTempAccess(ucb::SimpleFileAccess::create(m_pImpl->m_aContext.getUNOContext()));
1129 [ + - ][ + - ]: 172 : Reference< io::XStream > xStream = xTempAccess->openFileReadWrite( _rURL );
1130 [ + - ]: 172 : Reference< io::XTruncate > xTruncate(xStream,UNO_QUERY);
1131 [ + - ]: 172 : if ( xTruncate.is() )
1132 : : {
1133 [ + - ][ + - ]: 172 : xTruncate->truncate();
1134 : : }
1135 [ + - ]: 172 : Sequence<Any> aParam(2);
1136 [ + - ][ + - ]: 172 : aParam[0] <<= xStream;
1137 [ + - ][ + - ]: 172 : aParam[1] <<= ElementModes::READWRITE | ElementModes::TRUNCATE;
1138 : :
1139 [ + - ][ + - ]: 172 : Reference< XSingleServiceFactory > xStorageFactory( m_pImpl->createStorageFactory(), UNO_SET_THROW );
1140 [ + - ][ + - ]: 172 : return Reference< XStorage >( xStorageFactory->createInstanceWithArguments( aParam ), UNO_QUERY_THROW );
[ + - ][ + - ]
1141 : : }
1142 : :
1143 : 172 : void SAL_CALL ODatabaseDocument::storeAsURL( const ::rtl::OUString& _rURL, const Sequence< PropertyValue >& _rArguments ) throw (IOException, RuntimeException)
1144 : : {
1145 : : // SYNCHRONIZED ->
1146 [ + - ]: 172 : DocumentGuard aGuard( *this, DocumentGuard::MethodWithoutInit );
1147 : :
1148 : : // Normally, a document initialization is done via XLoadable::load or XLoadable::initNew. For convenience
1149 : : // reasons, and to not break existing API clients, it's allowed to call storeAsURL without having initialized
1150 : : // the document, in which case the initialization will be done implicitly.
1151 : 172 : bool bImplicitInitialization = !impl_isInitialized();
1152 : : // implicit initialization while another initialization is just running is not possible
1153 [ - + ][ - + ]: 172 : if ( bImplicitInitialization && impl_isInitializing() )
[ + - ]
1154 [ # # ]: 0 : throw DoubleInitializationException();
1155 : :
1156 [ + - ]: 172 : if ( bImplicitInitialization )
1157 : 172 : impl_setInitializing();
1158 : :
1159 : : try
1160 : : {
1161 [ + - ][ + - ]: 172 : impl_storeAs_throw( _rURL, _rArguments, SAVE_AS, aGuard );
[ + - ]
1162 : : // <- SYNCHRONIZED
1163 : :
1164 : : // impl_storeAs_throw cleared the lock on our mutex, but the below lines need this lock
1165 : : // SYNCHRONIZED ->
1166 [ + - ]: 172 : aGuard.reset();
1167 : :
1168 : : // our title might have changed, potentially at least
1169 : : // Sadly, we cannot check this: Calling getTitle here and now would not deliver
1170 : : // an up-to-date result, as the call is delegated to our TitleHelper instance, which itself
1171 : : // updates its title only if it gets the OnSaveAsDone event (which was sent asynchronously
1172 : : // by impl_storeAs_throw). So, we simply notify always, and also asynchronously
1173 [ + - ][ + - ]: 172 : m_aEventNotifier.notifyDocumentEventAsync( "OnTitleChanged" );
1174 : : }
1175 [ # # ]: 0 : catch( const Exception& )
1176 : : {
1177 [ # # ]: 0 : impl_reset_nothrow();
1178 : 0 : throw;
1179 : : }
1180 : :
1181 [ + - ]: 172 : if ( bImplicitInitialization )
1182 : 172 : m_bAllowDocumentScripting = true;
1183 : :
1184 [ + - ]: 172 : aGuard.clear();
1185 : : // <- SYNCHRONIZED
1186 : :
1187 [ + - ]: 172 : if ( bImplicitInitialization )
1188 [ + - ][ + - ]: 172 : m_aEventNotifier.notifyDocumentEvent( "OnCreate" );
[ + - ]
1189 : 172 : }
1190 : :
1191 : 174 : void ODatabaseDocument::impl_storeToStorage_throw( const Reference< XStorage >& _rxTargetStorage, const Sequence< PropertyValue >& _rMediaDescriptor,
1192 : : DocumentGuard& _rDocGuard ) const
1193 : : {
1194 [ - + ]: 174 : if ( !_rxTargetStorage.is() )
1195 [ # # ][ # # ]: 0 : throw IllegalArgumentException( ::rtl::OUString(), *const_cast< ODatabaseDocument* >( this ), 1 );
1196 : :
1197 [ - + ]: 174 : if ( !m_pImpl.is() )
1198 [ # # ][ # # ]: 0 : throw DisposedException( ::rtl::OUString(), *const_cast< ODatabaseDocument* >( this ) );
1199 : :
1200 : : try
1201 : : {
1202 : : // commit everything
1203 [ + - ]: 174 : m_pImpl->commitEmbeddedStorage();
1204 [ + - ]: 174 : m_pImpl->commitStorages();
1205 : :
1206 : : // copy own storage to target storage
1207 [ + + ]: 174 : if ( impl_isInitialized() )
1208 : : {
1209 [ + - ][ + - ]: 2 : Reference< XStorage > xCurrentStorage( m_pImpl->getOrCreateRootStorage(), UNO_QUERY_THROW );
1210 [ - + ][ + - ]: 2 : if ( xCurrentStorage != _rxTargetStorage )
1211 [ # # ][ # # ]: 2 : xCurrentStorage->copyToStorage( _rxTargetStorage );
1212 : : }
1213 : :
1214 : : // write into target storage
1215 [ + - ]: 174 : ::comphelper::NamedValueCollection aWriteArgs( _rMediaDescriptor );
1216 [ + - ]: 174 : lcl_triggerStatusIndicator_throw( aWriteArgs, _rDocGuard, true );
1217 [ + - ]: 174 : impl_writeStorage_throw( _rxTargetStorage, aWriteArgs );
1218 [ + - ]: 174 : lcl_triggerStatusIndicator_throw( aWriteArgs, _rDocGuard, false );
1219 : :
1220 : : // commit target storage
1221 [ + - ][ + - ]: 174 : OSL_VERIFY( tools::stor::commitStorageIfWriteable( _rxTargetStorage ) );
1222 : : }
1223 : 0 : catch( const IOException& ) { throw; }
1224 : 0 : catch( const RuntimeException& ) { throw; }
1225 [ # # # # ]: 0 : catch ( const Exception& e )
1226 : : {
1227 [ # # # # ]: 0 : throw IOException( e.Message, *const_cast< ODatabaseDocument* >( this ) );
1228 : : }
1229 : 174 : }
1230 : :
1231 : 0 : void SAL_CALL ODatabaseDocument::storeToURL( const ::rtl::OUString& _rURL, const Sequence< PropertyValue >& _rArguments ) throw (IOException, RuntimeException)
1232 : : {
1233 [ # # ]: 0 : DocumentGuard aGuard( *this );
1234 [ # # ]: 0 : ModifyLock aLock( *this );
1235 : :
1236 : : {
1237 [ # # ]: 0 : aGuard.clear();
1238 [ # # ][ # # ]: 0 : m_aEventNotifier.notifyDocumentEvent( "OnSaveTo", NULL, makeAny( _rURL ) );
[ # # ]
1239 [ # # ]: 0 : aGuard.reset();
1240 : : }
1241 : :
1242 : : try
1243 : : {
1244 : : // create storage for target URL
1245 [ # # ]: 0 : Reference< XStorage > xTargetStorage( impl_createStorageFor_throw( _rURL ) );
1246 : :
1247 : : // extend media descriptor with URL
1248 [ # # ][ # # ]: 0 : Sequence< PropertyValue > aMediaDescriptor( lcl_appendFileNameToDescriptor( _rArguments, _rURL ) );
[ # # ]
1249 : :
1250 : : // store to this storage
1251 [ # # ][ # # ]: 0 : impl_storeToStorage_throw( xTargetStorage, aMediaDescriptor, aGuard );
1252 : : }
1253 [ # # # # ]: 0 : catch( const Exception& )
1254 : : {
1255 [ # # ]: 0 : Any aError = ::cppu::getCaughtException();
1256 [ # # # # ]: 0 : m_aEventNotifier.notifyDocumentEventAsync( "OnSaveToFailed", NULL, aError );
1257 : :
1258 [ # # # # : 0 : if ( aError.isExtractableTo( ::cppu::UnoType< IOException >::get() )
# # # # ]
1259 [ # # ]: 0 : || aError.isExtractableTo( ::cppu::UnoType< RuntimeException >::get() )
1260 : : )
1261 : : {
1262 : : // allowed to leave
1263 : 0 : throw;
1264 : : }
1265 : :
1266 [ # # ]: 0 : impl_throwIOExceptionCausedBySave_throw( aError, _rURL );
1267 : : }
1268 : :
1269 [ # # ][ # # ]: 0 : m_aEventNotifier.notifyDocumentEventAsync( "OnSaveToDone", NULL, makeAny( _rURL ) );
[ # # ][ # # ]
[ # # ]
1270 : 0 : }
1271 : :
1272 : : // XModifyBroadcaster
1273 : 0 : void SAL_CALL ODatabaseDocument::addModifyListener( const Reference< XModifyListener >& _xListener ) throw (RuntimeException)
1274 : : {
1275 [ # # ]: 0 : DocumentGuard aGuard( *this );
1276 [ # # ][ # # ]: 0 : m_aModifyListeners.addInterface(_xListener);
1277 : 0 : }
1278 : :
1279 : 0 : void SAL_CALL ODatabaseDocument::removeModifyListener( const Reference< XModifyListener >& _xListener ) throw (RuntimeException)
1280 : : {
1281 [ # # ]: 0 : DocumentGuard aGuard( *this );
1282 [ # # ][ # # ]: 0 : m_aModifyListeners.removeInterface(_xListener);
1283 : 0 : }
1284 : :
1285 : : // XModifiable
1286 : 0 : sal_Bool SAL_CALL ODatabaseDocument::isModified( ) throw (RuntimeException)
1287 : : {
1288 [ # # ]: 0 : DocumentGuard aGuard( *this );
1289 : :
1290 [ # # ]: 0 : return m_pImpl->m_bModified;
1291 : : }
1292 : :
1293 : 2048 : void SAL_CALL ODatabaseDocument::setModified( sal_Bool _bModified ) throw (PropertyVetoException, RuntimeException)
1294 : : {
1295 [ + - ]: 2048 : DocumentGuard aGuard( *this, DocumentGuard::MethodWithoutInit );
1296 [ + + ]: 2048 : if ( impl_isInitialized() )
1297 [ + - ][ + - ]: 2048 : impl_setModified_nothrow( _bModified, aGuard );
1298 : : // it's allowed to call setModified without the document being initialized already. In this case,
1299 : : // we simply ignore the call - when the initialization is finished, the respective code will set
1300 : : // a proper "modified" flag
1301 : 2048 : }
1302 : :
1303 : 222 : void ODatabaseDocument::impl_setModified_nothrow( sal_Bool _bModified, DocumentGuard& _rGuard )
1304 : : {
1305 : : // SYNCHRONIZED ->
1306 [ + + ][ + - ]: 222 : bool bModifiedChanged = ( m_pImpl->m_bModified != _bModified ) && ( !m_pImpl->isModifyLocked() );
1307 : :
1308 [ + + ]: 222 : if ( bModifiedChanged )
1309 : : {
1310 : 202 : m_pImpl->m_bModified = _bModified;
1311 [ + - ][ + - ]: 202 : m_aEventNotifier.notifyDocumentEventAsync( "OnModifyChanged" );
1312 : : }
1313 : 222 : _rGuard.clear();
1314 : : // <- SYNCHRONIZED
1315 : :
1316 [ + + ]: 222 : if ( bModifiedChanged )
1317 : : {
1318 [ + - ][ + - ]: 202 : lang::EventObject aEvent( *this );
1319 [ + - ][ + - ]: 202 : m_aModifyListeners.notifyEach( &XModifyListener::modified, aEvent );
1320 : : }
1321 : 222 : }
1322 : :
1323 : : // ::com::sun::star::document::XEventBroadcaster
1324 : 2 : void SAL_CALL ODatabaseDocument::addEventListener(const uno::Reference< document::XEventListener >& _Listener ) throw (uno::RuntimeException)
1325 : : {
1326 : 2 : m_aEventNotifier.addLegacyEventListener( _Listener );
1327 : 2 : }
1328 : :
1329 : 0 : void SAL_CALL ODatabaseDocument::removeEventListener( const uno::Reference< document::XEventListener >& _Listener ) throw (uno::RuntimeException)
1330 : : {
1331 : 0 : m_aEventNotifier.removeLegacyEventListener( _Listener );
1332 : 0 : }
1333 : :
1334 : 372 : void SAL_CALL ODatabaseDocument::addDocumentEventListener( const Reference< XDocumentEventListener >& _Listener ) throw (RuntimeException)
1335 : : {
1336 : 372 : m_aEventNotifier.addDocumentEventListener( _Listener );
1337 : 372 : }
1338 : :
1339 : 0 : void SAL_CALL ODatabaseDocument::removeDocumentEventListener( const Reference< XDocumentEventListener >& _Listener ) throw (RuntimeException)
1340 : : {
1341 : 0 : m_aEventNotifier.removeDocumentEventListener( _Listener );
1342 : 0 : }
1343 : :
1344 : 0 : void SAL_CALL ODatabaseDocument::notifyDocumentEvent( const ::rtl::OUString& _EventName, const Reference< XController2 >& _ViewController, const Any& _Supplement ) throw (IllegalArgumentException, NoSupportException, RuntimeException)
1345 : : {
1346 [ # # ]: 0 : if ( _EventName.isEmpty() )
1347 [ # # ][ # # ]: 0 : throw IllegalArgumentException( ::rtl::OUString(), *this, 1 );
1348 : :
1349 : : // SYNCHRONIZED ->
1350 [ # # ]: 0 : DocumentGuard aGuard( *this );
1351 : :
1352 [ # # ][ # # ]: 0 : if ( !DocumentEvents::needsSynchronousNotification( _EventName ) )
1353 : : {
1354 [ # # ]: 0 : m_aEventNotifier.notifyDocumentEventAsync( _EventName, _ViewController, _Supplement );
1355 : 0 : return;
1356 : : }
1357 [ # # ]: 0 : aGuard.clear();
1358 : : // <- SYNCHRONIZED
1359 : :
1360 [ # # ][ # # ]: 0 : m_aEventNotifier.notifyDocumentEvent( _EventName, _ViewController, _Supplement );
[ # # ]
1361 : : }
1362 : :
1363 : 0 : Sequence< PropertyValue > SAL_CALL ODatabaseDocument::getPrinter( ) throw (RuntimeException)
1364 : : {
1365 : : OSL_FAIL( "ODatabaseDocument::getPrinter: not supported!" );
1366 : 0 : return Sequence< PropertyValue >();
1367 : : }
1368 : :
1369 : 0 : void SAL_CALL ODatabaseDocument::setPrinter( const Sequence< PropertyValue >& /*aPrinter*/ ) throw (IllegalArgumentException, RuntimeException)
1370 : : {
1371 : : OSL_FAIL( "ODatabaseDocument::setPrinter: not supported!" );
1372 : 0 : }
1373 : :
1374 : 0 : void SAL_CALL ODatabaseDocument::print( const Sequence< PropertyValue >& /*xOptions*/ ) throw (IllegalArgumentException, RuntimeException)
1375 : : {
1376 : : OSL_FAIL( "ODatabaseDocument::print: not supported!" );
1377 : 0 : }
1378 : :
1379 : 1092 : void ODatabaseDocument::impl_reparent_nothrow( const WeakReference< XNameAccess >& _rxContainer )
1380 : : {
1381 [ + - ][ + - ]: 1092 : Reference< XChild > xChild( _rxContainer.get(), UNO_QUERY );
1382 [ + + ]: 1092 : if ( xChild.is() )
1383 [ + - ][ + - ]: 1092 : xChild->setParent( *this );
[ + - ]
1384 : 1092 : }
1385 : :
1386 : 1580 : void ODatabaseDocument::clearObjectContainer( WeakReference< XNameAccess >& _rxContainer)
1387 : : {
1388 [ + - ]: 1580 : Reference< XNameAccess > xContainer = _rxContainer;
1389 [ + - ]: 1580 : ::comphelper::disposeComponent( xContainer );
1390 : :
1391 [ + - ][ + - ]: 1580 : Reference< XChild > xChild( _rxContainer.get(),UNO_QUERY );
1392 [ + + ]: 1580 : if ( xChild.is() )
1393 [ + - ][ + - ]: 8 : xChild->setParent( NULL );
[ + - ]
1394 [ + - ]: 1580 : _rxContainer = Reference< XNameAccess >();
1395 : 1580 : }
1396 : :
1397 : 348 : Reference< XNameAccess > ODatabaseDocument::impl_getDocumentContainer_throw( ODatabaseModelImpl::ObjectType _eType )
1398 : : {
1399 [ + + ][ - + ]: 348 : if ( ( _eType != ODatabaseModelImpl::E_FORM ) && ( _eType != ODatabaseModelImpl::E_REPORT ) )
1400 [ # # ]: 0 : throw IllegalArgumentException();
1401 : :
1402 : 348 : bool bFormsContainer = _eType == ODatabaseModelImpl::E_FORM;
1403 : :
1404 [ + + ]: 348 : WeakReference< XNameAccess >& rContainerRef( bFormsContainer ? m_xForms : m_xReports );
1405 : 348 : Reference< XNameAccess > xContainer = rContainerRef;
1406 [ + - ]: 348 : if ( !xContainer.is() )
1407 : : {
1408 : 348 : Any aValue;
1409 [ + - ]: 348 : ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xMy(*this);
1410 [ + + ][ + - ]: 348 : if ( dbtools::getDataSourceSetting(xMy,bFormsContainer ? "Forms" : "Reports",aValue) )
[ + - ]
1411 : : {
1412 : 348 : ::rtl::OUString sSupportService;
1413 : 348 : aValue >>= sSupportService;
1414 [ - + ]: 348 : if ( !sSupportService.isEmpty() )
1415 : : {
1416 [ # # ]: 0 : Sequence<Any> aArgs(1);
1417 [ # # ][ # # ]: 0 : aArgs[0] <<= NamedValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DatabaseDocument")),makeAny(xMy));
[ # # ][ # # ]
1418 [ # # ][ # # ]: 0 : xContainer.set(m_pImpl->m_aContext.createComponentWithArguments(sSupportService,aArgs),UNO_QUERY);
1419 [ # # ][ # # ]: 0 : rContainerRef = xContainer;
1420 : 348 : }
1421 : : }
1422 [ + - ]: 348 : if ( !xContainer.is() )
1423 : : {
1424 [ + - ]: 348 : TContentPtr& rContainerData( m_pImpl->getObjectContainer( _eType ) );
1425 [ + - ][ + - ]: 348 : rContainerRef = xContainer = new ODocumentContainer( m_pImpl->m_aContext.getLegacyServiceFactory(), *this, rContainerData, bFormsContainer );
[ + - ][ + - ]
[ + - ][ + - ]
1426 : : }
1427 [ + - ][ + - ]: 348 : impl_reparent_nothrow( xContainer );
[ + - ]
1428 : : }
1429 : 348 : return xContainer;
1430 : : }
1431 : :
1432 : 186 : void ODatabaseDocument::impl_closeControllerFrames_nolck_throw( sal_Bool _bDeliverOwnership )
1433 : : {
1434 [ + - ]: 186 : Controllers aCopy = m_aControllers;
1435 : :
1436 : 186 : Controllers::iterator aEnd = aCopy.end();
1437 [ + - ][ - + ]: 186 : for ( Controllers::iterator aIter = aCopy.begin(); aIter != aEnd ; ++aIter )
1438 : : {
1439 [ # # ]: 0 : if ( !aIter->is() )
1440 : 0 : continue;
1441 : :
1442 : : try
1443 : : {
1444 [ # # ][ # # ]: 0 : Reference< XCloseable> xFrame( (*aIter)->getFrame(), UNO_QUERY );
[ # # ]
1445 [ # # ]: 0 : if ( xFrame.is() )
1446 [ # # ][ # # ]: 0 : xFrame->close( _bDeliverOwnership );
1447 : : }
1448 [ # # # ]: 0 : catch( const CloseVetoException& ) { throw; }
1449 [ # # ]: 0 : catch( const Exception& )
1450 : : {
1451 : : DBG_UNHANDLED_EXCEPTION();
1452 : : }
1453 : 186 : }
1454 : 186 : }
1455 : :
1456 : : struct DisposeControllerFrame : public ::std::unary_function< Reference< XController >, void >
1457 : : {
1458 : 0 : void operator()( const Reference< XController >& _rxController ) const
1459 : : {
1460 : : try
1461 : : {
1462 [ # # ]: 0 : if ( !_rxController.is() )
1463 : 0 : return;
1464 : :
1465 [ # # ][ # # ]: 0 : Reference< XFrame > xFrame( _rxController->getFrame() );
1466 [ # # ][ # # ]: 0 : ::comphelper::disposeComponent( xFrame );
1467 : : }
1468 : 0 : catch( const Exception& )
1469 : : {
1470 : : DBG_UNHANDLED_EXCEPTION();
1471 : : }
1472 : : };
1473 : : };
1474 : :
1475 : 186 : void ODatabaseDocument::impl_disposeControllerFrames_nothrow()
1476 : : {
1477 [ + - ]: 186 : Controllers aCopy;
1478 : 186 : aCopy.swap( m_aControllers ); // ensure m_aControllers is empty afterwards
1479 [ + - ]: 186 : ::std::for_each( aCopy.begin(), aCopy.end(), DisposeControllerFrame() );
1480 : 186 : }
1481 : :
1482 : 186 : void SAL_CALL ODatabaseDocument::close( sal_Bool _bDeliverOwnership ) throw (CloseVetoException, RuntimeException)
1483 : : {
1484 : : // nearly everything below can/must be done without our mutex locked, the below is just for
1485 : : // the checks for being disposed and the like
1486 : : // SYNCHRONIZED ->
1487 : : {
1488 [ + - ]: 186 : DocumentGuard aGuard( *this );
1489 [ + - ]: 186 : m_bClosing = true;
1490 : : }
1491 : : // <- SYNCHRONIZED
1492 : :
1493 : : try
1494 : : {
1495 : : // allow listeners to veto
1496 [ + - ][ + - ]: 186 : lang::EventObject aEvent( *this );
1497 : : m_aCloseListener.forEach< XCloseListener >(
1498 [ + - ][ + - ]: 186 : boost::bind( &XCloseListener::queryClosing, _1, boost::cref( aEvent ), boost::cref( _bDeliverOwnership ) ) );
[ + - ][ + - ]
1499 : :
1500 : : // notify that we're going to unload
1501 [ + - ][ + - ]: 186 : m_aEventNotifier.notifyDocumentEvent( "OnPrepareUnload" );
1502 : :
1503 [ + - ]: 186 : impl_closeControllerFrames_nolck_throw( _bDeliverOwnership );
1504 : :
1505 [ + - ]: 186 : m_aCloseListener.notifyEach( &XCloseListener::notifyClosing, (const lang::EventObject&)aEvent );
1506 : :
1507 [ + - ][ + - ]: 186 : dispose();
1508 : : }
1509 [ # # ]: 0 : catch ( const Exception& )
1510 : : {
1511 [ # # # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
1512 : 0 : m_bClosing = false;
1513 : 0 : throw;
1514 : : }
1515 : :
1516 : : // SYNCHRONIZED ->
1517 [ + - ][ + - ]: 186 : ::osl::MutexGuard aGuard( m_aMutex );
1518 [ + - ]: 186 : m_bClosing = false;
1519 : : // <- SYNCHRONIZED
1520 : 186 : }
1521 : :
1522 : 16 : void SAL_CALL ODatabaseDocument::addCloseListener( const Reference< ::com::sun::star::util::XCloseListener >& Listener ) throw (RuntimeException)
1523 : : {
1524 [ + - ]: 16 : DocumentGuard aGuard( *this );
1525 [ + - ][ + - ]: 16 : m_aCloseListener.addInterface(Listener);
1526 : 16 : }
1527 : :
1528 : 16 : void SAL_CALL ODatabaseDocument::removeCloseListener( const Reference< ::com::sun::star::util::XCloseListener >& Listener ) throw (RuntimeException)
1529 : : {
1530 [ + - ]: 16 : DocumentGuard aGuard( *this );
1531 [ + - ][ + - ]: 16 : m_aCloseListener.removeInterface(Listener);
1532 : 16 : }
1533 : :
1534 : 174 : Reference< XNameAccess > SAL_CALL ODatabaseDocument::getFormDocuments( ) throw (RuntimeException)
1535 : : {
1536 [ + - ]: 174 : DocumentGuard aGuard( *this, DocumentGuard::MethodUsedDuringInit );
1537 [ + - ][ + - ]: 174 : return impl_getDocumentContainer_throw( ODatabaseModelImpl::E_FORM );
1538 : : }
1539 : :
1540 : 174 : Reference< XNameAccess > SAL_CALL ODatabaseDocument::getReportDocuments( ) throw (RuntimeException)
1541 : : {
1542 [ + - ]: 174 : DocumentGuard aGuard( *this, DocumentGuard::MethodUsedDuringInit );
1543 [ + - ][ + - ]: 174 : return impl_getDocumentContainer_throw( ODatabaseModelImpl::E_REPORT );
1544 : : }
1545 : :
1546 : 348 : void ODatabaseDocument::WriteThroughComponent( const Reference< XComponent >& xComponent, const sal_Char* pStreamName,
1547 : : const sal_Char* pServiceName, const Sequence< Any >& _rArguments, const Sequence< PropertyValue >& rMediaDesc,
1548 : : const Reference<XStorage>& _xStorageToSaveTo ) const
1549 : : {
1550 : : OSL_ENSURE( pStreamName, "Need stream name!" );
1551 : : OSL_ENSURE( pServiceName, "Need service name!" );
1552 : :
1553 : : // open stream
1554 : 348 : ::rtl::OUString sStreamName = ::rtl::OUString::createFromAscii( pStreamName );
1555 [ + - ][ + - ]: 348 : Reference< XStream > xStream = _xStorageToSaveTo->openStreamElement( sStreamName, ElementModes::READWRITE | ElementModes::TRUNCATE );
1556 [ - + ]: 348 : if ( !xStream.is() )
1557 : : return;
1558 : :
1559 [ + - ][ + - ]: 348 : Reference< XOutputStream > xOutputStream( xStream->getOutputStream() );
1560 : : OSL_ENSURE( xOutputStream.is(), "Can't create output stream in package!" );
1561 [ - + ]: 348 : if ( !xOutputStream.is() )
1562 : : return;
1563 : :
1564 [ + - ]: 348 : Reference< XSeekable > xSeek( xOutputStream, UNO_QUERY );
1565 [ + - ]: 348 : if ( xSeek.is() )
1566 [ + - ][ + - ]: 348 : xSeek->seek(0);
1567 : :
1568 [ + - ]: 348 : Reference< XPropertySet > xStreamProp( xOutputStream, UNO_QUERY_THROW );
1569 [ + - ][ + - ]: 348 : xStreamProp->setPropertyValue( INFO_MEDIATYPE, makeAny( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "text/xml" ) ) ) );
[ + - ][ + - ]
[ + - ]
1570 [ + - ][ + - ]: 348 : xStreamProp->setPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Compressed" ) ), makeAny( (sal_Bool)sal_True ) );
[ + - ][ + - ]
1571 : :
1572 : : // write the stuff
1573 [ - + ][ - + ]: 348 : WriteThroughComponent( xOutputStream, xComponent, pServiceName, _rArguments, rMediaDesc );
[ + - ][ + - ]
1574 : : }
1575 : :
1576 : 348 : void ODatabaseDocument::WriteThroughComponent( const Reference< XOutputStream >& xOutputStream,
1577 : : const Reference< XComponent >& xComponent, const sal_Char* pServiceName, const Sequence< Any >& _rArguments,
1578 : : const Sequence< PropertyValue >& rMediaDesc ) const
1579 : : {
1580 : : OSL_ENSURE( xOutputStream.is(), "I really need an output stream!" );
1581 : : OSL_ENSURE( xComponent.is(), "Need component!" );
1582 : : OSL_ENSURE( NULL != pServiceName, "Need component name!" );
1583 : :
1584 : : // get component
1585 : 348 : Reference< XActiveDataSource > xSaxWriter;
1586 [ + - ]: 348 : OSL_VERIFY( m_pImpl->m_aContext.createComponent( "com.sun.star.xml.sax.Writer", xSaxWriter ) );
1587 [ - + ]: 348 : if ( !xSaxWriter.is() )
1588 : : return;
1589 : :
1590 : : // connect XML writer to output stream
1591 [ + - ][ + - ]: 348 : xSaxWriter->setOutputStream( xOutputStream );
1592 : :
1593 : : // prepare arguments (prepend doc handler to given arguments)
1594 [ + - ]: 348 : Reference< XDocumentHandler > xDocHandler( xSaxWriter,UNO_QUERY);
1595 [ + - ]: 348 : Sequence<Any> aArgs( 1 + _rArguments.getLength() );
1596 [ + - ][ + - ]: 348 : aArgs[0] <<= xDocHandler;
1597 [ + + ]: 696 : for ( sal_Int32 i = 0; i < _rArguments.getLength(); ++i )
1598 [ + - ]: 348 : aArgs[ i+1 ] = _rArguments[i];
1599 : :
1600 : : // get filter component
1601 : 348 : Reference< XExporter > xExporter;
1602 [ + - ]: 348 : OSL_VERIFY( m_pImpl->m_aContext.createComponentWithArguments( pServiceName, aArgs, xExporter ) );
1603 [ - + ]: 348 : if ( !xExporter.is() )
1604 : : return;
1605 : :
1606 : : // connect model and filter
1607 [ + - ][ + - ]: 348 : xExporter->setSourceDocument( xComponent );
1608 : :
1609 : : // filter
1610 [ + - ]: 348 : Reference< XFilter > xFilter( xExporter, UNO_QUERY_THROW );
1611 [ + - ][ + - ]: 348 : xFilter->filter( rMediaDesc );
[ - + ][ + - ]
[ - + ][ - + ]
[ + - ]
1612 : : }
1613 : :
1614 : 174 : void ODatabaseDocument::impl_writeStorage_throw( const Reference< XStorage >& _rxTargetStorage, const ::comphelper::NamedValueCollection& _rMediaDescriptor ) const
1615 : : {
1616 : : // extract status indicator
1617 [ + - ]: 174 : Sequence< Any > aDelegatorArguments;
1618 [ + - ]: 174 : lcl_extractStatusIndicator( _rMediaDescriptor, aDelegatorArguments );
1619 : :
1620 : : /** property map for export info set */
1621 : : comphelper::PropertyMapEntry aExportInfoMap[] =
1622 : : {
1623 [ + - ]: 174 : { MAP_LEN( "BaseURI"), 0,&::getCppuType( (::rtl::OUString *)0 ),beans::PropertyAttribute::MAYBEVOID, 0 },
1624 [ + - ]: 174 : { MAP_LEN( "StreamName"), 0,&::getCppuType( (::rtl::OUString *)0 ),beans::PropertyAttribute::MAYBEVOID, 0 },
1625 [ + - ]: 174 : { MAP_LEN( "UsePrettyPrinting" ), 0, &::getCppuType((sal_Bool*)0), beans::PropertyAttribute::MAYBEVOID, 0},
1626 : : { NULL, 0, 0, NULL, 0, 0 }
1627 : 696 : };
1628 [ + - ]: 174 : uno::Reference< beans::XPropertySet > xInfoSet( comphelper::GenericPropertySet_CreateInstance( new comphelper::PropertySetInfo( aExportInfoMap ) ) );
1629 : :
1630 [ + - ]: 174 : SvtSaveOptions aSaveOpt;
1631 [ + - ][ + - ]: 174 : xInfoSet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("UsePrettyPrinting")), uno::makeAny(aSaveOpt.IsPrettyPrinting()));
[ + - ][ + - ]
[ + - ]
1632 [ + - ][ + - ]: 174 : if ( aSaveOpt.IsSaveRelFSys() )
1633 [ + - ][ + - ]: 174 : xInfoSet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("BaseURI")), uno::makeAny(_rMediaDescriptor.getOrDefault("URL",::rtl::OUString())));
[ + - ][ + - ]
[ + - ]
1634 : :
1635 : 174 : ::rtl::OUString aVersion;
1636 [ + - ]: 174 : SvtSaveOptions::ODFDefaultVersion nDefVersion = aSaveOpt.GetODFDefaultVersion();
1637 : :
1638 : : // older versions can not have this property set, it exists only starting from ODF1.2
1639 [ + - ]: 174 : if ( nDefVersion >= SvtSaveOptions::ODFVER_012 )
1640 [ + - ]: 174 : aVersion = ODFVER_012_TEXT;
1641 : :
1642 [ + - ]: 174 : if ( !aVersion.isEmpty() )
1643 : : {
1644 : : try
1645 : : {
1646 [ + - ][ + - ]: 174 : xInfoSet->setPropertyValue( rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Version" )), uno::makeAny( aVersion ) );
[ + - ][ - + ]
[ - + ]
1647 : : }
1648 [ + - ]: 174 : catch( const uno::Exception& )
1649 : : {
1650 : : }
1651 : : }
1652 : :
1653 : 174 : sal_Int32 nArgsLen = aDelegatorArguments.getLength();
1654 [ + - ]: 174 : aDelegatorArguments.realloc(nArgsLen+1);
1655 [ + - ][ + - ]: 174 : aDelegatorArguments[nArgsLen++] <<= xInfoSet;
1656 : :
1657 [ + - ]: 174 : Reference< XPropertySet > xProp( _rxTargetStorage, UNO_QUERY_THROW );
1658 [ + - ][ + - ]: 174 : xProp->setPropertyValue( INFO_MEDIATYPE, makeAny( (rtl::OUString)MIMETYPE_OASIS_OPENDOCUMENT_DATABASE ) );
[ + - ][ + - ]
[ + - ]
1659 : :
1660 [ + - ][ + - ]: 174 : Reference< XComponent > xComponent( *const_cast< ODatabaseDocument* >( this ), UNO_QUERY_THROW );
1661 : :
1662 [ + - ]: 174 : Sequence< PropertyValue > aMediaDescriptor;
1663 [ + - ]: 174 : _rMediaDescriptor >>= aMediaDescriptor;
1664 : :
1665 [ + - ][ + - ]: 174 : xInfoSet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("StreamName")), uno::makeAny(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("settings.xml"))));
[ + - ][ + - ]
[ + - ]
1666 : : WriteThroughComponent( xComponent, "settings.xml", "com.sun.star.comp.sdb.XMLSettingsExporter",
1667 [ + - ]: 174 : aDelegatorArguments, aMediaDescriptor, _rxTargetStorage );
1668 : :
1669 [ + - ][ + - ]: 174 : xInfoSet->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("StreamName")), uno::makeAny(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("content.xml"))));
[ + - ][ + - ]
[ + - ]
1670 : : WriteThroughComponent( xComponent, "content.xml", "com.sun.star.comp.sdb.DBExportFilter",
1671 [ + - ]: 174 : aDelegatorArguments, aMediaDescriptor, _rxTargetStorage );
1672 : :
1673 [ + - ][ + - ]: 174 : if ( _rxTargetStorage->hasByName ( sPictures ) )
[ - + ]
1674 : : {
1675 : : try
1676 : : {
1677 : : // Delete any previously existing Pictures folder and regenerate
1678 : : // any needed content if needed
1679 [ # # ]: 0 : Reference< XStorageBasedLibraryContainer > xDlgs = m_pImpl->getLibraryContainer( false );
1680 [ # # ]: 0 : if ( xDlgs.is() )
1681 : : {
1682 [ # # ]: 0 : Reference< XModel > xModel(const_cast< ODatabaseDocument*>(this));
1683 [ # # ][ # # ]: 0 : lcl_uglyHackToStoreDialogeEmbedImages( m_pImpl->getLibraryContainer(false), _rxTargetStorage, xModel, m_pImpl->m_aContext );
1684 [ # # ]: 0 : }
1685 : : }
1686 [ # # ]: 0 : catch ( const Exception& )
1687 : : {
1688 : : DBG_UNHANDLED_EXCEPTION();
1689 : : }
1690 : : }
1691 [ + - ][ + - ]: 174 : m_pImpl->storeLibraryContainersTo( _rxTargetStorage );
[ + - ][ + - ]
1692 : 174 : }
1693 : :
1694 : 0 : Reference< XUIConfigurationManager > SAL_CALL ODatabaseDocument::getUIConfigurationManager( ) throw (RuntimeException)
1695 : : {
1696 [ # # ]: 0 : DocumentGuard aGuard( *this );
1697 : :
1698 [ # # ]: 0 : if ( !m_xUIConfigurationManager.is() )
1699 : : {
1700 [ # # ]: 0 : m_pImpl->m_aContext.createComponent( "com.sun.star.ui.UIConfigurationManager", m_xUIConfigurationManager );
1701 [ # # ]: 0 : Reference< XUIConfigurationStorage > xUIConfigStorage( m_xUIConfigurationManager, UNO_QUERY );
1702 [ # # ]: 0 : if ( xUIConfigStorage.is() )
1703 : : {
1704 [ # # ]: 0 : rtl::OUString aUIConfigFolderName( RTL_CONSTASCII_USTRINGPARAM( "Configurations2" ));
1705 : 0 : Reference< XStorage > xConfigStorage;
1706 : :
1707 : : // First try to open with READWRITE and then READ
1708 [ # # ][ # # ]: 0 : xConfigStorage = getDocumentSubStorage( aUIConfigFolderName, ElementModes::READWRITE );
1709 [ # # ]: 0 : if ( xConfigStorage.is() )
1710 : : {
1711 [ # # ]: 0 : rtl::OUString aUIConfigMediaType( RTL_CONSTASCII_USTRINGPARAM( "application/vnd.sun.xml.ui.configuration" ));
1712 : 0 : rtl::OUString aMediaType;
1713 [ # # ]: 0 : Reference< XPropertySet > xPropSet( xConfigStorage, UNO_QUERY );
1714 [ # # ][ # # ]: 0 : Any a = xPropSet->getPropertyValue( INFO_MEDIATYPE );
[ # # ]
1715 [ # # ][ # # ]: 0 : if ( !( a >>= aMediaType ) || aMediaType.isEmpty() )
[ # # ]
1716 : : {
1717 [ # # ]: 0 : a <<= aUIConfigMediaType;
1718 [ # # ][ # # ]: 0 : xPropSet->setPropertyValue( INFO_MEDIATYPE, a );
[ # # ]
1719 : 0 : }
1720 : : }
1721 : : else
1722 [ # # ][ # # ]: 0 : xConfigStorage = getDocumentSubStorage( aUIConfigFolderName, ElementModes::READ );
1723 : :
1724 : : // initialize ui configuration manager with document substorage
1725 [ # # ][ # # ]: 0 : xUIConfigStorage->setStorage( xConfigStorage );
1726 : 0 : }
1727 : : }
1728 : :
1729 [ # # ]: 0 : return m_xUIConfigurationManager;
1730 : : }
1731 : :
1732 : 0 : Reference< XStorage > SAL_CALL ODatabaseDocument::getDocumentSubStorage( const ::rtl::OUString& aStorageName, sal_Int32 nMode ) throw (RuntimeException)
1733 : : {
1734 [ # # ]: 0 : DocumentGuard aGuard( *this );
1735 : :
1736 [ # # ]: 0 : Reference< XDocumentSubStorageSupplier > xStorageAccess( m_pImpl->getDocumentSubStorageSupplier() );
1737 [ # # ][ # # ]: 0 : return xStorageAccess->getDocumentSubStorage( aStorageName, nMode );
[ # # ]
1738 : : }
1739 : :
1740 : 0 : Sequence< ::rtl::OUString > SAL_CALL ODatabaseDocument::getDocumentSubStoragesNames( ) throw (::com::sun::star::io::IOException, RuntimeException)
1741 : : {
1742 [ # # ]: 0 : Reference< XDocumentSubStorageSupplier > xStorageAccess( m_pImpl->getDocumentSubStorageSupplier() );
1743 [ # # ][ # # ]: 0 : return xStorageAccess->getDocumentSubStoragesNames();
1744 : : }
1745 : :
1746 : 172 : void ODatabaseDocument::impl_notifyStorageChange_nolck_nothrow( const Reference< XStorage >& _rxNewRootStorage )
1747 : : {
1748 [ + - ]: 172 : Reference< XInterface > xMe( *const_cast< ODatabaseDocument* >( this ) );
1749 : :
1750 : : m_aStorageListeners.forEach< XStorageChangeListener >(
1751 [ + - ][ + - ]: 172 : boost::bind( &XStorageChangeListener::notifyStorageChange, _1, boost::cref( xMe ), boost::cref( _rxNewRootStorage ) ) );
[ + - ][ + - ]
1752 : 172 : }
1753 : :
1754 : 186 : void ODatabaseDocument::disposing()
1755 : : {
1756 : : OSL_TRACE( "DD: disp: %p: %p", this, m_pImpl.get() );
1757 [ + - ]: 186 : if ( !m_pImpl.is() )
1758 : : {
1759 : : // this means that we're already disposed
1760 : : OSL_ENSURE( ODatabaseDocument_OfficeDocument::rBHelper.bDisposed, "ODatabaseDocument::disposing: no impl anymore, but not yet disposed!" );
1761 : 186 : return;
1762 : : }
1763 : :
1764 [ + - ]: 186 : if ( impl_isInitialized() )
1765 [ + - ][ + - ]: 186 : m_aEventNotifier.notifyDocumentEvent( "OnUnload" );
1766 : :
1767 [ + - ]: 186 : Reference< XModel > xHoldAlive( this );
1768 : :
1769 [ + - ]: 186 : m_aEventNotifier.disposing();
1770 : :
1771 [ + - ][ + - ]: 186 : lang::EventObject aDisposeEvent(static_cast<XWeak*>(this));
1772 [ + - ]: 186 : m_aModifyListeners.disposeAndClear( aDisposeEvent );
1773 [ + - ]: 186 : m_aCloseListener.disposeAndClear( aDisposeEvent );
1774 [ + - ]: 186 : m_aStorageListeners.disposeAndClear( aDisposeEvent );
1775 : :
1776 : : // this is the list of objects which we currently hold as member. Upon resetting
1777 : : // those members, we can (potentially) release the last reference to them, in which
1778 : : // case they will be deleted - if they're C++ implementations, that is :).
1779 : : // Some of those implementations are offending enough to require the SolarMutex, which
1780 : : // means we should not release the last reference while our own mutex is locked ...
1781 [ + - ]: 186 : ::std::list< Reference< XInterface > > aKeepAlive;
1782 : :
1783 : : // SYNCHRONIZED ->
1784 [ + - ][ + - ]: 186 : ::osl::ClearableMutexGuard aGuard( m_aMutex );
1785 : :
1786 : : OSL_ENSURE( m_aControllers.empty(), "ODatabaseDocument::disposing: there still are controllers!" );
1787 : : // normally, nobody should explicitly dispose, but only XCloseable::close
1788 : : // the document. And upon closing, our controllers are closed, too
1789 : :
1790 : : {
1791 : 186 : uno::Reference<uno::XInterface> xUIInterface( m_xUIConfigurationManager );
1792 [ + - ]: 186 : aKeepAlive.push_back( xUIInterface );
1793 : : }
1794 [ + - ]: 186 : m_xUIConfigurationManager = NULL;
1795 : :
1796 [ + - ]: 186 : clearObjectContainer( m_xForms );
1797 [ + - ]: 186 : clearObjectContainer( m_xReports );
1798 : :
1799 : : // reset the macro mode: in case the our impl struct stays alive (e.g. because our DataSource
1800 : : // object still exists), and somebody subsequently re-opens the document, we want to have
1801 : : // the security warning, again.
1802 [ + - ]: 186 : m_pImpl->resetMacroExecutionMode();
1803 : :
1804 : : // similar arguing for our ViewMonitor
1805 [ + - ]: 186 : m_aViewMonitor.reset();
1806 : :
1807 : : // tell our Impl to forget us
1808 [ + - ]: 186 : m_pImpl->modelIsDisposing( impl_isInitialized(), ODatabaseModelImpl::ResetModelAccess() );
1809 : :
1810 : : // now, at the latest, the controller array should be empty. Controllers are
1811 : : // expected to listen for our disposal, and disconnect then
1812 : : OSL_ENSURE( m_aControllers.empty(), "ODatabaseDocument::disposing: there still are controllers!" );
1813 [ + - ]: 186 : impl_disposeControllerFrames_nothrow();
1814 : :
1815 : : {
1816 : 186 : uno::Reference<uno::XInterface> xModuleInterface( m_xModuleManager );
1817 [ + - ]: 186 : aKeepAlive.push_back( xModuleInterface );
1818 : : }
1819 : 186 : m_xModuleManager.clear();
1820 : :
1821 : : {
1822 : 186 : uno::Reference<uno::XInterface> xTitleInterface( m_xTitleHelper );
1823 [ + - ]: 186 : aKeepAlive.push_back( xTitleInterface );
1824 : : }
1825 : 186 : m_xTitleHelper.clear();
1826 : :
1827 [ + - ]: 186 : m_pImpl.clear();
1828 : :
1829 [ + - ]: 186 : aGuard.clear();
1830 : : // <- SYNCHRONIZED
1831 : :
1832 [ + - ][ + - ]: 186 : aKeepAlive.clear();
1833 : : }
1834 : :
1835 : : // XComponent
1836 : 186 : void SAL_CALL ODatabaseDocument::dispose( ) throw (RuntimeException)
1837 : : {
1838 : 186 : ::cppu::WeakComponentImplHelperBase::dispose();
1839 : 186 : }
1840 : :
1841 : 362 : void SAL_CALL ODatabaseDocument::addEventListener( const Reference< lang::XEventListener >& _xListener ) throw (RuntimeException)
1842 : : {
1843 : 362 : ::cppu::WeakComponentImplHelperBase::addEventListener( _xListener );
1844 : 362 : }
1845 : :
1846 : 362 : void SAL_CALL ODatabaseDocument::removeEventListener( const Reference< lang::XEventListener >& _xListener ) throw (RuntimeException)
1847 : : {
1848 : 362 : ::cppu::WeakComponentImplHelperBase::removeEventListener( _xListener );
1849 : 362 : }
1850 : :
1851 : : // XServiceInfo
1852 : 0 : rtl::OUString ODatabaseDocument::getImplementationName( ) throw(RuntimeException)
1853 : : {
1854 : 0 : return getImplementationName_static();
1855 : : }
1856 : :
1857 : 32 : rtl::OUString ODatabaseDocument::getImplementationName_static( ) throw(RuntimeException)
1858 : : {
1859 : 32 : return rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.comp.dba.ODatabaseDocument"));
1860 : : }
1861 : :
1862 : 10702 : Sequence< ::rtl::OUString > ODatabaseDocument::getSupportedServiceNames( ) throw (RuntimeException)
1863 : : {
1864 : 10702 : return getSupportedServiceNames_static();
1865 : : }
1866 : :
1867 : 2 : Reference< XInterface > ODatabaseDocument::Create( const Reference< XComponentContext >& _rxContext )
1868 : : {
1869 [ + - ]: 2 : ::comphelper::ComponentContext aContext( _rxContext );
1870 [ + - ][ + - ]: 2 : Reference< XUnoTunnel > xDBContextTunnel( aContext.createComponent( (::rtl::OUString)SERVICE_SDB_DATABASECONTEXT ), UNO_QUERY_THROW );
[ + - ]
1871 [ + - ][ + - ]: 2 : ODatabaseContext* pContext = reinterpret_cast< ODatabaseContext* >( xDBContextTunnel->getSomething( ODatabaseContext::getUnoTunnelImplementationId() ) );
[ + - ][ + - ]
1872 : :
1873 [ + - ][ + - ]: 2 : ::rtl::Reference<ODatabaseModelImpl> pImpl( new ODatabaseModelImpl( aContext.getLegacyServiceFactory(), *pContext ) );
[ + - ][ + - ]
1874 [ + - ]: 2 : Reference< XModel > xModel( pImpl->createNewModel_deliverOwnership( false ) );
1875 [ + - ][ + - ]: 2 : return xModel.get();
[ + - ][ + - ]
1876 : : }
1877 : :
1878 : 10734 : Sequence< ::rtl::OUString > ODatabaseDocument::getSupportedServiceNames_static( ) throw (RuntimeException)
1879 : : {
1880 : 10734 : Sequence< ::rtl::OUString > aSNS( 2 );
1881 [ + - ][ + - ]: 10734 : aSNS[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.sdb.OfficeDatabaseDocument"));
1882 [ + - ][ + - ]: 10734 : aSNS[1] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.document.OfficeDocument"));
1883 : 10734 : return aSNS;
1884 : : }
1885 : :
1886 : 10354 : sal_Bool ODatabaseDocument::supportsService( const ::rtl::OUString& _rServiceName ) throw (RuntimeException)
1887 : : {
1888 [ + - ][ + - ]: 10354 : return ::comphelper::findValue(getSupportedServiceNames(), _rServiceName, sal_True).getLength() != 0;
1889 : : }
1890 : :
1891 : 712 : Reference< XDataSource > SAL_CALL ODatabaseDocument::getDataSource() throw (RuntimeException)
1892 : : {
1893 [ + - ]: 712 : DocumentGuard aGuard( *this, DocumentGuard::MethodWithoutInit );
1894 [ + - ][ + - ]: 712 : return m_pImpl->getOrCreateDataSource();
1895 : : }
1896 : :
1897 : 0 : void SAL_CALL ODatabaseDocument::loadFromStorage( const Reference< XStorage >& /*xStorage*/, const Sequence< PropertyValue >& /*aMediaDescriptor*/ ) throw (IllegalArgumentException, DoubleInitializationException, IOException, Exception, RuntimeException)
1898 : : {
1899 [ # # ]: 0 : DocumentGuard aGuard( *this );
1900 : :
1901 : : throw Exception(
1902 : : DBACORE_RESSTRING( RID_STR_NO_EMBEDDING ),
1903 : : *this
1904 [ # # ][ # # ]: 0 : );
[ # # ]
1905 : : }
1906 : :
1907 : 0 : void SAL_CALL ODatabaseDocument::storeToStorage( const Reference< XStorage >& _rxStorage, const Sequence< PropertyValue >& _rMediaDescriptor ) throw (IllegalArgumentException, IOException, Exception, RuntimeException)
1908 : : {
1909 [ # # ]: 0 : DocumentGuard aGuard( *this );
1910 [ # # ][ # # ]: 0 : impl_storeToStorage_throw( _rxStorage, _rMediaDescriptor, aGuard );
1911 : 0 : }
1912 : :
1913 : 0 : void SAL_CALL ODatabaseDocument::switchToStorage( const Reference< XStorage >& _rxNewRootStorage ) throw (IllegalArgumentException, IOException, Exception, RuntimeException)
1914 : : {
1915 [ # # ]: 0 : DocumentGuard aGuard( *this );
1916 : :
1917 [ # # ]: 0 : Reference< XStorage > xNewRootStorage( m_pImpl->switchToStorage( _rxNewRootStorage ) );
1918 : :
1919 [ # # ]: 0 : aGuard.clear();
1920 [ # # ][ # # ]: 0 : impl_notifyStorageChange_nolck_nothrow( xNewRootStorage );
1921 : 0 : }
1922 : :
1923 : 30 : Reference< XStorage > SAL_CALL ODatabaseDocument::getDocumentStorage( ) throw (IOException, Exception, RuntimeException)
1924 : : {
1925 [ + + ]: 30 : DocumentGuard aGuard( *this );
1926 [ + - ][ + - ]: 30 : return m_pImpl->getOrCreateRootStorage();
1927 : : }
1928 : :
1929 : 0 : void SAL_CALL ODatabaseDocument::addStorageChangeListener( const Reference< XStorageChangeListener >& _Listener ) throw (RuntimeException)
1930 : : {
1931 [ # # ]: 0 : DocumentGuard aGuard( *this );
1932 [ # # ][ # # ]: 0 : m_aStorageListeners.addInterface( _Listener );
1933 : 0 : }
1934 : :
1935 : 0 : void SAL_CALL ODatabaseDocument::removeStorageChangeListener( const Reference< XStorageChangeListener >& _Listener ) throw (RuntimeException)
1936 : : {
1937 [ # # ]: 0 : DocumentGuard aGuard( *this );
1938 [ # # ][ # # ]: 0 : m_aStorageListeners.addInterface( _Listener );
1939 : 0 : }
1940 : :
1941 : 0 : Reference< XStorageBasedLibraryContainer > SAL_CALL ODatabaseDocument::getBasicLibraries() throw (RuntimeException)
1942 : : {
1943 [ # # ]: 0 : DocumentGuard aGuard( *this, DocumentGuard::MethodUsedDuringInit );
1944 [ # # ][ # # ]: 0 : return m_pImpl->getLibraryContainer( true );
1945 : : }
1946 : :
1947 : 0 : Reference< XStorageBasedLibraryContainer > SAL_CALL ODatabaseDocument::getDialogLibraries() throw (RuntimeException)
1948 : : {
1949 [ # # ]: 0 : DocumentGuard aGuard( *this );
1950 [ # # ][ # # ]: 0 : return m_pImpl->getLibraryContainer( false );
1951 : : }
1952 : :
1953 : 0 : ::sal_Bool SAL_CALL ODatabaseDocument::getAllowMacroExecution() throw (RuntimeException)
1954 : : {
1955 [ # # ]: 0 : DocumentGuard aGuard( *this );
1956 [ # # ][ # # ]: 0 : return m_pImpl->adjustMacroMode_AutoReject();
1957 : : }
1958 : :
1959 : 0 : Reference< XEmbeddedScripts > SAL_CALL ODatabaseDocument::getScriptContainer() throw (RuntimeException)
1960 : : {
1961 [ # # ]: 0 : DocumentGuard aGuard( *this );
1962 [ # # ][ # # ]: 0 : return this;
1963 : : }
1964 : :
1965 : 0 : Reference< provider::XScriptProvider > SAL_CALL ODatabaseDocument::getScriptProvider( ) throw (RuntimeException)
1966 : : {
1967 [ # # ]: 0 : DocumentGuard aGuard( *this );
1968 : :
1969 [ # # ]: 0 : Reference< XScriptProvider > xScriptProvider( m_xScriptProvider );
1970 [ # # ]: 0 : if ( !xScriptProvider.is() )
1971 : : {
1972 : : Reference < XScriptProviderFactory > xFactory(
1973 [ # # ][ # # ]: 0 : m_pImpl->m_aContext.getSingleton( "com.sun.star.script.provider.theMasterScriptProviderFactory" ), UNO_QUERY_THROW );
1974 : :
1975 : 0 : Any aScriptProviderContext;
1976 [ # # ]: 0 : if ( m_bAllowDocumentScripting )
1977 [ # # ][ # # ]: 0 : aScriptProviderContext <<= Reference< XModel >( this );
1978 : :
1979 [ # # ][ # # ]: 0 : xScriptProvider.set( xFactory->createScriptProvider( aScriptProviderContext ), UNO_SET_THROW );
[ # # ]
1980 [ # # ]: 0 : m_xScriptProvider = xScriptProvider;
1981 : : }
1982 : :
1983 [ # # ]: 0 : return xScriptProvider;
1984 : : }
1985 : :
1986 : 1110 : Reference< XNameReplace > SAL_CALL ODatabaseDocument::getEvents( ) throw (RuntimeException)
1987 : : {
1988 [ + - ]: 1110 : DocumentGuard aGuard( *this, DocumentGuard::MethodUsedDuringInit );
1989 [ + - ][ + - ]: 1110 : return m_pEventContainer;
[ + - ]
1990 : : }
1991 : :
1992 : 0 : void SAL_CALL ODatabaseDocument::disposing( const ::com::sun::star::lang::EventObject& Source ) throw(RuntimeException)
1993 : : {
1994 [ # # ]: 0 : if ( m_pImpl.is() )
1995 : 0 : m_pImpl->disposing(Source);
1996 : 0 : }
1997 : :
1998 : 30 : Reference< XInterface > ODatabaseDocument::getThis() const
1999 : : {
2000 : 30 : return *const_cast< ODatabaseDocument* >( this );
2001 : : }
2002 : :
2003 : : struct CreateAny : public ::std::unary_function< Reference<XController>, Any>
2004 : : {
2005 : 0 : Any operator() (const Reference<XController>& lhs) const
2006 : : {
2007 : 0 : return makeAny(lhs);
2008 : : }
2009 : : };
2010 : :
2011 : : // XModel2
2012 : 2 : Reference< XEnumeration > SAL_CALL ODatabaseDocument::getControllers( ) throw (RuntimeException)
2013 : : {
2014 [ + - ]: 2 : DocumentGuard aGuard( *this );
2015 [ + - ]: 2 : uno::Sequence< Any> aController( m_aControllers.size() );
2016 [ + - ][ + - ]: 2 : ::std::transform( m_aControllers.begin(), m_aControllers.end(), aController.getArray(), CreateAny() );
2017 [ + - ][ + - ]: 2 : return new ::comphelper::OAnyEnumeration(aController);
[ + - ][ + - ]
[ + - ]
2018 : : }
2019 : :
2020 : 0 : Sequence< ::rtl::OUString > SAL_CALL ODatabaseDocument::getAvailableViewControllerNames( ) throw (RuntimeException)
2021 : : {
2022 : 0 : Sequence< ::rtl::OUString > aNames(1);
2023 [ # # ][ # # ]: 0 : aNames[0] = SERVICE_SDB_APPLICATIONCONTROLLER;
2024 : 0 : return aNames;
2025 : : }
2026 : :
2027 : 0 : Reference< XController2 > SAL_CALL ODatabaseDocument::createDefaultViewController( const Reference< XFrame >& _Frame ) throw (IllegalArgumentException, Exception, RuntimeException)
2028 : : {
2029 : : return createViewController(
2030 : : ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Default" ) ),
2031 : : Sequence< PropertyValue >(),
2032 : : _Frame
2033 [ # # ][ # # ]: 0 : );
2034 : : }
2035 : :
2036 : 0 : Reference< XController2 > SAL_CALL ODatabaseDocument::createViewController( const ::rtl::OUString& _ViewName, const Sequence< PropertyValue >& _Arguments, const Reference< XFrame >& _Frame ) throw (IllegalArgumentException, Exception, RuntimeException)
2037 : : {
2038 [ # # ][ # # ]: 0 : if ( _ViewName != "Default" && _ViewName != "Preview" )
[ # # ]
2039 [ # # ][ # # ]: 0 : throw IllegalArgumentException( ::rtl::OUString(), *this, 1 );
2040 [ # # ]: 0 : if ( !_Frame.is() )
2041 [ # # ][ # # ]: 0 : throw IllegalArgumentException( ::rtl::OUString(), *this, 3 );
2042 : :
2043 [ # # ]: 0 : DocumentGuard aGuard( *this );
2044 [ # # ]: 0 : ::comphelper::ComponentContext aContext( m_pImpl->m_aContext );
2045 [ # # ]: 0 : aGuard.clear();
2046 : :
2047 : 0 : Reference< XController2 > xController;
2048 [ # # ]: 0 : aContext.createComponent( "org.openoffice.comp.dbu.OApplicationController", xController );
2049 : :
2050 [ # # ]: 0 : ::comphelper::NamedValueCollection aInitArgs( _Arguments );
2051 [ # # ]: 0 : aInitArgs.put( "Frame", _Frame );
2052 [ # # ]: 0 : if ( _ViewName == "Preview" )
2053 [ # # ]: 0 : aInitArgs.put( "Preview", sal_Bool( sal_True ) );
2054 [ # # ]: 0 : Reference< XInitialization > xInitController( xController, UNO_QUERY_THROW );
2055 [ # # ][ # # ]: 0 : xInitController->initialize( aInitArgs.getWrappedPropertyValues() );
[ # # ][ # # ]
2056 : :
2057 [ # # ][ # # ]: 0 : return xController;
[ # # ]
2058 : : }
2059 : :
2060 : 2 : Reference< XTitle > ODatabaseDocument::impl_getTitleHelper_throw()
2061 : : {
2062 [ + - ]: 2 : if ( ! m_xTitleHelper.is ())
2063 : : {
2064 : : Reference< XUntitledNumbers > xDesktop(
2065 : 2 : m_pImpl->m_aContext.createComponent( "com.sun.star.frame.Desktop" ),
2066 [ + - ][ + - ]: 2 : UNO_QUERY_THROW );
2067 [ + - ][ + - ]: 2 : uno::Reference< frame::XModel > xThis (getThis(), uno::UNO_QUERY_THROW);
2068 : :
2069 [ + - ][ + - ]: 2 : ::framework::TitleHelper* pHelper = new ::framework::TitleHelper(m_pImpl->m_aContext.getLegacyServiceFactory());
2070 [ + - ]: 2 : m_xTitleHelper.set(static_cast< ::cppu::OWeakObject* >(pHelper), uno::UNO_QUERY_THROW);
2071 [ + - ]: 2 : pHelper->setOwner (xThis );
2072 [ + - ]: 2 : pHelper->connectWithUntitledNumbers (xDesktop);
2073 : : }
2074 : :
2075 : 2 : return m_xTitleHelper;
2076 : : }
2077 : :
2078 : 0 : uno::Reference< frame::XUntitledNumbers > ODatabaseDocument::impl_getUntitledHelper_throw(const uno::Reference< uno::XInterface >& _xComponent)
2079 : : {
2080 [ # # ]: 0 : if ( !m_xModuleManager.is() )
2081 [ # # ][ # # ]: 0 : m_xModuleManager.set( m_pImpl->m_aContext.createComponent( "com.sun.star.frame.ModuleManager" ), UNO_QUERY_THROW );
[ # # ]
2082 : :
2083 : 0 : ::rtl::OUString sModuleId;
2084 : : try
2085 : : {
2086 [ # # ][ # # ]: 0 : sModuleId = m_xModuleManager->identify( _xComponent );
2087 : : }
2088 [ # # ]: 0 : catch(const uno::Exception&)
2089 : : {
2090 : : }
2091 : 0 : uno::Reference< frame::XUntitledNumbers > xNumberedControllers;
2092 : :
2093 [ # # ]: 0 : TNumberedController::iterator aFind = m_aNumberedControllers.find(sModuleId);
2094 [ # # ]: 0 : if ( aFind == m_aNumberedControllers.end() )
2095 : : {
2096 [ # # ]: 0 : uno::Reference< frame::XModel > xThis(static_cast< frame::XModel* >(this), uno::UNO_QUERY_THROW);
2097 [ # # ]: 0 : ::comphelper::NumberedCollection* pHelper = new ::comphelper::NumberedCollection();
2098 [ # # ]: 0 : xNumberedControllers.set(static_cast< ::cppu::OWeakObject* >(pHelper), uno::UNO_QUERY_THROW);
2099 : :
2100 [ # # ]: 0 : pHelper->setOwner (xThis);
2101 : : //pHelper->setUntitledPrefix (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" : ")));
2102 : :
2103 [ # # ][ # # ]: 0 : m_aNumberedControllers.insert(TNumberedController::value_type(sModuleId,xNumberedControllers));
[ # # ]
2104 : : }
2105 : : else
2106 [ # # ]: 0 : xNumberedControllers = aFind->second;
2107 : :
2108 : 0 : return xNumberedControllers;
2109 : : }
2110 : :
2111 : : // css.frame.XTitle
2112 : 2 : ::rtl::OUString SAL_CALL ODatabaseDocument::getTitle()
2113 : : throw (uno::RuntimeException)
2114 : : {
2115 : : // SYNCHRONIZED ->
2116 [ + - ]: 2 : DocumentGuard aGuard( *this, DocumentGuard::MethodUsedDuringInit );
2117 [ + - ][ + - ]: 2 : return impl_getTitleHelper_throw()->getTitle();
[ + - ][ + - ]
2118 : : }
2119 : :
2120 : : // css.frame.XTitle
2121 : 0 : void SAL_CALL ODatabaseDocument::setTitle( const ::rtl::OUString& sTitle )
2122 : : throw (uno::RuntimeException)
2123 : : {
2124 : : // SYNCHRONIZED ->
2125 [ # # ]: 0 : DocumentGuard aGuard( *this );
2126 [ # # ][ # # ]: 0 : impl_getTitleHelper_throw()->setTitle( sTitle );
[ # # ]
2127 [ # # ][ # # ]: 0 : m_aEventNotifier.notifyDocumentEventAsync( "OnTitleChanged" );
[ # # ]
2128 : : // <- SYNCHRONIZED
2129 : 0 : }
2130 : :
2131 : : // css.frame.XTitleChangeBroadcaster
2132 : 0 : void SAL_CALL ODatabaseDocument::addTitleChangeListener( const uno::Reference< frame::XTitleChangeListener >& xListener )
2133 : : throw (uno::RuntimeException)
2134 : : {
2135 : : // SYNCHRONIZED ->
2136 [ # # ]: 0 : DocumentGuard aGuard( *this );
2137 : :
2138 [ # # ][ # # ]: 0 : uno::Reference< frame::XTitleChangeBroadcaster > xBroadcaster( impl_getTitleHelper_throw(), uno::UNO_QUERY_THROW );
2139 [ # # ][ # # ]: 0 : xBroadcaster->addTitleChangeListener( xListener );
[ # # ]
2140 : 0 : }
2141 : :
2142 : : // css.frame.XTitleChangeBroadcaster
2143 : 0 : void SAL_CALL ODatabaseDocument::removeTitleChangeListener( const uno::Reference< frame::XTitleChangeListener >& xListener )
2144 : : throw (uno::RuntimeException)
2145 : : {
2146 : : // SYNCHRONIZED ->
2147 [ # # ]: 0 : DocumentGuard aGuard( *this );
2148 : :
2149 [ # # ][ # # ]: 0 : uno::Reference< frame::XTitleChangeBroadcaster > xBroadcaster( impl_getTitleHelper_throw(), uno::UNO_QUERY_THROW );
2150 [ # # ][ # # ]: 0 : xBroadcaster->removeTitleChangeListener( xListener );
[ # # ]
2151 : 0 : }
2152 : :
2153 : : // css.frame.XUntitledNumbers
2154 : 0 : ::sal_Int32 SAL_CALL ODatabaseDocument::leaseNumber( const uno::Reference< uno::XInterface >& xComponent )
2155 : : throw (lang::IllegalArgumentException,
2156 : : uno::RuntimeException )
2157 : : {
2158 [ # # ]: 0 : DocumentGuard aGuard( *this );
2159 [ # # ][ # # ]: 0 : return impl_getUntitledHelper_throw(xComponent)->leaseNumber (xComponent);
[ # # ][ # # ]
2160 : : }
2161 : :
2162 : : // css.frame.XUntitledNumbers
2163 : 0 : void SAL_CALL ODatabaseDocument::releaseNumber( ::sal_Int32 nNumber )
2164 : : throw (lang::IllegalArgumentException,
2165 : : uno::RuntimeException )
2166 : : {
2167 [ # # ]: 0 : DocumentGuard aGuard( *this );
2168 [ # # ][ # # ]: 0 : impl_getUntitledHelper_throw()->releaseNumber (nNumber);
[ # # ][ # # ]
2169 : 0 : }
2170 : :
2171 : : // css.frame.XUntitledNumbers
2172 : 0 : void SAL_CALL ODatabaseDocument::releaseNumberForComponent( const uno::Reference< uno::XInterface >& xComponent )
2173 : : throw (lang::IllegalArgumentException,
2174 : : uno::RuntimeException )
2175 : : {
2176 [ # # ]: 0 : DocumentGuard aGuard( *this );
2177 [ # # ][ # # ]: 0 : impl_getUntitledHelper_throw(xComponent)->releaseNumberForComponent (xComponent);
[ # # ][ # # ]
2178 : 0 : }
2179 : :
2180 : : // css.frame.XUntitledNumbers
2181 : 0 : ::rtl::OUString SAL_CALL ODatabaseDocument::getUntitledPrefix() throw (uno::RuntimeException)
2182 : : {
2183 : 0 : return ::rtl::OUString();/*RTL_CONSTASCII_USTRINGPARAM(" : "));*/
2184 : : }
2185 : :
2186 [ + - ][ + - ]: 120 : } // namespace dbaccess
2187 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|