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 : #include "subcomponentrecovery.hxx"
21 :
22 : #include "sdbcoretools.hxx"
23 : #include "storagexmlstream.hxx"
24 : #include "subcomponentloader.hxx"
25 : #include "settingsimport.hxx"
26 :
27 : #include <com/sun/star/embed/ElementModes.hpp>
28 : #include <com/sun/star/frame/ModuleManager.hpp>
29 : #include <com/sun/star/document/XStorageBasedDocument.hpp>
30 : #include <com/sun/star/ucb/XCommandProcessor.hpp>
31 : #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
32 : #include <com/sun/star/sdb/XFormDocumentsSupplier.hpp>
33 : #include <com/sun/star/sdb/XReportDocumentsSupplier.hpp>
34 : #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
35 :
36 : #include <comphelper/namedvaluecollection.hxx>
37 : #include <connectivity/dbtools.hxx>
38 : #include <tools/diagnose_ex.h>
39 : #include <xmloff/XMLSettingsExportContext.hxx>
40 : #include <xmloff/SettingsExportHelper.hxx>
41 :
42 : namespace dbaccess
43 : {
44 :
45 : using css::uno::Reference;
46 : using css::uno::XInterface;
47 : using css::uno::UNO_QUERY;
48 : using css::uno::UNO_QUERY_THROW;
49 : using css::uno::UNO_SET_THROW;
50 : using css::uno::Exception;
51 : using css::uno::RuntimeException;
52 : using css::uno::Any;
53 : using css::uno::makeAny;
54 : using css::uno::Sequence;
55 : using css::uno::Type;
56 : using css::uno::XComponentContext;
57 : using css::lang::XMultiServiceFactory;
58 : using css::embed::XStorage;
59 : using css::sdb::application::XDatabaseDocumentUI;
60 : using css::beans::Pair;
61 : using css::frame::ModuleManager;
62 : using css::frame::XModuleManager2;
63 : using css::lang::XComponent;
64 : using css::frame::XModel;
65 : using css::frame::XController;
66 : using css::beans::XPropertySet;
67 : using css::beans::PropertyValue;
68 : using css::document::XStorageBasedDocument;
69 : using css::ucb::XCommandProcessor;
70 : using css::container::XHierarchicalNameAccess;
71 : using css::sdb::XFormDocumentsSupplier;
72 : using css::sdb::XReportDocumentsSupplier;
73 : using css::xml::sax::SAXException;
74 : using css::xml::sax::XLocator;
75 : using css::xml::sax::XDocumentHandler;
76 : using css::xml::sax::XAttributeList;
77 :
78 : namespace ElementModes = css::embed::ElementModes;
79 : namespace DatabaseObject = css::sdb::application::DatabaseObject;
80 :
81 : // helper
82 : namespace
83 : {
84 0 : static OUString lcl_getComponentStorageBaseName( const SubComponentType i_eType )
85 : {
86 0 : switch ( i_eType )
87 : {
88 : case FORM:
89 0 : return OUString("form");
90 : case REPORT:
91 0 : return OUString("report");
92 : case TABLE:
93 0 : return OUString("table");
94 : case QUERY:
95 0 : return OUString("query");
96 : default:
97 0 : break;
98 : }
99 :
100 : OSL_FAIL( "lcl_getComponentStorageBaseName: unimplemented case!" );
101 0 : return OUString();
102 : }
103 :
104 0 : static SubComponentType lcl_databaseObjectToSubComponentType( const sal_Int32 i_nObjectType )
105 : {
106 0 : switch ( i_nObjectType )
107 : {
108 0 : case DatabaseObject::TABLE: return TABLE;
109 0 : case DatabaseObject::QUERY: return QUERY;
110 0 : case DatabaseObject::FORM: return FORM;
111 0 : case DatabaseObject::REPORT:return REPORT;
112 : default:
113 0 : break;
114 : }
115 0 : return UNKNOWN;
116 : }
117 :
118 0 : static bool lcl_determineReadOnly( const Reference< XComponent >& i_rComponent )
119 : {
120 0 : Reference< XModel > xDocument( i_rComponent, UNO_QUERY );
121 0 : if ( !xDocument.is() )
122 : {
123 0 : Reference< XController > xController( i_rComponent, UNO_QUERY_THROW );
124 0 : xDocument = xController->getModel();
125 : }
126 :
127 0 : if ( !xDocument.is() )
128 0 : return false;
129 :
130 0 : ::comphelper::NamedValueCollection aDocArgs( xDocument->getArgs() );
131 0 : return aDocArgs.getOrDefault( "ReadOnly", false );
132 : }
133 :
134 0 : static Reference< XCommandProcessor > lcl_getSubComponentDef_nothrow( const Reference< XDatabaseDocumentUI >& i_rAppUI,
135 : const SubComponentType i_eType, const OUString& i_rName )
136 : {
137 0 : Reference< XController > xController( i_rAppUI, UNO_QUERY_THROW );
138 0 : ENSURE_OR_RETURN( ( i_eType == FORM ) || ( i_eType == REPORT ), "lcl_getSubComponentDef_nothrow: illegal controller", NULL );
139 :
140 0 : Reference< XCommandProcessor > xCommandProcessor;
141 : try
142 : {
143 0 : Reference< XHierarchicalNameAccess > xDefinitionContainer;
144 0 : if ( i_eType == FORM )
145 : {
146 0 : Reference< XFormDocumentsSupplier > xSuppForms( xController->getModel(), UNO_QUERY_THROW );
147 0 : xDefinitionContainer.set( xSuppForms->getFormDocuments(), UNO_QUERY_THROW );
148 : }
149 : else
150 : {
151 0 : Reference< XReportDocumentsSupplier > xSuppReports( xController->getModel(), UNO_QUERY_THROW );
152 0 : xDefinitionContainer.set( xSuppReports->getReportDocuments(), UNO_QUERY_THROW );
153 : }
154 0 : xCommandProcessor.set( xDefinitionContainer->getByHierarchicalName( i_rName ), UNO_QUERY_THROW );
155 : }
156 0 : catch( const Exception& )
157 : {
158 : DBG_UNHANDLED_EXCEPTION();
159 : }
160 0 : return xCommandProcessor;
161 : }
162 :
163 : static const char sSettingsStreamName[] = "settings.xml";
164 : static const char sCurrentQueryDesignName[] = "ooo:current-query-design";
165 : }
166 :
167 : // SettingsExportContext
168 : class DBACCESS_DLLPRIVATE SettingsExportContext : public ::xmloff::XMLSettingsExportContext
169 : {
170 : public:
171 0 : SettingsExportContext( const Reference<XComponentContext>& i_rContext, const StorageXMLOutputStream& i_rDelegator )
172 : :m_rContext( i_rContext )
173 : ,m_rDelegator( i_rDelegator )
174 0 : ,m_aNamespace( ::xmloff::token::GetXMLToken( ::xmloff::token::XML_NP_CONFIG ) )
175 : {
176 0 : }
177 :
178 0 : virtual ~SettingsExportContext()
179 0 : {
180 0 : }
181 :
182 : public:
183 : virtual void AddAttribute( enum ::xmloff::token::XMLTokenEnum i_eName, const OUString& i_rValue ) SAL_OVERRIDE;
184 : virtual void AddAttribute( enum ::xmloff::token::XMLTokenEnum i_eName, enum ::xmloff::token::XMLTokenEnum i_eValue ) SAL_OVERRIDE;
185 : virtual void StartElement( enum ::xmloff::token::XMLTokenEnum i_eName, const bool i_bIgnoreWhitespace ) SAL_OVERRIDE;
186 : virtual void EndElement ( const bool i_bIgnoreWhitespace ) SAL_OVERRIDE;
187 : virtual void Characters( const OUString& i_rCharacters ) SAL_OVERRIDE;
188 :
189 : virtual css::uno::Reference< css::uno::XComponentContext >
190 : GetComponentContext() const SAL_OVERRIDE;
191 :
192 : private:
193 0 : OUString impl_prefix( const ::xmloff::token::XMLTokenEnum i_eToken )
194 : {
195 0 : return m_aNamespace + ":" + ::xmloff::token::GetXMLToken( i_eToken );
196 : }
197 :
198 : private:
199 : const Reference<XComponentContext>& m_rContext;
200 : const StorageXMLOutputStream& m_rDelegator;
201 : const OUString m_aNamespace;
202 : };
203 :
204 0 : void SettingsExportContext::AddAttribute( enum ::xmloff::token::XMLTokenEnum i_eName, const OUString& i_rValue )
205 : {
206 0 : m_rDelegator.addAttribute( impl_prefix( i_eName ), i_rValue );
207 0 : }
208 :
209 0 : void SettingsExportContext::AddAttribute( enum ::xmloff::token::XMLTokenEnum i_eName, enum ::xmloff::token::XMLTokenEnum i_eValue )
210 : {
211 0 : m_rDelegator.addAttribute( impl_prefix( i_eName ), ::xmloff::token::GetXMLToken( i_eValue ) );
212 0 : }
213 :
214 0 : void SettingsExportContext::StartElement( enum ::xmloff::token::XMLTokenEnum i_eName, const bool i_bIgnoreWhitespace )
215 : {
216 0 : if ( i_bIgnoreWhitespace )
217 0 : m_rDelegator.ignorableWhitespace( " " );
218 :
219 0 : m_rDelegator.startElement( impl_prefix( i_eName ) );
220 0 : }
221 :
222 0 : void SettingsExportContext::EndElement( const bool i_bIgnoreWhitespace )
223 : {
224 0 : if ( i_bIgnoreWhitespace )
225 0 : m_rDelegator.ignorableWhitespace( " " );
226 0 : m_rDelegator.endElement();
227 0 : }
228 :
229 0 : void SettingsExportContext::Characters( const OUString& i_rCharacters )
230 : {
231 0 : m_rDelegator.characters( i_rCharacters );
232 0 : }
233 :
234 0 : Reference< com::sun::star::uno::XComponentContext > SettingsExportContext::GetComponentContext() const
235 : {
236 0 : return m_rContext;
237 : }
238 :
239 : // SettingsDocumentHandler
240 : typedef ::cppu::WeakImplHelper1 < XDocumentHandler
241 : > SettingsDocumentHandler_Base;
242 : class DBACCESS_DLLPRIVATE SettingsDocumentHandler : public SettingsDocumentHandler_Base
243 : {
244 : public:
245 0 : SettingsDocumentHandler()
246 0 : {
247 0 : }
248 :
249 : protected:
250 0 : virtual ~SettingsDocumentHandler()
251 0 : {
252 0 : }
253 :
254 : public:
255 : // XDocumentHandler
256 : virtual void SAL_CALL startDocument( ) throw (SAXException, RuntimeException, std::exception) SAL_OVERRIDE;
257 : virtual void SAL_CALL endDocument( ) throw (SAXException, RuntimeException, std::exception) SAL_OVERRIDE;
258 : virtual void SAL_CALL startElement( const OUString& aName, const Reference< XAttributeList >& xAttribs ) throw (SAXException, RuntimeException, std::exception) SAL_OVERRIDE;
259 : virtual void SAL_CALL endElement( const OUString& aName ) throw (SAXException, RuntimeException, std::exception) SAL_OVERRIDE;
260 : virtual void SAL_CALL characters( const OUString& aChars ) throw (SAXException, RuntimeException, std::exception) SAL_OVERRIDE;
261 : virtual void SAL_CALL ignorableWhitespace( const OUString& aWhitespaces ) throw (SAXException, RuntimeException, std::exception) SAL_OVERRIDE;
262 : virtual void SAL_CALL processingInstruction( const OUString& aTarget, const OUString& aData ) throw (SAXException, RuntimeException, std::exception) SAL_OVERRIDE;
263 : virtual void SAL_CALL setDocumentLocator( const Reference< XLocator >& xLocator ) throw (SAXException, RuntimeException, std::exception) SAL_OVERRIDE;
264 :
265 0 : const ::comphelper::NamedValueCollection& getSettings() const { return m_aSettings; }
266 :
267 : private:
268 : ::std::stack< ::rtl::Reference< SettingsImport > > m_aStates;
269 : ::comphelper::NamedValueCollection m_aSettings;
270 : };
271 :
272 0 : void SAL_CALL SettingsDocumentHandler::startDocument( ) throw (SAXException, RuntimeException, std::exception)
273 : {
274 0 : }
275 :
276 0 : void SAL_CALL SettingsDocumentHandler::endDocument( ) throw (SAXException, RuntimeException, std::exception)
277 : {
278 0 : }
279 :
280 0 : void SAL_CALL SettingsDocumentHandler::startElement( const OUString& i_Name, const Reference< XAttributeList >& i_Attribs ) throw (SAXException, RuntimeException, std::exception)
281 : {
282 0 : ::rtl::Reference< SettingsImport > pNewState;
283 :
284 0 : if ( m_aStates.empty() )
285 : {
286 0 : if ( i_Name == "office:settings" )
287 : {
288 0 : pNewState = new OfficeSettingsImport( m_aSettings );
289 : }
290 : else
291 : {
292 : OSL_FAIL( "SettingsDocumentHandler::startElement: invalid settings file!" );
293 : // Yes, that's not correct. Somebody could, in theory, give us a document which starts with "foo:settings",
294 : // where "foo" is mapped to the proper namespace URL.
295 : // However, there's no need to bother with this. The "recovery" sub storage we're recovering from is
296 : // not part of ODF, so we can impose any format restrictions on it ...
297 : }
298 : }
299 : else
300 : {
301 0 : ::rtl::Reference< SettingsImport > pCurrentState( m_aStates.top() );
302 0 : pNewState = pCurrentState->nextState( i_Name );
303 : }
304 :
305 0 : ENSURE_OR_THROW( pNewState.is(), "no new state - aborting import" );
306 0 : pNewState->startElement( i_Attribs );
307 :
308 0 : m_aStates.push( pNewState );
309 0 : }
310 :
311 0 : void SAL_CALL SettingsDocumentHandler::endElement( const OUString& i_Name ) throw (SAXException, RuntimeException, std::exception)
312 : {
313 0 : ENSURE_OR_THROW( !m_aStates.empty(), "no active element" );
314 : (void)i_Name;
315 :
316 0 : ::rtl::Reference< SettingsImport > pCurrentState( m_aStates.top() );
317 0 : pCurrentState->endElement();
318 0 : m_aStates.pop();
319 0 : }
320 :
321 0 : void SAL_CALL SettingsDocumentHandler::characters( const OUString& i_Chars ) throw (SAXException, RuntimeException, std::exception)
322 : {
323 0 : ENSURE_OR_THROW( !m_aStates.empty(), "no active element" );
324 :
325 0 : ::rtl::Reference< SettingsImport > pCurrentState( m_aStates.top() );
326 0 : pCurrentState->characters( i_Chars );
327 0 : }
328 :
329 0 : void SAL_CALL SettingsDocumentHandler::ignorableWhitespace( const OUString& aWhitespaces ) throw (SAXException, RuntimeException, std::exception)
330 : {
331 : // ignore them - that's why they're called "ignorable"
332 : (void)aWhitespaces;
333 0 : }
334 :
335 0 : void SAL_CALL SettingsDocumentHandler::processingInstruction( const OUString& i_Target, const OUString& i_Data ) throw (SAXException, RuntimeException, std::exception)
336 : {
337 : OSL_FAIL( "SettingsDocumentHandler::processingInstruction: unexpected ..." );
338 : (void)i_Target;
339 : (void)i_Data;
340 0 : }
341 :
342 0 : void SAL_CALL SettingsDocumentHandler::setDocumentLocator( const Reference< XLocator >& i_Locator ) throw (SAXException, RuntimeException, std::exception)
343 : {
344 : (void)i_Locator;
345 0 : }
346 :
347 : // SubComponentRecovery
348 0 : const OUString SubComponentRecovery::getComponentsStorageName( const SubComponentType i_eType )
349 : {
350 0 : switch ( i_eType )
351 : {
352 : case FORM:
353 0 : return OUString("forms");
354 : case REPORT:
355 0 : return OUString("reports");
356 : case TABLE:
357 0 : return OUString("tables");
358 : case QUERY:
359 0 : return OUString("queries");
360 : case RELATION_DESIGN:
361 0 : return OUString("relations");
362 : default:
363 0 : break;
364 : }
365 :
366 : OSL_FAIL( "SubComponentRecovery::getComponentsStorageName: unimplemented case!" );
367 0 : return OUString();
368 : }
369 :
370 0 : void SubComponentRecovery::saveToRecoveryStorage( const Reference< XStorage >& i_rRecoveryStorage,
371 : MapCompTypeToCompDescs& io_mapCompDescs )
372 : {
373 0 : if ( m_eType == UNKNOWN )
374 : // quite fatal, but has already been reported (as assertion) before
375 0 : return;
376 :
377 : // open the sub storage for the given kind of components
378 0 : const OUString& rStorageName( getComponentsStorageName( m_eType ) );
379 0 : const Reference< XStorage > xComponentsStorage( i_rRecoveryStorage->openStorageElement(
380 0 : rStorageName, ElementModes::READWRITE ), UNO_QUERY_THROW );
381 :
382 : // find a free sub storage name, and create Yet Another Sub Storage
383 0 : const OUString& rBaseName( lcl_getComponentStorageBaseName( m_eType ) );
384 0 : const OUString sStorName = ::dbtools::createUniqueName( xComponentsStorage.get(), rBaseName, true );
385 0 : const Reference< XStorage > xObjectStor( xComponentsStorage->openStorageElement(
386 0 : sStorName, ElementModes::READWRITE ), UNO_QUERY_THROW );
387 :
388 0 : switch ( m_eType )
389 : {
390 : case FORM:
391 : case REPORT:
392 0 : impl_saveSubDocument_throw( xObjectStor );
393 0 : break;
394 :
395 : case QUERY:
396 0 : impl_saveQueryDesign_throw( xObjectStor );
397 0 : break;
398 :
399 : default:
400 : // TODO
401 : OSL_FAIL( "SubComponentRecoverys::saveToRecoveryStorage: unimplemented case!" );
402 0 : break;
403 : }
404 :
405 : // commit the storage(s)
406 0 : tools::stor::commitStorageIfWriteable( xObjectStor );
407 0 : tools::stor::commitStorageIfWriteable( xComponentsStorage );
408 :
409 : // remember the relationship from the component name to the storage name
410 0 : MapStringToCompDesc& rMapCompDescs = io_mapCompDescs[ m_eType ];
411 : OSL_ENSURE( rMapCompDescs.find( sStorName ) == rMapCompDescs.end(),
412 : "SubComponentRecoverys::saveToRecoveryStorage: object name already used!" );
413 0 : rMapCompDescs[ sStorName ] = m_aCompDesc;
414 : }
415 :
416 0 : void SubComponentRecovery::impl_identifyComponent_throw()
417 : {
418 : // ask the controller
419 0 : Pair< sal_Int32, OUString > aComponentIdentity = m_xDocumentUI->identifySubComponent( m_xComponent );
420 0 : m_eType = lcl_databaseObjectToSubComponentType( aComponentIdentity.First );
421 0 : m_aCompDesc.sName = aComponentIdentity.Second;
422 :
423 : // what the controller didn't give us is the information whether this is in edit mode or not ...
424 0 : Reference< XModuleManager2 > xModuleManager( ModuleManager::create(m_rContext) );
425 0 : const OUString sModuleIdentifier = xModuleManager->identify( m_xComponent );
426 :
427 0 : switch ( m_eType )
428 : {
429 : case TABLE:
430 0 : m_aCompDesc.bForEditing = sModuleIdentifier == "com.sun.star.sdb.TableDesign";
431 0 : break;
432 :
433 : case QUERY:
434 0 : m_aCompDesc.bForEditing = sModuleIdentifier == "com.sun.star.sdb.QueryDesign";
435 0 : break;
436 :
437 : case REPORT:
438 0 : if ( sModuleIdentifier == "com.sun.star.report.ReportDefinition" )
439 : {
440 : // it's an SRB report designer
441 0 : m_aCompDesc.bForEditing = true;
442 0 : break;
443 : }
444 : // fall through
445 :
446 : case FORM:
447 0 : m_aCompDesc.bForEditing = !lcl_determineReadOnly( m_xComponent );
448 0 : break;
449 :
450 : default:
451 0 : if ( sModuleIdentifier == "com.sun.star.sdb.RelationDesign" )
452 : {
453 0 : m_eType = RELATION_DESIGN;
454 0 : m_aCompDesc.bForEditing = true;
455 : }
456 : else
457 : {
458 : OSL_FAIL( "SubComponentRecovery::impl_identifyComponent_throw: couldn't classify the given sub component!" );
459 : }
460 0 : break;
461 : }
462 :
463 : SAL_WARN_IF( m_eType == UNKNOWN, "dbaccess",
464 0 : "SubComponentRecovery::impl_identifyComponent_throw: couldn't classify the component!" );
465 0 : }
466 :
467 0 : void SubComponentRecovery::impl_saveQueryDesign_throw( const Reference< XStorage >& i_rObjectStorage )
468 : {
469 0 : ENSURE_OR_THROW( m_eType == QUERY, "illegal sub component type" );
470 0 : ENSURE_OR_THROW( i_rObjectStorage.is(), "illegal storage" );
471 :
472 : // retrieve the current query design (which might differ from what we can retrieve as ActiveCommand property, since
473 : // the latter is updated only upon successful save of the design)
474 0 : Reference< XPropertySet > xDesignerProps( m_xComponent, UNO_QUERY_THROW );
475 0 : Sequence< PropertyValue > aCurrentQueryDesign;
476 0 : OSL_VERIFY( xDesignerProps->getPropertyValue( "CurrentQueryDesign" ) >>= aCurrentQueryDesign );
477 :
478 : // write the query design
479 0 : StorageXMLOutputStream aDesignOutput( m_rContext, i_rObjectStorage, sSettingsStreamName );
480 0 : SettingsExportContext aSettingsExportContext( m_rContext, aDesignOutput );
481 :
482 0 : const OUString sWhitespace( " " );
483 :
484 0 : aDesignOutput.startElement( "office:settings" );
485 0 : aDesignOutput.ignorableWhitespace( sWhitespace );
486 :
487 0 : XMLSettingsExportHelper aSettingsExporter( aSettingsExportContext );
488 0 : aSettingsExporter.exportAllSettings( aCurrentQueryDesign, sCurrentQueryDesignName );
489 :
490 0 : aDesignOutput.ignorableWhitespace( sWhitespace );
491 0 : aDesignOutput.endElement();
492 0 : aDesignOutput.close();
493 0 : }
494 :
495 0 : void SubComponentRecovery::impl_saveSubDocument_throw( const Reference< XStorage >& i_rObjectStorage )
496 : {
497 0 : ENSURE_OR_THROW( ( m_eType == FORM ) || ( m_eType == REPORT ), "illegal sub component type" );
498 0 : ENSURE_OR_THROW( i_rObjectStorage.is(), "illegal storage" );
499 :
500 : // store the document into the storage
501 0 : Reference< XStorageBasedDocument > xStorageDocument( m_xComponent, UNO_QUERY_THROW );
502 0 : xStorageDocument->storeToStorage( i_rObjectStorage, Sequence< PropertyValue >() );
503 0 : }
504 :
505 0 : Reference< XComponent > SubComponentRecovery::impl_recoverSubDocument_throw( const Reference< XStorage >& i_rRecoveryStorage,
506 : const OUString& i_rComponentName, const bool i_bForEditing )
507 : {
508 0 : Reference< XComponent > xSubComponent;
509 0 : Reference< XCommandProcessor > xDocDefinition;
510 :
511 0 : ::comphelper::NamedValueCollection aLoadArgs;
512 0 : aLoadArgs.put( "RecoveryStorage", i_rRecoveryStorage );
513 :
514 : // load/create the sub component hidden. We'll show it when the main app window is shown.
515 0 : aLoadArgs.put( "Hidden", true );
516 :
517 0 : if ( !i_rComponentName.isEmpty() )
518 : {
519 0 : xDocDefinition = lcl_getSubComponentDef_nothrow( m_xDocumentUI, m_eType, i_rComponentName );
520 0 : xSubComponent.set( m_xDocumentUI->loadComponentWithArguments(
521 : m_eType,
522 : i_rComponentName,
523 : i_bForEditing,
524 : aLoadArgs.getPropertyValues()
525 0 : ),
526 : UNO_SET_THROW
527 0 : );
528 : }
529 : else
530 : {
531 0 : Reference< XComponent > xDocDefComponent;
532 0 : xSubComponent.set( m_xDocumentUI->createComponentWithArguments(
533 : m_eType,
534 : aLoadArgs.getPropertyValues(),
535 : xDocDefComponent
536 0 : ),
537 : UNO_SET_THROW
538 0 : );
539 :
540 0 : xDocDefinition.set( xDocDefComponent, UNO_QUERY );
541 0 : OSL_ENSURE( xDocDefinition.is(), "DatabaseDocumentRecovery::recoverSubDocuments: loaded a form/report, but don't have a document definition?!" );
542 : }
543 :
544 0 : if ( xDocDefinition.is() )
545 : {
546 0 : Reference< XController > xController( m_xDocumentUI, UNO_QUERY_THROW );
547 0 : Reference< XInterface > xLoader( *new SubComponentLoader( xController, xDocDefinition ) );
548 0 : (void)xLoader;
549 : }
550 :
551 0 : return xSubComponent;
552 : }
553 :
554 0 : Reference< XComponent > SubComponentRecovery::impl_recoverQueryDesign_throw( const Reference< XStorage >& i_rRecoveryStorage,
555 : const OUString& i_rComponentName, const bool i_bForEditing )
556 : {
557 0 : Reference< XComponent > xSubComponent;
558 :
559 : // first read the settings query design settings from the storage
560 0 : StorageXMLInputStream aDesignInput( m_rContext, i_rRecoveryStorage, sSettingsStreamName );
561 :
562 0 : ::rtl::Reference< SettingsDocumentHandler > pDocHandler( new SettingsDocumentHandler );
563 0 : aDesignInput.import( pDocHandler.get() );
564 :
565 0 : const ::comphelper::NamedValueCollection& rSettings( pDocHandler->getSettings() );
566 0 : const Any aCurrentQueryDesign = rSettings.get( sCurrentQueryDesignName );
567 : #if OSL_DEBUG_LEVEL > 0
568 : Sequence< PropertyValue > aQueryDesignLayout;
569 : OSL_VERIFY( aCurrentQueryDesign >>= aQueryDesignLayout );
570 : #endif
571 :
572 : // then load the query designer
573 0 : ::comphelper::NamedValueCollection aLoadArgs;
574 0 : aLoadArgs.put( "CurrentQueryDesign", aCurrentQueryDesign );
575 0 : aLoadArgs.put( "Hidden", true );
576 :
577 0 : if ( !i_rComponentName.isEmpty() )
578 : {
579 0 : xSubComponent.set( m_xDocumentUI->loadComponentWithArguments(
580 : m_eType,
581 : i_rComponentName,
582 : i_bForEditing,
583 : aLoadArgs.getPropertyValues()
584 0 : ),
585 : UNO_SET_THROW
586 0 : );
587 : }
588 : else
589 : {
590 0 : Reference< XComponent > xDummy;
591 0 : xSubComponent.set( m_xDocumentUI->createComponentWithArguments(
592 : m_eType,
593 : aLoadArgs.getPropertyValues(),
594 : xDummy
595 0 : ),
596 : UNO_SET_THROW
597 0 : );
598 : }
599 :
600 0 : Reference< XController > xController( m_xDocumentUI, UNO_QUERY_THROW );
601 0 : Reference< XInterface > xLoader( *new SubComponentLoader( xController, xSubComponent ) );
602 : (void)xLoader;
603 :
604 0 : return xSubComponent;
605 : }
606 :
607 0 : Reference< XComponent > SubComponentRecovery::recoverFromStorage( const Reference< XStorage >& i_rRecoveryStorage,
608 : const OUString& i_rComponentName, const bool i_bForEditing )
609 : {
610 0 : Reference< XComponent > xSubComponent;
611 0 : switch ( m_eType )
612 : {
613 : case FORM:
614 : case REPORT:
615 0 : xSubComponent = impl_recoverSubDocument_throw( i_rRecoveryStorage, i_rComponentName, i_bForEditing );
616 0 : break;
617 : case QUERY:
618 0 : xSubComponent = impl_recoverQueryDesign_throw( i_rRecoveryStorage, i_rComponentName, i_bForEditing );
619 0 : break;
620 : default:
621 : OSL_FAIL( "SubComponentRecovery::recoverFromStorage: unimplemented case!" );
622 0 : break;
623 : }
624 0 : return xSubComponent;
625 : }
626 :
627 : } // namespace dbaccess
628 :
629 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|