Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : :
21 : : #include "flt_reghelper.hxx"
22 : : #include "xmlstrings.hrc"
23 : :
24 : : #include <com/sun/star/beans/NamedValue.hpp>
25 : : #include <com/sun/star/beans/XPropertySet.hpp>
26 : : #include <com/sun/star/document/XEventListener.hpp>
27 : : #include <com/sun/star/document/XExtendedFilterDetection.hpp>
28 : : #include <com/sun/star/document/XFilter.hpp>
29 : : #include <com/sun/star/embed/ElementModes.hpp>
30 : : #include <com/sun/star/embed/XStorage.hpp>
31 : : #include <com/sun/star/frame/XController.hpp>
32 : : #include <com/sun/star/frame/XFrame.hpp>
33 : : #include <com/sun/star/frame/XFrameLoader.hpp>
34 : : #include <com/sun/star/frame/XFramesSupplier.hpp>
35 : : #include <com/sun/star/frame/XLoadEventListener.hpp>
36 : : #include <com/sun/star/frame/XModel2.hpp>
37 : : #include <com/sun/star/io/XInputStream.hpp>
38 : : #include <com/sun/star/lang/XInitialization.hpp>
39 : : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
40 : : #include <com/sun/star/lang/XServiceInfo.hpp>
41 : : #include <com/sun/star/lang/XSingleServiceFactory.hpp>
42 : : #include <com/sun/star/registry/XRegistryKey.hpp>
43 : : #include <com/sun/star/sdb/XDocumentDataSource.hpp>
44 : : #include <com/sun/star/task/XJobExecutor.hpp>
45 : : #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp>
46 : : #include <com/sun/star/util/URLTransformer.hpp>
47 : : #include <com/sun/star/util/XURLTransformer.hpp>
48 : : #include <com/sun/star/view/XSelectionSupplier.hpp>
49 : : #include <com/sun/star/sdb/application/DatabaseObjectContainer.hpp>
50 : : #include <com/sun/star/sdb/application/NamedDatabaseObject.hpp>
51 : : #include <com/sun/star/frame/XLoadable.hpp>
52 : :
53 : : #include <comphelper/componentcontext.hxx>
54 : : #include <comphelper/documentconstants.hxx>
55 : : #include <comphelper/namedvaluecollection.hxx>
56 : : #include <comphelper/processfactory.hxx>
57 : : #include <comphelper/sequenceashashmap.hxx>
58 : : #include <comphelper/stl_types.hxx>
59 : : #include <comphelper/storagehelper.hxx>
60 : : #include <comphelper/types.hxx>
61 : : #include <cppuhelper/implbase2.hxx>
62 : : #include <osl/file.hxx>
63 : : #include <sfx2/docfile.hxx>
64 : : #include <unotools/moduleoptions.hxx>
65 : : #include <toolkit/awt/vclxwindow.hxx>
66 : : #include <toolkit/helper/vclunohelper.hxx>
67 : : #include <tools/diagnose_ex.h>
68 : : #include <ucbhelper/commandenvironment.hxx>
69 : : #include <ucbhelper/content.hxx>
70 : : #include <ucbhelper/contentbroker.hxx>
71 : : #include <vcl/msgbox.hxx>
72 : : #include <vcl/svapp.hxx>
73 : :
74 : : using namespace ::ucbhelper;
75 : : using namespace ::com::sun::star::task;
76 : : using namespace ::com::sun::star::uno;
77 : : using namespace ::com::sun::star::ucb;
78 : : using namespace ::com::sun::star::io;
79 : : using namespace ::com::sun::star::util;
80 : : using namespace ::com::sun::star::frame;
81 : : using namespace ::com::sun::star::beans;
82 : : using namespace ::com::sun::star::container;
83 : : using namespace ::com::sun::star::lang;
84 : : using namespace ::com::sun::star::document;
85 : : using namespace ::com::sun::star::registry;
86 : : using namespace ::com::sun::star::sdb;
87 : : using namespace ::com::sun::star::embed;
88 : : namespace css = ::com::sun::star;
89 : : using namespace ::com::sun::star::ui::dialogs;
90 : : using ::com::sun::star::awt::XWindow;
91 : : using ::com::sun::star::sdb::application::NamedDatabaseObject;
92 : :
93 : : // -------------------------------------------------------------------------
94 : : namespace dbaxml
95 : : {
96 : :
97 [ + - ][ - + ]: 20 : class DBTypeDetection : public ::cppu::WeakImplHelper2< XExtendedFilterDetection, XServiceInfo>
98 : : {
99 : : ::comphelper::ComponentContext m_aContext;
100 : :
101 : : public:
102 : : DBTypeDetection(const Reference< XMultiServiceFactory >&);
103 : :
104 : : // XServiceInfo
105 : : ::rtl::OUString SAL_CALL getImplementationName() throw( );
106 : : sal_Bool SAL_CALL supportsService(const ::rtl::OUString& ServiceName) throw( );
107 : : Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(void) throw( );
108 : :
109 : : // static methods
110 : 34 : static ::rtl::OUString getImplementationName_Static() throw( )
111 : : {
112 : 34 : return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.comp.dbflt.DBTypeDetection"));
113 : : }
114 : : static Sequence< ::rtl::OUString> getSupportedServiceNames_Static(void) throw( );
115 : : static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
116 : : SAL_CALL Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&);
117 : :
118 : : virtual ::rtl::OUString SAL_CALL detect( ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& Descriptor ) throw (::com::sun::star::uno::RuntimeException);
119 : : };
120 : : // -------------------------------------------------------------------------
121 : 10 : DBTypeDetection::DBTypeDetection(const Reference< XMultiServiceFactory >& _rxFactory)
122 [ + - ]: 10 : :m_aContext( _rxFactory )
123 : : {
124 : 10 : }
125 : : // -------------------------------------------------------------------------
126 : 10 : ::rtl::OUString SAL_CALL DBTypeDetection::detect( ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& Descriptor ) throw (::com::sun::star::uno::RuntimeException)
127 : : {
128 : : try
129 : : {
130 [ + - ]: 10 : ::comphelper::NamedValueCollection aMedia( Descriptor );
131 : 10 : sal_Bool bStreamFromDescr = sal_False;
132 [ + - ]: 10 : ::rtl::OUString sURL = aMedia.getOrDefault( "URL", ::rtl::OUString() );
133 : :
134 [ + - ]: 10 : Reference< XInputStream > xInStream( aMedia.getOrDefault( "InputStream", Reference< XInputStream >() ) );
135 : 10 : Reference< XPropertySet > xStorageProperties;
136 [ + - ]: 10 : if ( xInStream.is() )
137 : : {
138 : 10 : bStreamFromDescr = sal_True;
139 : : xStorageProperties.set( ::comphelper::OStorageHelper::GetStorageFromInputStream(
140 [ + - ][ + - ]: 10 : xInStream, m_aContext.getLegacyServiceFactory() ), UNO_QUERY );
[ + - ]
141 : : }
142 : : else
143 : : {
144 [ # # ]: 0 : ::rtl::OUString sSalvagedURL( aMedia.getOrDefault( "SalvagedFile", ::rtl::OUString() ) );
145 : :
146 [ # # ]: 0 : ::rtl::OUString sFileLocation( sSalvagedURL.isEmpty() ? sURL : sSalvagedURL );
147 [ # # ]: 0 : if ( !sFileLocation.isEmpty() )
148 : : {
149 : : xStorageProperties.set( ::comphelper::OStorageHelper::GetStorageFromURL(
150 [ # # ][ # # ]: 0 : sFileLocation, ElementModes::READ, m_aContext.getLegacyServiceFactory() ), UNO_QUERY );
[ # # ]
151 : 0 : }
152 : : }
153 : :
154 [ + - ]: 10 : if ( xStorageProperties.is() )
155 : : {
156 : 10 : ::rtl::OUString sMediaType;
157 [ + - ][ + - ]: 10 : xStorageProperties->getPropertyValue( INFO_MEDIATYPE ) >>= sMediaType;
[ + - ]
158 [ - + ][ - + ]: 10 : if ( sMediaType == MIMETYPE_OASIS_OPENDOCUMENT_DATABASE_ASCII || sMediaType == MIMETYPE_VND_SUN_XML_BASE_ASCII )
[ + - ]
159 : : {
160 [ # # ][ # # ]: 0 : if ( bStreamFromDescr && sURL.compareTo( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:stream" ) ), 14 ) != COMPARE_EQUAL )
[ # # ][ # # ]
[ # # # # ]
161 : : {
162 : : // After fixing of the i88522 issue ( use the new file locking for database files ) the stream from the type detection can be used further
163 : : // for now the file should be reopened to have read/write access
164 [ # # ][ # # ]: 0 : aMedia.remove( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "InputStream" ) ) );
165 [ # # ][ # # ]: 0 : aMedia.remove( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Stream" ) ) );
[ # # ]
166 [ # # ]: 0 : aMedia >>= Descriptor;
167 : : try
168 : : {
169 [ # # ]: 0 : ::comphelper::disposeComponent(xStorageProperties);
170 [ # # ]: 0 : if ( xInStream.is() )
171 [ # # ][ # # ]: 0 : xInStream->closeInput();
172 : : }
173 [ # # ]: 0 : catch( Exception& )
174 : : {
175 : : DBG_UNHANDLED_EXCEPTION();
176 : : }
177 : : }
178 : :
179 [ # # ]: 0 : return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("StarBase"));
180 : : }
181 [ + - ][ + - ]: 10 : ::comphelper::disposeComponent(xStorageProperties);
182 [ - + ][ - + ]: 10 : }
[ - + ][ + - ]
[ + - ][ # # ]
183 : 0 : } catch(Exception&){}
184 : 10 : return ::rtl::OUString();
185 : : }
186 : : // -------------------------------------------------------------------------
187 : 10 : Reference< XInterface > SAL_CALL DBTypeDetection::Create( const Reference< XMultiServiceFactory > & rSMgr )
188 : : {
189 [ + - ]: 10 : return *(new DBTypeDetection(rSMgr));
190 : : }
191 : : // -------------------------------------------------------------------------
192 : : // XServiceInfo
193 : 0 : ::rtl::OUString SAL_CALL DBTypeDetection::getImplementationName() throw( )
194 : : {
195 : 0 : return getImplementationName_Static();
196 : : }
197 : : // -------------------------------------------------------------------------
198 : :
199 : : // XServiceInfo
200 : 0 : sal_Bool SAL_CALL DBTypeDetection::supportsService(const ::rtl::OUString& ServiceName) throw( )
201 : : {
202 : 0 : Sequence< ::rtl::OUString > aSNL = getSupportedServiceNames();
203 : 0 : const ::rtl::OUString * pBegin = aSNL.getConstArray();
204 : 0 : const ::rtl::OUString * pEnd = pBegin + aSNL.getLength();
205 [ # # ]: 0 : for( ; pBegin != pEnd; ++pBegin)
206 [ # # ]: 0 : if( *pBegin == ServiceName )
207 : 0 : return sal_True;
208 [ # # ]: 0 : return sal_False;
209 : : }
210 : : // -------------------------------------------------------------------------
211 : : // XServiceInfo
212 : 0 : Sequence< ::rtl::OUString > SAL_CALL DBTypeDetection::getSupportedServiceNames(void) throw( )
213 : : {
214 : 0 : return getSupportedServiceNames_Static();
215 : : }
216 : : // -------------------------------------------------------------------------
217 : : // ORegistryServiceManager_Static
218 : 17 : Sequence< ::rtl::OUString > DBTypeDetection::getSupportedServiceNames_Static(void) throw( )
219 : : {
220 : 17 : Sequence< ::rtl::OUString > aSNS( 1 );
221 [ + - ][ + - ]: 17 : aSNS.getArray()[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.document.ExtendedTypeDetection"));
222 : 17 : return aSNS;
223 : : }
224 : : // -------------------------------------------------------------------------
225 : 17 : extern "C" void SAL_CALL createRegistryInfo_DBTypeDetection()
226 : : {
227 [ + - ][ + - ]: 17 : static ::dbaxml::OMultiInstanceAutoRegistration< ::dbaxml::DBTypeDetection > aAutoRegistration;
[ + - ][ # # ]
228 : 17 : }
229 : : // -----------------------------------------------------------------------------
230 : :
231 : : class DBContentLoader : public ::cppu::WeakImplHelper2< XFrameLoader, XServiceInfo>
232 : : {
233 : : private:
234 : : ::comphelper::ComponentContext m_aContext;
235 : : Reference< XFrameLoader > m_xMySelf;
236 : : ::rtl::OUString m_sCurrentURL;
237 : : sal_uLong m_nStartWizard;
238 : :
239 : : DECL_LINK( OnStartTableWizard, void* );
240 : : public:
241 : : DBContentLoader(const Reference< XMultiServiceFactory >&);
242 : : ~DBContentLoader();
243 : :
244 : : // XServiceInfo
245 : : ::rtl::OUString SAL_CALL getImplementationName() throw( );
246 : : sal_Bool SAL_CALL supportsService(const ::rtl::OUString& ServiceName) throw( );
247 : : Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames(void) throw( );
248 : :
249 : : // static methods
250 : 34 : static ::rtl::OUString getImplementationName_Static() throw( )
251 : : {
252 : 34 : return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("org.openoffice.comp.dbflt.DBContentLoader2"));
253 : : }
254 : : static Sequence< ::rtl::OUString> getSupportedServiceNames_Static(void) throw( );
255 : : static ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >
256 : : SAL_CALL Create(const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >&);
257 : :
258 : : // XLoader
259 : : virtual void SAL_CALL load( const Reference< XFrame > & _rFrame, const ::rtl::OUString& _rURL,
260 : : const Sequence< PropertyValue >& _rArgs,
261 : : const Reference< XLoadEventListener > & _rListener) throw(::com::sun::star::uno::RuntimeException);
262 : : virtual void SAL_CALL cancel(void) throw();
263 : :
264 : : private:
265 : : sal_Bool impl_executeNewDatabaseWizard( Reference< XModel >& _rxModel, sal_Bool& _bShouldStartTableWizard );
266 : : };
267 : : DBG_NAME(DBContentLoader)
268 : :
269 : 2 : DBContentLoader::DBContentLoader(const Reference< XMultiServiceFactory >& _rxFactory)
270 : : :m_aContext( _rxFactory )
271 [ + - ]: 2 : ,m_nStartWizard(0)
272 : : {
273 : : DBG_CTOR(DBContentLoader,NULL);
274 : :
275 : 2 : }
276 : : // -------------------------------------------------------------------------
277 : :
278 [ + - ]: 2 : DBContentLoader::~DBContentLoader()
279 : : {
280 : :
281 : : DBG_DTOR(DBContentLoader,NULL);
282 [ - + ]: 4 : }
283 : : // -------------------------------------------------------------------------
284 : :
285 : : // -------------------------------------------------------------------------
286 : 2 : Reference< XInterface > SAL_CALL DBContentLoader::Create( const Reference< XMultiServiceFactory > & rSMgr )
287 : : {
288 [ + - ]: 2 : return *(new DBContentLoader(rSMgr));
289 : : }
290 : : // -------------------------------------------------------------------------
291 : : // XServiceInfo
292 : 0 : ::rtl::OUString SAL_CALL DBContentLoader::getImplementationName() throw( )
293 : : {
294 : 0 : return getImplementationName_Static();
295 : : }
296 : : // -------------------------------------------------------------------------
297 : :
298 : : // XServiceInfo
299 : 0 : sal_Bool SAL_CALL DBContentLoader::supportsService(const ::rtl::OUString& ServiceName) throw( )
300 : : {
301 : 0 : Sequence< ::rtl::OUString > aSNL = getSupportedServiceNames();
302 : 0 : const ::rtl::OUString * pBegin = aSNL.getConstArray();
303 : 0 : const ::rtl::OUString * pEnd = pBegin + aSNL.getLength();
304 [ # # ]: 0 : for( ; pBegin != pEnd; ++pBegin)
305 [ # # ]: 0 : if( *pBegin == ServiceName )
306 : 0 : return sal_True;
307 [ # # ]: 0 : return sal_False;
308 : : }
309 : : // -------------------------------------------------------------------------
310 : : // XServiceInfo
311 : 0 : Sequence< ::rtl::OUString > SAL_CALL DBContentLoader::getSupportedServiceNames(void) throw( )
312 : : {
313 : 0 : return getSupportedServiceNames_Static();
314 : : }
315 : : // -------------------------------------------------------------------------
316 : : // ORegistryServiceManager_Static
317 : 17 : Sequence< ::rtl::OUString > DBContentLoader::getSupportedServiceNames_Static(void) throw( )
318 : : {
319 : 17 : Sequence< ::rtl::OUString > aSNS( 1 );
320 [ + - ][ + - ]: 17 : aSNS.getArray()[0] = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.frame.FrameLoader"));
321 : 17 : return aSNS;
322 : : }
323 : :
324 : : // -----------------------------------------------------------------------
325 : : namespace
326 : : {
327 : : // ...................................................................
328 : 0 : sal_Bool lcl_urlAllowsInteraction( const ::comphelper::ComponentContext& _rContext, const ::rtl::OUString& _rURL )
329 : : {
330 : 0 : bool bDoesAllow = sal_False;
331 : : try
332 : : {
333 [ # # ][ # # ]: 0 : Reference< XURLTransformer > xTransformer( URLTransformer::create(_rContext.getUNOContext()) );
334 : 0 : URL aURL;
335 : 0 : aURL.Complete = _rURL;
336 [ # # ][ # # ]: 0 : xTransformer->parseStrict( aURL );
337 [ # # ]: 0 : bDoesAllow = aURL.Arguments == "Interactive";
338 : : }
339 : 0 : catch( const Exception& )
340 : : {
341 : : OSL_FAIL( "lcl_urlAllowsInteraction: caught an exception while analyzing the URL!" );
342 : : }
343 : 0 : return bDoesAllow;
344 : : }
345 : :
346 : : // ...................................................................
347 : 0 : Reference< XWindow > lcl_getTopMostWindow( const ::comphelper::ComponentContext& _rContext )
348 : : {
349 : 0 : Reference< XWindow > xWindow;
350 : : // get the top most window
351 : 0 : Reference < XFramesSupplier > xDesktop;
352 [ # # ][ # # ]: 0 : if ( _rContext.createComponent( "com.sun.star.frame.Desktop", xDesktop ) )
353 : : {
354 [ # # ][ # # ]: 0 : Reference < XFrame > xActiveFrame = xDesktop->getActiveFrame();
355 [ # # ]: 0 : if ( xActiveFrame.is() )
356 : : {
357 [ # # ][ # # ]: 0 : xWindow = xActiveFrame->getContainerWindow();
[ # # ]
358 : 0 : Reference<XFrame> xFrame = xActiveFrame;
359 [ # # ][ # # ]: 0 : while ( xFrame.is() && !xFrame->isTop() )
[ # # ][ # # ]
[ # # ]
360 [ # # ][ # # ]: 0 : xFrame.set(xFrame->getCreator(),UNO_QUERY);
[ # # ]
361 : :
362 [ # # ]: 0 : if ( xFrame.is() )
363 [ # # ][ # # ]: 0 : xWindow = xFrame->getContainerWindow();
[ # # ]
364 : 0 : }
365 : : }
366 : 0 : return xWindow;
367 : : }
368 : : }
369 : :
370 : : // -----------------------------------------------------------------------
371 : 0 : sal_Bool DBContentLoader::impl_executeNewDatabaseWizard( Reference< XModel >& _rxModel, sal_Bool& _bShouldStartTableWizard )
372 : : {
373 [ # # ]: 0 : Sequence< Any > aWizardArgs(2);
374 [ # # ]: 0 : aWizardArgs[0] <<= PropertyValue(
375 : : ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParentWindow")),
376 : : 0,
377 : : makeAny( lcl_getTopMostWindow( m_aContext ) ),
378 [ # # ][ # # ]: 0 : PropertyState_DIRECT_VALUE);
[ # # ][ # # ]
379 : :
380 [ # # ]: 0 : aWizardArgs[1] <<= PropertyValue(
381 : : ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("InitialSelection")),
382 : : 0,
383 : : makeAny( _rxModel ),
384 [ # # ][ # # ]: 0 : PropertyState_DIRECT_VALUE);
[ # # ]
385 : :
386 : : // create the dialog
387 : 0 : Reference< XExecutableDialog > xAdminDialog;
388 [ # # ]: 0 : OSL_VERIFY( m_aContext.createComponentWithArguments( "com.sun.star.sdb.DatabaseWizardDialog", aWizardArgs, xAdminDialog ) );
389 : :
390 : : // execute it
391 [ # # ][ # # ]: 0 : if ( !xAdminDialog.is() || ( RET_OK != xAdminDialog->execute() ) )
[ # # ][ # # ]
[ # # ]
392 : 0 : return sal_False;
393 : :
394 [ # # ]: 0 : Reference<XPropertySet> xProp(xAdminDialog,UNO_QUERY);
395 : 0 : sal_Bool bSuccess = sal_False;
396 [ # # ][ # # ]: 0 : xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("OpenDatabase"))) >>= bSuccess;
[ # # ]
397 [ # # ][ # # ]: 0 : xProp->getPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("StartTableWizard"))) >>= _bShouldStartTableWizard;
[ # # ]
398 [ # # ]: 0 : return bSuccess;
399 : : }
400 : :
401 : : // -----------------------------------------------------------------------
402 : 0 : void SAL_CALL DBContentLoader::load(const Reference< XFrame > & rFrame, const ::rtl::OUString& _rURL,
403 : : const Sequence< PropertyValue >& rArgs,
404 : : const Reference< XLoadEventListener > & rListener) throw(::com::sun::star::uno::RuntimeException)
405 : : {
406 : : // first check if preview is true, if so return with out creating a controller. Preview is not supported
407 [ # # ]: 0 : ::comphelper::NamedValueCollection aMediaDesc( rArgs );
408 [ # # ]: 0 : sal_Bool bPreview = aMediaDesc.getOrDefault( "Preview", sal_False );
409 [ # # ]: 0 : if ( bPreview )
410 : : {
411 [ # # ]: 0 : if (rListener.is())
412 [ # # ][ # # ]: 0 : rListener->loadCancelled(this);
[ # # ]
413 : : return;
414 : : }
415 : :
416 [ # # ]: 0 : Reference< XModel > xModel = aMediaDesc.getOrDefault( "Model", Reference< XModel >() );
417 [ # # ]: 0 : ::rtl::OUString sSalvagedURL = aMediaDesc.getOrDefault( "SalvagedFile", _rURL );
418 : :
419 : 0 : sal_Bool bCreateNew = sal_False; // does the URL denote the private:factory URL?
420 : 0 : sal_Bool bStartTableWizard = sal_False; // start the table wizard after everything was loaded successfully?
421 : :
422 : 0 : sal_Bool bSuccess = sal_True;
423 : :
424 : : // If there's no interaction handler in the media descriptor, put one.
425 : : // By definition, loading via loadComponentFromURL (and thus via the content loader here)
426 : : // is allowed to raise UI. To not burden every place inside the document with creating
427 : : // a default handler, we simply ensure there is one.
428 : : // If a handler is present in the media descriptor, even if it is NULL, we will
429 : : // not touch it.
430 [ # # ][ # # ]: 0 : if ( !aMediaDesc.has( "InteractionHandler" ) )
431 : : {
432 : 0 : Reference< XInteractionHandler > xHandler;
433 [ # # ][ # # ]: 0 : if ( m_aContext.createComponent( "com.sun.star.task.InteractionHandler", xHandler ) )
434 [ # # ]: 0 : aMediaDesc.put( "InteractionHandler", xHandler );
435 : : }
436 : :
437 : : // it's allowed to pass an existing document
438 : 0 : Reference< XOfficeDatabaseDocument > xExistentDBDoc;
439 [ # # ][ # # ]: 0 : xModel.set( aMediaDesc.getOrDefault( "Model", xExistentDBDoc ), UNO_QUERY );
440 [ # # ]: 0 : aMediaDesc.remove( "Model" );
441 : :
442 : : // also, it's allowed to specify the type of view which should be created
443 [ # # ][ # # ]: 0 : ::rtl::OUString sViewName = aMediaDesc.getOrDefault( "ViewName", ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Default" ) ) );
444 [ # # ]: 0 : aMediaDesc.remove( "ViewName" );
445 : :
446 : 0 : sal_Int32 nInitialSelection = -1;
447 [ # # ]: 0 : if ( !xModel.is() )
448 : : {
449 : 0 : Reference< XSingleServiceFactory > xDatabaseContext;
450 [ # # ][ # # ]: 0 : if ( !m_aContext.createComponent( (::rtl::OUString)SERVICE_SDB_DATABASECONTEXT, xDatabaseContext ) )
[ # # ]
451 [ # # ][ # # ]: 0 : throw RuntimeException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "css.sdb.DatabaseContext not available" ) ), NULL );
[ # # ]
452 : :
453 [ # # ][ # # ]: 0 : ::rtl::OUString sFactoryName = SvtModuleOptions().GetFactoryEmptyDocumentURL(SvtModuleOptions::E_DATABASE);
[ # # ]
454 : 0 : bCreateNew = sFactoryName.match(_rURL);
455 : :
456 : 0 : Reference< XDocumentDataSource > xDocumentDataSource;
457 : 0 : bool bNewAndInteractive = false;
458 [ # # ]: 0 : if ( bCreateNew )
459 : : {
460 [ # # ]: 0 : bNewAndInteractive = lcl_urlAllowsInteraction( m_aContext, _rURL );
461 [ # # ][ # # ]: 0 : xDocumentDataSource.set( xDatabaseContext->createInstance(), UNO_QUERY_THROW );
[ # # ]
462 : : }
463 : : else
464 : : {
465 [ # # ]: 0 : ::comphelper::NamedValueCollection aCreationArgs;
466 [ # # ][ # # ]: 0 : aCreationArgs.put( (::rtl::OUString)INFO_POOLURL, sSalvagedURL );
467 [ # # ][ # # ]: 0 : xDocumentDataSource.set( xDatabaseContext->createInstanceWithArguments( aCreationArgs.getWrappedNamedValues() ), UNO_QUERY_THROW );
[ # # ][ # # ]
[ # # ][ # # ]
468 : : }
469 : :
470 [ # # ][ # # ]: 0 : xModel.set( xDocumentDataSource->getDatabaseDocument(), UNO_QUERY );
[ # # ]
471 : :
472 [ # # ][ # # ]: 0 : if ( bCreateNew && xModel.is() )
[ # # ]
473 : : {
474 [ # # ]: 0 : if ( bNewAndInteractive )
475 : : {
476 [ # # ]: 0 : bSuccess = impl_executeNewDatabaseWizard( xModel, bStartTableWizard );
477 : : }
478 : : else
479 : : {
480 : : try
481 : : {
482 [ # # ]: 0 : Reference< XLoadable > xLoad( xModel, UNO_QUERY_THROW );
483 [ # # ][ # # ]: 0 : xLoad->initNew();
484 [ # # ]: 0 : bSuccess = true;
485 : : }
486 [ # # ]: 0 : catch( const Exception& )
487 : : {
488 : 0 : bSuccess = false;
489 : : }
490 : : }
491 : :
492 : : // initially select the "Tables" category (will be done below)
493 : 0 : nInitialSelection = ::com::sun::star::sdb::application::DatabaseObjectContainer::TABLES;
494 : 0 : }
495 : : }
496 : :
497 [ # # ]: 0 : if ( !xModel.is() )
498 : : {
499 [ # # ]: 0 : if ( rListener.is() )
500 [ # # ][ # # ]: 0 : rListener->loadCancelled(this);
[ # # ]
501 : : return;
502 : : }
503 : :
504 [ # # ]: 0 : if ( !bCreateNew )
505 : : {
506 : : // We need to XLoadable::load the document if it does not yet have an URL.
507 : : // If it already *does* have an URL, then it was either passed in the arguments, or a previous incarnation
508 : : // of that model existed before (which can happen if a model is closed, but an associated DataSource is kept
509 : : // alive 'til loading the document again).
510 [ # # ][ # # ]: 0 : bool bNeedLoad = ( xModel->getURL().isEmpty() );
511 : : try
512 : : {
513 [ # # ]: 0 : aMediaDesc.put( "FileName", _rURL );
514 [ # # ]: 0 : Sequence< PropertyValue > aResource( aMediaDesc.getPropertyValues() );
515 : :
516 [ # # ]: 0 : if ( bNeedLoad )
517 : : {
518 [ # # ]: 0 : Reference< XLoadable > xLoad( xModel, UNO_QUERY_THROW );
519 [ # # ][ # # ]: 0 : xLoad->load( aResource );
520 : : }
521 : :
522 : : // always attach the resource, even if the document has not been freshly loaded
523 [ # # ][ # # ]: 0 : xModel->attachResource( _rURL, aResource );
[ # # ][ # # ]
524 : : }
525 [ # # ]: 0 : catch(const Exception&)
526 : : {
527 : : DBG_UNHANDLED_EXCEPTION();
528 : 0 : bSuccess = sal_False;
529 : : }
530 : : }
531 : :
532 [ # # ]: 0 : if ( bSuccess )
533 : : {
534 : : try
535 : : {
536 [ # # ]: 0 : Reference< XModel2 > xModel2( xModel, UNO_QUERY_THROW );
537 [ # # ][ # # ]: 0 : Reference< XController2 > xController( xModel2->createViewController( sViewName, Sequence< PropertyValue >(), rFrame ), UNO_QUERY_THROW );
[ # # ][ # # ]
[ # # ]
538 : :
539 [ # # ][ # # ]: 0 : xController->attachModel( xModel );
540 [ # # ][ # # ]: 0 : xModel->connectController( xController.get() );
[ # # ][ # # ]
541 [ # # ][ # # ]: 0 : rFrame->setComponent( xController->getComponentWindow(), xController.get() );
[ # # ][ # # ]
[ # # ][ # # ]
542 [ # # ][ # # ]: 0 : xController->attachFrame( rFrame );
543 [ # # ][ # # ]: 0 : xModel->setCurrentController( xController.get() );
[ # # ][ # # ]
544 : :
545 [ # # ]: 0 : bSuccess = sal_True;
546 : : }
547 [ # # ]: 0 : catch( const Exception& )
548 : : {
549 : : DBG_UNHANDLED_EXCEPTION();
550 : 0 : bSuccess = sal_False;
551 : : }
552 : : }
553 : :
554 [ # # ]: 0 : if (bSuccess)
555 : : {
556 [ # # ]: 0 : if ( rListener.is() )
557 [ # # ][ # # ]: 0 : rListener->loadFinished(this);
[ # # ]
558 : :
559 [ # # ]: 0 : if ( nInitialSelection != -1 )
560 : : {
561 [ # # ][ # # ]: 0 : Reference< css::view::XSelectionSupplier > xDocView( xModel->getCurrentController(), UNO_QUERY );
[ # # ]
562 [ # # ]: 0 : if ( xDocView.is() )
563 : : {
564 : 0 : NamedDatabaseObject aSelection;
565 : 0 : aSelection.Type = nInitialSelection;
566 [ # # ][ # # ]: 0 : xDocView->select( makeAny( aSelection ) );
[ # # ]
567 : 0 : }
568 : : }
569 : :
570 [ # # ]: 0 : if ( bStartTableWizard )
571 : : {
572 : : // reset the data of the previous async drop (if any)
573 [ # # ]: 0 : if ( m_nStartWizard )
574 [ # # ]: 0 : Application::RemoveUserEvent(m_nStartWizard);
575 [ # # ][ # # ]: 0 : m_sCurrentURL = xModel->getURL();
576 [ # # ]: 0 : m_xMySelf = this;
577 [ # # ][ # # ]: 0 : m_nStartWizard = Application::PostUserEvent(LINK(this, DBContentLoader, OnStartTableWizard));
578 : : }
579 : : }
580 : : else
581 : : {
582 [ # # ]: 0 : if ( rListener.is() )
583 [ # # ][ # # ]: 0 : rListener->loadCancelled( this );
[ # # ]
584 : : }
585 : :
586 [ # # ]: 0 : if ( !bSuccess )
587 [ # # ][ # # ]: 0 : ::comphelper::disposeComponent(xModel);
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ]
588 : : }
589 : :
590 : : // -----------------------------------------------------------------------
591 : 0 : void DBContentLoader::cancel(void) throw()
592 : : {
593 : 0 : }
594 : : // -----------------------------------------------------------------------------
595 : 0 : IMPL_LINK( DBContentLoader, OnStartTableWizard, void*, /*NOTINTERESTEDIN*/ )
596 : : {
597 : 0 : m_nStartWizard = 0;
598 : : try
599 : : {
600 [ # # ]: 0 : Sequence< Any > aWizArgs(1);
601 : 0 : PropertyValue aValue;
602 [ # # ]: 0 : aValue.Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("DatabaseLocation"));
603 [ # # ]: 0 : aValue.Value <<= m_sCurrentURL;
604 [ # # ][ # # ]: 0 : aWizArgs[0] <<= aValue;
605 : :
606 [ # # ]: 0 : SolarMutexGuard aGuard;
607 : 0 : Reference< XJobExecutor > xTableWizard;
608 [ # # ][ # # ]: 0 : if ( m_aContext.createComponentWithArguments( "com.sun.star.wizards.table.CallTableWizard", aWizArgs, xTableWizard ) )
609 [ # # ][ # # ]: 0 : xTableWizard->trigger(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("start")));
[ # # ][ # # ]
[ # # ][ # # ]
610 : : }
611 : 0 : catch(const Exception&)
612 : : {
613 : : OSL_FAIL("caught an exception while starting the table wizard!");
614 : : }
615 : 0 : m_xMySelf = NULL;
616 : 0 : return 0L;
617 : : }
618 : : }
619 : : // -------------------------------------------------------------------------
620 : 17 : extern "C" void SAL_CALL createRegistryInfo_DBContentLoader2()
621 : : {
622 [ + - ][ + - ]: 17 : static ::dbaxml::OMultiInstanceAutoRegistration< ::dbaxml::DBContentLoader > aAutoRegistration;
[ + - ][ # # ]
623 : 17 : }
624 : : // -------------------------------------------------------------------------
625 : 0 : extern "C" void SAL_CALL writeDBLoaderInfo2(void* pRegistryKey)
626 : : {
627 [ # # ]: 0 : Reference< XRegistryKey> xKey(reinterpret_cast< XRegistryKey*>(pRegistryKey));
628 : :
629 : : // register content loader for dispatch
630 [ # # ]: 0 : ::rtl::OUString aImpl(RTL_CONSTASCII_USTRINGPARAM("/"));
631 : 0 : aImpl += ::dbaxml::DBContentLoader::getImplementationName_Static();
632 : :
633 : 0 : ::rtl::OUString aImpltwo = aImpl;
634 [ # # ]: 0 : aImpltwo += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/UNO/Loader"));
635 [ # # ][ # # ]: 0 : Reference< XRegistryKey> xNewKey = xKey->createKey( aImpltwo );
636 : 0 : aImpltwo = aImpl;
637 [ # # ]: 0 : aImpltwo += ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("/Loader"));
638 [ # # ][ # # ]: 0 : Reference< XRegistryKey > xLoaderKey = xKey->createKey( aImpltwo );
639 [ # # ][ # # ]: 0 : xNewKey = xLoaderKey->createKey( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Pattern")) );
[ # # ][ # # ]
640 [ # # ][ # # ]: 0 : xNewKey->setAsciiValue( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("private:factory/sdatabase")) );
[ # # ]
641 : 0 : }
642 : : // -----------------------------------------------------------------------------
643 : :
644 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|