Tag: odbmacros_2_5 User: fs Date: 2008-02-27 14:39:24+0000 Modified: dba/dbaccess/source/ext/macromigration/migrationengine.cxx dba/dbaccess/source/ext/macromigration/migrationengine.hxx
Log: properly load the documents, and do some logging File Changes: Directory: /dba/dbaccess/source/ext/macromigration/ =================================================== File [changed]: migrationengine.cxx Url: http://dba.openoffice.org/source/browse/dba/dbaccess/source/ext/macromigration/migrationengine.cxx?r1=1.1.2.2&r2=1.1.2.3 Delta lines: +128 -21 ---------------------- --- migrationengine.cxx 2008-02-14 22:25:00+0000 1.1.2.2 +++ migrationengine.cxx 2008-02-27 14:39:21+0000 1.1.2.3 @@ -4,9 +4,9 @@ * * $RCSfile: migrationengine.cxx,v $ * - * $Revision: 1.1.2.2 $ + * $Revision: 1.1.2.3 $ * - * last change: $Author: fs $ $Date: 2008/02/14 22:25:00 $ + * last change: $Author: fs $ $Date: 2008/02/27 14:39:21 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -38,19 +38,29 @@ #include "dbmm_global.hrc" #include "dbmm_module.hxx" +#include "dbmm_types.hxx" #include "docerrorhandling.hxx" #include "migrationengine.hxx" #include "migrationprogress.hxx" +#include "migrationlog.hxx" +#include "progresscapture.hxx" /** === begin UNO includes === **/ #include <com/sun/star/sdb/XFormDocumentsSupplier.hpp> #include <com/sun/star/sdb/XReportDocumentsSupplier.hpp> +#include <com/sun/star/util/XCloseable.hpp> +#include <com/sun/star/frame/XModel.hpp> +#include <com/sun/star/frame/XComponentLoader.hpp> +#include <com/sun/star/ucb/XCommandProcessor.hpp> +#include <com/sun/star/embed/XComponentSupplier.hpp> /** === end UNO includes === **/ #include <comphelper/string.hxx> +#include <comphelper/namedvaluecollection.hxx> #include <tools/string.hxx> #include <tools/diagnose_ex.h> #include <rtl/ustrbuf.hxx> +#include <rtl/ref.hxx> #include <vector> @@ -76,26 +86,30 @@ using ::com::sun::star::sdb::XReportDocumentsSupplier; using ::com::sun::star::container::XNameAccess; using ::com::sun::star::uno::Sequence; + using ::com::sun::star::util::XCloseable; + using ::com::sun::star::util::CloseVetoException; + using ::com::sun::star::lang::XComponent; + using ::com::sun::star::frame::XModel; + using ::com::sun::star::frame::XComponentLoader; + using ::com::sun::star::ucb::XCommandProcessor; + using ::com::sun::star::ucb::Command; + using ::com::sun::star::embed::XComponentSupplier; + using ::com::sun::star::task::XStatusIndicator; /** === end UNO using === **/ //==================================================================== - //= helpers + //= SubDocument //==================================================================== - - enum SubDocumentType - { - eForm, - eReport - }; - struct SubDocument { - SubDocumentType eType; - ::rtl::OUString sHierarchicalName; + const Reference< XCommandProcessor > xCommandProcessor; + const ::rtl::OUString sHierarchicalName; + const SubDocumentType eType; - SubDocument( const SubDocumentType _eType, const ::rtl::OUString& _rName ) - :eType( _eType ) + SubDocument( const Reference< XCommandProcessor >& _rxCommandProcessor, const ::rtl::OUString& _rName, const SubDocumentType _eType ) + :xCommandProcessor( _rxCommandProcessor ) ,sHierarchicalName( _rName ) + ,eType( _eType ) { } }; @@ -111,7 +125,8 @@ MigrationEngine_Impl( const ::comphelper::ComponentContext& _rContext, const Reference< XOfficeDatabaseDocument >& _rxDocument, - IMigrationProgress& _rProgress + IMigrationProgress& _rProgress, + MigrationLog& _rLogger ); ~MigrationEngine_Impl(); @@ -123,6 +138,7 @@ ::comphelper::ComponentContext m_aContext; const Reference< XOfficeDatabaseDocument > m_xDocument; IMigrationProgress& m_rProgress; + MigrationLog& m_rLogger; SubDocuments m_aSubDocs; size_t m_nFormCount; size_t m_nReportCount; @@ -150,10 +166,11 @@ //==================================================================== //-------------------------------------------------------------------- MigrationEngine_Impl::MigrationEngine_Impl( const ::comphelper::ComponentContext& _rContext, - const Reference< XOfficeDatabaseDocument >& _rxDocument, IMigrationProgress& _rProgress ) + const Reference< XOfficeDatabaseDocument >& _rxDocument, IMigrationProgress& _rProgress, MigrationLog& _rLogger ) :m_aContext( _rContext ) ,m_xDocument( _rxDocument ) ,m_rProgress( _rProgress ) + ,m_rLogger( _rLogger ) ,m_aSubDocs() ,m_nFormCount( 0 ) ,m_nReportCount( 0 ) @@ -235,10 +252,15 @@ } else { - _out_rDocs.push_back( SubDocument( _eType, sElementName ) ); + Reference< XCommandProcessor > xCommandProcessor( aElement, UNO_QUERY ); + OSL_ENSURE( xCommandProcessor.is(), "lcl_collectHierarchicalElementNames_throw: no container, and no comand processor? What *is* it, then?!" ); + if ( xCommandProcessor.is() ) + { + _out_rDocs.push_back( SubDocument( xCommandProcessor, sElementName, _eType ) ); ++nAddedElements; } } + } return nAddedElements; } } @@ -269,19 +291,103 @@ } //-------------------------------------------------------------------- + namespace + { + //................................................................ + static void lcl_disposeComponent_nothrow( const Reference< XCommandProcessor >& _rxCommandProc ) + { + OSL_PRECOND( _rxCommandProc.is(), "lcl_disposeComponent_nothrow: illegal object!" ); + if ( !_rxCommandProc.is() ) + return; + + bool bCouldClose = false; + try + { + Command aCommand; + aCommand.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "shutdown" ) ); + OSL_VERIFY( _rxCommandProc->execute( + aCommand, _rxCommandProc->createCommandIdentifier(), NULL ) >>= bCouldClose ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + if ( !bCouldClose ) + { + ; + // TODO: can we handle this somehow? + } + } + + //................................................................ + static Reference< XModel > lcl_loadSubDocument_nothrow( const SubDocument& _rDocument, + const Reference< XStatusIndicator >& _rxProgress ) + { + Reference< XModel > xDocument; + + try + { + ::comphelper::NamedValueCollection aLoadArgs; + aLoadArgs.put( "Hidden", (sal_Bool)sal_True ); + aLoadArgs.put( "StatusIndicator", _rxProgress ); + + Reference< XCommandProcessor > xCommandProcessor( _rDocument.xCommandProcessor, UNO_SET_THROW ); + Command aCommand; + aCommand.Name = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "openDesign" ) ); + aCommand.Argument <<= aLoadArgs.getPropertyValues(); + Reference< XComponent > xDocComponent( + xCommandProcessor->execute( + aCommand, xCommandProcessor->createCommandIdentifier(), NULL + ), + UNO_QUERY + ); + OSL_ENSURE( xDocComponent.is(), "lcl_loadSubDocument_nothrow: no component loaded!" ); + + xDocument.set( xDocComponent, UNO_QUERY_THROW ); + } + catch( const Exception& ) + { + // TODO: how to proceed? + DBG_UNHANDLED_EXCEPTION(); + } + + return xDocument; + } + } + + //-------------------------------------------------------------------- bool MigrationEngine_Impl::impl_handleDocument_nothrow( const SubDocument& _rDocument ) const { + DocumentID nDocID = m_rLogger.startedDocument( _rDocument.eType, _rDocument.sHierarchicalName ); + // start the progress ::rtl::OUString aProgress; aProgress = String( MacroMigrationResId( _rDocument.eType == eForm ? STR_FORM : STR_REPORT ) ); ::comphelper::string::searchAndReplaceAsciiI( aProgress, "$name$", _rDocument.sHierarchicalName ); m_rProgress.startObject( aProgress, ::rtl::OUString(), DEFAULT_DOC_PROGRESS_RANGE ); + // load the document + ::rtl::Reference< ProgressCapture > pStatusIndicator( new ProgressCapture( aProgress, m_rProgress ) ); + Reference< XModel > xDocument( lcl_loadSubDocument_nothrow( _rDocument, pStatusIndicator.get() ) ); + if ( !xDocument.is() ) + { + pStatusIndicator->dispose(); + m_rProgress.endObject(); + m_rLogger.finishedDocument( nDocID, false ); + // TODO: log the *reason* for the failure + return false; + } + // TODO - // end the progress + // clean up + lcl_disposeComponent_nothrow( _rDocument.xCommandProcessor ); + pStatusIndicator->dispose(); + + // end the progress, just in case the ProgressCapture didn't receive the XStatusIndicator::end event m_rProgress.endObject(); + m_rLogger.finishedDocument( nDocID, true ); return true; } @@ -295,8 +401,9 @@ //= MigrationEngine //==================================================================== //-------------------------------------------------------------------- - MigrationEngine::MigrationEngine( const ::comphelper::ComponentContext& _rContext, const Reference< XOfficeDatabaseDocument >& _rxDocument, IMigrationProgress& _rProgress ) - :m_pImpl( new MigrationEngine_Impl( _rContext, _rxDocument, _rProgress ) ) + MigrationEngine::MigrationEngine( const ::comphelper::ComponentContext& _rContext, const Reference< XOfficeDatabaseDocument >& _rxDocument, + IMigrationProgress& _rProgress, MigrationLog& _rLogger ) + :m_pImpl( new MigrationEngine_Impl( _rContext, _rxDocument, _rProgress, _rLogger ) ) { } File [changed]: migrationengine.hxx Url: http://dba.openoffice.org/source/browse/dba/dbaccess/source/ext/macromigration/migrationengine.hxx?r1=1.1.2.2&r2=1.1.2.3 Delta lines: +5 -3 ------------------- --- migrationengine.hxx 2008-02-14 22:25:00+0000 1.1.2.2 +++ migrationengine.hxx 2008-02-27 14:39:22+0000 1.1.2.3 @@ -4,9 +4,9 @@ * * $RCSfile: migrationengine.hxx,v $ * - * $Revision: 1.1.2.2 $ + * $Revision: 1.1.2.3 $ * - * last change: $Author: fs $ $Date: 2008/02/14 22:25:00 $ + * last change: $Author: fs $ $Date: 2008/02/27 14:39:22 $ * * The Contents of this file are made available subject to * the terms of GNU Lesser General Public License Version 2.1. @@ -54,6 +54,7 @@ //........................................................................ class IMigrationProgress; + class MigrationLog; //==================================================================== //= MigrationEngine @@ -72,7 +73,8 @@ MigrationEngine( const ::comphelper::ComponentContext& _rContext, const ::com::sun::star::uno::Reference< ::com::sun::star::sdb::XOfficeDatabaseDocument >& _rxDocument, - IMigrationProgress& _rProgress + IMigrationProgress& _rProgress, + MigrationLog& _rLogger ); ~MigrationEngine(); --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
