Tag: cws_dev300_odbmacros3 User: fs Date: 2008-09-09 11:00:08+0000 Modified: dba/dbaccess/source/ext/macromigration/macromigrationdialog.cxx
Log: #i49133# don't allow to backup to the location of the document itself File Changes: Directory: /dba/dbaccess/source/ext/macromigration/ =================================================== File [changed]: macromigrationdialog.cxx Url: http://dba.openoffice.org/source/browse/dba/dbaccess/source/ext/macromigration/macromigrationdialog.cxx?r1=1.3.2.7&r2=1.3.2.8 Delta lines: +66 -8 -------------------- --- macromigrationdialog.cxx 2008-05-11 21:16:07+0000 1.3.2.7 +++ macromigrationdialog.cxx 2008-09-09 11:00:05+0000 1.3.2.8 @@ -7,7 +7,7 @@ * OpenOffice.org - a multi-platform office productivity suite * * $RCSfile: macromigrationdialog.cxx,v $ - * $Revision: 1.3.2.7 $ + * $Revision: 1.3.2.8 $ * * This file is part of OpenOffice.org. * @@ -48,6 +48,8 @@ #include <com/sun/star/util/XCloseable.hpp> #include <com/sun/star/frame/XComponentLoader.hpp> #include <com/sun/star/util/XModifiable.hpp> +#include <com/sun/star/ucb/XContent.hpp> +#include <com/sun/star/ucb/XContentProvider.hpp> /** === end UNO includes === **/ #include <comphelper/namedvaluecollection.hxx> @@ -56,6 +58,9 @@ #include <rtl/ref.hxx> #include <svtools/filenotation.hxx> #include <tools/diagnose_ex.h> +#include <ucbhelper/content.hxx> +#include <ucbhelper/contentbroker.hxx> +#include <vcl/msgbox.hxx> #include <list> @@ -98,6 +103,10 @@ using ::com::sun::star::lang::EventObject; using ::com::sun::star::frame::XComponentLoader; using ::com::sun::star::util::XModifiable; + using ::com::sun::star::ucb::XCommandEnvironment; + using ::com::sun::star::ucb::XContent; + using ::com::sun::star::ucb::XContentIdentifier; + using ::com::sun::star::ucb::XContentProvider; /** === end UNO using === **/ //==================================================================== @@ -141,7 +150,6 @@ } }; - //==================================================================== //= MacroMigrationDialog //==================================================================== @@ -401,14 +409,61 @@ } //-------------------------------------------------------------------- + namespace + { + bool lcl_equalURLs_nothrow( const ::rtl::OUString& _lhs, const ::rtl::OUString _rhs ) + { + // the cheap situation: the URLs are equal + if ( _lhs == _rhs ) + return true; + + bool bEqual = true; + try + { + ::ucbhelper::Content aContentLHS = ::ucbhelper::Content( _lhs, Reference< XCommandEnvironment >() ); + ::ucbhelper::Content aContentRHS = ::ucbhelper::Content( _rhs, Reference< XCommandEnvironment >() ); + Reference< XContent > xContentLHS( aContentLHS.get(), UNO_SET_THROW ); + Reference< XContent > xContentRHS( aContentRHS.get(), UNO_SET_THROW ); + Reference< XContentIdentifier > xID1( xContentLHS->getIdentifier(), UNO_SET_THROW ); + Reference< XContentIdentifier > xID2( xContentRHS->getIdentifier(), UNO_SET_THROW ); + + ::ucbhelper::ContentBroker* pBroker = ::ucbhelper::ContentBroker::get(); + Reference< XContentProvider > xProvider( + pBroker ? pBroker->getContentProviderInterface() : Reference< XContentProvider >(), UNO_SET_THROW ); + + bEqual = ( 0 == xProvider->compareContentIds( xID1, xID2 ) ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + return bEqual; + } + } + + //-------------------------------------------------------------------- bool MacroMigrationDialog::impl_backupDocument_nothrow() const { - const SaveDBDocPage& rBackupPage = dynamic_cast< const SaveDBDocPage& >( *GetPage( STATE_BACKUP_DBDOC ) ); + if ( !m_pData->xDocumentModel.is() ) + // should never happen, but has been reported as assertion before + return false; + + SaveDBDocPage& rBackupPage = dynamic_cast< SaveDBDocPage& >( *GetPage( STATE_BACKUP_DBDOC ) ); ::rtl::OUString sBackupLocation( rBackupPage.getBackupLocation() ); Any aError; try { + // check that the backup location isn't the same as the document itself + if ( lcl_equalURLs_nothrow( sBackupLocation, m_pData->xDocumentModel->getURL() ) ) + { + ErrorBox aError( const_cast< MacroMigrationDialog* >( this ), MacroMigrationResId( ERR_INVALID_BACKUP_LOCATION ) ); + aError.Execute(); + rBackupPage.grabLocationFocus(); + return false; + } + + // store to the backup location const Reference< XStorable > xDocument( getDocument(), UNO_QUERY_THROW ); xDocument->storeToURL( sBackupLocation, Sequence< PropertyValue >() ); m_pData->sSuccessfulBackupLocation = sBackupLocation; @@ -539,12 +594,15 @@ // finally, now that the document has been reloaded - if the migration was not successful, // then it was reloaded from the backup, but the real document still is broken. So, save // the document once, which will write the content loaded from the backup to the real docfile. + if ( !_bMigrationSuccess ) + { Reference< XModifiable > xModify( m_pData->xDocument, UNO_QUERY_THROW ); xModify->setModified( sal_True ); // this is just parnoia - in case saving the doc fails, perhaps the user is tempted to do so Reference< XStorable > xStor( m_pData->xDocument, UNO_QUERY_THROW ); xStor->store(); } + } catch( const Exception& ) { DBG_UNHANDLED_EXCEPTION(); --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
