diff options
Diffstat (limited to 'sd/source/filter/xml/sdxmlwrp.cxx')
-rw-r--r-- | sd/source/filter/xml/sdxmlwrp.cxx | 140 |
1 files changed, 46 insertions, 94 deletions
diff --git a/sd/source/filter/xml/sdxmlwrp.cxx b/sd/source/filter/xml/sdxmlwrp.cxx index 9a6e8d9a9afe..e102ce27e333 100644 --- a/sd/source/filter/xml/sdxmlwrp.cxx +++ b/sd/source/filter/xml/sdxmlwrp.cxx @@ -17,6 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <officecfg/Office/Common.hxx> #include <vcl/errinf.hxx> #include <sal/log.hxx> #include <com/sun/star/container/XChild.hpp> @@ -25,6 +26,7 @@ #include <com/sun/star/xml/sax/SAXParseException.hpp> #include <comphelper/processfactory.hxx> #include <comphelper/propertysequence.hxx> +#include <o3tl/string_view.hxx> #include <editeng/outlobj.hxx> #include <sfx2/docfile.hxx> #include <sfx2/docfilt.hxx> @@ -59,7 +61,6 @@ #include <comphelper/genericpropertyset.hxx> #include <comphelper/propertysetinfo.hxx> #include <editeng/eeitem.hxx> -#include <unotools/saveopt.hxx> // include necessary for XML progress bar at load time #include <svl/itemset.hxx> @@ -74,7 +75,7 @@ #include <sfx2/frame.hxx> #include <tools/debug.hxx> -#include <tools/diagnose_ex.h> +#include <comphelper/diagnose_ex.hxx> using namespace com::sun::star; using namespace com::sun::star::uno; @@ -165,7 +166,7 @@ SdXMLFilter::~SdXMLFilter() namespace { -ErrCode ReadThroughComponent( +ErrCodeMsg ReadThroughComponent( const Reference<io::XInputStream>& xInputStream, const Reference<XComponent>& xModelComponent, const OUString& rStreamName, @@ -173,7 +174,7 @@ ErrCode ReadThroughComponent( const char* pFilterName, const Sequence<Any>& rFilterArguments, const OUString& rName, - bool bMustBeSuccessfull, + bool bMustBeSuccessful, bool bEncrypted ) { DBG_ASSERT(xInputStream.is(), "input stream missing"); @@ -258,16 +259,16 @@ ErrCode ReadThroughComponent( if (!rStreamName.isEmpty()) { - return *new TwoStringErrorInfo( - (bMustBeSuccessfull ? ERR_FORMAT_FILE_ROWCOL + return ErrCodeMsg( + (bMustBeSuccessful ? ERR_FORMAT_FILE_ROWCOL : WARN_FORMAT_FILE_ROWCOL), rStreamName, sErr, DialogMask::ButtonsOk | DialogMask::MessageError ); } else { - DBG_ASSERT( bMustBeSuccessfull, "Warnings are not supported" ); - return *new StringErrorInfo( ERR_FORMAT_ROWCOL, sErr, + DBG_ASSERT( bMustBeSuccessful, "Warnings are not supported" ); + return ErrCodeMsg( ERR_FORMAT_ROWCOL, sErr, DialogMask::ButtonsOk | DialogMask::MessageError ); } } @@ -304,7 +305,7 @@ ErrCode ReadThroughComponent( return ERRCODE_NONE; } -ErrCode ReadThroughComponent( +ErrCodeMsg ReadThroughComponent( const uno::Reference < embed::XStorage >& xStorage, const Reference<XComponent>& xModelComponent, const char* pStreamName, @@ -312,7 +313,7 @@ ErrCode ReadThroughComponent( const char* pFilterName, const Sequence<Any>& rFilterArguments, const OUString& rName, - bool bMustBeSuccessfull ) + bool bMustBeSuccessful ) { DBG_ASSERT(xStorage.is(), "Need storage!"); DBG_ASSERT(nullptr != pStreamName, "Please, please, give me a name!"); @@ -341,7 +342,7 @@ ErrCode ReadThroughComponent( DBG_ASSERT( xInfoSet.is(), "missing property set" ); if( xInfoSet.is() ) { - xInfoSet->setPropertyValue( "StreamName", makeAny( sStreamName ) ); + xInfoSet->setPropertyValue( "StreamName", Any( sStreamName ) ); } try @@ -364,7 +365,7 @@ ErrCode ReadThroughComponent( return ReadThroughComponent( xInputStream, xModelComponent, sStreamName, rxContext, pFilterName, rFilterArguments, - rName, bMustBeSuccessfull, bEncrypted ); + rName, bMustBeSuccessful, bEncrypted ); } catch (const packages::WrongPasswordException&) { @@ -441,7 +442,7 @@ static void fixupOutlinePlaceholderNumberingDepths(SdDrawDocument* pDoc) bool SdXMLFilter::Import( ErrCode& nError ) { - ErrCode nRet = ERRCODE_NONE; + ErrCodeMsg nRet = ERRCODE_NONE; // Get service factory Reference< uno::XComponentContext > rxContext = @@ -457,7 +458,7 @@ bool SdXMLFilter::Import( ErrCode& nError ) mxModel->lockControllers(); /** property map for import info set */ - PropertyMapEntry const aImportInfoMap[] = + static PropertyMapEntry const aImportInfoMap[] = { // necessary properties for XML progress bar at load time { OUString("ProgressRange"), 0, cppu::UnoType<sal_Int32>::get(), css::beans::PropertyAttribute::MAYBEVOID, 0}, @@ -472,11 +473,10 @@ bool SdXMLFilter::Import( ErrCode& nError ) { OUString("BuildId"), 0, cppu::UnoType<OUString>::get(), css::beans::PropertyAttribute::MAYBEVOID, 0 }, { OUString("OrganizerMode"), 0, cppu::UnoType<bool>::get(), css::beans::PropertyAttribute::MAYBEVOID, 0 }, { OUString("SourceStorage"), 0, cppu::UnoType<embed::XStorage>::get(), css::beans::PropertyAttribute::MAYBEVOID, 0 }, - { OUString(), 0, css::uno::Type(), 0, 0 } }; uno::Reference< beans::XPropertySet > xInfoSet( GenericPropertySet_CreateInstance( new PropertySetInfo( aImportInfoMap ) ) ); - xInfoSet->setPropertyValue( "Preview" , uno::makeAny( mrDocShell.GetDoc()->IsStarDrawPreviewMode() ) ); + xInfoSet->setPropertyValue( "Preview" , uno::Any( mrDocShell.GetDoc()->IsStarDrawPreviewMode() ) ); // ---- get BuildId from parent container if available @@ -504,15 +504,10 @@ bool SdXMLFilter::Import( ErrCode& nError ) // try to get an XStatusIndicator from the Medium { - SfxItemSet* pSet = mrMedium.GetItemSet(); - if(pSet) + const SfxUnoAnyItem* pItem = mrMedium.GetItemSet().GetItem(SID_PROGRESS_STATUSBAR_CONTROL); + if (pItem) { - const SfxUnoAnyItem* pItem = static_cast<const SfxUnoAnyItem*>( - pSet->GetItem(SID_PROGRESS_STATUSBAR_CONTROL) ); - if (pItem) - { - pItem->GetValue() >>= mxStatusIndicator; - } + pItem->GetValue() >>= mxStatusIndicator; } if(mxStatusIndicator.is()) @@ -557,18 +552,15 @@ bool SdXMLFilter::Import( ErrCode& nError ) OUString const baseURI(mrMedium.GetBaseURL()); // needed for relative URLs, but in clipboard copy/paste there may be none SAL_INFO_IF(baseURI.isEmpty(), "sd.filter", "SdXMLFilter: no base URL"); - xInfoSet->setPropertyValue("BaseURI", makeAny(baseURI)); + xInfoSet->setPropertyValue("BaseURI", Any(baseURI)); if( ERRCODE_NONE == nRet && SfxObjectCreateMode::EMBEDDED == mrDocShell.GetCreateMode() ) { OUString aName; - if ( mrMedium.GetItemSet() ) - { - const SfxStringItem* pDocHierarchItem = static_cast<const SfxStringItem*>( - mrMedium.GetItemSet()->GetItem(SID_DOC_HIERARCHICALNAME) ); - if ( pDocHierarchItem ) - aName = pDocHierarchItem->GetValue(); - } + const SfxStringItem* pDocHierarchItem = + mrMedium.GetItemSet().GetItem(SID_DOC_HIERARCHICALNAME); + if ( pDocHierarchItem ) + aName = pDocHierarchItem->GetValue(); else aName = "dummyObjectName" ; @@ -577,7 +569,7 @@ bool SdXMLFilter::Import( ErrCode& nError ) } if (SdXMLFilterMode::Organizer == meFilterMode) - xInfoSet->setPropertyValue("OrganizerMode", uno::makeAny(true)); + xInfoSet->setPropertyValue("OrganizerMode", uno::Any(true)); if( ERRCODE_NONE == nRet ) { @@ -599,8 +591,8 @@ bool SdXMLFilter::Import( ErrCode& nError ) XML_SERVICES const * pServices = getServices( true, IsDraw(), mnStoreVer ); - ErrCode nWarn = ERRCODE_NONE; - ErrCode nWarn2 = ERRCODE_NONE; + ErrCodeMsg nWarn = ERRCODE_NONE; + ErrCodeMsg nWarn2 = ERRCODE_NONE; // read storage streams // #i103539#: always read meta.xml for generator nWarn = ReadThroughComponent( @@ -654,7 +646,7 @@ bool SdXMLFilter::Import( ErrCode& nError ) if( nRet == ERRCODE_NONE ) pDoc->UpdateAllLinks(); - if( nRet.anyOf( ERRCODE_NONE, SD_XML_READERROR ) ) + if( nRet == ERRCODE_NONE || nRet == SD_XML_READERROR ) ; else if( nRet == ERRCODE_IO_BROKENPACKAGE && xStorage.is() ) nError = ERRCODE_IO_BROKENPACKAGE; @@ -668,41 +660,7 @@ bool SdXMLFilter::Import( ErrCode& nError ) // clear unused named items from item pool - uno::Reference< lang::XMultiServiceFactory> xModelFactory( mxModel, uno::UNO_QUERY ); - if( xModelFactory.is() ) - { - try - { - static const OUStringLiteral aName(u"~clear~" ); - uno::Reference< container::XNameContainer > xGradient( xModelFactory->createInstance( "com.sun.star.drawing.GradientTable" ), uno::UNO_QUERY ); - if( xGradient.is() ) - xGradient->removeByName( aName ); - - uno::Reference< container::XNameContainer > xHatch( xModelFactory->createInstance( "com.sun.star.drawing.HatchTable" ), uno::UNO_QUERY ); - if( xHatch.is() ) - xHatch->removeByName( aName ); - - uno::Reference< container::XNameContainer > xBitmap( xModelFactory->createInstance( "com.sun.star.drawing.BitmapTable" ), uno::UNO_QUERY ); - if( xBitmap.is() ) - xBitmap->removeByName( aName ); - - uno::Reference< container::XNameContainer > xTransGradient( xModelFactory->createInstance( "com.sun.star.drawing.TransparencyGradientTable" ), uno::UNO_QUERY ); - if( xTransGradient.is() ) - xTransGradient->removeByName( aName ); - - uno::Reference< container::XNameContainer > xMarker( xModelFactory->createInstance( "com.sun.star.drawing.MarkerTable" ), uno::UNO_QUERY ); - if( xMarker.is() ) - xMarker->removeByName( aName ); - - uno::Reference< container::XNameContainer > xDashes( xModelFactory->createInstance( "com.sun.star.drawing.DashTable" ), uno::UNO_QUERY ); - if( xDashes.is() ) - xDashes->removeByName( aName ); - } - catch (const Exception&) - { - TOOLS_WARN_EXCEPTION( "sd.filter","sd::SdXMLFilter::Import(), exception during clearing of unused named items"); - } - } + ::svx::DropUnusedNamedItems(mxModel); // set BuildId on XModel for later OLE object loading if( xInfoSet.is() ) @@ -711,7 +669,7 @@ bool SdXMLFilter::Import( ErrCode& nError ) if( xModelSet.is() ) { uno::Reference< beans::XPropertySetInfo > xModelSetInfo( xModelSet->getPropertySetInfo() ); - static const OUStringLiteral sPropName( u"BuildId" ); + static constexpr OUString sPropName( u"BuildId"_ustr ); OUString sBuildId; xInfoSet->getPropertyValue(sPropName) >>= sBuildId; @@ -728,13 +686,13 @@ bool SdXMLFilter::Import( ErrCode& nError ) if( !sBuildId.isEmpty() ) { sal_Int32 nIndex = sBuildId.indexOf('$'); - if( nIndex != -1 ) + if (sBuildId.indexOf(';') == -1 && nIndex != -1) { - sal_Int32 nUPD = sBuildId.copy( 0, nIndex ).toInt32(); + sal_Int32 nUPD = o3tl::toInt32(sBuildId.subView( 0, nIndex )); if( nUPD == 300 ) { - sal_Int32 nBuildId = sBuildId.copy( nIndex+1 ).toInt32(); + sal_Int32 nBuildId = o3tl::toInt32(sBuildId.subView( nIndex+1 )); if( (nBuildId > 0) && (nBuildId < 9316) ) bTransform = true; // treat OOo 3.0 beta1 as OOo 2.x } @@ -801,7 +759,7 @@ bool SdXMLFilter::Export() uno::Reference< xml::sax::XWriter > xWriter = xml::sax::Writer::create( xContext ); /** property map for export info set */ - PropertyMapEntry const aExportInfoMap[] = + static PropertyMapEntry const aExportInfoMap[] = { { OUString("ProgressRange"), 0, cppu::UnoType<sal_Int32>::get(), css::beans::PropertyAttribute::MAYBEVOID, 0}, { OUString("ProgressMax"), 0, cppu::UnoType<sal_Int32>::get(), css::beans::PropertyAttribute::MAYBEVOID, 0}, @@ -814,38 +772,33 @@ bool SdXMLFilter::Export() { OUString("StyleNames"), 0, cppu::UnoType<Sequence<OUString>>::get(), css::beans::PropertyAttribute::MAYBEVOID, 0 }, { OUString("StyleFamilies"), 0, cppu::UnoType<Sequence<sal_Int32>>::get(), css::beans::PropertyAttribute::MAYBEVOID, 0 }, { OUString("TargetStorage"), 0, cppu::UnoType<embed::XStorage>::get(), css::beans::PropertyAttribute::MAYBEVOID, 0 }, - { OUString(), 0, css::uno::Type(), 0, 0 } }; uno::Reference< beans::XPropertySet > xInfoSet( GenericPropertySet_CreateInstance( new PropertySetInfo( aExportInfoMap ) ) ); - SvtSaveOptions aSaveOpt; - bool bUsePrettyPrinting( aSaveOpt.IsPrettyPrinting() ); - xInfoSet->setPropertyValue( "UsePrettyPrinting", makeAny( bUsePrettyPrinting ) ); + bool bUsePrettyPrinting = officecfg::Office::Common::Save::Document::PrettyPrinting::get(); + xInfoSet->setPropertyValue( "UsePrettyPrinting", Any( bUsePrettyPrinting ) ); const uno::Reference < embed::XStorage >& xStorage = mrMedium.GetOutputStorage(); // Set base URI OUString sPropName( "BaseURI" ); - xInfoSet->setPropertyValue( sPropName, makeAny( mrMedium.GetBaseURL( true ) ) ); + xInfoSet->setPropertyValue( sPropName, Any( mrMedium.GetBaseURL( true ) ) ); xInfoSet->setPropertyValue( "TargetStorage", Any( xStorage ) ); if( SfxObjectCreateMode::EMBEDDED == mrDocShell.GetCreateMode() ) { OUString aName; - if ( mrMedium.GetItemSet() ) - { - const SfxStringItem* pDocHierarchItem = static_cast<const SfxStringItem*>( - mrMedium.GetItemSet()->GetItem(SID_DOC_HIERARCHICALNAME) ); - if ( pDocHierarchItem ) - aName = pDocHierarchItem->GetValue(); - } + const SfxStringItem* pDocHierarchItem = + mrMedium.GetItemSet().GetItem(SID_DOC_HIERARCHICALNAME); + if ( pDocHierarchItem ) + aName = pDocHierarchItem->GetValue(); if( !aName.isEmpty() ) { sPropName = "StreamRelPath"; - xInfoSet->setPropertyValue( sPropName, makeAny( aName ) ); + xInfoSet->setPropertyValue( sPropName, Any( aName ) ); } } @@ -937,7 +890,7 @@ bool SdXMLFilter::Export() // encrypt all streams xProps->setPropertyValue( "UseCommonStoragePasswordEncryption", - uno::makeAny( true ) ); + uno::Any( true ) ); xInfoSet->setPropertyValue( "StreamName", Any( sDocName ) ); } @@ -1021,8 +974,7 @@ extern "C" SAL_DLLPUBLIC_EXPORT bool TestImportFODP(SvStream &rStream) { { "UserData", uno::Any(aUserData) }, })); - css::uno::Sequence<uno::Any> aOuterArgs(1); - aOuterArgs[0] <<= aAdaptorArgs; + css::uno::Sequence<uno::Any> aOuterArgs{ uno::Any(aAdaptorArgs) }; uno::Reference<lang::XInitialization> xInit(xInterface, uno::UNO_QUERY_THROW); xInit->initialize(aOuterArgs); @@ -1065,8 +1017,8 @@ extern "C" SAL_DLLPUBLIC_EXPORT bool TestImportPPTX(SvStream &rStream) uno::Reference<document::XImporter> xImporter(xFilter, uno::UNO_QUERY_THROW); uno::Sequence<beans::PropertyValue> aArgs(comphelper::InitPropertySequence( { - { "InputStream", uno::makeAny(xStream) }, - { "InputMode", uno::makeAny(true) }, + { "InputStream", uno::Any(xStream) }, + { "InputMode", uno::Any(true) }, })); xImporter->setTargetDocument(xModel); |