loplugin:unocast (DocumentSettingsSerializer)

(See the upcoming commit introducing that loplugin:unocast on why such
dynamic_casts from UNO types are dangerous.)

Change-Id: I803f62085264511976ed9bb0744ee301de2a7dab
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/144754
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
This commit is contained in:
Stephan Bergmann
2022-12-08 11:10:50 +01:00
parent 73df933f5f
commit f481f036de
7 changed files with 52 additions and 10 deletions

View File

@@ -12,7 +12,10 @@
#ifndef INCLUDED_XMLOFF_SETTINGSSTORE_HXX
#define INCLUDED_XMLOFF_SETTINGSSTORE_HXX
#include <com/sun/star/lang/XUnoTunnel.hpp>
#include <com/sun/star/uno/Sequence.hxx>
#include <cppuhelper/implbase.hxx>
#include <xmloff/dllapi.h>
namespace com::sun::star::beans { struct PropertyValue; }
namespace com::sun::star::embed { class XStorage; }
@@ -20,7 +23,9 @@ namespace com::sun::star::uno { template <typename > class Reference; }
// Scans list of properties for certain URL properties that could refer
// to internal objects, and initializes from these.
class SAL_DLLPUBLIC_RTTI SAL_LOPLUGIN_ANNOTATE("crosscast") DocumentSettingsSerializer {
class XMLOFF_DLLPUBLIC DocumentSettingsSerializer:
public cppu::WeakImplHelper<css::lang::XUnoTunnel>
{
public:
// Import objects and update properties (eliding URLs)
virtual css::uno::Sequence<css::beans::PropertyValue>
@@ -34,8 +39,11 @@ public:
const css::uno::Reference< css::embed::XStorage > &xStorage,
const css::uno::Sequence<css::beans::PropertyValue>& aConfigProps ) = 0;
sal_Int64 SAL_CALL getSomething(css::uno::Sequence<sal_Int8> const & aIdentifier) override;
static css::uno::Sequence<sal_Int8> const & getUnoTunnelId();
protected:
~DocumentSettingsSerializer() {}
~DocumentSettingsSerializer() override;
};
#endif // INCLUDED_XMLOFF_SETTINGSSTORE_HXX

View File

@@ -97,6 +97,7 @@ $(eval $(call gb_Library_use_libraries,sd,\
ucbhelper \
utl \
vcl \
xo \
$(if $(ENABLE_NSS),xmlsecurity) \
))

View File

@@ -69,9 +69,10 @@ namespace sd
{
namespace {
class DocumentSettings : public WeakImplHelper< XPropertySet, XMultiPropertySet, XServiceInfo >,
public comphelper::PropertySetHelper,
public DocumentSettingsSerializer
class DocumentSettings : public ImplInheritanceHelper<
DocumentSettingsSerializer, XPropertySet, XMultiPropertySet,
XServiceInfo >,
public comphelper::PropertySetHelper
{
public:
explicit DocumentSettings( SdXImpressDocument* pModel );
@@ -1336,17 +1337,17 @@ DocumentSettings::_getPropertyValues(
// XInterface
Any SAL_CALL DocumentSettings::queryInterface( const Type& aType )
{
return WeakImplHelper< XPropertySet, XMultiPropertySet, XServiceInfo >::queryInterface( aType );
return ImplInheritanceHelper::queryInterface( aType );
}
void SAL_CALL DocumentSettings::acquire( ) noexcept
{
WeakImplHelper< XPropertySet, XMultiPropertySet, XServiceInfo >::acquire();
ImplInheritanceHelper::acquire();
}
void SAL_CALL DocumentSettings::release( ) noexcept
{
WeakImplHelper< XPropertySet, XMultiPropertySet, XServiceInfo >::release();
ImplInheritanceHelper::release();
}
// XPropertySet

View File

@@ -154,6 +154,7 @@ $(eval $(call gb_Library_add_exception_objects,xo,\
xmloff/source/draw/sdpropls \
xmloff/source/draw/sdxmlexp \
xmloff/source/draw/sdxmlimp \
xmloff/source/draw/settingsstore \
xmloff/source/draw/shapeexport \
xmloff/source/draw/shapeimport \
xmloff/source/draw/SignatureLineContext \

View File

@@ -52,6 +52,7 @@
#include <rtl/ustrbuf.hxx>
#include <sal/log.hxx>
#include <comphelper/diagnose_ex.hxx>
#include <comphelper/servicehelper.hxx>
#include <tools/gen.hxx>
#include <sax/tools/converter.hxx>
#include <xmloff/xmlaustp.hxx>
@@ -2473,7 +2474,8 @@ void SdXMLExport::GetConfigurationSettings(uno::Sequence<beans::PropertyValue>&
Reference< beans::XPropertySet > xProps( xFac->createInstance("com.sun.star.document.Settings"), UNO_QUERY );
if( xProps.is() )
SvXMLUnitConverter::convertPropertySet( rProps, xProps );
DocumentSettingsSerializer *pFilter(dynamic_cast<DocumentSettingsSerializer *>(xProps.get()));
DocumentSettingsSerializer *pFilter(
comphelper::getFromUnoTunnel<DocumentSettingsSerializer>(xProps));
if (!pFilter)
return;
const uno::Reference< embed::XStorage > xStorage(GetTargetStorage());

View File

@@ -21,6 +21,7 @@
#include <sal/log.hxx>
#include <comphelper/processfactory.hxx>
#include <comphelper/sequence.hxx>
#include <comphelper/servicehelper.hxx>
#include <xmloff/xmlscripti.hxx>
#include "sdxmlimp_impl.hxx"
@@ -552,7 +553,7 @@ void SdXMLImport::SetConfigurationSettings(const css::uno::Sequence<css::beans::
const uno::Sequence<beans::PropertyValue>* pValues = &aConfigProps;
DocumentSettingsSerializer *pFilter;
pFilter = dynamic_cast<DocumentSettingsSerializer *>(xProps.get());
pFilter = comphelper::getFromUnoTunnel<DocumentSettingsSerializer>(xProps);
uno::Sequence<beans::PropertyValue> aFiltered;
if( pFilter )
{

View File

@@ -0,0 +1,28 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <sal/config.h>
#include <comphelper/servicehelper.hxx>
#include <xmloff/settingsstore.hxx>
sal_Int64 DocumentSettingsSerializer::getSomething(css::uno::Sequence<sal_Int8> const& aIdentifier)
{
return comphelper::getSomethingImpl(aIdentifier, this);
}
css::uno::Sequence<sal_Int8> const& DocumentSettingsSerializer::getUnoTunnelId()
{
static comphelper::UnoIdInit const id;
return id.getSeq();
}
DocumentSettingsSerializer::~DocumentSettingsSerializer() {}
/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */