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