sw/source/filter/xml/wrtxml.cxx | 19 +++++++++++++++---- sw/source/filter/xml/wrtxml.hxx | 2 +- sw/source/filter/xml/xmlexp.cxx | 39 +++++++++++++++++++++++++++++++++++---- 3 files changed, 51 insertions(+), 9 deletions(-)
New commits: commit 83876642498b0203b25b8b95e612603d46addd62 Author: Caolán McNamara <caol...@redhat.com> AuthorDate: Tue Sep 28 10:23:29 2021 +0100 Commit: Michael Stahl <michael.st...@allotropia.de> CommitDate: Tue Sep 28 14:28:14 2021 +0200 tdf#144532 closing mail merge wizard preview removed document's data source Filter out the "EmbeddedDatabaseName" property from the document settings on saving document that will be loaded by the mail merge preview so that when the temp mailmerge preview document is closed it doesn't unregister the database of the same name which was registered by the document this is a copy of. This looks like a similar problem to tdf#118634 addressed by: commit edc62adae9a354ca1305e83b10c98a545f58d341 Date: Mon Jul 9 19:49:34 2018 +1000 tdf#118634: Don't save embedded data source to a temporary preview document Change-Id: I3fecc2ace1c9e06354b145609f0130dbbb2c036b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122767 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.st...@allotropia.de> diff --git a/sw/source/filter/xml/wrtxml.cxx b/sw/source/filter/xml/wrtxml.cxx index be2a21aeeefa..da1d344b6ce6 100644 --- a/sw/source/filter/xml/wrtxml.cxx +++ b/sw/source/filter/xml/wrtxml.cxx @@ -80,8 +80,8 @@ SwXMLWriter::~SwXMLWriter() { } -ErrCode SwXMLWriter::Write_( const uno::Reference < task::XStatusIndicator >& xStatusIndicator, - const OUString& aDocHierarchicalName ) +ErrCode SwXMLWriter::Write_(const uno::Reference < task::XStatusIndicator >& xStatusIndicator, + const OUString& aDocHierarchicalName, bool bNoEmbDS) { // Get service factory uno::Reference< uno::XComponentContext > xContext = @@ -159,6 +159,10 @@ ErrCode SwXMLWriter::Write_( const uno::Reference < task::XStatusIndicator >& xS beans::PropertyAttribute::MAYBEVOID, 0 }, { OUString("TargetStorage"),0, cppu::UnoType<embed::XStorage>::get(), css::beans::PropertyAttribute::MAYBEVOID, 0 }, + // tdf#144532 + { OUString("NoEmbDataSet"), 0, + cppu::UnoType<bool>::get(), + beans::PropertyAttribute::MAYBEVOID, 0 }, { OUString(), 0, css::uno::Type(), 0, 0 } }; uno::Reference< beans::XPropertySet > xInfoSet( @@ -167,6 +171,8 @@ ErrCode SwXMLWriter::Write_( const uno::Reference < task::XStatusIndicator >& xS xInfoSet->setPropertyValue( "TargetStorage", Any( m_xStg ) ); + xInfoSet->setPropertyValue("NoEmbDataSet", makeAny(bNoEmbDS)); + if (m_bShowProgress) { // set progress range and start status indicator @@ -441,13 +447,15 @@ ErrCode SwXMLWriter::Write_( const uno::Reference < task::XStatusIndicator >& xS ErrCode SwXMLWriter::WriteStorage() { - return Write_( uno::Reference < task::XStatusIndicator >(), OUString() ); + return Write_(uno::Reference<task::XStatusIndicator>(), OUString(), false); } ErrCode SwXMLWriter::WriteMedium( SfxMedium& aTargetMedium ) { uno::Reference < task::XStatusIndicator > xStatusIndicator; OUString aName; + bool bNoEmbDS(false); + const SfxUnoAnyItem* pStatusBarItem = static_cast<const SfxUnoAnyItem*>( aTargetMedium.GetItemSet()->GetItem(SID_PROGRESS_STATUSBAR_CONTROL) ); if ( pStatusBarItem ) @@ -456,8 +464,11 @@ ErrCode SwXMLWriter::WriteMedium( SfxMedium& aTargetMedium ) aTargetMedium.GetItemSet()->GetItem(SID_DOC_HIERARCHICALNAME) ); if ( pDocHierarchItem ) aName = pDocHierarchItem->GetValue(); + const SfxBoolItem* pNoEmbDS = SfxItemSet::GetItem(aTargetMedium.GetItemSet(), SID_NO_EMBEDDED_DS, false); + if (pNoEmbDS) + bNoEmbDS = pNoEmbDS->GetValue(); - return Write_( xStatusIndicator, aName ); + return Write_(xStatusIndicator, aName, bNoEmbDS); } ErrCode SwXMLWriter::Write( SwPaM& rPaM, SfxMedium& rMed, diff --git a/sw/source/filter/xml/wrtxml.hxx b/sw/source/filter/xml/wrtxml.hxx index c82afcc97436..7e4ed6580c15 100644 --- a/sw/source/filter/xml/wrtxml.hxx +++ b/sw/source/filter/xml/wrtxml.hxx @@ -40,7 +40,7 @@ namespace com::sun::star { class SwXMLWriter : public StgWriter { - ErrCode Write_( const css::uno::Reference < css::task::XStatusIndicator>&, const OUString& ); + ErrCode Write_(const css::uno::Reference < css::task::XStatusIndicator>&, const OUString&, bool bNoEmbDS); using StgWriter::Write; diff --git a/sw/source/filter/xml/xmlexp.cxx b/sw/source/filter/xml/xmlexp.cxx index 3ed4a25570d6..6017bc2f1e59 100644 --- a/sw/source/filter/xml/xmlexp.cxx +++ b/sw/source/filter/xml/xmlexp.cxx @@ -385,12 +385,43 @@ void SwXMLExport::GetViewSettings(Sequence<PropertyValue>& aProps) void SwXMLExport::GetConfigurationSettings( Sequence < PropertyValue >& rProps) { Reference< XMultiServiceFactory > xFac( GetModel(), UNO_QUERY ); - if( xFac.is() ) + if (!xFac.is()) + return; + + Reference< XPropertySet > xProps( xFac->createInstance("com.sun.star.document.Settings"), UNO_QUERY ); + if (!xProps.is()) + return; + + SvXMLUnitConverter::convertPropertySet( rProps, xProps ); + + // tdf#144532 if NoEmbDataSet was set, to indicate not to write an embedded + // database for the case of a temporary mail merge preview document, then + // also filter out the "EmbeddedDatabaseName" property from the document + // settings so that when the temp mailmerge preview document is closed it + // doesn't unregister the database of the same name which was registered by + // the document this is a copy of + Reference<XPropertySet> rInfoSet = getExportInfo(); + + if (!rInfoSet.is() || !rInfoSet->getPropertySetInfo()->hasPropertyByName(u"NoEmbDataSet")) + return; + + Any aAny = rInfoSet->getPropertyValue(u"NoEmbDataSet"); + bool bNoEmbDataSet = *o3tl::doAccess<bool>(aAny); + if (!bNoEmbDataSet) + return; + + Sequence<PropertyValue> aFilteredProps(rProps.getLength()); + sal_Int32 nFilteredPropLen = 0; + PropertyValue *pValue = rProps.getArray(); + for (sal_Int32 i = 0; i < rProps.getLength(); ++i) { - Reference< XPropertySet > xProps( xFac->createInstance("com.sun.star.document.Settings"), UNO_QUERY ); - if( xProps.is() ) - SvXMLUnitConverter::convertPropertySet( rProps, xProps ); + if (pValue[i].Name == "EmbeddedDatabaseName") + continue; + aFilteredProps[nFilteredPropLen] = rProps[i]; + ++nFilteredPropLen; } + aFilteredProps.realloc(nFilteredPropLen); + std::swap(rProps, aFilteredProps); } sal_Int32 SwXMLExport::GetDocumentSpecificSettings( std::vector< SettingsGroup >& _out_rSettings )