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