diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-08-26 13:12:36 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-08-27 14:17:47 +0200 |
commit | 6a33cdd0c440bdf3a563d514da3fdaef841c1588 (patch) | |
tree | 6bd190e42f749931c4be736d812a99a80d9645b7 | |
parent | 00791931967170aecc4260e568efa11724386692 (diff) |
convert remaining XMLPropStyleContext subclasses to fastparser
Change-Id: If78be8caf1b1a87ef16abf04a29bc30762ddb90b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101440
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
23 files changed, 391 insertions, 500 deletions
diff --git a/include/xmloff/XMLDrawingPageStyleContext.hxx b/include/xmloff/XMLDrawingPageStyleContext.hxx index 22fa6f88f041..5587e5ddde07 100644 --- a/include/xmloff/XMLDrawingPageStyleContext.hxx +++ b/include/xmloff/XMLDrawingPageStyleContext.hxx @@ -27,11 +27,6 @@ class XMLOFF_DLLPUBLIC XMLDrawingPageStyleContext : public XMLPropStyleContext { public: - XMLDrawingPageStyleContext(SvXMLImport& rImport, sal_uInt16 nPrefix, OUString const& rLocalName, - css::uno::Reference<css::xml::sax::XAttributeList> const& xAttrList, - SvXMLStylesContext& rStyles, - ContextID_Index_Pair const pContextIDs[], - XmlStyleFamily const pFamilies[]); XMLDrawingPageStyleContext( SvXMLImport& rImport, sal_Int32 nElement, css::uno::Reference<css::xml::sax::XFastAttributeList> const& xAttrList, diff --git a/include/xmloff/XMLGraphicsDefaultStyle.hxx b/include/xmloff/XMLGraphicsDefaultStyle.hxx index 0d3c088c76f0..20c6c1dbfe7e 100644 --- a/include/xmloff/XMLGraphicsDefaultStyle.hxx +++ b/include/xmloff/XMLGraphicsDefaultStyle.hxx @@ -28,21 +28,14 @@ class XMLOFF_DLLPUBLIC XMLGraphicsDefaultStyle final : public XMLPropStyleContex { public: - XMLGraphicsDefaultStyle( SvXMLImport& rImport, sal_uInt16 nPrfx, - const OUString& rLName, - const css::uno::Reference< css::xml::sax::XAttributeList >& xAttrList, - SvXMLStylesContext& rStyles); - XMLGraphicsDefaultStyle( SvXMLImport& rImport, sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList, SvXMLStylesContext& rStyles); virtual ~XMLGraphicsDefaultStyle() override; - virtual SvXMLImportContextRef CreateChildContext( - sal_uInt16 nPrefix, - const OUString& rLocalName, - const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList ) override; + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override; // This method is called for every default style virtual void SetDefaults() override; diff --git a/include/xmloff/XMLShapeStyleContext.hxx b/include/xmloff/XMLShapeStyleContext.hxx index 93e0ffa72031..86f18a8340c3 100644 --- a/include/xmloff/XMLShapeStyleContext.hxx +++ b/include/xmloff/XMLShapeStyleContext.hxx @@ -50,10 +50,8 @@ public: XmlStyleFamily nFamily); virtual ~XMLShapeStyleContext() override; - SvXMLImportContextRef CreateChildContext( - sal_uInt16 nPrefix, - const OUString& rLocalName, - const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList ) override; + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override; virtual void Finish( bool bOverwrite ) override; diff --git a/include/xmloff/XMLTextShapeStyleContext.hxx b/include/xmloff/XMLTextShapeStyleContext.hxx index 531e81da0377..3d03dcc578af 100644 --- a/include/xmloff/XMLTextShapeStyleContext.hxx +++ b/include/xmloff/XMLTextShapeStyleContext.hxx @@ -41,10 +41,8 @@ public: SvXMLStylesContext& rStyles, XmlStyleFamily nFamily ); virtual ~XMLTextShapeStyleContext() override; - virtual SvXMLImportContextRef CreateChildContext( - sal_uInt16 nPrefix, - const OUString& rLocalName, - const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList ) override; + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override; virtual void CreateAndInsert( bool bOverwrite ) override; diff --git a/include/xmloff/prstylei.hxx b/include/xmloff/prstylei.hxx index b99b945f5977..38d0147eb148 100644 --- a/include/xmloff/prstylei.hxx +++ b/include/xmloff/prstylei.hxx @@ -88,11 +88,6 @@ protected: public: - XMLPropStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx, - const OUString& rLName, - const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList, - SvXMLStylesContext& rStyles, XmlStyleFamily nFamily, - bool bDefaultStyle=false ); XMLPropStyleContext( SvXMLImport& rImport, sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList, SvXMLStylesContext& rStyles, XmlStyleFamily nFamily, @@ -102,11 +97,6 @@ public: virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override; - virtual SvXMLImportContextRef CreateChildContext( - sal_uInt16 nPrefix, - const OUString& rLocalName, - const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList ) override; - virtual void FillPropertySet( const css::uno::Reference< css::beans::XPropertySet > & rPropSet ); diff --git a/include/xmloff/txtstyli.hxx b/include/xmloff/txtstyli.hxx index 4a2997ce1223..4224d49e4869 100644 --- a/include/xmloff/txtstyli.hxx +++ b/include/xmloff/txtstyli.hxx @@ -53,12 +53,6 @@ protected: public: - - XMLTextStyleContext( SvXMLImport& rImport, sal_uInt16 nPrfx, - const OUString& rLName, - const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList, - SvXMLStylesContext& rStyles, XmlStyleFamily nFamily, - bool bDefaultStyle = false ); XMLTextStyleContext( SvXMLImport& rImport, sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList, SvXMLStylesContext& rStyles, XmlStyleFamily nFamily, @@ -68,10 +62,8 @@ public: XMLTextStyleContext(const XMLTextStyleContext &) = delete; XMLTextStyleContext operator=(const XMLTextStyleContext &) = delete; - virtual SvXMLImportContextRef CreateChildContext( - sal_uInt16 nPrefix, - const OUString& rLocalName, - const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList ) override; + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override; const OUString& GetListStyle() const { return m_sListStyleName; } // XML import: reconstruction of assignment of paragraph style to outline levels (#i69629#) diff --git a/include/xmloff/xmlimppr.hxx b/include/xmloff/xmlimppr.hxx index 3694219d353b..2b8594597de4 100644 --- a/include/xmloff/xmlimppr.hxx +++ b/include/xmloff/xmlimppr.hxx @@ -33,6 +33,7 @@ namespace com::sun::star::beans { class XPropertySet; } namespace com::sun::star::beans { class XPropertySetInfo; } namespace com::sun::star::beans { class XTolerantMultiPropertySet; } namespace com::sun::star::beans { struct PropertyValue; } +namespace com::sun::star::container { class XNameContainer; } namespace com::sun::star::uno { class Any; } namespace com::sun::star::uno { template <typename > class Reference; } namespace com::sun::star::uno { template <typename > class Sequence; } @@ -186,6 +187,20 @@ public: ContextID_Index_Pair* pSpecialContextIds, css::uno::Sequence< OUString >& rNames, css::uno::Sequence< css::uno::Any >& rValues); + +private: + void importXMLAttribute( + std::vector< XMLPropertyState >& rProperties, + const SvXMLUnitConverter& rUnitConverter, + const SvXMLNamespaceMap& rNamespaceMap, + sal_uInt32 nPropType, + sal_Int32 nStartIdx, + sal_Int32 nEndIdx, + css::uno::Reference< css::container::XNameContainer >& xAttrContainer, + const OUString& aPrefix, + const OUString& sAttrName, + const OUString& aNamespaceURI, + const OUString& sValue) const; }; diff --git a/sw/source/filter/xml/xmlfmt.cxx b/sw/source/filter/xml/xmlfmt.cxx index e2d2e6d34ebf..f56c2009035d 100644 --- a/sw/source/filter/xml/xmlfmt.cxx +++ b/sw/source/filter/xml/xmlfmt.cxx @@ -209,9 +209,8 @@ class SwXMLConditionContext_Impl : public SvXMLImportContext public: SwXMLConditionContext_Impl( - SvXMLImport& rImport, sal_uInt16 nPrfx, - const OUString& rLName, - const uno::Reference< xml::sax::XAttributeList > & xAttrList ); + SvXMLImport& rImport, sal_Int32 nElement, + const uno::Reference< xml::sax::XFastAttributeList > & xAttrList ); bool IsValid() const { return Master_CollCondition::NONE != nCondition; } @@ -223,39 +222,32 @@ public: } SwXMLConditionContext_Impl::SwXMLConditionContext_Impl( - SvXMLImport& rImport, sal_uInt16 nPrfx, - const OUString& rLName, - const uno::Reference< xml::sax::XAttributeList > & xAttrList ) : - SvXMLImportContext( rImport, nPrfx, rLName ), + SvXMLImport& rImport, sal_Int32 /*nElement*/, + const uno::Reference< xml::sax::XFastAttributeList > & xAttrList ) : + SvXMLImportContext( rImport ), nCondition( Master_CollCondition::NONE ), nSubCondition( 0 ) { - sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; - for( sal_Int16 i=0; i < nAttrCount; i++ ) + for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList )) { - const OUString& rAttrName = xAttrList->getNameByIndex( i ); - OUString aLocalName; - const sal_uInt16 nPrefix = - GetImport().GetNamespaceMap().GetKeyByAttrName( rAttrName, - &aLocalName ); - const OUString& rValue = xAttrList->getValueByIndex( i ); - - // TODO: use a map here - if( XML_NAMESPACE_STYLE == nPrefix ) + OUString sValue = aIter.toString(); + switch (aIter.getToken()) { - if( IsXMLToken( aLocalName, XML_CONDITION ) ) + case XML_ELEMENT(STYLE, XML_CONDITION): { - SwXMLConditionParser_Impl aCondParser( rValue ); + SwXMLConditionParser_Impl aCondParser( sValue ); if( aCondParser.IsValid() ) { nCondition = aCondParser.GetCondition(); nSubCondition = aCondParser.GetSubCondition(); } + break; } - else if( IsXMLToken( aLocalName, XML_APPLY_STYLE_NAME ) ) - { - sApplyStyle = rValue; - } + case XML_ELEMENT(STYLE, XML_APPLY_STYLE_NAME): + sApplyStyle = sValue; + break; + default: + SAL_WARN("sw", "unknown attribute " << SvXMLImport::getPrefixAndNameFromToken(aIter.getToken()) << "=" << sValue); } } } @@ -277,21 +269,13 @@ protected: public: - SwXMLTextStyleContext_Impl( SwXMLImport& rImport, sal_uInt16 nElement, - const OUString& rLName, - const uno::Reference< xml::sax::XAttributeList > & xAttrList, - XmlStyleFamily nFamily, - SvXMLStylesContext& rStyles ); - SwXMLTextStyleContext_Impl( SwXMLImport& rImport, sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList > & xAttrList, XmlStyleFamily nFamily, SvXMLStylesContext& rStyles ); - virtual SvXMLImportContextRef CreateChildContext( - sal_uInt16 nPrefix, - const OUString& rLocalName, - const uno::Reference< xml::sax::XAttributeList > & xAttrList ) override; + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override; }; } @@ -364,15 +348,6 @@ SwXMLTextStyleContext_Impl::Finish( bool bOverwrite ) } SwXMLTextStyleContext_Impl::SwXMLTextStyleContext_Impl( SwXMLImport& rImport, - sal_uInt16 nPrfx, const OUString& rLName, - const uno::Reference< xml::sax::XAttributeList > & xAttrList, - XmlStyleFamily nFamily, - SvXMLStylesContext& rStyles ) : - XMLTextStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles, nFamily ) -{ -} - -SwXMLTextStyleContext_Impl::SwXMLTextStyleContext_Impl( SwXMLImport& rImport, sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList > & xAttrList, XmlStyleFamily nFamily, @@ -381,32 +356,24 @@ SwXMLTextStyleContext_Impl::SwXMLTextStyleContext_Impl( SwXMLImport& rImport, { } -SvXMLImportContextRef SwXMLTextStyleContext_Impl::CreateChildContext( - sal_uInt16 nPrefix, - const OUString& rLocalName, - const uno::Reference< xml::sax::XAttributeList > & xAttrList ) +css::uno::Reference< css::xml::sax::XFastContextHandler > SwXMLTextStyleContext_Impl::createFastChildContext( + sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) { - SvXMLImportContextRef xContext; - - if( XML_NAMESPACE_STYLE == nPrefix && IsXMLToken( rLocalName, XML_MAP ) ) + if( nElement == XML_ELEMENT(STYLE, XML_MAP) ) { rtl::Reference<SwXMLConditionContext_Impl> xCond{ - new SwXMLConditionContext_Impl( GetImport(), nPrefix, - rLocalName, xAttrList )}; + new SwXMLConditionContext_Impl( GetImport(), nElement, xAttrList )}; if( xCond->IsValid() ) { if( !pConditions ) pConditions = std::make_unique<SwXMLConditions_Impl>(); pConditions->push_back( xCond ); } - xContext = xCond.get(); + return xCond.get(); } - if (!xContext) - xContext = XMLTextStyleContext::CreateChildContext( nPrefix, rLocalName, - xAttrList ); - - return xContext; + return XMLTextStyleContext::createFastChildContext( nElement, xAttrList ); } namespace { @@ -460,10 +427,6 @@ public: virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override; - virtual SvXMLImportContextRef CreateChildContext( sal_uInt16 nPrefix, - const OUString& rLocalName, - const css::uno::Reference< css::xml::sax::XAttributeList >& xAttrList ) override; - // The item set may be empty! SfxItemSet *GetItemSet() { return pItemSet.get(); } @@ -630,37 +593,6 @@ void SwXMLItemSetStyleContext_Impl::CreateAndInsert( bool bOverwrite ) pTextStyle->CreateAndInsert( bOverwrite ); } -SvXMLImportContextRef SwXMLItemSetStyleContext_Impl::CreateChildContext( - sal_uInt16 nPrefix, - const OUString& rLocalName, - const css::uno::Reference< css::xml::sax::XAttributeList >& xAttrList ) -{ - SvXMLImportContextRef xContext; - - if( XML_NAMESPACE_STYLE == nPrefix ) - { - if( IsXMLToken( rLocalName, XML_TEXT_PROPERTIES ) || - IsXMLToken( rLocalName, XML_PARAGRAPH_PROPERTIES )) - { - if( !pTextStyle ) - { - SvXMLAttributeList *pTmp = new SvXMLAttributeList; - const OUString aStr = GetImport().GetNamespaceMap().GetQNameByKey( - nPrefix, GetXMLToken(XML_NAME) ); - pTmp->AddAttribute( aStr, GetName() ); - uno::Reference <xml::sax::XAttributeList> xTmpAttrList = pTmp; - pTextStyle = new SwXMLTextStyleContext_Impl( GetSwImport(), nPrefix, - rLocalName, xTmpAttrList, XmlStyleFamily::TEXT_PARAGRAPH, rStyles ); - pTextStyle->StartElement( xTmpAttrList ); - rStyles.AddStyle( *pTextStyle ); - } - xContext = pTextStyle->CreateChildContext( nPrefix, rLocalName, xAttrList ); - } - } - - return xContext; -} - css::uno::Reference< css::xml::sax::XFastContextHandler > SwXMLItemSetStyleContext_Impl::createFastChildContext( sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList > & xAttrList ) @@ -675,8 +607,18 @@ css::uno::Reference< css::xml::sax::XFastContextHandler > SwXMLItemSetStyleConte break; case XML_ELEMENT(STYLE, XML_TEXT_PROPERTIES): case XML_ELEMENT(STYLE, XML_PARAGRAPH_PROPERTIES): - // handled in CreateChildContext - break; + { + if( !pTextStyle ) + { + rtl::Reference<sax_fastparser::FastAttributeList> xTmpAttrList = new sax_fastparser::FastAttributeList(nullptr); + xTmpAttrList->add(XML_ELEMENT(STYLE, XML_NAME), GetName().toUtf8() ); + pTextStyle = new SwXMLTextStyleContext_Impl( GetSwImport(), nElement, + xTmpAttrList.get(), XmlStyleFamily::TEXT_PARAGRAPH, rStyles ); + pTextStyle->startFastElement( nElement, xTmpAttrList.get() ); + rStyles.AddStyle( *pTextStyle ); + } + return pTextStyle->createFastChildContext( nElement, xAttrList ); + } default: SAL_WARN("sw", "unknown element " << SvXMLImport::getPrefixAndNameFromToken(nElement)); } diff --git a/xmloff/inc/XMLChartStyleContext.hxx b/xmloff/inc/XMLChartStyleContext.hxx index 9da6900862f6..8fc13f3cc6da 100644 --- a/xmloff/inc/XMLChartStyleContext.hxx +++ b/xmloff/inc/XMLChartStyleContext.hxx @@ -46,10 +46,8 @@ public: const css::uno::Reference<css::beans::XPropertySet > & rPropSet ) override; /// necessary for property context (element-property symbol-image) - virtual SvXMLImportContextRef CreateChildContext( - sal_uInt16 nPrefix, - const OUString& rLocalName, - const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList ) override; + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override; bool isEmptyDataStyleName() override { return msDataStyleName.isEmpty(); } }; diff --git a/xmloff/inc/XMLShapePropertySetContext.hxx b/xmloff/inc/XMLShapePropertySetContext.hxx index 2a5ac3c81129..9aab3078d5d5 100644 --- a/xmloff/inc/XMLShapePropertySetContext.hxx +++ b/xmloff/inc/XMLShapePropertySetContext.hxx @@ -36,6 +36,11 @@ public: sal_uInt32 nFam, ::std::vector< XMLPropertyState > &rProps, const rtl::Reference < SvXMLImportPropertyMapper > &rMap ); + XMLShapePropertySetContext( SvXMLImport& rImport, sal_Int32 nElement, + const css::uno::Reference<css::xml::sax::XFastAttributeList >& xAttrList, + sal_uInt32 nFam, + ::std::vector< XMLPropertyState > &rProps, + const rtl::Reference < SvXMLImportPropertyMapper > &rMap ); virtual ~XMLShapePropertySetContext() override; diff --git a/xmloff/source/chart/XMLChartPropertyContext.cxx b/xmloff/source/chart/XMLChartPropertyContext.cxx index ea3ead155232..4055332f3efe 100644 --- a/xmloff/source/chart/XMLChartPropertyContext.cxx +++ b/xmloff/source/chart/XMLChartPropertyContext.cxx @@ -25,18 +25,16 @@ #include <xmloff/xmlimppr.hxx> #include <xmloff/xmlprmap.hxx> - using namespace ::com::sun::star; XMLChartPropertyContext::XMLChartPropertyContext( SvXMLImport& rImport, - sal_uInt16 nPrfx, - const OUString& rLName, - const uno::Reference< xml::sax::XAttributeList > & xAttrList, + sal_Int32 nElement, + const uno::Reference< xml::sax::XFastAttributeList > & xAttrList, sal_uInt32 nFamily, ::std::vector< XMLPropertyState >& rProps, const rtl::Reference< SvXMLImportPropertyMapper >& rMapper ) : - SvXMLPropertySetContext( rImport, nPrfx, rLName, xAttrList, nFamily, rProps, rMapper ) + SvXMLPropertySetContext( rImport, nElement, xAttrList, nFamily, rProps, rMapper ) { } diff --git a/xmloff/source/chart/XMLChartPropertyContext.hxx b/xmloff/source/chart/XMLChartPropertyContext.hxx index ba572e7e5c9e..4689aa6973e6 100644 --- a/xmloff/source/chart/XMLChartPropertyContext.hxx +++ b/xmloff/source/chart/XMLChartPropertyContext.hxx @@ -25,9 +25,8 @@ class XMLChartPropertyContext : public SvXMLPropertySetContext { public: - XMLChartPropertyContext( SvXMLImport& rImport, sal_uInt16 nPrfx, - const OUString& rLName, - const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList, + XMLChartPropertyContext( SvXMLImport& rImport, sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList, sal_uInt32 nFamily, ::std::vector< XMLPropertyState >& rProps, const rtl::Reference< SvXMLImportPropertyMapper >& rMapper ); diff --git a/xmloff/source/chart/XMLChartStyleContext.cxx b/xmloff/source/chart/XMLChartStyleContext.cxx index fe4634664f5b..7433cf10c4cc 100644 --- a/xmloff/source/chart/XMLChartStyleContext.cxx +++ b/xmloff/source/chart/XMLChartStyleContext.cxx @@ -23,6 +23,7 @@ #include <xmloff/xmlnumfi.hxx> #include <xmloff/families.hxx> #include <xmloff/xmltypes.hxx> +#include <xmloff/xmlimp.hxx> #include <xmloff/xmlimppr.hxx> #include <com/sun/star/beans/XPropertySet.hpp> @@ -108,40 +109,37 @@ void XMLChartStyleContext::FillPropertySet( lcl_NumberFormatStyleToProperty( msPercentageDataStyleName, "PercentageNumberFormat", mrStyles, rPropSet ); } -SvXMLImportContextRef XMLChartStyleContext::CreateChildContext( - sal_uInt16 nPrefix, - const OUString& rLocalName, - const uno::Reference< xml::sax::XAttributeList > & xAttrList ) +css::uno::Reference< css::xml::sax::XFastContextHandler > XMLChartStyleContext::createFastChildContext( + sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) { SvXMLImportContextRef xContext; - if( XML_NAMESPACE_STYLE == nPrefix || XML_NAMESPACE_LO_EXT == nPrefix ) + if( IsTokenInNamespace(nElement, XML_NAMESPACE_STYLE) || + IsTokenInNamespace(nElement, XML_NAMESPACE_LO_EXT) ) { + sal_Int32 nLocalName = nElement & TOKEN_MASK; sal_uInt32 nFamily = 0; - if( IsXMLToken( rLocalName, XML_TEXT_PROPERTIES ) ) + if( nLocalName == XML_TEXT_PROPERTIES ) nFamily = XML_TYPE_PROP_TEXT; - else if( IsXMLToken( rLocalName, XML_PARAGRAPH_PROPERTIES ) ) + else if( nLocalName == XML_PARAGRAPH_PROPERTIES ) nFamily = XML_TYPE_PROP_PARAGRAPH; - else if( IsXMLToken( rLocalName, XML_GRAPHIC_PROPERTIES ) ) + else if( nLocalName == XML_GRAPHIC_PROPERTIES ) nFamily = XML_TYPE_PROP_GRAPHIC; - else if( IsXMLToken( rLocalName, XML_CHART_PROPERTIES ) ) + else if( nLocalName == XML_CHART_PROPERTIES ) nFamily = XML_TYPE_PROP_CHART; if( nFamily ) { rtl::Reference < SvXMLImportPropertyMapper > xImpPrMap = GetStyles()->GetImportPropertyMapper( GetFamily() ); if( xImpPrMap.is() ) - xContext = new XMLChartPropertyContext( - GetImport(), nPrefix, rLocalName, xAttrList, nFamily, + return new XMLChartPropertyContext( + GetImport(), nElement, xAttrList, nFamily, GetProperties(), xImpPrMap ); } } - if (!xContext) - xContext = XMLShapeStyleContext::CreateChildContext( nPrefix, rLocalName, - xAttrList ); - - return xContext; + return XMLShapeStyleContext::createFastChildContext( nElement, xAttrList ); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/xmloff/source/draw/XMLGraphicsDefaultStyle.cxx b/xmloff/source/draw/XMLGraphicsDefaultStyle.cxx index 5a18b149a354..8224bed6392a 100644 --- a/xmloff/source/draw/XMLGraphicsDefaultStyle.cxx +++ b/xmloff/source/draw/XMLGraphicsDefaultStyle.cxx @@ -49,11 +49,6 @@ using ::xmloff::token::XML_GRAPHIC_PROPERTIES; using ::xmloff::token::XML_PARAGRAPH_PROPERTIES; -XMLGraphicsDefaultStyle::XMLGraphicsDefaultStyle( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName, const Reference< XAttributeList >& xAttrList, SvXMLStylesContext& rStyles ) -: XMLPropStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles, XmlStyleFamily::SD_GRAPHICS_ID, true ) -{ -} - XMLGraphicsDefaultStyle::XMLGraphicsDefaultStyle( SvXMLImport& rImport, sal_Int32 nElement, const Reference< XFastAttributeList >& xAttrList, SvXMLStylesContext& rStyles ) : XMLPropStyleContext( rImport, nElement, xAttrList, rStyles, XmlStyleFamily::SD_GRAPHICS_ID, true ) { @@ -63,31 +58,32 @@ XMLGraphicsDefaultStyle::~XMLGraphicsDefaultStyle() { } -SvXMLImportContextRef XMLGraphicsDefaultStyle::CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const Reference< XAttributeList > & xAttrList ) +css::uno::Reference< css::xml::sax::XFastContextHandler > XMLGraphicsDefaultStyle::createFastChildContext( + sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) { SvXMLImportContextRef xContext; - if( XML_NAMESPACE_STYLE == nPrefix || XML_NAMESPACE_LO_EXT == nPrefix ) + if( IsTokenInNamespace(nElement, XML_NAMESPACE_STYLE) || + IsTokenInNamespace(nElement, XML_NAMESPACE_LO_EXT) ) { + sal_Int32 nLocalName = nElement & TOKEN_MASK; sal_uInt32 nFamily = 0; - if( IsXMLToken( rLocalName, XML_TEXT_PROPERTIES ) ) + if( nLocalName == XML_TEXT_PROPERTIES ) nFamily = XML_TYPE_PROP_TEXT; - else if( IsXMLToken( rLocalName, XML_PARAGRAPH_PROPERTIES ) ) + else if( nLocalName == XML_PARAGRAPH_PROPERTIES ) nFamily = XML_TYPE_PROP_PARAGRAPH; - else if( IsXMLToken( rLocalName, XML_GRAPHIC_PROPERTIES ) ) + else if( nLocalName == XML_GRAPHIC_PROPERTIES ) nFamily = XML_TYPE_PROP_GRAPHIC; if( nFamily ) { rtl::Reference < SvXMLImportPropertyMapper > xImpPrMap = GetStyles()->GetImportPropertyMapper( GetFamily() ); if( xImpPrMap.is() ) - xContext = new XMLShapePropertySetContext( GetImport(), nPrefix, rLocalName, xAttrList, nFamily, GetProperties(), xImpPrMap ); + return new XMLShapePropertySetContext( GetImport(), nElement, xAttrList, nFamily, GetProperties(), xImpPrMap ); } } - if (!xContext) - xContext = XMLPropStyleContext::CreateChildContext( nPrefix, rLocalName, xAttrList ); - - return xContext; + return XMLPropStyleContext::createFastChildContext( nElement, xAttrList ); } namespace { diff --git a/xmloff/source/draw/XMLShapePropertySetContext.cxx b/xmloff/source/draw/XMLShapePropertySetContext.cxx index 8d172a35eac0..2fbcbb57e551 100644 --- a/xmloff/source/draw/XMLShapePropertySetContext.cxx +++ b/xmloff/source/draw/XMLShapePropertySetContext.cxx @@ -44,6 +44,18 @@ XMLShapePropertySetContext::XMLShapePropertySetContext( { } +XMLShapePropertySetContext::XMLShapePropertySetContext( + SvXMLImport& rImport, sal_Int32 nElement, + const Reference< xml::sax::XFastAttributeList > & xAttrList, + sal_uInt32 nFam, + ::std::vector< XMLPropertyState > &rProps, + const rtl::Reference < SvXMLImportPropertyMapper > &rMap ) : + SvXMLPropertySetContext( rImport, nElement, xAttrList, nFam, + rProps, rMap ), + mnBulletIndex(-1) +{ +} + XMLShapePropertySetContext::~XMLShapePropertySetContext() { } diff --git a/xmloff/source/draw/XMLShapeStyleContext.cxx b/xmloff/source/draw/XMLShapeStyleContext.cxx index b10ef865ec2d..1096c0aae417 100644 --- a/xmloff/source/draw/XMLShapeStyleContext.cxx +++ b/xmloff/source/draw/XMLShapeStyleContext.cxx @@ -89,40 +89,36 @@ void XMLShapeStyleContext::SetAttribute( sal_uInt16 nPrefixKey, const OUString& } } -SvXMLImportContextRef XMLShapeStyleContext::CreateChildContext( - sal_uInt16 nPrefix, - const OUString& rLocalName, - const Reference< xml::sax::XAttributeList > & xAttrList ) +css::uno::Reference< css::xml::sax::XFastContextHandler > XMLShapeStyleContext::createFastChildContext( + sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) { SvXMLImportContextRef xContext; - if( XML_NAMESPACE_STYLE == nPrefix || XML_NAMESPACE_LO_EXT == nPrefix ) + if( IsTokenInNamespace(nElement, XML_NAMESPACE_STYLE) || + IsTokenInNamespace(nElement, XML_NAMESPACE_LO_EXT) ) { + sal_Int32 nLocalName = nElement & TOKEN_MASK; sal_uInt32 nFamily = 0; - if( IsXMLToken( rLocalName, XML_TEXT_PROPERTIES ) ) + if( nLocalName == XML_TEXT_PROPERTIES ) nFamily = XML_TYPE_PROP_TEXT; - else if( IsXMLToken( rLocalName, XML_PARAGRAPH_PROPERTIES ) ) + else if( nLocalName == XML_PARAGRAPH_PROPERTIES ) nFamily = XML_TYPE_PROP_PARAGRAPH; - else if( IsXMLToken( rLocalName, XML_GRAPHIC_PROPERTIES ) ) + else if( nLocalName == XML_GRAPHIC_PROPERTIES ) nFamily = XML_TYPE_PROP_GRAPHIC; if( nFamily ) { rtl::Reference < SvXMLImportPropertyMapper > xImpPrMap = GetStyles()->GetImportPropertyMapper( GetFamily() ); if( xImpPrMap.is() ) - xContext = new XMLShapePropertySetContext( GetImport(), nPrefix, - rLocalName, xAttrList, + return new XMLShapePropertySetContext( GetImport(), nElement, xAttrList, nFamily, GetProperties(), xImpPrMap ); } } - if (!xContext) - xContext = XMLPropStyleContext::CreateChildContext( nPrefix, rLocalName, - xAttrList ); - - return xContext; + return XMLPropStyleContext::createFastChildContext( nElement, xAttrList ); } void XMLShapeStyleContext::FillPropertySet( const Reference< beans::XPropertySet > & rPropSet ) diff --git a/xmloff/source/draw/ximpstyl.cxx b/xmloff/source/draw/ximpstyl.cxx index 66db57439674..70082c166c68 100644 --- a/xmloff/source/draw/ximpstyl.cxx +++ b/xmloff/source/draw/ximpstyl.cxx @@ -62,10 +62,8 @@ class SdXMLDrawingPagePropertySetContext : public SvXMLPropertySetContext { public: - - SdXMLDrawingPagePropertySetContext( SvXMLImport& rImport, sal_uInt16 nPrfx, - const OUString& rLName, - const css::uno::Reference< css::xml::sax::XAttributeList >& xAttrList, + SdXMLDrawingPagePropertySetContext( SvXMLImport& rImport, sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList, ::std::vector< XMLPropertyState > &rProps, const rtl::Reference < SvXMLImportPropertyMapper > &rMap ); @@ -80,12 +78,11 @@ public: } SdXMLDrawingPagePropertySetContext::SdXMLDrawingPagePropertySetContext( - SvXMLImport& rImport, sal_uInt16 nPrfx, - const OUString& rLName, - const uno::Reference< xml::sax::XAttributeList > & xAttrList, + SvXMLImport& rImport, sal_Int32 nElement, + const uno::Reference< xml::sax::XFastAttributeList > & xAttrList, ::std::vector< XMLPropertyState > &rProps, const rtl::Reference < SvXMLImportPropertyMapper > &rMap ) : - SvXMLPropertySetContext( rImport, nPrfx, rLName, xAttrList, + SvXMLPropertySetContext( rImport, nElement, xAttrList, XML_TYPE_PROP_DRAWING_PAGE, rProps, rMap ) { } @@ -141,10 +138,8 @@ public: const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList, SvXMLStylesContext& rStyles); - SvXMLImportContextRef CreateChildContext( - sal_uInt16 nPrefix, - const OUString& rLocalName, - const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList ) override; + virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( + sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& AttrList ) override; virtual void Finish( bool bOverwrite ) override; }; @@ -176,23 +171,6 @@ XmlStyleFamily const g_Families[MAX_SPECIAL_DRAW_STYLES] = XMLDrawingPageStyleContext::XMLDrawingPageStyleContext( SvXMLImport& rImport, - sal_uInt16 const nPrefix, - const OUString& rLName, - const uno::Reference< xml::sax::XAttributeList >& xAttrList, - SvXMLStylesContext& rStyles, - ContextID_Index_Pair const pContextIDs[], - XmlStyleFamily const pFamilies[]) - : XMLPropStyleContext(rImport, nPrefix, rLName, xAttrList, rStyles, XmlStyleFamily::SD_DRAWINGPAGE_ID) - , m_pFamilies(pFamilies) -{ - size_t size(1); // for the -1 entry - for (ContextID_Index_Pair const* pTemp(pContextIDs); pTemp->nContextID != -1; ++size, ++pTemp); - m_pContextIDs.reset(new ContextID_Index_Pair[size]); - std::memcpy(m_pContextIDs.get(), pContextIDs, size * sizeof(ContextID_Index_Pair)); -} - -XMLDrawingPageStyleContext::XMLDrawingPageStyleContext( - SvXMLImport& rImport, sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList, SvXMLStylesContext& rStyles, @@ -217,30 +195,22 @@ SdXMLDrawingPageStyleContext::SdXMLDrawingPageStyleContext( { } -SvXMLImportContextRef SdXMLDrawingPageStyleContext::CreateChildContext( - sal_uInt16 nPrefix, - const OUString& rLocalName, - const uno::Reference< xml::sax::XAttributeList > & xAttrList ) +css::uno::Reference< css::xml::sax::XFastContextHandler > SdXMLDrawingPageStyleContext::createFastChildContext( + sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) { - SvXMLImportContextRef xContext; - - if( XML_NAMESPACE_STYLE == nPrefix && - IsXMLToken( rLocalName, XML_DRAWING_PAGE_PROPERTIES ) ) + if( nElement == XML_ELEMENT(STYLE, XML_DRAWING_PAGE_PROPERTIES) ) { rtl::Reference < SvXMLImportPropertyMapper > xImpPrMap = GetStyles()->GetImportPropertyMapper( GetFamily() ); if( xImpPrMap.is() ) - xContext = new SdXMLDrawingPagePropertySetContext( GetImport(), nPrefix, - rLocalName, xAttrList, + return new SdXMLDrawingPagePropertySetContext( GetImport(), nElement, + xAttrList, GetProperties(), xImpPrMap ); } - if (!xContext) - xContext = XMLPropStyleContext::CreateChildContext( nPrefix, rLocalName, - xAttrList ); - - return xContext; + return XMLPropStyleContext::createFastChildContext( nElement, xAttrList ); } void SdXMLDrawingPageStyleContext::Finish( bool bOverwrite ) diff --git a/xmloff/source/style/prstylei.cxx b/xmloff/source/style/prstylei.cxx index b39d3cb708cd..412db9a75417 100644 --- a/xmloff/source/style/prstylei.cxx +++ b/xmloff/source/style/prstylei.cxx @@ -147,16 +147,6 @@ const OUStringLiteral gsIsPhysical( "IsPhysical" ); const OUStringLiteral gsFollowStyle( "FollowStyle" ); XMLPropStyleContext::XMLPropStyleContext( SvXMLImport& rImport, - sal_uInt16 nPrfx, const OUString& rLName, - const Reference< XAttributeList > & xAttrList, - SvXMLStylesContext& rStyles, XmlStyleFamily nFamily, - bool bDefault ) -: SvXMLStyleContext( rImport, nPrfx, rLName, xAttrList, nFamily, bDefault ) -, mxStyles( &rStyles ) -{ -} - -XMLPropStyleContext::XMLPropStyleContext( SvXMLImport& rImport, sal_Int32 nElement, const Reference< XFastAttributeList > & xAttrList, SvXMLStylesContext& rStyles, XmlStyleFamily nFamily, @@ -186,43 +176,35 @@ const OldFillStyleDefinitionSet& XMLPropStyleContext::getFooterSet() } css::uno::Reference< css::xml::sax::XFastContextHandler > XMLPropStyleContext::createFastChildContext( - sal_Int32 /*nElement*/, - const css::uno::Reference< css::xml::sax::XFastAttributeList >& /*xAttrList*/ ) + sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) { - return nullptr; -} - -SvXMLImportContextRef XMLPropStyleContext::CreateChildContext( - sal_uInt16 nPrefix, - const OUString& rLocalName, - const Reference< XAttributeList > & xAttrList ) -{ - SvXMLImportContextRef xContext; - sal_uInt32 nFamily = 0; - if( XML_NAMESPACE_STYLE == nPrefix || XML_NAMESPACE_LO_EXT == nPrefix ) + if( IsTokenInNamespace(nElement, XML_NAMESPACE_STYLE) || + IsTokenInNamespace(nElement, XML_NAMESPACE_LO_EXT) ) { - if( IsXMLToken( rLocalName, XML_GRAPHIC_PROPERTIES ) ) + sal_Int32 nLocalName = nElement & TOKEN_MASK; + if( nLocalName == XML_GRAPHIC_PROPERTIES ) nFamily = XML_TYPE_PROP_GRAPHIC; - else if( IsXMLToken( rLocalName, XML_DRAWING_PAGE_PROPERTIES ) ) + else if( nLocalName == XML_DRAWING_PAGE_PROPERTIES ) nFamily = XML_TYPE_PROP_DRAWING_PAGE; - else if( IsXMLToken( rLocalName, XML_TEXT_PROPERTIES ) ) + else if( nLocalName == XML_TEXT_PROPERTIES ) nFamily = XML_TYPE_PROP_TEXT; - else if( IsXMLToken( rLocalName, XML_PARAGRAPH_PROPERTIES ) ) + else if( nLocalName == XML_PARAGRAPH_PROPERTIES ) nFamily = XML_TYPE_PROP_PARAGRAPH; - else if( IsXMLToken( rLocalName, XML_RUBY_PROPERTIES ) ) + else if( nLocalName == XML_RUBY_PROPERTIES ) nFamily = XML_TYPE_PROP_RUBY; - else if( IsXMLToken( rLocalName, XML_SECTION_PROPERTIES ) ) + else if( nLocalName == XML_SECTION_PROPERTIES ) nFamily = XML_TYPE_PROP_SECTION; - else if( IsXMLToken( rLocalName, XML_TABLE_PROPERTIES ) ) + else if( nLocalName == XML_TABLE_PROPERTIES ) nFamily = XML_TYPE_PROP_TABLE; - else if( IsXMLToken( rLocalName, XML_TABLE_COLUMN_PROPERTIES ) ) + else if( nLocalName == XML_TABLE_COLUMN_PROPERTIES ) nFamily = XML_TYPE_PROP_TABLE_COLUMN; - else if( IsXMLToken( rLocalName, XML_TABLE_ROW_PROPERTIES ) ) + else if( nLocalName ==XML_TABLE_ROW_PROPERTIES ) nFamily = XML_TYPE_PROP_TABLE_ROW; - else if( IsXMLToken( rLocalName, XML_TABLE_CELL_PROPERTIES ) ) + else if( nLocalName == XML_TABLE_CELL_PROPERTIES ) nFamily = XML_TYPE_PROP_TABLE_CELL; - else if( IsXMLToken( rLocalName, XML_CHART_PROPERTIES ) ) + else if( nLocalName == XML_CHART_PROPERTIES ) nFamily = XML_TYPE_PROP_CHART; } if( nFamily ) @@ -230,14 +212,14 @@ SvXMLImportContextRef XMLPropStyleContext::CreateChildContext( rtl::Reference < SvXMLImportPropertyMapper > xImpPrMap = mxStyles->GetImportPropertyMapper( GetFamily() ); if( xImpPrMap.is() ) - xContext = new SvXMLPropertySetContext( GetImport(), nPrefix, - rLocalName, xAttrList, + return new SvXMLPropertySetContext( GetImport(), nElement, + xAttrList, nFamily, maProperties, xImpPrMap ); } - - return xContext; + SAL_WARN("xmloff", "unknown element " << SvXMLImport::getPrefixAndNameFromToken(nElement)); + return nullptr; } void XMLPropStyleContext::FillPropertySet( diff --git a/xmloff/source/style/xmlimppr.cxx b/xmloff/source/style/xmlimppr.cxx index bcd2b4491989..a3600aa09890 100644 --- a/xmloff/source/style/xmlimppr.cxx +++ b/xmloff/source/style/xmlimppr.cxx @@ -334,210 +334,238 @@ void SvXMLImportPropertyMapper::importXML( nStartIdx = 0; if( -1 == nEndIdx ) nEndIdx = maPropMapper->GetEntryCount(); + for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList )) { sal_Int32 nToken = aIter.getToken(); + if( IsTokenInNamespace(nToken, XML_NAMESPACE_XMLNS) ) + continue; + const OUString aPrefix = SvXMLImport::getNamespacePrefixFromToken(nToken, &rNamespaceMap); const OUString aNamespaceURI = SvXMLImport::getNamespaceURIFromToken(nToken); OUString sAttrName = SvXMLImport::getNameFromToken( nToken ); if ( !aPrefix.isEmpty() ) sAttrName = aPrefix + SvXMLImport::aNamespaceSeparator + sAttrName; - OUString aLocalName; - sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName ); -// const OUString& rAttrName = xAttrList->getNameByIndex( i ); -// OUString aLocalName, aPrefix, aNamespace; -// sal_uInt16 nPrefix = rNamespaceMap.GetKeyByAttrName( rAttrName, &aPrefix, -// &aLocalName, &aNamespace ); + const OUString sValue = aIter.toString(); - if( XML_NAMESPACE_XMLNS == nPrefix ) - continue; + importXMLAttribute(rProperties, rUnitConverter, rNamespaceMap, + nPropType, nStartIdx, nEndIdx, xAttrContainer, + aPrefix, sAttrName, aNamespaceURI, sValue); + } - const OUString sValue = aIter.toString(); + const css::uno::Sequence< css::xml::Attribute > unknownAttribs = xAttrList->getUnknownAttributes(); + for (const css::xml::Attribute& rAttribute : unknownAttribs) + { + OUString aPrefix; + int nSepIndex = rAttribute.Name.indexOf(SvXMLImport::aNamespaceSeparator); + if (nSepIndex != -1) + aPrefix = rAttribute.Name.copy(0, nSepIndex); + + importXMLAttribute(rProperties, rUnitConverter, rNamespaceMap, + nPropType, nStartIdx, nEndIdx, xAttrContainer, + aPrefix, rAttribute.Name, rAttribute.NamespaceURL, rAttribute.Value); + } - // index of actual property map entry - // This looks very strange, but it works well: - // If the start index is 0, the new value will become -1, and - // GetEntryIndex will start searching with position 0. - // Otherwise GetEntryIndex will start with the next position specified. - sal_Int32 nIndex = nStartIdx - 1; - sal_uInt32 nFlags = 0; // flags of actual property map entry - bool bFound = false; + finished( rProperties, nStartIdx, nEndIdx ); +} - // for better error reporting: this should be set true if no - // warning is needed - bool bNoWarning = false; - bool bAlienImport = false; +void SvXMLImportPropertyMapper::importXMLAttribute( + vector< XMLPropertyState >& rProperties, + const SvXMLUnitConverter& rUnitConverter, + const SvXMLNamespaceMap& rNamespaceMap, + const sal_uInt32 nPropType, + const sal_Int32 nStartIdx, + const sal_Int32 nEndIdx, + Reference< XNameContainer >& xAttrContainer, + const OUString& aPrefix, + const OUString& sAttrName, + const OUString& aNamespaceURI, + const OUString& sValue) const +{ + OUString aLocalName; + sal_uInt16 nPrefix = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName ); + + // index of actual property map entry + // This looks very strange, but it works well: + // If the start index is 0, the new value will become -1, and + // GetEntryIndex will start searching with position 0. + // Otherwise GetEntryIndex will start with the next position specified. + sal_Int32 nIndex = nStartIdx - 1; + sal_uInt32 nFlags = 0; // flags of actual property map entry + bool bFound = false; + + // for better error reporting: this should be set true if no + // warning is needed + bool bNoWarning = false; + bool bAlienImport = false; + + do + { + // find an entry for this attribute + nIndex = maPropMapper->GetEntryIndex( nPrefix, aLocalName, + nPropType, nIndex ); - do + if( nIndex > -1 && nIndex < nEndIdx ) { - // find an entry for this attribute - nIndex = maPropMapper->GetEntryIndex( nPrefix, aLocalName, - nPropType, nIndex ); + // create a XMLPropertyState with an empty value - if( nIndex > -1 && nIndex < nEndIdx ) + nFlags = maPropMapper->GetEntryFlags( nIndex ); + if( (( nFlags & MID_FLAG_NO_PROPERTY ) == MID_FLAG_NO_PROPERTY) && (maPropMapper->GetEntryContextId( nIndex ) == CTF_ALIEN_ATTRIBUTE_IMPORT) ) { - // create a XMLPropertyState with an empty value - - nFlags = maPropMapper->GetEntryFlags( nIndex ); - if( (( nFlags & MID_FLAG_NO_PROPERTY ) == MID_FLAG_NO_PROPERTY) && (maPropMapper->GetEntryContextId( nIndex ) == CTF_ALIEN_ATTRIBUTE_IMPORT) ) - { - bAlienImport = true; - nIndex = -1; - } - else + bAlienImport = true; + nIndex = -1; + } + else + { + if( ( nFlags & MID_FLAG_ELEMENT_ITEM_IMPORT ) == 0 ) { - if( ( nFlags & MID_FLAG_ELEMENT_ITEM_IMPORT ) == 0 ) - { - XMLPropertyState aNewProperty( nIndex ); - sal_Int32 nReference = -1; + XMLPropertyState aNewProperty( nIndex ); + sal_Int32 nReference = -1; - // if this is a multi attribute check if another attribute already set - // this any. If so use this as an initial value - if( ( nFlags & MID_FLAG_MERGE_PROPERTY ) != 0 ) + // if this is a multi attribute check if another attribute already set + // this any. If so use this as an initial value + if( ( nFlags & MID_FLAG_MERGE_PROPERTY ) != 0 ) + { + const OUString aAPIName( maPropMapper->GetEntryAPIName( nIndex ) ); + const sal_Int32 nSize = rProperties.size(); + for( nReference = 0; nReference < nSize; nReference++ ) { - const OUString aAPIName( maPropMapper->GetEntryAPIName( nIndex ) ); - const sal_Int32 nSize = rProperties.size(); - for( nReference = 0; nReference < nSize; nReference++ ) + sal_Int32 nRefIdx = rProperties[nReference].mnIndex; + if( (nRefIdx != -1) && (nIndex != nRefIdx) && + (maPropMapper->GetEntryAPIName( nRefIdx ) == aAPIName )) { - sal_Int32 nRefIdx = rProperties[nReference].mnIndex; - if( (nRefIdx != -1) && (nIndex != nRefIdx) && - (maPropMapper->GetEntryAPIName( nRefIdx ) == aAPIName )) - { - aNewProperty = rProperties[nReference]; - aNewProperty.mnIndex = nIndex; - break; - } + aNewProperty = rProperties[nReference]; + aNewProperty.mnIndex = nIndex; + break; } - - if( nReference == nSize ) - nReference = -1; } - bool bSet = false; - if( ( nFlags & MID_FLAG_SPECIAL_ITEM_IMPORT ) == 0 ) - { - // let the XMLPropertySetMapper decide how to import the value - bSet = maPropMapper->importXML( sValue, aNewProperty, - rUnitConverter ); - } - else - { - sal_uInt32 nOldSize = rProperties.size(); + if( nReference == nSize ) + nReference = -1; + } - bSet = handleSpecialItem( aNewProperty, rProperties, - sValue, rUnitConverter, - rNamespaceMap ); + bool bSet = false; + if( ( nFlags & MID_FLAG_SPECIAL_ITEM_IMPORT ) == 0 ) + { + // let the XMLPropertySetMapper decide how to import the value + bSet = maPropMapper->importXML( sValue, aNewProperty, + rUnitConverter ); + } + else + { + sal_uInt32 nOldSize = rProperties.size(); - // no warning if handleSpecialItem added properties - bNoWarning |= ( nOldSize != rProperties.size() ); - } + bSet = handleSpecialItem( aNewProperty, rProperties, + sValue, rUnitConverter, + rNamespaceMap ); - // no warning if we found could set the item. This - // 'remembers' bSet across multi properties. - bNoWarning |= bSet; + // no warning if handleSpecialItem added properties + bNoWarning |= ( nOldSize != rProperties.size() ); + } - // store the property in the given vector - if( bSet ) - { - if( nReference == -1 ) - rProperties.push_back( aNewProperty ); - else - rProperties[nReference] = aNewProperty; - } + // no warning if we found could set the item. This + // 'remembers' bSet across multi properties. + bNoWarning |= bSet; + + // store the property in the given vector + if( bSet ) + { + if( nReference == -1 ) + rProperties.push_back( aNewProperty ); else + rProperties[nReference] = aNewProperty; + } + else + { + // warn about unknown value. Unless it's a + // multi property: Then we get another chance + // to set the value. + if( !bNoWarning && + ((nFlags & MID_FLAG_MULTI_PROPERTY) == 0) ) { - // warn about unknown value. Unless it's a - // multi property: Then we get another chance - // to set the value. - if( !bNoWarning && - ((nFlags & MID_FLAG_MULTI_PROPERTY) == 0) ) - { - Sequence<OUString> aSeq(2); - aSeq[0] = sAttrName; - aSeq[1] = sValue; - rImport.SetError( XMLERROR_FLAG_WARNING | - XMLERROR_STYLE_ATTR_VALUE, - aSeq ); - } + Sequence<OUString> aSeq(2); + aSeq[0] = sAttrName; + aSeq[1] = sValue; + rImport.SetError( XMLERROR_FLAG_WARNING | + XMLERROR_STYLE_ATTR_VALUE, + aSeq ); } } - bFound = true; - continue; } + bFound = true; + continue; } + } - if( !bFound ) + if( !bFound ) + { + SAL_INFO_IF((XML_NAMESPACE_NONE != nPrefix) && + !(XML_NAMESPACE_UNKNOWN_FLAG & nPrefix) && + !bAlienImport, "xmloff.style", + "unknown attribute: \"" << sAttrName << "\""); + if( (XML_NAMESPACE_UNKNOWN_FLAG & nPrefix) || (XML_NAMESPACE_NONE == nPrefix) || bAlienImport ) { - SAL_INFO_IF((XML_NAMESPACE_NONE != nPrefix) && - !(XML_NAMESPACE_UNKNOWN_FLAG & nPrefix) && - !bAlienImport, "xmloff.style", - "unknown attribute: \"" << sAttrName << "\""); - if( (XML_NAMESPACE_UNKNOWN_FLAG & nPrefix) || (XML_NAMESPACE_NONE == nPrefix) || bAlienImport ) + if( !xAttrContainer.is() ) { - if( !xAttrContainer.is() ) - { - // add an unknown attribute container to the properties - Reference< XNameContainer > xNew( SvUnoAttributeContainer_CreateInstance(), UNO_QUERY ); - xAttrContainer = xNew; - - // find map entry and create new property state - if( -1 == nIndex ) - { - switch( nPropType ) - { - case XML_TYPE_PROP_CHART: - nIndex = maPropMapper->FindEntryIndex( "ChartUserDefinedAttributes", XML_NAMESPACE_TEXT, GetXMLToken(XML_XMLNS) ); - break; - case XML_TYPE_PROP_PARAGRAPH: - nIndex = maPropMapper->FindEntryIndex( "ParaUserDefinedAttributes", XML_NAMESPACE_TEXT, GetXMLToken(XML_XMLNS) ); - break; - case XML_TYPE_PROP_TEXT: - nIndex = maPropMapper->FindEntryIndex( "TextUserDefinedAttributes", XML_NAMESPACE_TEXT, GetXMLToken(XML_XMLNS) ); - break; - default: - break; - } - // other property type or property not found - if( -1 == nIndex ) - nIndex = maPropMapper->FindEntryIndex( "UserDefinedAttributes", XML_NAMESPACE_TEXT, GetXMLToken(XML_XMLNS) ); - } + // add an unknown attribute container to the properties + Reference< XNameContainer > xNew( SvUnoAttributeContainer_CreateInstance(), UNO_QUERY ); + xAttrContainer = xNew; - // #106963#; use userdefined attribute only if it is in the specified property range - if( nIndex != -1 && nIndex >= nStartIdx && nIndex < nEndIdx) + // find map entry and create new property state + if( -1 == nIndex ) + { + switch( nPropType ) { - XMLPropertyState aNewProperty( nIndex, Any(xAttrContainer) ); - - // push it on our stack so we export it later - rProperties.push_back( aNewProperty ); + case XML_TYPE_PROP_CHART: + nIndex = maPropMapper->FindEntryIndex( "ChartUserDefinedAttributes", XML_NAMESPACE_TEXT, GetXMLToken(XML_XMLNS) ); + break; + case XML_TYPE_PROP_PARAGRAPH: + nIndex = maPropMapper->FindEntryIndex( "ParaUserDefinedAttributes", XML_NAMESPACE_TEXT, GetXMLToken(XML_XMLNS) ); + break; + case XML_TYPE_PROP_TEXT: + nIndex = maPropMapper->FindEntryIndex( "TextUserDefinedAttributes", XML_NAMESPACE_TEXT, GetXMLToken(XML_XMLNS) ); + break; + default: + break; } + // other property type or property not found + if( -1 == nIndex ) + nIndex = maPropMapper->FindEntryIndex( "UserDefinedAttributes", XML_NAMESPACE_TEXT, GetXMLToken(XML_XMLNS) ); } - if( xAttrContainer.is() ) + // #106963#; use userdefined attribute only if it is in the specified property range + if( nIndex != -1 && nIndex >= nStartIdx && nIndex < nEndIdx) { - AttributeData aData; - aData.Type = GetXMLToken( XML_CDATA ); - aData.Value = sValue; + XMLPropertyState aNewProperty( nIndex, Any(xAttrContainer) ); - OUStringBuffer sName; - if( XML_NAMESPACE_NONE != nPrefix ) - { - sName.append( aPrefix ); - sName.append( ':' ); - aData.Namespace = aNamespaceURI; - } + // push it on our stack so we export it later + rProperties.push_back( aNewProperty ); + } + } - sName.append( aLocalName ); + if( xAttrContainer.is() ) + { + AttributeData aData; + aData.Type = GetXMLToken( XML_CDATA ); + aData.Value = sValue; - xAttrContainer->insertByName( sName.makeStringAndClear(), Any(aData) ); + OUStringBuffer sName; + if( XML_NAMESPACE_NONE != nPrefix ) + { + sName.append( aPrefix ); + sName.append( ':' ); + aData.Namespace = aNamespaceURI; } + + sName.append( aLocalName ); + + xAttrContainer->insertByName( sName.makeStringAndClear(), Any(aData) ); } } } - while( ( nIndex >= 0 && nIndex + 1 < nEndIdx ) && (( nFlags & MID_FLAG_MULTI_PROPERTY ) != 0 ) ); } - - finished( rProperties, nStartIdx, nEndIdx ); + while( ( nIndex >= 0 && nIndex + 1 < nEndIdx ) && (( nFlags & MID_FLAG_MULTI_PROPERTY ) != 0 ) ); } /** this method is called for every item that has the MID_FLAG_SPECIAL_ITEM_IMPORT flag set */ diff --git a/xmloff/source/text/XMLTextPropertySetContext.cxx b/xmloff/source/text/XMLTextPropertySetContext.cxx index 14f2b76e8b1c..e0d03481c315 100644 --- a/xmloff/source/text/XMLTextPropertySetContext.cxx +++ b/xmloff/source/text/XMLTextPropertySetContext.cxx @@ -46,6 +46,19 @@ XMLTextPropertySetContext::XMLTextPropertySetContext( { } +XMLTextPropertySetContext::XMLTextPropertySetContext( + SvXMLImport& rImport, sal_Int32 nElement, + const Reference< xml::sax::XFastAttributeList > & xAttrList, + sal_uInt32 nFamily, + ::std::vector< XMLPropertyState > &rProps, + const rtl::Reference < SvXMLImportPropertyMapper > &rMap, + OUString& rDCTextStyleName ) : + SvXMLPropertySetContext( rImport, nElement, xAttrList, nFamily, + rProps, rMap ), + rDropCapTextStyleName( rDCTextStyleName ) +{ +} + XMLTextPropertySetContext::~XMLTextPropertySetContext() { } diff --git a/xmloff/source/text/XMLTextPropertySetContext.hxx b/xmloff/source/text/XMLTextPropertySetContext.hxx index a35b4b389a67..f53b6bd7521f 100644 --- a/xmloff/source/text/XMLTextPropertySetContext.hxx +++ b/xmloff/source/text/XMLTextPropertySetContext.hxx @@ -39,6 +39,13 @@ public: const rtl::Reference < SvXMLImportPropertyMapper > &rMap, OUString& rDopCapTextStyleName ); + XMLTextPropertySetContext( SvXMLImport& rImport, sal_Int32 nElement, + const css::uno::Reference<css::xml::sax::XFastAttributeList >& xAttrList, + sal_uInt32 nFamily, + ::std::vector< XMLPropertyState > &rProps, + const rtl::Reference < SvXMLImportPropertyMapper > &rMap, + OUString& rDopCapTextStyleName ); + virtual ~XMLTextPropertySetContext() override; using SvXMLPropertySetContext::CreateChildContext; diff --git a/xmloff/source/text/XMLTextShapeStyleContext.cxx b/xmloff/source/text/XMLTextShapeStyleContext.cxx index 77363e0eaacf..610cf98e18f4 100644 --- a/xmloff/source/text/XMLTextShapeStyleContext.cxx +++ b/xmloff/source/text/XMLTextShapeStyleContext.cxx @@ -47,10 +47,9 @@ namespace { class XMLTextShapePropertySetContext_Impl : public XMLShapePropertySetContext { public: - XMLTextShapePropertySetContext_Impl( SvXMLImport& rImport, sal_uInt16 nPrfx, - const OUString& rLName, - const Reference< XAttributeList >& xAttrList, - sal_uInt32 nFamily, + XMLTextShapePropertySetContext_Impl( SvXMLImport& rImport, sal_Int32 nElement, + const Reference< XFastAttributeList >& xAttrList, + sal_uInt32 nFamily, ::std::vector< XMLPropertyState > &rProps, const rtl::Reference < SvXMLImportPropertyMapper > &rMap ); @@ -65,13 +64,12 @@ public: } XMLTextShapePropertySetContext_Impl::XMLTextShapePropertySetContext_Impl( - SvXMLImport& rImport, sal_uInt16 nPrfx, - const OUString& rLName, - const Reference< XAttributeList > & xAttrList, + SvXMLImport& rImport, sal_Int32 nElement, + const Reference< XFastAttributeList > & xAttrList, sal_uInt32 nFamily, ::std::vector< XMLPropertyState > &rProps, const rtl::Reference < SvXMLImportPropertyMapper > &rMap ) : - XMLShapePropertySetContext( rImport, nPrfx, rLName, xAttrList, nFamily, + XMLShapePropertySetContext( rImport, nElement, xAttrList, nFamily, rProps, rMap ) { } @@ -156,21 +154,20 @@ XMLTextShapeStyleContext::~XMLTextShapeStyleContext() { } -SvXMLImportContextRef XMLTextShapeStyleContext::CreateChildContext( - sal_uInt16 nPrefix, - const OUString& rLocalName, - const Reference< XAttributeList > & xAttrList ) +css::uno::Reference< css::xml::sax::XFastContextHandler > XMLTextShapeStyleContext::createFastChildContext( + sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) { - SvXMLImportContextRef xContext; - - if( XML_NAMESPACE_STYLE == nPrefix || XML_NAMESPACE_LO_EXT == nPrefix ) + if( IsTokenInNamespace(nElement, XML_NAMESPACE_STYLE) || + IsTokenInNamespace(nElement, XML_NAMESPACE_LO_EXT) ) { + sal_Int32 nLocalName = nElement & TOKEN_MASK; sal_uInt32 nFamily = 0; - if( IsXMLToken( rLocalName, XML_TEXT_PROPERTIES ) ) + if( nLocalName == XML_TEXT_PROPERTIES ) nFamily = XML_TYPE_PROP_TEXT; - else if( IsXMLToken( rLocalName, XML_PARAGRAPH_PROPERTIES ) ) + else if( nLocalName == XML_PARAGRAPH_PROPERTIES ) nFamily = XML_TYPE_PROP_PARAGRAPH; - else if( IsXMLToken( rLocalName, XML_GRAPHIC_PROPERTIES ) ) + else if( nLocalName == XML_GRAPHIC_PROPERTIES ) nFamily = XML_TYPE_PROP_GRAPHIC; if( nFamily ) { @@ -178,27 +175,21 @@ SvXMLImportContextRef XMLTextShapeStyleContext::CreateChildContext( GetStyles()->GetImportPropertyMapper( GetFamily() ); if( xImpPrMap.is() ) { - xContext = new XMLTextShapePropertySetContext_Impl( - GetImport(), nPrefix, rLocalName, xAttrList, nFamily, + return new XMLTextShapePropertySetContext_Impl( + GetImport(), nElement, xAttrList, nFamily, GetProperties(), xImpPrMap ); } } } - else if ( (XML_NAMESPACE_OFFICE == nPrefix) && - IsXMLToken( rLocalName, XML_EVENT_LISTENERS ) ) + else if ( nElement == XML_ELEMENT(OFFICE, XML_EVENT_LISTENERS) ) { // create and remember events import context // (for delayed processing of events) - xEventContext = new XMLEventsImportContext( GetImport(), nPrefix, - rLocalName); - xContext = xEventContext; + xEventContext = new XMLEventsImportContext( GetImport() ); + return xEventContext.get(); } - if (!xContext) - xContext = XMLShapeStyleContext::CreateChildContext( nPrefix, rLocalName, - xAttrList ); - - return xContext; + return XMLShapeStyleContext::createFastChildContext( nElement, xAttrList ); } void XMLTextShapeStyleContext::CreateAndInsert( bool bOverwrite ) diff --git a/xmloff/source/text/txtstyli.cxx b/xmloff/source/text/txtstyli.cxx index 140c90d1bafb..b475423f4509 100644 --- a/xmloff/source/text/txtstyli.cxx +++ b/xmloff/source/text/txtstyli.cxx @@ -125,22 +125,6 @@ void XMLTextStyleContext::SetAttribute( sal_uInt16 nPrefixKey, } } - -XMLTextStyleContext::XMLTextStyleContext( SvXMLImport& rImport, - sal_uInt16 nPrfx, const OUString& rLName, - const Reference< XAttributeList > & xAttrList, - SvXMLStylesContext& rStyles, XmlStyleFamily nFamily, - bool bDefaultStyle ) -: XMLPropStyleContext( rImport, nPrfx, rLName, xAttrList, rStyles, nFamily, bDefaultStyle ) -, m_nOutlineLevel( -1 ) -, m_isAutoUpdate( false ) -, m_bHasMasterPageName( false ) -, m_bHasCombinedCharactersLetter( false ) -// Inherited paragraph style lost information about unset numbering (#i69523#) -, m_bListStyleSet( false ) -{ -} - XMLTextStyleContext::XMLTextStyleContext( SvXMLImport& rImport, sal_Int32 nElement, const Reference< XFastAttributeList > & xAttrList, @@ -159,54 +143,45 @@ XMLTextStyleContext::XMLTextStyleContext( SvXMLImport& rImport, XMLTextStyleContext::~XMLTextStyleContext() {} -SvXMLImportContextRef XMLTextStyleContext::CreateChildContext( - sal_uInt16 nPrefix, - const OUString& rLocalName, - const Reference< XAttributeList > & xAttrList ) +css::uno::Reference< css::xml::sax::XFastContextHandler > XMLTextStyleContext::createFastChildContext( + sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) { - SvXMLImportContextRef xContext; - - if( XML_NAMESPACE_STYLE == nPrefix ) + if( IsTokenInNamespace(nElement, XML_NAMESPACE_STYLE) ) { + sal_Int32 nLocalName = nElement & TOKEN_MASK; sal_uInt32 nFamily = 0; - if( IsXMLToken( rLocalName, XML_TEXT_PROPERTIES ) ) + if( nLocalName == XML_TEXT_PROPERTIES ) nFamily = XML_TYPE_PROP_TEXT; - else if( IsXMLToken( rLocalName, XML_PARAGRAPH_PROPERTIES ) ) + else if( nLocalName == XML_PARAGRAPH_PROPERTIES ) nFamily = XML_TYPE_PROP_PARAGRAPH; - else if( IsXMLToken( rLocalName, XML_SECTION_PROPERTIES ) ) + else if( nLocalName == XML_SECTION_PROPERTIES ) nFamily = XML_TYPE_PROP_SECTION; - else if( IsDefaultStyle() && IsXMLToken( rLocalName, XML_TABLE_PROPERTIES ) ) + else if( IsDefaultStyle() && nLocalName == XML_TABLE_PROPERTIES ) nFamily = XML_TYPE_PROP_TABLE; - else if( IsDefaultStyle() && IsXMLToken( rLocalName, XML_TABLE_ROW_PROPERTIES ) ) + else if( IsDefaultStyle() && nLocalName == XML_TABLE_ROW_PROPERTIES ) nFamily = XML_TYPE_PROP_TABLE_ROW; if( nFamily ) { rtl::Reference < SvXMLImportPropertyMapper > xImpPrMap = GetStyles()->GetImportPropertyMapper( GetFamily() ); if( xImpPrMap.is() ) - xContext = new XMLTextPropertySetContext( GetImport(), nPrefix, - rLocalName, xAttrList, + return new XMLTextPropertySetContext( GetImport(), nElement, xAttrList, nFamily, GetProperties(), xImpPrMap, m_sDropCapTextStyleName); } } - else if ( (XML_NAMESPACE_OFFICE == nPrefix) && - IsXMLToken( rLocalName, XML_EVENT_LISTENERS ) ) + else if ( nElement == XML_ELEMENT(OFFICE, XML_EVENT_LISTENERS) ) { // create and remember events import context // (for delayed processing of events) - m_xEventContext.set(new XMLEventsImportContext( GetImport(), nPrefix, - rLocalName)); - xContext = m_xEventContext.get(); + m_xEventContext.set(new XMLEventsImportContext( GetImport() )); + return m_xEventContext.get(); } - if (!xContext) - xContext = XMLPropStyleContext::CreateChildContext( nPrefix, rLocalName, - xAttrList ); - - return xContext; + return XMLPropStyleContext::createFastChildContext( nElement, xAttrList ); } void XMLTextStyleContext::CreateAndInsert( bool bOverwrite ) |