Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / dbaccess / source / core / recovery / subcomponentrecovery.cxx
blobd9129d18644be4e695bd296cfce220f89ca4522a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "subcomponentrecovery.hxx"
23 #include "sdbcoretools.hxx"
24 #include "storagexmlstream.hxx"
25 #include "subcomponentloader.hxx"
26 #include "settingsimport.hxx"
28 #include <com/sun/star/embed/ElementModes.hpp>
29 #include <com/sun/star/frame/ModuleManager.hpp>
30 #include <com/sun/star/document/XStorageBasedDocument.hpp>
31 #include <com/sun/star/ucb/XCommandProcessor.hpp>
32 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
33 #include <com/sun/star/sdb/XFormDocumentsSupplier.hpp>
34 #include <com/sun/star/sdb/XReportDocumentsSupplier.hpp>
35 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
37 #include <comphelper/namedvaluecollection.hxx>
38 #include <connectivity/dbtools.hxx>
39 #include <tools/diagnose_ex.h>
40 #include <xmloff/XMLSettingsExportContext.hxx>
41 #include <xmloff/SettingsExportHelper.hxx>
43 //........................................................................
44 namespace dbaccess
46 //........................................................................
48 /** === begin UNO using === **/
49 using ::com::sun::star::uno::Reference;
50 using ::com::sun::star::uno::XInterface;
51 using ::com::sun::star::uno::UNO_QUERY;
52 using ::com::sun::star::uno::UNO_QUERY_THROW;
53 using ::com::sun::star::uno::UNO_SET_THROW;
54 using ::com::sun::star::uno::Exception;
55 using ::com::sun::star::uno::RuntimeException;
56 using ::com::sun::star::uno::Any;
57 using ::com::sun::star::uno::makeAny;
58 using ::com::sun::star::uno::Sequence;
59 using ::com::sun::star::uno::Type;
60 using ::com::sun::star::lang::XMultiServiceFactory;
61 using ::com::sun::star::embed::XStorage;
62 using ::com::sun::star::sdb::application::XDatabaseDocumentUI;
63 using ::com::sun::star::beans::Pair;
64 using ::com::sun::star::frame::ModuleManager;
65 using ::com::sun::star::frame::XModuleManager2;
66 using ::com::sun::star::lang::XComponent;
67 using ::com::sun::star::frame::XModel;
68 using ::com::sun::star::frame::XController;
69 using ::com::sun::star::beans::XPropertySet;
70 using ::com::sun::star::beans::PropertyValue;
71 using ::com::sun::star::document::XStorageBasedDocument;
72 using ::com::sun::star::ucb::XCommandProcessor;
73 using ::com::sun::star::container::XHierarchicalNameAccess;
74 using ::com::sun::star::sdb::XFormDocumentsSupplier;
75 using ::com::sun::star::sdb::XReportDocumentsSupplier;
76 using ::com::sun::star::xml::sax::SAXException;
77 using ::com::sun::star::xml::sax::XLocator;
78 using ::com::sun::star::xml::sax::XDocumentHandler;
79 using ::com::sun::star::xml::sax::XAttributeList;
80 /** === end UNO using === **/
82 namespace ElementModes = ::com::sun::star::embed::ElementModes;
85 //====================================================================
86 //= helper
87 //====================================================================
88 namespace
90 // .........................................................................
91 static const ::rtl::OUString& lcl_getComponentStorageBaseName( const SubComponentType i_eType )
93 static const ::rtl::OUString s_sFormBaseName( RTL_CONSTASCII_USTRINGPARAM( "form" ) );
94 static const ::rtl::OUString s_sReportBaseName( RTL_CONSTASCII_USTRINGPARAM( "report" ) );
95 static const ::rtl::OUString s_sTableBaseName( RTL_CONSTASCII_USTRINGPARAM( "table" ) );
96 static const ::rtl::OUString s_sQueryBaseName( RTL_CONSTASCII_USTRINGPARAM( "query" ) );
98 switch ( i_eType )
100 case FORM:
101 return s_sFormBaseName;
102 case REPORT:
103 return s_sReportBaseName;
104 case TABLE:
105 return s_sTableBaseName;
106 case QUERY:
107 return s_sQueryBaseName;
108 default:
109 break;
112 OSL_FAIL( "lcl_getComponentStorageBaseName: unimplemented case!" );
113 static const ::rtl::OUString s_sFallback;
114 return s_sFallback;
117 // .........................................................................
118 static SubComponentType lcl_databaseObjectToSubComponentType( const sal_Int32 i_nObjectType )
120 switch ( i_nObjectType )
122 case DatabaseObject::TABLE: return TABLE;
123 case DatabaseObject::QUERY: return QUERY;
124 case DatabaseObject::FORM: return FORM;
125 case DatabaseObject::REPORT:return REPORT;
126 default:
127 break;
129 return UNKNOWN;
132 // .........................................................................
133 static bool lcl_determineReadOnly( const Reference< XComponent >& i_rComponent )
135 Reference< XModel > xDocument( i_rComponent, UNO_QUERY );
136 if ( !xDocument.is() )
138 Reference< XController > xController( i_rComponent, UNO_QUERY_THROW );
139 xDocument = xController->getModel();
142 if ( !xDocument.is() )
143 return false;
145 ::comphelper::NamedValueCollection aDocArgs( xDocument->getArgs() );
146 return aDocArgs.getOrDefault( "ReadOnly", false );
149 // .........................................................................
150 static Reference< XCommandProcessor > lcl_getSubComponentDef_nothrow( const Reference< XDatabaseDocumentUI >& i_rAppUI,
151 const SubComponentType i_eType, const ::rtl::OUString& i_rName )
153 Reference< XController > xController( i_rAppUI, UNO_QUERY_THROW );
154 ENSURE_OR_RETURN( ( i_eType == FORM ) || ( i_eType == REPORT ), "lcl_getSubComponentDef_nothrow: illegal controller", NULL );
156 Reference< XCommandProcessor > xCommandProcessor;
159 Reference< XHierarchicalNameAccess > xDefinitionContainer;
160 if ( i_eType == FORM )
162 Reference< XFormDocumentsSupplier > xSuppForms( xController->getModel(), UNO_QUERY_THROW );
163 xDefinitionContainer.set( xSuppForms->getFormDocuments(), UNO_QUERY_THROW );
165 else
167 Reference< XReportDocumentsSupplier > xSuppReports( xController->getModel(), UNO_QUERY_THROW );
168 xDefinitionContainer.set( xSuppReports->getReportDocuments(), UNO_QUERY_THROW );
170 xCommandProcessor.set( xDefinitionContainer->getByHierarchicalName( i_rName ), UNO_QUERY_THROW );
172 catch( const Exception& )
174 DBG_UNHANDLED_EXCEPTION();
176 return xCommandProcessor;
179 // .........................................................................
180 static const ::rtl::OUString& lcl_getSettingsStreamName()
182 static const ::rtl::OUString s_sStatementStreamName( RTL_CONSTASCII_USTRINGPARAM( "settings.xml" ) );
183 return s_sStatementStreamName;
186 // .........................................................................
187 static const ::rtl::OUString& lcl_getCurrentQueryDesignName()
189 static const ::rtl::OUString s_sQuerySettingsName( RTL_CONSTASCII_USTRINGPARAM( "ooo:current-query-design" ) );
190 return s_sQuerySettingsName;
194 //====================================================================
195 //= SettingsExportContext
196 //====================================================================
197 class DBACCESS_DLLPRIVATE SettingsExportContext : public ::xmloff::XMLSettingsExportContext
199 public:
200 SettingsExportContext( const ::comphelper::ComponentContext& i_rContext, const StorageXMLOutputStream& i_rDelegator )
201 :m_rContext( i_rContext )
202 ,m_rDelegator( i_rDelegator )
203 ,m_aNamespace( ::xmloff::token::GetXMLToken( ::xmloff::token::XML_NP_CONFIG ) )
207 virtual ~SettingsExportContext()
211 public:
212 virtual void AddAttribute( enum ::xmloff::token::XMLTokenEnum i_eName, const ::rtl::OUString& i_rValue );
213 virtual void AddAttribute( enum ::xmloff::token::XMLTokenEnum i_eName, enum ::xmloff::token::XMLTokenEnum i_eValue );
214 virtual void StartElement( enum ::xmloff::token::XMLTokenEnum i_eName, const sal_Bool i_bIgnoreWhitespace );
215 virtual void EndElement ( const sal_Bool i_bIgnoreWhitespace );
216 virtual void Characters( const ::rtl::OUString& i_rCharacters );
218 virtual ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >
219 GetServiceFactory() const;
221 private:
222 ::rtl::OUString impl_prefix( const ::xmloff::token::XMLTokenEnum i_eToken )
224 ::rtl::OUStringBuffer aQualifiedName( m_aNamespace );
225 aQualifiedName.append( sal_Unicode( ':' ) );
226 aQualifiedName.append( ::xmloff::token::GetXMLToken( i_eToken ) );
227 return aQualifiedName.makeStringAndClear();
230 private:
231 const ::comphelper::ComponentContext& m_rContext;
232 const StorageXMLOutputStream& m_rDelegator;
233 const ::rtl::OUStringBuffer m_aNamespace;
236 //--------------------------------------------------------------------
237 void SettingsExportContext::AddAttribute( enum ::xmloff::token::XMLTokenEnum i_eName, const ::rtl::OUString& i_rValue )
239 m_rDelegator.addAttribute( impl_prefix( i_eName ), i_rValue );
242 //--------------------------------------------------------------------
243 void SettingsExportContext::AddAttribute( enum ::xmloff::token::XMLTokenEnum i_eName, enum ::xmloff::token::XMLTokenEnum i_eValue )
245 m_rDelegator.addAttribute( impl_prefix( i_eName ), ::xmloff::token::GetXMLToken( i_eValue ) );
248 //--------------------------------------------------------------------
249 void SettingsExportContext::StartElement( enum ::xmloff::token::XMLTokenEnum i_eName, const sal_Bool i_bIgnoreWhitespace )
251 if ( i_bIgnoreWhitespace )
252 m_rDelegator.ignorableWhitespace( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " " ) ) );
254 m_rDelegator.startElement( impl_prefix( i_eName ) );
257 //--------------------------------------------------------------------
258 void SettingsExportContext::EndElement( const sal_Bool i_bIgnoreWhitespace )
260 if ( i_bIgnoreWhitespace )
261 m_rDelegator.ignorableWhitespace( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " " ) ) );
262 m_rDelegator.endElement();
265 //--------------------------------------------------------------------
266 void SettingsExportContext::Characters( const ::rtl::OUString& i_rCharacters )
268 m_rDelegator.characters( i_rCharacters );
271 //--------------------------------------------------------------------
272 Reference< XMultiServiceFactory > SettingsExportContext::GetServiceFactory() const
274 return m_rContext.getLegacyServiceFactory();
277 //==================================================================================================================
278 //= SettingsDocumentHandler
279 //==================================================================================================================
280 typedef ::cppu::WeakImplHelper1 < XDocumentHandler
281 > SettingsDocumentHandler_Base;
282 class DBACCESS_DLLPRIVATE SettingsDocumentHandler : public SettingsDocumentHandler_Base
284 public:
285 SettingsDocumentHandler()
289 protected:
290 virtual ~SettingsDocumentHandler()
294 public:
295 // XDocumentHandler
296 virtual void SAL_CALL startDocument( ) throw (SAXException, RuntimeException);
297 virtual void SAL_CALL endDocument( ) throw (SAXException, RuntimeException);
298 virtual void SAL_CALL startElement( const ::rtl::OUString& aName, const Reference< XAttributeList >& xAttribs ) throw (SAXException, RuntimeException);
299 virtual void SAL_CALL endElement( const ::rtl::OUString& aName ) throw (SAXException, RuntimeException);
300 virtual void SAL_CALL characters( const ::rtl::OUString& aChars ) throw (SAXException, RuntimeException);
301 virtual void SAL_CALL ignorableWhitespace( const ::rtl::OUString& aWhitespaces ) throw (SAXException, RuntimeException);
302 virtual void SAL_CALL processingInstruction( const ::rtl::OUString& aTarget, const ::rtl::OUString& aData ) throw (SAXException, RuntimeException);
303 virtual void SAL_CALL setDocumentLocator( const Reference< XLocator >& xLocator ) throw (SAXException, RuntimeException);
305 const ::comphelper::NamedValueCollection& getSettings() const { return m_aSettings; }
307 private:
308 ::std::stack< ::rtl::Reference< SettingsImport > > m_aStates;
309 ::comphelper::NamedValueCollection m_aSettings;
312 //--------------------------------------------------------------------
313 void SAL_CALL SettingsDocumentHandler::startDocument( ) throw (SAXException, RuntimeException)
317 //--------------------------------------------------------------------
318 void SAL_CALL SettingsDocumentHandler::endDocument( ) throw (SAXException, RuntimeException)
322 //--------------------------------------------------------------------
323 void SAL_CALL SettingsDocumentHandler::startElement( const ::rtl::OUString& i_Name, const Reference< XAttributeList >& i_Attribs ) throw (SAXException, RuntimeException)
325 ::rtl::Reference< SettingsImport > pNewState;
327 if ( m_aStates.empty() )
329 if ( i_Name == "office:settings" )
331 pNewState = new OfficeSettingsImport( m_aSettings );
333 else
335 OSL_FAIL( "SettingsDocumentHandler::startElement: invalid settings file!" );
336 // Yes, that's not correct. Somebody could, in theory, give us a document which starts with "foo:settings",
337 // where "foo" is mapped to the proper namespace URL.
338 // However, there's no need to bother with this. The "recovery" sub storage we're recovering from is
339 // not part of ODF, so we can impose any format restrictions on it ...
342 else
344 ::rtl::Reference< SettingsImport > pCurrentState( m_aStates.top() );
345 pNewState = pCurrentState->nextState( i_Name );
348 ENSURE_OR_THROW( pNewState.is(), "no new state - aborting import" );
349 pNewState->startElement( i_Attribs );
351 m_aStates.push( pNewState );
354 //--------------------------------------------------------------------
355 void SAL_CALL SettingsDocumentHandler::endElement( const ::rtl::OUString& i_Name ) throw (SAXException, RuntimeException)
357 ENSURE_OR_THROW( !m_aStates.empty(), "no active element" );
358 (void)i_Name;
360 ::rtl::Reference< SettingsImport > pCurrentState( m_aStates.top() );
361 pCurrentState->endElement();
362 m_aStates.pop();
365 //--------------------------------------------------------------------
366 void SAL_CALL SettingsDocumentHandler::characters( const ::rtl::OUString& i_Chars ) throw (SAXException, RuntimeException)
368 ENSURE_OR_THROW( !m_aStates.empty(), "no active element" );
370 ::rtl::Reference< SettingsImport > pCurrentState( m_aStates.top() );
371 pCurrentState->characters( i_Chars );
374 //--------------------------------------------------------------------
375 void SAL_CALL SettingsDocumentHandler::ignorableWhitespace( const ::rtl::OUString& aWhitespaces ) throw (SAXException, RuntimeException)
377 // ignore them - that's why they're called "ignorable"
378 (void)aWhitespaces;
381 //--------------------------------------------------------------------
382 void SAL_CALL SettingsDocumentHandler::processingInstruction( const ::rtl::OUString& i_Target, const ::rtl::OUString& i_Data ) throw (SAXException, RuntimeException)
384 OSL_FAIL( "SettingsDocumentHandler::processingInstruction: unexpected ..." );
385 (void)i_Target;
386 (void)i_Data;
389 //--------------------------------------------------------------------
390 void SAL_CALL SettingsDocumentHandler::setDocumentLocator( const Reference< XLocator >& i_Locator ) throw (SAXException, RuntimeException)
392 (void)i_Locator;
395 //====================================================================
396 //= SubComponentRecovery
397 //====================================================================
398 //--------------------------------------------------------------------
399 const ::rtl::OUString SubComponentRecovery::getComponentsStorageName( const SubComponentType i_eType )
401 static const ::rtl::OUString s_sFormsStorageName( RTL_CONSTASCII_USTRINGPARAM( "forms" ) );
402 static const ::rtl::OUString s_sReportsStorageName( RTL_CONSTASCII_USTRINGPARAM( "reports" ) );
403 static const ::rtl::OUString s_sTablesStorageName( RTL_CONSTASCII_USTRINGPARAM( "tables" ) );
404 static const ::rtl::OUString s_sQueriesStorageName( RTL_CONSTASCII_USTRINGPARAM( "queries" ) );
405 static const ::rtl::OUString s_sRelationsStorageName( RTL_CONSTASCII_USTRINGPARAM( "relations" ) );
407 switch ( i_eType )
409 case FORM:
410 return s_sFormsStorageName;
411 case REPORT:
412 return s_sReportsStorageName;
413 case TABLE:
414 return s_sTablesStorageName;
415 case QUERY:
416 return s_sQueriesStorageName;
417 case RELATION_DESIGN:
418 return s_sRelationsStorageName;
419 default:
420 break;
423 OSL_FAIL( "SubComponentRecovery::getComponentsStorageName: unimplemented case!" );
424 static const ::rtl::OUString s_sFallback;
425 return s_sFallback;
428 //--------------------------------------------------------------------
429 void SubComponentRecovery::saveToRecoveryStorage( const Reference< XStorage >& i_rRecoveryStorage,
430 MapCompTypeToCompDescs& io_mapCompDescs )
432 if ( m_eType == UNKNOWN )
433 // quite fatal, but has already been reported (as assertion) before
434 return;
436 // open the sub storage for the given kind of components
437 const ::rtl::OUString& rStorageName( getComponentsStorageName( m_eType ) );
438 const Reference< XStorage > xComponentsStorage( i_rRecoveryStorage->openStorageElement(
439 rStorageName, ElementModes::READWRITE ), UNO_QUERY_THROW );
441 // find a free sub storage name, and create Yet Another Sub Storage
442 const ::rtl::OUString& rBaseName( lcl_getComponentStorageBaseName( m_eType ) );
443 const ::rtl::OUString sStorName = ::dbtools::createUniqueName( xComponentsStorage.get(), rBaseName, true );
444 const Reference< XStorage > xObjectStor( xComponentsStorage->openStorageElement(
445 sStorName, ElementModes::READWRITE ), UNO_QUERY_THROW );
447 switch ( m_eType )
449 case FORM:
450 case REPORT:
451 impl_saveSubDocument_throw( xObjectStor );
452 break;
454 case QUERY:
455 impl_saveQueryDesign_throw( xObjectStor );
456 break;
458 default:
459 // TODO
460 OSL_FAIL( "SubComponentRecoverys::saveToRecoveryStorage: unimplemented case!" );
461 break;
464 // commit the storage(s)
465 tools::stor::commitStorageIfWriteable( xObjectStor );
466 tools::stor::commitStorageIfWriteable( xComponentsStorage );
468 // remember the relationship from the component name to the storage name
469 MapStringToCompDesc& rMapCompDescs = io_mapCompDescs[ m_eType ];
470 OSL_ENSURE( rMapCompDescs.find( sStorName ) == rMapCompDescs.end(),
471 "SubComponentRecoverys::saveToRecoveryStorage: object name already used!" );
472 rMapCompDescs[ sStorName ] = m_aCompDesc;
475 //--------------------------------------------------------------------
476 void SubComponentRecovery::impl_identifyComponent_throw()
478 // ask the controller
479 Pair< sal_Int32, ::rtl::OUString > aComponentIdentity = m_xDocumentUI->identifySubComponent( m_xComponent );
480 m_eType = lcl_databaseObjectToSubComponentType( aComponentIdentity.First );
481 m_aCompDesc.sName = aComponentIdentity.Second;
483 // what the controller didn't give us is the information whether this is in edit mode or not ...
484 Reference< XModuleManager2 > xModuleManager( ModuleManager::create(m_rContext.getUNOContext()) );
485 const ::rtl::OUString sModuleIdentifier = xModuleManager->identify( m_xComponent );
487 switch ( m_eType )
489 case TABLE:
490 m_aCompDesc.bForEditing = sModuleIdentifier.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.sdb.TableDesign" ) );
491 break;
493 case QUERY:
494 m_aCompDesc.bForEditing = sModuleIdentifier.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "com.sun.star.sdb.QueryDesign" ) );
495 break;
497 case REPORT:
498 if ( sModuleIdentifier == "com.sun.star.report.ReportDefinition" )
500 // it's an SRB report designer
501 m_aCompDesc.bForEditing = true;
502 break;
504 // fall through
506 case FORM:
507 m_aCompDesc.bForEditing = !lcl_determineReadOnly( m_xComponent );
508 break;
510 default:
511 if ( sModuleIdentifier == "com.sun.star.sdb.RelationDesign" )
513 m_eType = RELATION_DESIGN;
514 m_aCompDesc.bForEditing = true;
516 else
518 OSL_FAIL( "SubComponentRecovery::impl_identifyComponent_throw: couldn't classify the given sub component!" );
520 break;
523 OSL_POSTCOND( m_eType != UNKNOWN,
524 "SubComponentRecovery::impl_identifyComponent_throw: couldn't classify the component!" );
527 //--------------------------------------------------------------------
528 void SubComponentRecovery::impl_saveQueryDesign_throw( const Reference< XStorage >& i_rObjectStorage )
530 ENSURE_OR_THROW( m_eType == QUERY, "illegal sub component type" );
531 ENSURE_OR_THROW( i_rObjectStorage.is(), "illegal storage" );
533 // retrieve the current query design (which might differ from what we can retrieve as ActiveCommand property, since
534 // the latter is updated only upon successful save of the design)
535 Reference< XPropertySet > xDesignerProps( m_xComponent, UNO_QUERY_THROW );
536 Sequence< PropertyValue > aCurrentQueryDesign;
537 OSL_VERIFY( xDesignerProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "CurrentQueryDesign" ) ) ) >>= aCurrentQueryDesign );
539 // write the query design
540 StorageXMLOutputStream aDesignOutput( m_rContext, i_rObjectStorage, lcl_getSettingsStreamName() );
541 SettingsExportContext aSettingsExportContext( m_rContext, aDesignOutput );
543 const ::rtl::OUString sWhitespace( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( " " ) ) );
545 aDesignOutput.startElement( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "office:settings" ) ) );
546 aDesignOutput.ignorableWhitespace( sWhitespace );
548 XMLSettingsExportHelper aSettingsExporter( aSettingsExportContext );
549 aSettingsExporter.exportAllSettings( aCurrentQueryDesign, lcl_getCurrentQueryDesignName() );
551 aDesignOutput.ignorableWhitespace( sWhitespace );
552 aDesignOutput.endElement();
553 aDesignOutput.close();
556 //--------------------------------------------------------------------
557 void SubComponentRecovery::impl_saveSubDocument_throw( const Reference< XStorage >& i_rObjectStorage )
559 ENSURE_OR_THROW( ( m_eType == FORM ) || ( m_eType == REPORT ), "illegal sub component type" );
560 ENSURE_OR_THROW( i_rObjectStorage.is(), "illegal storage" );
562 // store the document into the storage
563 Reference< XStorageBasedDocument > xStorageDocument( m_xComponent, UNO_QUERY_THROW );
564 xStorageDocument->storeToStorage( i_rObjectStorage, Sequence< PropertyValue >() );
567 //--------------------------------------------------------------------
568 Reference< XComponent > SubComponentRecovery::impl_recoverSubDocument_throw( const Reference< XStorage >& i_rRecoveryStorage,
569 const ::rtl::OUString& i_rComponentName, const bool i_bForEditing )
571 Reference< XComponent > xSubComponent;
572 Reference< XCommandProcessor > xDocDefinition;
574 ::comphelper::NamedValueCollection aLoadArgs;
575 aLoadArgs.put( "RecoveryStorage", i_rRecoveryStorage );
577 // load/create the sub component hidden. We'll show it when the main app window is shown.
578 aLoadArgs.put( "Hidden", true );
580 if ( !i_rComponentName.isEmpty() )
582 xDocDefinition = lcl_getSubComponentDef_nothrow( m_xDocumentUI, m_eType, i_rComponentName );
583 xSubComponent.set( m_xDocumentUI->loadComponentWithArguments(
584 m_eType,
585 i_rComponentName,
586 i_bForEditing,
587 aLoadArgs.getPropertyValues()
589 UNO_SET_THROW
592 else
594 Reference< XComponent > xDocDefComponent;
595 xSubComponent.set( m_xDocumentUI->createComponentWithArguments(
596 m_eType,
597 aLoadArgs.getPropertyValues(),
598 xDocDefComponent
600 UNO_SET_THROW
603 xDocDefinition.set( xDocDefComponent, UNO_QUERY );
604 OSL_ENSURE( xDocDefinition.is(), "DatabaseDocumentRecovery::recoverSubDocuments: loaded a form/report, but don't have a document definition?!" );
607 if ( xDocDefinition.is() )
609 Reference< XController > xController( m_xDocumentUI, UNO_QUERY_THROW );
610 Reference< XInterface > xLoader( *new SubComponentLoader( xController, xDocDefinition ) );
611 (void)xLoader;
614 return xSubComponent;
617 //--------------------------------------------------------------------
618 Reference< XComponent > SubComponentRecovery::impl_recoverQueryDesign_throw( const Reference< XStorage >& i_rRecoveryStorage,
619 const ::rtl::OUString& i_rComponentName, const bool i_bForEditing )
621 Reference< XComponent > xSubComponent;
623 // first read the settings query design settings from the storage
624 StorageXMLInputStream aDesignInput( m_rContext, i_rRecoveryStorage, lcl_getSettingsStreamName() );
626 ::rtl::Reference< SettingsDocumentHandler > pDocHandler( new SettingsDocumentHandler );
627 aDesignInput.import( pDocHandler.get() );
629 const ::comphelper::NamedValueCollection& rSettings( pDocHandler->getSettings() );
630 const Any aCurrentQueryDesign = rSettings.get( lcl_getCurrentQueryDesignName() );
631 #if OSL_DEBUG_LEVEL > 0
632 Sequence< PropertyValue > aQueryDesignLayout;
633 OSL_VERIFY( aCurrentQueryDesign >>= aQueryDesignLayout );
634 #endif
636 // then load the query designer
637 ::comphelper::NamedValueCollection aLoadArgs;
638 aLoadArgs.put( "CurrentQueryDesign", aCurrentQueryDesign );
639 aLoadArgs.put( "Hidden", true );
641 if ( !i_rComponentName.isEmpty() )
643 xSubComponent.set( m_xDocumentUI->loadComponentWithArguments(
644 m_eType,
645 i_rComponentName,
646 i_bForEditing,
647 aLoadArgs.getPropertyValues()
649 UNO_SET_THROW
652 else
654 Reference< XComponent > xDummy;
655 xSubComponent.set( m_xDocumentUI->createComponentWithArguments(
656 m_eType,
657 aLoadArgs.getPropertyValues(),
658 xDummy
660 UNO_SET_THROW
664 Reference< XController > xController( m_xDocumentUI, UNO_QUERY_THROW );
665 Reference< XInterface > xLoader( *new SubComponentLoader( xController, xSubComponent ) );
666 (void)xLoader;
668 return xSubComponent;
671 //--------------------------------------------------------------------
672 Reference< XComponent > SubComponentRecovery::recoverFromStorage( const Reference< XStorage >& i_rRecoveryStorage,
673 const ::rtl::OUString& i_rComponentName, const bool i_bForEditing )
675 Reference< XComponent > xSubComponent;
676 switch ( m_eType )
678 case FORM:
679 case REPORT:
680 xSubComponent = impl_recoverSubDocument_throw( i_rRecoveryStorage, i_rComponentName, i_bForEditing );
681 break;
682 case QUERY:
683 xSubComponent = impl_recoverQueryDesign_throw( i_rRecoveryStorage, i_rComponentName, i_bForEditing );
684 break;
685 default:
686 OSL_FAIL( "SubComponentRecovery::recoverFromStorage: unimplemented case!" );
687 break;
689 return xSubComponent;
692 //........................................................................
693 } // namespace dbaccess
694 //........................................................................
696 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */