Tag: cws_dev300_odbmacros3 User: fs Date: 2008-04-23 13:29:44+0000 Modified: dba/dbaccess/source/ext/macromigration/migrationengine.cxx
Log: #i49133# adjust script references in the sub documents 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.4.2.3&r2=1.4.2.4 Delta lines: +462 -57 ---------------------- --- migrationengine.cxx 2008-04-21 21:23:24+0000 1.4.2.3 +++ migrationengine.cxx 2008-04-23 13:29:42+0000 1.4.2.4 @@ -7,7 +7,7 @@ * OpenOffice.org - a multi-platform office productivity suite * * $RCSfile: migrationengine.cxx,v $ - * $Revision: 1.4.2.3 $ + * $Revision: 1.4.2.4 $ * * This file is part of OpenOffice.org. * @@ -57,6 +57,13 @@ #include <com/sun/star/script/DocumentScriptLibraryContainer.hpp> #include <com/sun/star/script/DocumentDialogLibraryContainer.hpp> #include <com/sun/star/document/XEmbeddedScripts.hpp> +#include <com/sun/star/document/XEventsSupplier.hpp> +#include <com/sun/star/uri/UriReferenceFactory.hpp> +#include <com/sun/star/uri/XVndSunStarScriptUrlReference.hpp> +#include <com/sun/star/form/XFormsSupplier.hpp> +#include <com/sun/star/drawing/XDrawPageSupplier.hpp> +#include <com/sun/star/drawing/XDrawPagesSupplier.hpp> +#include <com/sun/star/script/XEventAttacherManager.hpp> /** === end UNO includes === **/ #include <comphelper/string.hxx> @@ -112,6 +119,19 @@ using ::com::sun::star::script::XStorageBasedLibraryContainer; using ::com::sun::star::document::XEmbeddedScripts; using ::com::sun::star::container::XNameContainer; + using ::com::sun::star::document::XEventsSupplier; + using ::com::sun::star::container::XNameReplace; + using com::sun::star::uri::UriReferenceFactory; + using com::sun::star::uri::XUriReferenceFactory; + using com::sun::star::uri::XVndSunStarScriptUrlReference; + using ::com::sun::star::form::XFormsSupplier; + using ::com::sun::star::drawing::XDrawPageSupplier; + using ::com::sun::star::drawing::XDrawPagesSupplier; + using ::com::sun::star::drawing::XDrawPage; + using ::com::sun::star::drawing::XDrawPages; + using ::com::sun::star::container::XIndexAccess; + using ::com::sun::star::script::XEventAttacherManager; + using ::com::sun::star::script::ScriptEventDescriptor; /** === end UNO using === **/ namespace ElementModes = ::com::sun::star::embed::ElementModes; @@ -129,11 +149,13 @@ struct SubDocument { Reference< XCommandProcessor > xCommandProcessor; + Reference< XModel > xDocument; // valid only temporarily ::rtl::OUString sHierarchicalName; SubDocumentType eType; SubDocument( const Reference< XCommandProcessor >& _rxCommandProcessor, const ::rtl::OUString& _rName, const SubDocumentType _eType ) :xCommandProcessor( _rxCommandProcessor ) + ,xDocument() ,sHierarchicalName( _rName ) ,eType( _eType ) { @@ -181,6 +203,40 @@ } //---------------------------------------------------------------- + static bool lcl_getScriptTypeFromLanguage( const ::rtl::OUString& _rLanguage, ScriptType& _out_rScriptType ) + { + struct LanguageMapping + { + const sal_Char* pAsciiLanguage; + const ScriptType eScriptType; + + LanguageMapping( const sal_Char* _pAsciiLanguage, const ScriptType _eScriptType ) + :pAsciiLanguage( _pAsciiLanguage ) + ,eScriptType( _eScriptType ) + { + } + } + aLanguageMapping[] = + { + LanguageMapping( "JavaScript", eJavaScript ), + LanguageMapping( "BeanShell", eBeanShell ), // TODO: is this correct? + LanguageMapping( "Java", eJava ), // TODO: is this correct? + LanguageMapping( "Python", ePython ), // TODO: is this correct? + LanguageMapping( "Basic", eBasic ) + }; + for ( size_t i=0; i < sizeof( aLanguageMapping ) / sizeof( aLanguageMapping[0] ); ++i ) + { + if ( _rLanguage.equalsAscii( aLanguageMapping[i].pAsciiLanguage ) ) + { + _out_rScriptType = aLanguageMapping[i].eScriptType; + return true; + } + } + OSL_ENSURE( false, "lcl_getScriptTypeFromLanguage: unknown language!" ); + return false; + } + + //---------------------------------------------------------------- static Any lcl_executeCommand_throw( const Reference< XCommandProcessor >& _rxCommandProc, const sal_Char* _pAsciiCommand ) { @@ -195,29 +251,10 @@ } //---------------------------------------------------------------- - static void lcl_closeComponent_nothrow( const Reference< XCommandProcessor >& _rxCommandProc ) - { - bool bCouldClose = false; - try - { - OSL_VERIFY( lcl_executeCommand_throw( _rxCommandProc, "close" ) >>= bCouldClose ); - } - catch( const Exception& ) - { - DBG_UNHANDLED_EXCEPTION(); - } - if ( !bCouldClose ) - { - ; - // TODO: can we handle this somehow? - } - } - - //---------------------------------------------------------------- - static Reference< XModel > lcl_loadSubDocument_nothrow( const SubDocument& _rDocument, + static bool lcl_loadSubDocument_nothrow( SubDocument& _rDocument, const Reference< XStatusIndicator >& _rxProgress ) { - Reference< XModel > xDocument; + OSL_PRECOND( !_rDocument.xDocument.is(), "lcl_loadSubDocument_nothrow: already loaded!" ); try { @@ -237,15 +274,34 @@ ); OSL_ENSURE( xDocComponent.is(), "lcl_loadSubDocument_nothrow: no component loaded!" ); - xDocument.set( xDocComponent, UNO_QUERY_THROW ); + _rDocument.xDocument.set( xDocComponent, UNO_QUERY_THROW ); } catch( const Exception& ) { // TODO: how to proceed? DBG_UNHANDLED_EXCEPTION(); } + return _rDocument.xDocument.is(); + } - return xDocument; + //---------------------------------------------------------------- + static void lcl_unloadSubDocument_nothrow( SubDocument& _rDocument ) + { + bool bCouldClose = false; + try + { + OSL_VERIFY( lcl_executeCommand_throw( _rDocument.xCommandProcessor, "close" ) >>= bCouldClose ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + if ( !bCouldClose ) + { + ; + // TODO: can we handle this somehow? + } + _rDocument.xDocument.clear(); } //---------------------------------------------------------------- @@ -313,6 +369,136 @@ } //==================================================================== + //= DrawPageIterator + //==================================================================== + class DrawPageIterator + { + public: + DrawPageIterator( const Reference< XModel >& _rxDocument ) + :m_xDocument( _rxDocument ) + ,m_nPageCount( 0 ) + ,m_nCurrentPage( 0 ) + { + Reference< XDrawPageSupplier > xSingle( _rxDocument, UNO_QUERY ); + Reference< XDrawPagesSupplier > xMulti( _rxDocument, UNO_QUERY ); + if ( xSingle.is() ) + { + m_xSinglePage.set( xSingle->getDrawPage(), UNO_SET_THROW ); + m_nPageCount = 1; + } + else if ( xMulti.is() ) + { + m_xMultiPages.set( xMulti->getDrawPages(), UNO_SET_THROW ); + m_nPageCount = m_xMultiPages->getCount(); + } + } + + bool hasMore() const + { + return m_nCurrentPage < m_nPageCount; + } + + Reference< XDrawPage > next() + { + Reference< XDrawPage > xNextPage; + + if ( m_xSinglePage.is() ) + { + xNextPage = m_xSinglePage; + } + else if ( m_xMultiPages.is() ) + { + xNextPage.set( m_xMultiPages->getByIndex( m_nCurrentPage ), UNO_QUERY_THROW ); + } + ++m_nCurrentPage; + return xNextPage; + } + + private: + const Reference< XModel > m_xDocument; + Reference< XDrawPage > m_xSinglePage; + Reference< XDrawPages > m_xMultiPages; + sal_Int32 m_nPageCount; + sal_Int32 m_nCurrentPage; + }; + + //==================================================================== + //= FormComponentScripts + //==================================================================== + class FormComponentScripts + { + public: + FormComponentScripts( + const Reference< XInterface >& _rxComponent, + const Reference< XEventAttacherManager >& _rxManager, + const sal_Int32 _nIndex + ) + :m_xComponent( _rxComponent, UNO_SET_THROW ) + ,m_xManager( _rxManager, UNO_SET_THROW ) + ,m_nIndex( _nIndex ) + { + } + + Sequence< ScriptEventDescriptor > getEvents() const + { + return m_xManager->getScriptEvents( m_nIndex ); + } + + void setEvents( const Sequence< ScriptEventDescriptor >& _rEvents ) const + { + m_xManager->registerScriptEvents( m_nIndex, _rEvents ); + } + + const Reference< XInterface >& getComponent() const + { + return m_xComponent; + } + + private: + const Reference< XInterface > m_xComponent; + const Reference< XEventAttacherManager > m_xManager; + const sal_Int32 m_nIndex; + }; + + //==================================================================== + //= FormComponentIterator + //==================================================================== + class FormComponentIterator + { + public: + FormComponentIterator( const Reference< XIndexAccess >& _rxContainer ) + :m_xContainer( _rxContainer, UNO_SET_THROW ) + ,m_xEventManager( _rxContainer, UNO_QUERY_THROW ) + ,m_nElementCount( _rxContainer->getCount() ) + ,m_nCurrentElement( 0 ) + { + } + + bool hasMore() const + { + return m_nCurrentElement < m_nElementCount; + } + + FormComponentScripts next() + { + FormComponentScripts aComponent( + Reference< XInterface >( m_xContainer->getByIndex( m_nCurrentElement ), UNO_QUERY_THROW ), + m_xEventManager, + m_nCurrentElement + ); + ++m_nCurrentElement; + return aComponent; + } + + private: + const Reference< XIndexAccess > m_xContainer; + const Reference< XEventAttacherManager > m_xEventManager; + const sal_Int32 m_nElementCount; + sal_Int32 m_nCurrentElement; + + }; + + //==================================================================== //= ScriptsStorage - declaration //==================================================================== /** a helper class which encapsulates access to the storages for Java/Script, BeanShell, and Python scripts, @@ -566,11 +752,6 @@ */ bool impl_collectSubDocuments_nothrow(); - /** reports the given error (usually an exception caught on the caller's side) - to the user, using the document's interaction handler, if any. - */ - void impl_reportError_nothrow( const Any& _rError ) const; - /** migrates the macros/scripts of the given sub document */ bool impl_handleDocument_nothrow( const SubDocument& _rDocument ) const; @@ -579,7 +760,6 @@ */ bool impl_migrateScriptStorage_nothrow( const SubDocument& _rDocument, - const Reference< XModel >& _rxDocument, const ScriptType _eScriptType, ProgressMixer& _rProgress, const PhaseID _nPhaseID @@ -589,11 +769,38 @@ */ bool impl_migrateContainerLibraries_nothrow( const SubDocument& _rDocument, - const Reference< XModel >& _rxDocument, const ScriptType _eScriptType, ProgressMixer& _rProgress, const PhaseID _nPhaseID ) const; + + /** adjust the document-events which refer to macros/scripts in the document, taking into + account the new names of the moved libraries + */ + bool impl_adjustDocumentEvents_nothrow( + const SubDocument& _rDocument + ) const; + + /** adjusts the script references bound to form component events + */ + bool impl_AdjustFormComponentEvents_nothrow( + const SubDocument& _rDocument + ) const; + + /** adjusts the script references for the elements of the given form component container + */ + void impl_AdjustFormComponentEvents_throw( const Reference< XIndexAccess >& _rxComponentContainer ) const; + + /** adjusts the library name in the given script URL, so that it reflects + the new name of the library + */ + bool impl_adjustScriptLibrary_nothrow( + const ::rtl::OUString& _rScriptType, + ::rtl::OUString& _inout_rScriptCode + ) const; + + bool impl_adjustScriptLibrary_nothrow( Any& _inout_rScriptDescriptor ) const; + bool impl_adjustScriptLibrary_nothrow( ScriptEventDescriptor& _inout_rScriptEvent ) const; }; //==================================================================== @@ -755,8 +962,8 @@ // ----------------- // load the document ::rtl::Reference< ProgressCapture > pStatusIndicator( new ProgressCapture( sObjectName, m_rProgress ) ); - Reference< XModel > xSubDocument( lcl_loadSubDocument_nothrow( _rDocument, pStatusIndicator.get() ) ); - if ( !xSubDocument.is() ) + SubDocument aSubDocument( _rDocument ); + if ( !lcl_loadSubDocument_nothrow( aSubDocument, pStatusIndicator.get() ) ) { pStatusIndicator->dispose(); m_rProgress.endObject(); @@ -775,32 +982,36 @@ aProgressMixer.registerPhase( PHASE_PYTHON, 1 ); aProgressMixer.registerPhase( PHASE_JAVA, 1 ); aProgressMixer.registerPhase( PHASE_BASIC, 5 ); - // more weight than then others, assuming their usually are much Basic macros than any other scripts + // more weight than then others, assuming usually, there are much more Basic macros than any other scripts aProgressMixer.registerPhase( PHASE_DIALOGS, 1 ); // migrate storage-based script libraries (which can be handled by mere storage operations) bool bSuccess = - impl_migrateScriptStorage_nothrow( _rDocument, xSubDocument, eJavaScript, aProgressMixer, PHASE_JAVASCRIPT ) - && impl_migrateScriptStorage_nothrow( _rDocument, xSubDocument, eBeanShell, aProgressMixer, PHASE_BEANSHELL ) - && impl_migrateScriptStorage_nothrow( _rDocument, xSubDocument, ePython, aProgressMixer, PHASE_PYTHON ) - && impl_migrateScriptStorage_nothrow( _rDocument, xSubDocument, eJava, aProgressMixer, PHASE_JAVA ); + impl_migrateScriptStorage_nothrow( aSubDocument, eJavaScript, aProgressMixer, PHASE_JAVASCRIPT ) + && impl_migrateScriptStorage_nothrow( aSubDocument, eBeanShell, aProgressMixer, PHASE_BEANSHELL ) + && impl_migrateScriptStorage_nothrow( aSubDocument, ePython, aProgressMixer, PHASE_PYTHON ) + && impl_migrateScriptStorage_nothrow( aSubDocument, eJava, aProgressMixer, PHASE_JAVA ); // migrate Basic and dialog libraries bSuccess = bSuccess - && impl_migrateContainerLibraries_nothrow( _rDocument, xSubDocument, eBasic, aProgressMixer, PHASE_BASIC ) - && impl_migrateContainerLibraries_nothrow( _rDocument, xSubDocument, eDialog, aProgressMixer, PHASE_DIALOGS ); + && impl_migrateContainerLibraries_nothrow( aSubDocument, eBasic, aProgressMixer, PHASE_BASIC ) + && impl_migrateContainerLibraries_nothrow( aSubDocument, eDialog, aProgressMixer, PHASE_DIALOGS ); - // TODO: more to come + // adjust the events in the document + // (note that errors are ignored here - failure to convert a script reference + // is not considered a critical error) + impl_adjustDocumentEvents_nothrow( aSubDocument ); + impl_AdjustFormComponentEvents_nothrow( aSubDocument ); // ----------------- // clean up // store the sub document, including removal of the (now obsolete) "Scripts" sub folder bSuccess = bSuccess - && ScriptsStorage::removeFromDocument( xSubDocument ) - && lcl_commitDocumentStorage_nothrow( xSubDocument ) - && lcl_storeEmbeddedDocument_nothrow( _rDocument ); + && ScriptsStorage::removeFromDocument( aSubDocument.xDocument ) + && lcl_commitDocumentStorage_nothrow( aSubDocument.xDocument ) + && lcl_storeEmbeddedDocument_nothrow( aSubDocument ); - lcl_closeComponent_nothrow( _rDocument.xCommandProcessor ); + lcl_unloadSubDocument_nothrow( aSubDocument ); pStatusIndicator->dispose(); // end the progress, just in case the ProgressCapture didn't receive the XStatusIndicator::end event @@ -845,11 +1056,11 @@ } //-------------------------------------------------------------------- - bool MigrationEngine_Impl::impl_migrateScriptStorage_nothrow( const SubDocument& _rDocument, const Reference< XModel >& _rxDocument, + bool MigrationEngine_Impl::impl_migrateScriptStorage_nothrow( const SubDocument& _rDocument, const ScriptType _eScriptType, ProgressMixer& _rProgress, const PhaseID _nPhaseID ) const { - OSL_PRECOND( _rxDocument.is(), "MigrationEngine_Impl::impl_migrateScriptStorage_nothrow: invalid document!" ); - if ( !_rxDocument.is() ) + OSL_PRECOND( _rDocument.xDocument.is(), "MigrationEngine_Impl::impl_migrateScriptStorage_nothrow: invalid document!" ); + if ( !_rDocument.xDocument.is() ) return false; ScriptsStorage aDatabaseScripts; @@ -860,7 +1071,7 @@ try { // the root storage of the document whose scripts are to be migrated - ScriptsStorage aDocStorage( _rxDocument, ScriptsStorage::WRITE ); + ScriptsStorage aDocStorage( _rDocument.xDocument, ScriptsStorage::WRITE ); if ( !aDocStorage.isValid() || !aDocStorage.hasScripts( _eScriptType ) ) @@ -946,8 +1157,7 @@ //-------------------------------------------------------------------- bool MigrationEngine_Impl::impl_migrateContainerLibraries_nothrow( const SubDocument& _rDocument, - const Reference< XModel >& _rxDocument, const ScriptType _eScriptType, - ProgressMixer& _rProgress, const PhaseID _nPhaseID ) const + const ScriptType _eScriptType, ProgressMixer& _rProgress, const PhaseID _nPhaseID ) const { OSL_PRECOND( ( _eScriptType == eBasic ) || ( _eScriptType == eDialog ), "MigrationEngine_Impl::impl_migrateContainerLibraries_nothrow: illegal script type!" ); @@ -955,7 +1165,7 @@ try { // access library container of the sub document - Reference< XEmbeddedScripts > xSubDocScripts( _rxDocument, UNO_QUERY ); + Reference< XEmbeddedScripts > xSubDocScripts( _rDocument.xDocument, UNO_QUERY ); if ( !xSubDocScripts.is() ) // no script support in the sub document -> nothing to migrate // (though ... this is suspicious, at least ...) @@ -1056,15 +1266,210 @@ { DBG_UNHANDLED_EXCEPTION(); // TODO: can we handle this? Do we need to revert the changes? + return false; } return true; } //-------------------------------------------------------------------- - void MigrationEngine_Impl::impl_reportError_nothrow( const Any& _rError ) const + bool MigrationEngine_Impl::impl_adjustScriptLibrary_nothrow( const ::rtl::OUString& _rScriptType, + ::rtl::OUString& _inout_rScriptCode ) const { - DocumentErrorHandling::reportError( m_aContext, m_xDocument, _rError ); + try + { + if ( !_rScriptType.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "Script" ) ) + || !_rScriptType.getLength() + ) + { + OSL_ENSURE( false, + "MigrationEngine_Impl::impl_adjustScriptLibrary_nothrow: no or unknown script type!" ); + return false; + } + + if ( !_inout_rScriptCode.getLength() ) + { + OSL_ENSURE( false, + "MigrationEngine_Impl::impl_adjustScriptLibrary_nothrow: invalid script!" ); + return false; + } + // analyze the script URI + Reference< XUriReferenceFactory > xUriRefFac = UriReferenceFactory::create( m_aContext.getUNOContext() ); + Reference< XVndSunStarScriptUrlReference > xUri( xUriRefFac->parse( _inout_rScriptCode ), UNO_QUERY_THROW ); + + ::rtl::OUString sScriptLanguage = xUri->getParameter( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "language" ) ) ); + ScriptType eScriptType = eBasic; + if ( !lcl_getScriptTypeFromLanguage( sScriptLanguage, eScriptType ) ) + { + OSL_ENSURE( false, + "MigrationEngine_Impl::impl_adjustScriptLibrary_nothrow: unknown script language!" ); + return false; + } + + ::rtl::OUString sLocation = xUri->getParameter( + ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "location" ) ) ); + if ( !sLocation.equalsAscii( "document" ) ) + { + // only document libraries have been migrated, of course + return false; + } + + ::rtl::OUString sScriptName = xUri->getName(); + sal_Int32 nLibModuleSeparator = sScriptName.indexOf( '.' ); + if ( nLibModuleSeparator < 0 ) + { + OSL_ENSURE( false, + "MigrationEngine_Impl::impl_adjustScriptLibrary_nothrow: invalid/unknown location format!" ); + return false; + } + + // replace the library name + ::rtl::OUString sLibrary = sScriptName.copy( 0, nLibModuleSeparator ); + ::rtl::OUString sNewLibName = m_rLogger.getNewLibraryName( + m_nCurrentDocumentID, eScriptType, sLibrary ); + OSL_ENSURE( sLibrary != sNewLibName, + "MigrationEngine_Impl::impl_adjustScriptLibrary_nothrow: a library which has not been migrated?" ); + + ::rtl::OUStringBuffer aNewLocation; + aNewLocation.append( sNewLibName ); + aNewLocation.append( sScriptName.copy( nLibModuleSeparator ) ); + xUri->setName( aNewLocation.makeStringAndClear() ); + + // update the new script URL + _inout_rScriptCode = xUri->getUriReference(); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + return false; + } + + return true; + } + + //-------------------------------------------------------------------- + bool MigrationEngine_Impl::impl_adjustScriptLibrary_nothrow( ScriptEventDescriptor& _inout_rScriptEvent ) const + { + if ( _inout_rScriptEvent.ScriptType.getLength() && _inout_rScriptEvent.ScriptCode.getLength() ) + return impl_adjustScriptLibrary_nothrow( _inout_rScriptEvent.ScriptType, _inout_rScriptEvent.ScriptCode ); + return false; + } + + //-------------------------------------------------------------------- + bool MigrationEngine_Impl::impl_adjustScriptLibrary_nothrow( Any& _inout_rScriptDescriptor ) const + { + ::comphelper::NamedValueCollection aScriptDesc( _inout_rScriptDescriptor ); + + ::rtl::OUString sScriptType; + ::rtl::OUString sScript; + try + { + OSL_VERIFY( aScriptDesc.get_ensureType( "EventType", sScriptType ) ); + OSL_VERIFY( aScriptDesc.get_ensureType( "Script", sScript ) ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + + bool bSuccess = impl_adjustScriptLibrary_nothrow( sScriptType, sScript ); + if ( bSuccess ) + { + aScriptDesc.put( "Script", sScript ); + _inout_rScriptDescriptor <<= aScriptDesc.getPropertyValues(); + } + return bSuccess; + } + + //-------------------------------------------------------------------- + bool MigrationEngine_Impl::impl_adjustDocumentEvents_nothrow( const SubDocument& _rDocument ) const + { + try + { + Reference< XEventsSupplier > xSuppEvents( _rDocument.xDocument, UNO_QUERY_THROW ); + Reference< XNameReplace > xEvents( xSuppEvents->getEvents(), UNO_SET_THROW ); + Sequence< ::rtl::OUString > aEventNames = xEvents->getElementNames(); + + Any aEvent; + for ( const ::rtl::OUString* eventName = aEventNames.getConstArray(); + eventName != aEventNames.getConstArray() + aEventNames.getLength(); + ++eventName + ) + { + aEvent = xEvents->getByName( *eventName ); + if ( !aEvent.hasValue() ) + continue; + + // translate + if ( !impl_adjustScriptLibrary_nothrow( aEvent ) ) + continue; + + // put back + xEvents->replaceByName( *eventName, aEvent ); + } + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + // TODO: can we handle this? Do we need to revert the changes? + return false; + } + return true; + } + + //-------------------------------------------------------------------- + void MigrationEngine_Impl::impl_AdjustFormComponentEvents_throw( const Reference< XIndexAccess >& _rxComponentContainer ) const + { + FormComponentIterator aCompIter( _rxComponentContainer ); + while ( aCompIter.hasMore() ) + { + // 1. adjust the component's scripts of the current component + FormComponentScripts aComponent( aCompIter.next() ); + Sequence< ScriptEventDescriptor > aEvents( aComponent.getEvents() ); + + bool bChangedComponentEvents = false; + for ( ScriptEventDescriptor* scriptEvent = aEvents.getArray(); + scriptEvent != aEvents.getArray() + aEvents.getLength(); + ++scriptEvent + ) + { + if ( !impl_adjustScriptLibrary_nothrow( *scriptEvent ) ) + continue; + + bChangedComponentEvents = true; + } + + if ( bChangedComponentEvents ) + aComponent.setEvents( aEvents ); + + // 2. step down if the component is a container itself + Reference< XIndexAccess > xContainer( aComponent.getComponent(), UNO_QUERY ); + if ( xContainer.is() ) + impl_AdjustFormComponentEvents_throw( xContainer ); + } + } + + //-------------------------------------------------------------------- + bool MigrationEngine_Impl::impl_AdjustFormComponentEvents_nothrow( const SubDocument& _rDocument ) const + { + try + { + DrawPageIterator aPageIter( _rDocument.xDocument ); + while ( aPageIter.hasMore() ) + { + Reference< XFormsSupplier > xSuppForms( aPageIter.next(), UNO_QUERY_THROW ); + Reference< XIndexAccess > xForms( xSuppForms->getForms(), UNO_QUERY_THROW ); + impl_AdjustFormComponentEvents_throw( xForms ); + } + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + // TODO: can we handle this? Do we need to revert the changes? + return false; + } + return true; } //==================================================================== --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
