diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-08-02 20:07:28 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-08-02 22:44:21 +0200 |
commit | 5ef5c1b294063d1d2d6554d5fcf1d4cfb4d3f06d (patch) | |
tree | f172ebf8cbf48e44a06bb22f91df364e6e814949 /xmlscript/source | |
parent | 0ba7063b3f065741915aff076343579b088da3dc (diff) |
loplugin:flatten in xmlscript
Change-Id: I326aa7ebea7925f580fd12c6c58f62e4add20d84
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99965
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'xmlscript/source')
-rw-r--r-- | xmlscript/source/xmldlg_imexp/xmldlg_export.cxx | 860 | ||||
-rw-r--r-- | xmlscript/source/xmldlg_imexp/xmldlg_impmodels.cxx | 9 | ||||
-rw-r--r-- | xmlscript/source/xmldlg_imexp/xmldlg_import.cxx | 244 |
3 files changed, 558 insertions, 555 deletions
diff --git a/xmlscript/source/xmldlg_imexp/xmldlg_export.cxx b/xmlscript/source/xmldlg_imexp/xmldlg_export.cxx index 392793ce4d67..32c61ad72497 100644 --- a/xmlscript/source/xmldlg_imexp/xmldlg_export.cxx +++ b/xmlscript/source/xmldlg_imexp/xmldlg_export.cxx @@ -527,194 +527,194 @@ void ElementDescriptor::readHexLongAttr( OUString const & rPropName, OUString co void ElementDescriptor::readDateFormatAttr( OUString const & rPropName, OUString const & rAttrName ) { - if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName )) + if (beans::PropertyState_DEFAULT_VALUE == _xPropState->getPropertyState( rPropName )) + return; + + Any a( _xProps->getPropertyValue( rPropName ) ); + if (auto n = o3tl::tryAccess<sal_Int16>(a)) { - Any a( _xProps->getPropertyValue( rPropName ) ); - if (auto n = o3tl::tryAccess<sal_Int16>(a)) + switch (*n) { - switch (*n) - { - case 0: - addAttribute( rAttrName, "system_short" ); - break; - case 1: - addAttribute( rAttrName, "system_short_YY" ); - break; - case 2: - addAttribute( rAttrName, "system_short_YYYY" ); - break; - case 3: - addAttribute( rAttrName, "system_long" ); - break; - case 4: - addAttribute( rAttrName, "short_DDMMYY" ); - break; - case 5: - addAttribute( rAttrName, "short_MMDDYY" ); - break; - case 6: - addAttribute( rAttrName, "short_YYMMDD" ); - break; - case 7: - addAttribute( rAttrName, "short_DDMMYYYY" ); - break; - case 8: - addAttribute( rAttrName, "short_MMDDYYYY" ); - break; - case 9: - addAttribute( rAttrName, "short_YYYYMMDD" ); - break; - case 10: - addAttribute( rAttrName, "short_YYMMDD_DIN5008" ); - break; - case 11: - addAttribute( rAttrName, "short_YYYYMMDD_DIN5008" ); - break; - default: - SAL_WARN( "xmlscript.xmldlg", "### unexpected date format!" ); - break; - } + case 0: + addAttribute( rAttrName, "system_short" ); + break; + case 1: + addAttribute( rAttrName, "system_short_YY" ); + break; + case 2: + addAttribute( rAttrName, "system_short_YYYY" ); + break; + case 3: + addAttribute( rAttrName, "system_long" ); + break; + case 4: + addAttribute( rAttrName, "short_DDMMYY" ); + break; + case 5: + addAttribute( rAttrName, "short_MMDDYY" ); + break; + case 6: + addAttribute( rAttrName, "short_YYMMDD" ); + break; + case 7: + addAttribute( rAttrName, "short_DDMMYYYY" ); + break; + case 8: + addAttribute( rAttrName, "short_MMDDYYYY" ); + break; + case 9: + addAttribute( rAttrName, "short_YYYYMMDD" ); + break; + case 10: + addAttribute( rAttrName, "short_YYMMDD_DIN5008" ); + break; + case 11: + addAttribute( rAttrName, "short_YYYYMMDD_DIN5008" ); + break; + default: + SAL_WARN( "xmlscript.xmldlg", "### unexpected date format!" ); + break; } - else - OSL_FAIL( "### unexpected property type!" ); } + else + OSL_FAIL( "### unexpected property type!" ); } void ElementDescriptor::readDateAttr( OUString const & rPropName, OUString const & rAttrName ) { - if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName )) + if (beans::PropertyState_DEFAULT_VALUE == _xPropState->getPropertyState( rPropName )) + return; + + Any a( _xProps->getPropertyValue( rPropName ) ); + if (a.getValueTypeClass() == TypeClass_STRUCT && a.getValueType() == cppu::UnoType<util::Date>::get()) { - Any a( _xProps->getPropertyValue( rPropName ) ); - if (a.getValueTypeClass() == TypeClass_STRUCT && a.getValueType() == cppu::UnoType<util::Date>::get()) + util::Date aUDate; + if (a >>= aUDate) { - util::Date aUDate; - if (a >>= aUDate) - { - ::Date aTDate(aUDate); - addAttribute( rAttrName, OUString::number( aTDate.GetDate() ) ); - } - else - OSL_FAIL( "### internal error" ); + ::Date aTDate(aUDate); + addAttribute( rAttrName, OUString::number( aTDate.GetDate() ) ); } else - OSL_FAIL( "### unexpected property type!" ); + OSL_FAIL( "### internal error" ); } + else + OSL_FAIL( "### unexpected property type!" ); } void ElementDescriptor::readTimeAttr( OUString const & rPropName, OUString const & rAttrName ) { - if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName )) + if (beans::PropertyState_DEFAULT_VALUE == _xPropState->getPropertyState( rPropName )) + return; + + Any a( _xProps->getPropertyValue( rPropName ) ); + if (a.getValueTypeClass() == TypeClass_STRUCT && a.getValueType() == cppu::UnoType<util::Time>::get()) { - Any a( _xProps->getPropertyValue( rPropName ) ); - if (a.getValueTypeClass() == TypeClass_STRUCT && a.getValueType() == cppu::UnoType<util::Time>::get()) + util::Time aUTime; + if (a >>= aUTime) { - util::Time aUTime; - if (a >>= aUTime) - { - ::tools::Time aTTime(aUTime); - addAttribute( rAttrName, OUString::number( aTTime.GetTime() / ::tools::Time::nanoPerCenti ) ); - } - else - OSL_FAIL( "### internal error" ); + ::tools::Time aTTime(aUTime); + addAttribute( rAttrName, OUString::number( aTTime.GetTime() / ::tools::Time::nanoPerCenti ) ); } else - OSL_FAIL( "### unexpected property type!" ); + OSL_FAIL( "### internal error" ); } + else + OSL_FAIL( "### unexpected property type!" ); } void ElementDescriptor::readTimeFormatAttr( OUString const & rPropName, OUString const & rAttrName ) { - if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName )) + if (beans::PropertyState_DEFAULT_VALUE == _xPropState->getPropertyState( rPropName )) + return; + + Any a( _xProps->getPropertyValue( rPropName ) ); + if (auto n = o3tl::tryAccess<sal_Int16>(a)) { - Any a( _xProps->getPropertyValue( rPropName ) ); - if (auto n = o3tl::tryAccess<sal_Int16>(a)) + switch (*n) { - switch (*n) - { - case 0: - addAttribute( rAttrName, "24h_short" ); - break; - case 1: - addAttribute( rAttrName, "24h_long" ); - break; - case 2: - addAttribute( rAttrName, "12h_short" ); - break; - case 3: - addAttribute( rAttrName, "12h_long" ); - break; - case 4: - addAttribute( rAttrName, "Duration_short" ); - break; - case 5: - addAttribute( rAttrName, "Duration_long" ); - break; - default: - SAL_WARN( "xmlscript.xmldlg", "### unexpected time format!" ); - break; - } + case 0: + addAttribute( rAttrName, "24h_short" ); + break; + case 1: + addAttribute( rAttrName, "24h_long" ); + break; + case 2: + addAttribute( rAttrName, "12h_short" ); + break; + case 3: + addAttribute( rAttrName, "12h_long" ); + break; + case 4: + addAttribute( rAttrName, "Duration_short" ); + break; + case 5: + addAttribute( rAttrName, "Duration_long" ); + break; + default: + SAL_WARN( "xmlscript.xmldlg", "### unexpected time format!" ); + break; } - else - OSL_FAIL( "### unexpected property type!" ); } + else + OSL_FAIL( "### unexpected property type!" ); } void ElementDescriptor::readAlignAttr( OUString const & rPropName, OUString const & rAttrName ) { - if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName )) + if (beans::PropertyState_DEFAULT_VALUE == _xPropState->getPropertyState( rPropName )) + return; + + Any a( _xProps->getPropertyValue( rPropName ) ); + if (auto n = o3tl::tryAccess<sal_Int16>(a)) { - Any a( _xProps->getPropertyValue( rPropName ) ); - if (auto n = o3tl::tryAccess<sal_Int16>(a)) + switch (*n) { - switch (*n) - { - case 0: - addAttribute( rAttrName, "left" ); - break; - case 1: - addAttribute( rAttrName, "center" ); - break; - case 2: - addAttribute( rAttrName, "right" ); - break; - default: - SAL_WARN( "xmlscript.xmldlg", "### illegal alignment value!" ); - break; - } + case 0: + addAttribute( rAttrName, "left" ); + break; + case 1: + addAttribute( rAttrName, "center" ); + break; + case 2: + addAttribute( rAttrName, "right" ); + break; + default: + SAL_WARN( "xmlscript.xmldlg", "### illegal alignment value!" ); + break; } - else - OSL_FAIL( "### unexpected property type!" ); } + else + OSL_FAIL( "### unexpected property type!" ); } void ElementDescriptor::readVerticalAlignAttr( OUString const & rPropName, OUString const & rAttrName ) { - if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName )) + if (beans::PropertyState_DEFAULT_VALUE == _xPropState->getPropertyState( rPropName )) + return; + + Any a( _xProps->getPropertyValue( rPropName ) ); + if (a.getValueTypeClass() == TypeClass_ENUM && a.getValueType() == cppu::UnoType<style::VerticalAlignment>::get()) { - Any a( _xProps->getPropertyValue( rPropName ) ); - if (a.getValueTypeClass() == TypeClass_ENUM && a.getValueType() == cppu::UnoType<style::VerticalAlignment>::get()) + style::VerticalAlignment eAlign; + a >>= eAlign; + switch (eAlign) { - style::VerticalAlignment eAlign; - a >>= eAlign; - switch (eAlign) - { - case style::VerticalAlignment_TOP: - addAttribute( rAttrName, "top" ); - break; - case style::VerticalAlignment_MIDDLE: - addAttribute( rAttrName, "center" ); - break; - case style::VerticalAlignment_BOTTOM: - addAttribute( rAttrName, "bottom" ); - break; - default: - SAL_WARN( "xmlscript.xmldlg", "### illegal vertical alignment value!" ); - break; - } + case style::VerticalAlignment_TOP: + addAttribute( rAttrName, "top" ); + break; + case style::VerticalAlignment_MIDDLE: + addAttribute( rAttrName, "center" ); + break; + case style::VerticalAlignment_BOTTOM: + addAttribute( rAttrName, "bottom" ); + break; + default: + SAL_WARN( "xmlscript.xmldlg", "### illegal vertical alignment value!" ); + break; } - else - OSL_FAIL( "### unexpected property type!" ); } + else + OSL_FAIL( "### unexpected property type!" ); } void ElementDescriptor::readImageOrGraphicAttr(OUString const & rAttrName) @@ -751,166 +751,170 @@ void ElementDescriptor::readImageOrGraphicAttr(OUString const & rAttrName) void ElementDescriptor::readImageAlignAttr( OUString const & rPropName, OUString const & rAttrName ) { - if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName )) + if (beans::PropertyState_DEFAULT_VALUE == _xPropState->getPropertyState( rPropName )) + return; + + Any a( _xProps->getPropertyValue( rPropName ) ); + if (auto n = o3tl::tryAccess<sal_Int16>(a)) { - Any a( _xProps->getPropertyValue( rPropName ) ); - if (auto n = o3tl::tryAccess<sal_Int16>(a)) + switch (*n) { - switch (*n) - { - case 0: - addAttribute( rAttrName, "left" ); - break; - case 1: - addAttribute( rAttrName, "top" ); - break; - case 2: - addAttribute( rAttrName, "right" ); - break; - case 3: - addAttribute( rAttrName, "bottom" ); - break; - default: - SAL_WARN( "xmlscript.xmldlg", "### illegal image alignment value!" ); - break; - } + case 0: + addAttribute( rAttrName, "left" ); + break; + case 1: + addAttribute( rAttrName, "top" ); + break; + case 2: + addAttribute( rAttrName, "right" ); + break; + case 3: + addAttribute( rAttrName, "bottom" ); + break; + default: + SAL_WARN( "xmlscript.xmldlg", "### illegal image alignment value!" ); + break; } - else - OSL_FAIL( "### unexpected property type!" ); } + else + OSL_FAIL( "### unexpected property type!" ); } void ElementDescriptor::readImagePositionAttr( OUString const & rPropName, OUString const & rAttrName ) { - if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName )) + if (beans::PropertyState_DEFAULT_VALUE == _xPropState->getPropertyState( rPropName )) + return; + + Any a( _xProps->getPropertyValue( rPropName ) ); + auto n = o3tl::tryAccess<sal_Int16>(a); + if (!n) + return; + + switch (*n) { - Any a( _xProps->getPropertyValue( rPropName ) ); - if (auto n = o3tl::tryAccess<sal_Int16>(a)) - { - switch (*n) - { - case awt::ImagePosition::LeftTop: - addAttribute( rAttrName, "left-top" ); - break; - case awt::ImagePosition::LeftCenter: - addAttribute( rAttrName, "left-center" ); - break; - case awt::ImagePosition::LeftBottom: - addAttribute( rAttrName, "left-bottom" ); - break; - case awt::ImagePosition::RightTop: - addAttribute( rAttrName, "right-top" ); - break; - case awt::ImagePosition::RightCenter: - addAttribute( rAttrName, "right-center" ); - break; - case awt::ImagePosition::RightBottom: - addAttribute( rAttrName, "right-bottom" ); - break; - case awt::ImagePosition::AboveLeft: - addAttribute( rAttrName, "top-left" ); - break; - case awt::ImagePosition::AboveCenter: - addAttribute( rAttrName, "top-center" ); - break; - case awt::ImagePosition::AboveRight: - addAttribute( rAttrName, "top-right" ); - break; - case awt::ImagePosition::BelowLeft: - addAttribute( rAttrName, "bottom-left" ); - break; - case awt::ImagePosition::BelowCenter: - addAttribute( rAttrName, "bottom-center" ); - break; - case awt::ImagePosition::BelowRight: - addAttribute( rAttrName, "bottom-right" ); - break; - case awt::ImagePosition::Centered: - addAttribute( rAttrName, "center" ); - break; - default: - SAL_WARN( "xmlscript.xmldlg", "### illegal image position value!" ); - break; - } - } + case awt::ImagePosition::LeftTop: + addAttribute( rAttrName, "left-top" ); + break; + case awt::ImagePosition::LeftCenter: + addAttribute( rAttrName, "left-center" ); + break; + case awt::ImagePosition::LeftBottom: + addAttribute( rAttrName, "left-bottom" ); + break; + case awt::ImagePosition::RightTop: + addAttribute( rAttrName, "right-top" ); + break; + case awt::ImagePosition::RightCenter: + addAttribute( rAttrName, "right-center" ); + break; + case awt::ImagePosition::RightBottom: + addAttribute( rAttrName, "right-bottom" ); + break; + case awt::ImagePosition::AboveLeft: + addAttribute( rAttrName, "top-left" ); + break; + case awt::ImagePosition::AboveCenter: + addAttribute( rAttrName, "top-center" ); + break; + case awt::ImagePosition::AboveRight: + addAttribute( rAttrName, "top-right" ); + break; + case awt::ImagePosition::BelowLeft: + addAttribute( rAttrName, "bottom-left" ); + break; + case awt::ImagePosition::BelowCenter: + addAttribute( rAttrName, "bottom-center" ); + break; + case awt::ImagePosition::BelowRight: + addAttribute( rAttrName, "bottom-right" ); + break; + case awt::ImagePosition::Centered: + addAttribute( rAttrName, "center" ); + break; + default: + SAL_WARN( "xmlscript.xmldlg", "### illegal image position value!" ); + break; } } void ElementDescriptor::readButtonTypeAttr( OUString const & rPropName, OUString const & rAttrName ) { - if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName )) + if (beans::PropertyState_DEFAULT_VALUE == _xPropState->getPropertyState( rPropName )) + return; + + Any a( _xProps->getPropertyValue( rPropName ) ); + auto n = o3tl::tryAccess<sal_Int16>(a); + if (!n) + return; + + switch (static_cast<awt::PushButtonType>(*n)) { - Any a( _xProps->getPropertyValue( rPropName ) ); - if (auto n = o3tl::tryAccess<sal_Int16>(a)) - { - switch (static_cast<awt::PushButtonType>(*n)) - { - case awt::PushButtonType_STANDARD: - addAttribute( rAttrName, "standard" ); - break; - case awt::PushButtonType_OK: - addAttribute( rAttrName, "ok" ); - break; - case awt::PushButtonType_CANCEL: - addAttribute( rAttrName, "cancel" ); - break; - case awt::PushButtonType_HELP: - addAttribute( rAttrName, "help" ); - break; - default: - SAL_WARN( "xmlscript.xmldlg", "### illegal button-type value!" ); - break; - } - } + case awt::PushButtonType_STANDARD: + addAttribute( rAttrName, "standard" ); + break; + case awt::PushButtonType_OK: + addAttribute( rAttrName, "ok" ); + break; + case awt::PushButtonType_CANCEL: + addAttribute( rAttrName, "cancel" ); + break; + case awt::PushButtonType_HELP: + addAttribute( rAttrName, "help" ); + break; + default: + SAL_WARN( "xmlscript.xmldlg", "### illegal button-type value!" ); + break; } } void ElementDescriptor::readOrientationAttr( OUString const & rPropName, OUString const & rAttrName ) { - if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName )) + if (beans::PropertyState_DEFAULT_VALUE == _xPropState->getPropertyState( rPropName )) + return; + + Any a( _xProps->getPropertyValue( rPropName ) ); + auto n = o3tl::tryAccess<sal_Int32>(a); + if (!n) + return; + + switch (*n) { - Any a( _xProps->getPropertyValue( rPropName ) ); - if (auto n = o3tl::tryAccess<sal_Int32>(a)) - { - switch (*n) - { - case 0: - addAttribute( rAttrName, "horizontal" ); - break; - case 1: - addAttribute( rAttrName, "vertical" ); - break; - default: - SAL_WARN( "xmlscript.xmldlg", "### illegal orientation value!" ); - break; - } - } + case 0: + addAttribute( rAttrName, "horizontal" ); + break; + case 1: + addAttribute( rAttrName, "vertical" ); + break; + default: + SAL_WARN( "xmlscript.xmldlg", "### illegal orientation value!" ); + break; } } void ElementDescriptor::readLineEndFormatAttr( OUString const & rPropName, OUString const & rAttrName ) { - if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName )) + if (beans::PropertyState_DEFAULT_VALUE == _xPropState->getPropertyState( rPropName )) + return; + + Any a( _xProps->getPropertyValue( rPropName ) ); + auto n = o3tl::tryAccess<sal_Int16>(a); + if (!n) + return; + + switch (*n) { - Any a( _xProps->getPropertyValue( rPropName ) ); - if (auto n = o3tl::tryAccess<sal_Int16>(a)) - { - switch (*n) - { - case awt::LineEndFormat::CARRIAGE_RETURN: - addAttribute( rAttrName, "carriage-return" ); - break; - case awt::LineEndFormat::LINE_FEED: - addAttribute( rAttrName, "line-feed" ); - break; - case awt::LineEndFormat::CARRIAGE_RETURN_LINE_FEED: - addAttribute( rAttrName, "carriage-return-line-feed" ); - break; - default: - SAL_WARN( "xmlscript.xmldlg", "### illegal line end format value!" ); - break; - } - } + case awt::LineEndFormat::CARRIAGE_RETURN: + addAttribute( rAttrName, "carriage-return" ); + break; + case awt::LineEndFormat::LINE_FEED: + addAttribute( rAttrName, "line-feed" ); + break; + case awt::LineEndFormat::CARRIAGE_RETURN_LINE_FEED: + addAttribute( rAttrName, "carriage-return-line-feed" ); + break; + default: + SAL_WARN( "xmlscript.xmldlg", "### illegal line end format value!" ); + break; } } @@ -947,62 +951,62 @@ void ElementDescriptor::readDataAwareAttr( OUString const & rAttrName ) } } Reference< form::binding::XListEntrySink > xEntrySink( _xProps, UNO_QUERY ); - if ( xEntrySink.is() && rAttrName == XMLNS_DIALOGS_PREFIX ":source-cell-range" ) + if ( !(xEntrySink.is() && rAttrName == XMLNS_DIALOGS_PREFIX ":source-cell-range") ) + return; + + Reference< beans::XPropertySet > xListSource( xEntrySink->getListEntrySource(), UNO_QUERY ); + if ( !xListSource.is() ) + return; + + try { - Reference< beans::XPropertySet > xListSource( xEntrySink->getListEntrySource(), UNO_QUERY ); - if ( xListSource.is() ) - { - try - { - Reference< beans::XPropertySet > xConvertor( xFac->createInstance( "com.sun.star.table.CellRangeAddressConversion" ), uno::UNO_QUERY ); + Reference< beans::XPropertySet > xConvertor( xFac->createInstance( "com.sun.star.table.CellRangeAddressConversion" ), uno::UNO_QUERY ); - table::CellRangeAddress aAddress; - xListSource->getPropertyValue( "CellRange" ) >>= aAddress; + table::CellRangeAddress aAddress; + xListSource->getPropertyValue( "CellRange" ) >>= aAddress; - OUString sAddress; - xConvertor->setPropertyValue( "Address", makeAny( aAddress ) ); - xConvertor->getPropertyValue( "PersistentRepresentation" ) >>= sAddress; - SAL_INFO("xmlscript.xmldlg","**** cell range source list " << sAddress ); - if ( !sAddress.isEmpty() ) - addAttribute( rAttrName, sAddress ); - } - catch( uno::Exception& ) - { - } - } + OUString sAddress; + xConvertor->setPropertyValue( "Address", makeAny( aAddress ) ); + xConvertor->getPropertyValue( "PersistentRepresentation" ) >>= sAddress; + SAL_INFO("xmlscript.xmldlg","**** cell range source list " << sAddress ); + if ( !sAddress.isEmpty() ) + addAttribute( rAttrName, sAddress ); + } + catch( uno::Exception& ) + { } } void ElementDescriptor::readSelectionTypeAttr( OUString const & rPropName, OUString const & rAttrName ) { - if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName )) - { - Any aSelectionType ( _xProps->getPropertyValue( rPropName ) ); + if (beans::PropertyState_DEFAULT_VALUE == _xPropState->getPropertyState( rPropName )) + return; - if (aSelectionType.getValueTypeClass() == TypeClass_ENUM && aSelectionType.getValueType() == cppu::UnoType<view::SelectionType>::get()) - { - ::view::SelectionType eSelectionType; - aSelectionType >>= eSelectionType; + Any aSelectionType ( _xProps->getPropertyValue( rPropName ) ); - switch (eSelectionType) - { - case ::view::SelectionType_NONE: - addAttribute( rAttrName, "none" ); - break; - case ::view::SelectionType_SINGLE: - addAttribute( rAttrName, "single" ); - break; - case ::view::SelectionType_MULTI: - addAttribute( rAttrName, "multi" ); - break; - case ::view::SelectionType_RANGE: - addAttribute( rAttrName, "range" ); - break; - default: - SAL_WARN( "xmlscript.xmldlg", "### illegal selection type value!" ); - break; - } - } + if (!(aSelectionType.getValueTypeClass() == TypeClass_ENUM && aSelectionType.getValueType() == cppu::UnoType<view::SelectionType>::get())) + return; + + ::view::SelectionType eSelectionType; + aSelectionType >>= eSelectionType; + + switch (eSelectionType) + { + case ::view::SelectionType_NONE: + addAttribute( rAttrName, "none" ); + break; + case ::view::SelectionType_SINGLE: + addAttribute( rAttrName, "single" ); + break; + case ::view::SelectionType_MULTI: + addAttribute( rAttrName, "multi" ); + break; + case ::view::SelectionType_RANGE: + addAttribute( rAttrName, "range" ); + break; + default: + SAL_WARN( "xmlscript.xmldlg", "### illegal selection type value!" ); + break; } } @@ -1024,31 +1028,31 @@ void ElementDescriptor::readScrollableSettings() void ElementDescriptor::readImageScaleModeAttr( OUString const & rPropName, OUString const & rAttrName ) { - if (beans::PropertyState_DEFAULT_VALUE != _xPropState->getPropertyState( rPropName )) - { - Any aImageScaleMode( _xProps->getPropertyValue( rPropName ) ); + if (beans::PropertyState_DEFAULT_VALUE == _xPropState->getPropertyState( rPropName )) + return; - if (aImageScaleMode.getValueTypeClass() == TypeClass_SHORT) - { - sal_Int16 nImageScaleMode = 0; - aImageScaleMode >>= nImageScaleMode; + Any aImageScaleMode( _xProps->getPropertyValue( rPropName ) ); - switch(nImageScaleMode) - { - case ::awt::ImageScaleMode::NONE: - addAttribute( rAttrName, "none" ); - break; - case ::awt::ImageScaleMode::ISOTROPIC: - addAttribute( rAttrName, "isotropic" ); - break; - case ::awt::ImageScaleMode::ANISOTROPIC: - addAttribute( rAttrName, "anisotropic" ); - break; - default: - OSL_ENSURE( false, "### illegal image scale mode value."); - break; - } - } + if (aImageScaleMode.getValueTypeClass() != TypeClass_SHORT) + return; + + sal_Int16 nImageScaleMode = 0; + aImageScaleMode >>= nImageScaleMode; + + switch(nImageScaleMode) + { + case ::awt::ImageScaleMode::NONE: + addAttribute( rAttrName, "none" ); + break; + case ::awt::ImageScaleMode::ISOTROPIC: + addAttribute( rAttrName, "isotropic" ); + break; + case ::awt::ImageScaleMode::ANISOTROPIC: + addAttribute( rAttrName, "anisotropic" ); + break; + default: + OSL_ENSURE( false, "### illegal image scale mode value."); + break; } } @@ -1145,94 +1149,94 @@ void ElementDescriptor::readDefaults( bool supportPrintable, bool supportVisible void ElementDescriptor::readEvents() { Reference< script::XScriptEventsSupplier > xSupplier( _xProps, UNO_QUERY ); - if (xSupplier.is()) + if (!xSupplier.is()) + return; + + Reference< container::XNameContainer > xEvents( xSupplier->getEvents() ); + if (!xEvents.is()) + return; + + const Sequence< OUString > aNames( xEvents->getElementNames() ); + for ( const auto& rName : aNames ) { - Reference< container::XNameContainer > xEvents( xSupplier->getEvents() ); - if (xEvents.is()) + script::ScriptEventDescriptor descr; + if (xEvents->getByName( rName ) >>= descr) { - const Sequence< OUString > aNames( xEvents->getElementNames() ); - for ( const auto& rName : aNames ) - { - script::ScriptEventDescriptor descr; - if (xEvents->getByName( rName ) >>= descr) - { - SAL_WARN_IF( descr.ListenerType.isEmpty() || - descr.EventMethod.isEmpty() || - descr.ScriptCode.isEmpty() || - descr.ScriptType.isEmpty() , "xmlscript.xmldlg", "### invalid event descr!" ); + SAL_WARN_IF( descr.ListenerType.isEmpty() || + descr.EventMethod.isEmpty() || + descr.ScriptCode.isEmpty() || + descr.ScriptType.isEmpty() , "xmlscript.xmldlg", "### invalid event descr!" ); - OUString aEventName; + OUString aEventName; - if (descr.AddListenerParam.isEmpty()) + if (descr.AddListenerParam.isEmpty()) + { + // detection of event-name + OString listenerType( OUStringToOString( descr.ListenerType, RTL_TEXTENCODING_ASCII_US ) ); + OString eventMethod( OUStringToOString( descr.EventMethod, RTL_TEXTENCODING_ASCII_US ) ); + StringTriple const * p = g_pEventTranslations; + while (p->first) + { + if (0 == ::rtl_str_compare( p->second, eventMethod.getStr() ) && + 0 == ::rtl_str_compare( p->first, listenerType.getStr() )) { - // detection of event-name - OString listenerType( OUStringToOString( descr.ListenerType, RTL_TEXTENCODING_ASCII_US ) ); - OString eventMethod( OUStringToOString( descr.EventMethod, RTL_TEXTENCODING_ASCII_US ) ); - StringTriple const * p = g_pEventTranslations; - while (p->first) - { - if (0 == ::rtl_str_compare( p->second, eventMethod.getStr() ) && - 0 == ::rtl_str_compare( p->first, listenerType.getStr() )) - { - aEventName = OUString( p->third, ::rtl_str_getLength( p->third ), RTL_TEXTENCODING_ASCII_US ); - break; - } - ++p; - } + aEventName = OUString( p->third, ::rtl_str_getLength( p->third ), RTL_TEXTENCODING_ASCII_US ); + break; } + ++p; + } + } - ElementDescriptor * pElem; - Reference< xml::sax::XAttributeList > xElem; - - if (!aEventName.isEmpty()) // script:event - { - pElem = new ElementDescriptor( XMLNS_SCRIPT_PREFIX ":event" ); - xElem = pElem; + ElementDescriptor * pElem; + Reference< xml::sax::XAttributeList > xElem; - pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":event-name", aEventName ); - } - else // script:listener-event - { - pElem = new ElementDescriptor( XMLNS_SCRIPT_PREFIX ":listener-event" ); - xElem = pElem; - - pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":listener-type", descr.ListenerType ); - pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":listener-method", descr.EventMethod ); + if (!aEventName.isEmpty()) // script:event + { + pElem = new ElementDescriptor( XMLNS_SCRIPT_PREFIX ":event" ); + xElem = pElem; - if (!descr.AddListenerParam.isEmpty()) - { - pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":listener-param", descr.AddListenerParam ); - } - } - if ( descr.ScriptType == "StarBasic" ) - { - // separate optional location - sal_Int32 nIndex = descr.ScriptCode.indexOf( ':' ); - if (nIndex >= 0) - { - pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":location", descr.ScriptCode.copy( 0, nIndex ) ); - pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":macro-name", descr.ScriptCode.copy( nIndex +1 ) ); - } - else - { - pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":macro-name", descr.ScriptCode ); - } - } - else - { - pElem->addAttribute(XMLNS_SCRIPT_PREFIX ":macro-name", descr.ScriptCode ); - } + pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":event-name", aEventName ); + } + else // script:listener-event + { + pElem = new ElementDescriptor( XMLNS_SCRIPT_PREFIX ":listener-event" ); + xElem = pElem; - // language - pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":language", descr.ScriptType ); + pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":listener-type", descr.ListenerType ); + pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":listener-method", descr.EventMethod ); - addSubElement( xElem ); + if (!descr.AddListenerParam.isEmpty()) + { + pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":listener-param", descr.AddListenerParam ); + } + } + if ( descr.ScriptType == "StarBasic" ) + { + // separate optional location + sal_Int32 nIndex = descr.ScriptCode.indexOf( ':' ); + if (nIndex >= 0) + { + pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":location", descr.ScriptCode.copy( 0, nIndex ) ); + pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":macro-name", descr.ScriptCode.copy( nIndex +1 ) ); } else { - SAL_WARN( "xmlscript.xmldlg", "### unexpected event type in container!" ); + pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":macro-name", descr.ScriptCode ); } } + else + { + pElem->addAttribute(XMLNS_SCRIPT_PREFIX ":macro-name", descr.ScriptCode ); + } + + // language + pElem->addAttribute( XMLNS_SCRIPT_PREFIX ":language", descr.ScriptType ); + + addSubElement( xElem ); + } + else + { + SAL_WARN( "xmlscript.xmldlg", "### unexpected event type in container!" ); } } } @@ -1345,20 +1349,20 @@ StyleBag::~StyleBag() void StyleBag::dump( Reference< xml::sax::XExtendedDocumentHandler > const & xOut ) { - if (! _styles.empty()) + if ( _styles.empty()) + return; + + OUString aStylesName( XMLNS_DIALOGS_PREFIX ":styles" ); + xOut->ignorableWhitespace( OUString() ); + xOut->startElement( aStylesName, Reference< xml::sax::XAttributeList >() ); + // export styles + for (auto const & _style : _styles) { - OUString aStylesName( XMLNS_DIALOGS_PREFIX ":styles" ); - xOut->ignorableWhitespace( OUString() ); - xOut->startElement( aStylesName, Reference< xml::sax::XAttributeList >() ); - // export styles - for (auto const & _style : _styles) - { - Reference< xml::sax::XAttributeList > xAttr( _style->createElement() ); - static_cast< ElementDescriptor * >( xAttr.get() )->dump( xOut.get() ); - } - xOut->ignorableWhitespace( OUString() ); - xOut->endElement( aStylesName ); + Reference< xml::sax::XAttributeList > xAttr( _style->createElement() ); + static_cast< ElementDescriptor * >( xAttr.get() )->dump( xOut.get() ); } + xOut->ignorableWhitespace( OUString() ); + xOut->endElement( aStylesName ); } void exportDialogModel( diff --git a/xmlscript/source/xmldlg_imexp/xmldlg_impmodels.cxx b/xmlscript/source/xmldlg_imexp/xmldlg_impmodels.cxx index 640776592e58..96177d502165 100644 --- a/xmlscript/source/xmldlg_imexp/xmldlg_impmodels.cxx +++ b/xmlscript/source/xmldlg_imexp/xmldlg_impmodels.cxx @@ -1844,14 +1844,13 @@ Reference< xml::input::XElement > GridControlElement::startChildElement( Reference< xml::input::XAttributes > const & xAttributes ) { // event - if (m_xImport->isEventElement( nUid, rLocalName )) - { - return new EventElement( nUid, rLocalName, xAttributes, this, m_xImport.get() ); - } - else + if (!m_xImport->isEventElement( nUid, rLocalName )) { throw xml::sax::SAXException( "expected event element!", Reference< XInterface >(), Any() ); } + + return new EventElement( nUid, rLocalName, xAttributes, this, m_xImport.get() ); + } void GridControlElement::endElement() diff --git a/xmlscript/source/xmldlg_imexp/xmldlg_import.cxx b/xmlscript/source/xmldlg_imexp/xmldlg_import.cxx index 4a355b72852a..75d5bd481a63 100644 --- a/xmlscript/source/xmldlg_imexp/xmldlg_import.cxx +++ b/xmlscript/source/xmldlg_imexp/xmldlg_import.cxx @@ -220,22 +220,22 @@ void StyleElement::importBorderStyle( _inited |= 0x4; OUString aValue; - if (getStringAttr(&aValue, "border", _xAttributes, m_xImport->XMLNS_DIALOGS_UID )) - { - if ( aValue == "none" ) - _border = BORDER_NONE; - else if ( aValue == "3d" ) - _border = BORDER_3D; - else if ( aValue == "simple" ) - _border = BORDER_SIMPLE; - else { - _border = BORDER_SIMPLE_COLOR; - _borderColor = toInt32(aValue); - } + if (!getStringAttr(&aValue, "border", _xAttributes, m_xImport->XMLNS_DIALOGS_UID )) + return; - _hasValue |= 0x4; - importBorderStyle(xProps); // write values + if ( aValue == "none" ) + _border = BORDER_NONE; + else if ( aValue == "3d" ) + _border = BORDER_3D; + else if ( aValue == "simple" ) + _border = BORDER_SIMPLE; + else { + _border = BORDER_SIMPLE_COLOR; + _borderColor = toInt32(aValue); } + + _hasValue |= 0x4; + importBorderStyle(xProps); // write values } void StyleElement::importVisualEffectStyle( @@ -252,26 +252,26 @@ void StyleElement::importVisualEffectStyle( _inited |= 0x40; OUString aValue; - if (getStringAttr( &aValue, "look", _xAttributes, m_xImport->XMLNS_DIALOGS_UID )) - { - if ( aValue == "none" ) - { - _visualEffect = awt::VisualEffect::NONE; - } - else if ( aValue == "3d" ) - { - _visualEffect = awt::VisualEffect::LOOK3D; - } - else if ( aValue == "simple" ) - { - _visualEffect = awt::VisualEffect::FLAT; - } - else - OSL_ASSERT( false ); + if (!getStringAttr( &aValue, "look", _xAttributes, m_xImport->XMLNS_DIALOGS_UID )) + return; - _hasValue |= 0x40; - xProps->setPropertyValue( "VisualEffect", makeAny(_visualEffect) ); + if ( aValue == "none" ) + { + _visualEffect = awt::VisualEffect::NONE; } + else if ( aValue == "3d" ) + { + _visualEffect = awt::VisualEffect::LOOK3D; + } + else if ( aValue == "simple" ) + { + _visualEffect = awt::VisualEffect::FLAT; + } + else + OSL_ASSERT( false ); + + _hasValue |= 0x40; + xProps->setPropertyValue( "VisualEffect", makeAny(_visualEffect) ); } void StyleElement::setFontProperties( @@ -1435,111 +1435,111 @@ void ImportContext::importEvents( { Reference< script::XScriptEventsSupplier > xSupplier( _xControlModel, UNO_QUERY ); - if (xSupplier.is()) + if (!xSupplier.is()) + return; + + Reference< container::XNameContainer > xEvents( xSupplier->getEvents() ); + if (!xEvents.is()) + return; + + for (const auto & rEvent : rEvents) { - Reference< container::XNameContainer > xEvents( xSupplier->getEvents() ); - if (xEvents.is()) + script::ScriptEventDescriptor descr; + + EventElement * pEventElement = static_cast< EventElement * >( rEvent.get() ); + sal_Int32 nUid = pEventElement->getUid(); + OUString aLocalName( pEventElement->getLocalName() ); + Reference< xml::input::XAttributes > xAttributes( pEventElement->getAttributes() ); + + // nowadays script events + if (_pImport->XMLNS_SCRIPT_UID == nUid) { - for (const auto & rEvent : rEvents) + if (!getStringAttr( &descr.ScriptType, "language" , xAttributes, _pImport->XMLNS_SCRIPT_UID ) || + !getStringAttr( &descr.ScriptCode, "macro-name", xAttributes, _pImport->XMLNS_SCRIPT_UID )) { - script::ScriptEventDescriptor descr; - - EventElement * pEventElement = static_cast< EventElement * >( rEvent.get() ); - sal_Int32 nUid = pEventElement->getUid(); - OUString aLocalName( pEventElement->getLocalName() ); - Reference< xml::input::XAttributes > xAttributes( pEventElement->getAttributes() ); + throw xml::sax::SAXException( "missing language or macro-name attribute(s) of event!", Reference< XInterface >(), Any() ); + } + if ( descr.ScriptType == "StarBasic" ) + { + OUString aLocation; + if (getStringAttr( &aLocation, "location", xAttributes, _pImport->XMLNS_SCRIPT_UID )) + { + // prepend location + descr.ScriptCode = aLocation + ":" + descr.ScriptCode; + } + } + else if ( descr.ScriptType == "Script" ) + { + // Check if there is a protocol, if not assume + // this is an early scripting framework url ( without + // the protocol ) and fix it up!! + if ( descr.ScriptCode.indexOf( ':' ) == -1 ) + { + descr.ScriptCode = "vnd.sun.start.script:" + descr.ScriptCode; + } + } - // nowadays script events - if (_pImport->XMLNS_SCRIPT_UID == nUid) + // script:event element + if ( aLocalName == "event" ) + { + OUString aEventName; + if (! getStringAttr( &aEventName, "event-name", xAttributes, _pImport->XMLNS_SCRIPT_UID )) { - if (!getStringAttr( &descr.ScriptType, "language" , xAttributes, _pImport->XMLNS_SCRIPT_UID ) || - !getStringAttr( &descr.ScriptCode, "macro-name", xAttributes, _pImport->XMLNS_SCRIPT_UID )) - { - throw xml::sax::SAXException( "missing language or macro-name attribute(s) of event!", Reference< XInterface >(), Any() ); - } - if ( descr.ScriptType == "StarBasic" ) - { - OUString aLocation; - if (getStringAttr( &aLocation, "location", xAttributes, _pImport->XMLNS_SCRIPT_UID )) - { - // prepend location - descr.ScriptCode = aLocation + ":" + descr.ScriptCode; - } - } - else if ( descr.ScriptType == "Script" ) - { - // Check if there is a protocol, if not assume - // this is an early scripting framework url ( without - // the protocol ) and fix it up!! - if ( descr.ScriptCode.indexOf( ':' ) == -1 ) - { - descr.ScriptCode = "vnd.sun.start.script:" + descr.ScriptCode; - } - } + throw xml::sax::SAXException( "missing event-name attribute!", Reference< XInterface >(), Any() ); + } - // script:event element - if ( aLocalName == "event" ) - { - OUString aEventName; - if (! getStringAttr( &aEventName, "event-name", xAttributes, _pImport->XMLNS_SCRIPT_UID )) - { - throw xml::sax::SAXException( "missing event-name attribute!", Reference< XInterface >(), Any() ); - } - - // lookup in table - OString str( OUStringToOString( aEventName, RTL_TEXTENCODING_ASCII_US ) ); - StringTriple const * p = g_pEventTranslations; - while (p->first) - { - if (0 == ::rtl_str_compare( p->third, str.getStr() )) - { - descr.ListenerType = OUString( - p->first, ::rtl_str_getLength( p->first ), - RTL_TEXTENCODING_ASCII_US ); - descr.EventMethod = OUString( - p->second, ::rtl_str_getLength( p->second ), - RTL_TEXTENCODING_ASCII_US ); - break; - } - ++p; - } - - if (! p->first) - { - throw xml::sax::SAXException( "no matching event-name found!", Reference< XInterface >(), Any() ); - } - } - else // script:listener-event element + // lookup in table + OString str( OUStringToOString( aEventName, RTL_TEXTENCODING_ASCII_US ) ); + StringTriple const * p = g_pEventTranslations; + while (p->first) + { + if (0 == ::rtl_str_compare( p->third, str.getStr() )) { - SAL_WARN_IF( aLocalName != "listener-event", "xmlscript.xmldlg", "aLocalName != listener-event" ); - - if (!getStringAttr( &descr.ListenerType, "listener-type" , xAttributes, _pImport->XMLNS_SCRIPT_UID ) || - !getStringAttr( &descr.EventMethod , "listener-method", xAttributes, _pImport->XMLNS_SCRIPT_UID )) - { - throw xml::sax::SAXException("missing listener-type or listener-method attribute(s)!", Reference< XInterface >(), Any() ); - } - // optional listener param - getStringAttr( &descr.AddListenerParam, "listener-param", xAttributes, _pImport->XMLNS_SCRIPT_UID ); + descr.ListenerType = OUString( + p->first, ::rtl_str_getLength( p->first ), + RTL_TEXTENCODING_ASCII_US ); + descr.EventMethod = OUString( + p->second, ::rtl_str_getLength( p->second ), + RTL_TEXTENCODING_ASCII_US ); + break; } + ++p; } - else // deprecated dlg:event element - { - SAL_WARN_IF( _pImport->XMLNS_DIALOGS_UID != nUid || aLocalName != "event", "xmlscript.xmldlg", "_pImport->XMLNS_DIALOGS_UID != nUid || aLocalName != \"event\"" ); - if (!getStringAttr( &descr.ListenerType, "listener-type", xAttributes, _pImport->XMLNS_DIALOGS_UID ) || - !getStringAttr( &descr.EventMethod, "event-method", xAttributes, _pImport->XMLNS_DIALOGS_UID )) - { - throw xml::sax::SAXException("missing listener-type or event-method attribute(s)!", Reference< XInterface >(), Any() ); - } + if (! p->first) + { + throw xml::sax::SAXException( "no matching event-name found!", Reference< XInterface >(), Any() ); + } + } + else // script:listener-event element + { + SAL_WARN_IF( aLocalName != "listener-event", "xmlscript.xmldlg", "aLocalName != listener-event" ); - getStringAttr( &descr.ScriptType, "script-type", xAttributes, _pImport->XMLNS_DIALOGS_UID ); - getStringAttr( &descr.ScriptCode, "script-code", xAttributes, _pImport->XMLNS_DIALOGS_UID ); - getStringAttr( &descr.AddListenerParam, "param", xAttributes, _pImport->XMLNS_DIALOGS_UID ); + if (!getStringAttr( &descr.ListenerType, "listener-type" , xAttributes, _pImport->XMLNS_SCRIPT_UID ) || + !getStringAttr( &descr.EventMethod , "listener-method", xAttributes, _pImport->XMLNS_SCRIPT_UID )) + { + throw xml::sax::SAXException("missing listener-type or listener-method attribute(s)!", Reference< XInterface >(), Any() ); } + // optional listener param + getStringAttr( &descr.AddListenerParam, "listener-param", xAttributes, _pImport->XMLNS_SCRIPT_UID ); + } + } + else // deprecated dlg:event element + { + SAL_WARN_IF( _pImport->XMLNS_DIALOGS_UID != nUid || aLocalName != "event", "xmlscript.xmldlg", "_pImport->XMLNS_DIALOGS_UID != nUid || aLocalName != \"event\"" ); - xEvents->insertByName( descr.ListenerType + "::" + descr.EventMethod, makeAny( descr ) ); + if (!getStringAttr( &descr.ListenerType, "listener-type", xAttributes, _pImport->XMLNS_DIALOGS_UID ) || + !getStringAttr( &descr.EventMethod, "event-method", xAttributes, _pImport->XMLNS_DIALOGS_UID )) + { + throw xml::sax::SAXException("missing listener-type or event-method attribute(s)!", Reference< XInterface >(), Any() ); } + + getStringAttr( &descr.ScriptType, "script-type", xAttributes, _pImport->XMLNS_DIALOGS_UID ); + getStringAttr( &descr.ScriptCode, "script-code", xAttributes, _pImport->XMLNS_DIALOGS_UID ); + getStringAttr( &descr.AddListenerParam, "param", xAttributes, _pImport->XMLNS_DIALOGS_UID ); } + + xEvents->insertByName( descr.ListenerType + "::" + descr.EventMethod, makeAny( descr ) ); } } void ImportContext::importScollableSettings( |