sw/source/filter/xml/xmlbrsh.cxx | 72 +++++++++++++---------------- sw/source/filter/xml/xmlbrshi.hxx | 21 ++++---- sw/source/filter/xml/xmlfmt.cxx | 59 +++++++++++++++--------- sw/source/filter/xml/xmlimp.hxx | 5 -- sw/source/filter/xml/xmlimpit.cxx | 92 +++++++++++++++++++++++++++++--------- sw/source/filter/xml/xmlimpit.hxx | 9 +++ sw/source/filter/xml/xmlitem.cxx | 30 ++++++------ sw/source/filter/xml/xmlitem.hxx | 20 ++++---- sw/source/filter/xml/xmlitemi.cxx | 13 ++--- sw/source/filter/xml/xmlitmap.hxx | 3 - sw/source/filter/xml/xmlitmpr.cxx | 8 +-- 11 files changed, 199 insertions(+), 133 deletions(-)
New commits: commit 6ad28942656ad6e707ffba5b64013af87b37aebf Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Wed Aug 26 09:43:45 2020 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Thu Aug 27 08:29:23 2020 +0200 use fastparser in CreateTableItemImportContext Change-Id: I172274089ef4cf669102cea020ee3135e86ef6ff Reviewed-on: https://gerrit.libreoffice.org/c/core/+/101390 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sw/source/filter/xml/xmlbrsh.cxx b/sw/source/filter/xml/xmlbrsh.cxx index e5fc7d67ca3e..8ecce1f1fc78 100644 --- a/sw/source/filter/xml/xmlbrsh.cxx +++ b/sw/source/filter/xml/xmlbrsh.cxx @@ -20,6 +20,7 @@ #include <editeng/memberids.h> #include <vcl/graph.hxx> +#include <sal/log.hxx> #include <xmloff/namespacemap.hxx> #include <xmloff/xmlnamespace.hxx> #include <xmloff/xmlimp.hxx> @@ -67,66 +68,61 @@ const SvXMLTokenMapEntry aBGImgAttributesAttrTokenMap[] = void SwXMLBrushItemImportContext::ProcessAttrs( - const uno::Reference< xml::sax::XAttributeList >& xAttrList, + const uno::Reference< xml::sax::XFastAttributeList >& xAttrList, const SvXMLUnitConverter& rUnitConv ) { SvXMLTokenMap aTokenMap( aBGImgAttributesAttrTokenMap ); - 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 ); - - switch( aTokenMap.Get( nPrefix, aLocalName ) ) + const OUString sValue = aIter.toString(); + + switch( aIter.getToken() ) { - case XML_TOK_BGIMG_HREF: - m_xGraphic = GetImport().loadGraphicByURL(rValue); + case XML_ELEMENT(XLINK, XML_HREF): + m_xGraphic = GetImport().loadGraphicByURL(sValue); break; - case XML_TOK_BGIMG_TYPE: - case XML_TOK_BGIMG_ACTUATE: - case XML_TOK_BGIMG_SHOW: + case XML_ELEMENT(XLINK, XML_TYPE): + case XML_ELEMENT(XLINK, XML_ACTUATE): + case XML_ELEMENT(XLINK, XML_SHOW): break; - case XML_TOK_BGIMG_POSITION: + case XML_ELEMENT(STYLE, XML_POSITION): SvXMLImportItemMapper::PutXMLValue( - *pItem, rValue, MID_GRAPHIC_POSITION, rUnitConv ); + *pItem, sValue, MID_GRAPHIC_POSITION, rUnitConv ); break; - case XML_TOK_BGIMG_REPEAT: + case XML_ELEMENT(STYLE, XML_REPEAT): SvXMLImportItemMapper::PutXMLValue( - *pItem, rValue, MID_GRAPHIC_REPEAT, rUnitConv ); + *pItem, sValue, MID_GRAPHIC_REPEAT, rUnitConv ); break; - case XML_TOK_BGIMG_FILTER: + case XML_ELEMENT(STYLE, XML_FILTER_NAME): SvXMLImportItemMapper::PutXMLValue( - *pItem, rValue, MID_GRAPHIC_FILTER, rUnitConv ); + *pItem, sValue, MID_GRAPHIC_FILTER, rUnitConv ); break; + default: + SAL_WARN("sw", "unknown attribute " << SvXMLImport::getPrefixAndNameFromToken(aIter.getToken()) << "=" << sValue); } } } -SvXMLImportContextRef SwXMLBrushItemImportContext::CreateChildContext( - sal_uInt16 nPrefix, const OUString& rLocalName, - const uno::Reference< xml::sax::XAttributeList > & xAttrList ) +css::uno::Reference< css::xml::sax::XFastContextHandler > SwXMLBrushItemImportContext::createFastChildContext( + sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& /*xAttrList*/ ) { - SvXMLImportContext *pContext = nullptr; - if (xmloff::token::IsXMLToken(rLocalName, xmloff::token::XML_BINARY_DATA)) + if ((nElement & TOKEN_MASK) == xmloff::token::XML_BINARY_DATA) { if (!m_xBase64Stream.is()) { m_xBase64Stream = GetImport().GetStreamForGraphicObjectURLFromBase64(); if (m_xBase64Stream.is()) - pContext = new XMLBase64ImportContext(GetImport(), nPrefix, rLocalName, xAttrList, m_xBase64Stream); + return new XMLBase64ImportContext(GetImport(), m_xBase64Stream); } } - - return pContext; + SAL_WARN("sw", "unknown element " << SvXMLImport::getPrefixAndNameFromToken(nElement)); + return nullptr; } -void SwXMLBrushItemImportContext::EndElement() +void SwXMLBrushItemImportContext::endFastElement(sal_Int32 ) { if (m_xBase64Stream.is()) { @@ -150,12 +146,11 @@ void SwXMLBrushItemImportContext::EndElement() } SwXMLBrushItemImportContext::SwXMLBrushItemImportContext( - 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, const SvXMLUnitConverter& rUnitConv, const SvxBrushItem& rItem ) : - SvXMLImportContext( rImport, nPrfx, rLName ), + SvXMLImportContext( rImport ), pItem( new SvxBrushItem( rItem ) ) { // delete any graphic that is existing @@ -165,12 +160,11 @@ SwXMLBrushItemImportContext::SwXMLBrushItemImportContext( } SwXMLBrushItemImportContext::SwXMLBrushItemImportContext( - 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, const SvXMLUnitConverter& rUnitConv, sal_uInt16 nWhich ) : - SvXMLImportContext( rImport, nPrfx, rLName ), + SvXMLImportContext( rImport ), pItem( new SvxBrushItem( nWhich ) ) { ProcessAttrs( xAttrList, rUnitConv ); diff --git a/sw/source/filter/xml/xmlbrshi.hxx b/sw/source/filter/xml/xmlbrshi.hxx index 7fb735e3080f..4e0af97bda30 100644 --- a/sw/source/filter/xml/xmlbrshi.hxx +++ b/sw/source/filter/xml/xmlbrshi.hxx @@ -43,34 +43,33 @@ private: std::unique_ptr<SvxBrushItem> pItem; void ProcessAttrs( - const css::uno::Reference<css::xml::sax::XAttributeList > & xAttrList, + const css::uno::Reference<css::xml::sax::XFastAttributeList > & xAttrList, const SvXMLUnitConverter& rUnitConv ); public: SwXMLBrushItemImportContext( SvXMLImport& rImport, - sal_uInt16 nPrfx, - const OUString& rLName, - const css::uno::Reference<css::xml::sax::XAttributeList > & xAttrList, + sal_Int32 nElement, + const css::uno::Reference<css::xml::sax::XFastAttributeList > & xAttrList, const SvXMLUnitConverter& rUnitConv, const SvxBrushItem& rItem ); SwXMLBrushItemImportContext( SvXMLImport& rImport, - sal_uInt16 nPrfx, - const OUString& rLName, - const css::uno::Reference<css::xml::sax::XAttributeList > & xAttrList, + sal_Int32 nElement, + const css::uno::Reference<css::xml::sax::XFastAttributeList > & xAttrList, const SvXMLUnitConverter& rUnitConv, sal_uInt16 nWhich ); virtual ~SwXMLBrushItemImportContext() 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 EndElement() override; + virtual void SAL_CALL startFastElement( sal_Int32 /*nElement*/, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& ) override {} + virtual void SAL_CALL endFastElement(sal_Int32 nElement) override; const SvxBrushItem& GetItem() const { return *pItem; } }; diff --git a/sw/source/filter/xml/xmlfmt.cxx b/sw/source/filter/xml/xmlfmt.cxx index c005665bd7af..e2d2e6d34ebf 100644 --- a/sw/source/filter/xml/xmlfmt.cxx +++ b/sw/source/filter/xml/xmlfmt.cxx @@ -435,9 +435,8 @@ class SwXMLItemSetStyleContext_Impl : public SvXMLStyleContext bool bDataStyleIsResolved; SvXMLImportContext *CreateItemSetContext( - sal_uInt16 nPrefix, - const OUString& rLName, - const uno::Reference< xml::sax::XAttributeList > & xAttrList); + sal_Int32 nElement, + const uno::Reference< xml::sax::XFastAttributeList > & xAttrList); protected: @@ -458,10 +457,12 @@ public: virtual void CreateAndInsert( bool bOverwrite ) override; - 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; + + 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(); } @@ -566,8 +567,8 @@ void SwXMLItemSetStyleContext_Impl::SetAttribute( sal_uInt16 nPrefixKey, } SvXMLImportContext *SwXMLItemSetStyleContext_Impl::CreateItemSetContext( - sal_uInt16 nPrefix, const OUString& rLName, - const uno::Reference< xml::sax::XAttributeList > & xAttrList ) + sal_Int32 nElement, + const uno::Reference< xml::sax::XFastAttributeList > & xAttrList ) { OSL_ENSURE( !pItemSet, "SwXMLItemSetStyleContext_Impl::CreateItemSetContext: item set exists" ); @@ -598,7 +599,7 @@ SvXMLImportContext *SwXMLItemSetStyleContext_Impl::CreateItemSetContext( } if( pItemSet ) pContext = GetSwImport().CreateTableItemImportContext( - nPrefix, rLName, xAttrList, GetFamily(), + nElement, xAttrList, GetFamily(), *pItemSet ); if( !pContext ) { @@ -630,22 +631,15 @@ void SwXMLItemSetStyleContext_Impl::CreateAndInsert( bool bOverwrite ) } SvXMLImportContextRef SwXMLItemSetStyleContext_Impl::CreateChildContext( - sal_uInt16 nPrefix, - const OUString& rLocalName, - const uno::Reference< xml::sax::XAttributeList > & xAttrList ) + 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_TABLE_PROPERTIES ) || - IsXMLToken( rLocalName, XML_TABLE_COLUMN_PROPERTIES ) || - IsXMLToken( rLocalName, XML_TABLE_ROW_PROPERTIES ) || - IsXMLToken( rLocalName, XML_TABLE_CELL_PROPERTIES ) ) - { - xContext = CreateItemSetContext( nPrefix, rLocalName, xAttrList ); - } - else if( IsXMLToken( rLocalName, XML_TEXT_PROPERTIES ) || + if( IsXMLToken( rLocalName, XML_TEXT_PROPERTIES ) || IsXMLToken( rLocalName, XML_PARAGRAPH_PROPERTIES )) { if( !pTextStyle ) @@ -667,6 +661,29 @@ SvXMLImportContextRef SwXMLItemSetStyleContext_Impl::CreateChildContext( return xContext; } +css::uno::Reference< css::xml::sax::XFastContextHandler > SwXMLItemSetStyleContext_Impl::createFastChildContext( + sal_Int32 nElement, + const uno::Reference< xml::sax::XFastAttributeList > & xAttrList ) +{ + switch (nElement) + { + case XML_ELEMENT(STYLE, XML_TABLE_PROPERTIES): + case XML_ELEMENT(STYLE, XML_TABLE_COLUMN_PROPERTIES): + case XML_ELEMENT(STYLE, XML_TABLE_ROW_PROPERTIES): + case XML_ELEMENT(STYLE, XML_TABLE_CELL_PROPERTIES): + return CreateItemSetContext( nElement, xAttrList ); + break; + case XML_ELEMENT(STYLE, XML_TEXT_PROPERTIES): + case XML_ELEMENT(STYLE, XML_PARAGRAPH_PROPERTIES): + // handled in CreateChildContext + break; + default: + SAL_WARN("sw", "unknown element " << SvXMLImport::getPrefixAndNameFromToken(nElement)); + } + + return nullptr; +} + void SwXMLItemSetStyleContext_Impl::ConnectPageDesc() { if( bPageDescConnected || !HasMasterPageName() ) diff --git a/sw/source/filter/xml/xmlimp.hxx b/sw/source/filter/xml/xmlimp.hxx index 4b62c408b97b..060186339e46 100644 --- a/sw/source/filter/xml/xmlimp.hxx +++ b/sw/source/filter/xml/xmlimp.hxx @@ -146,9 +146,8 @@ public: inline const SvXMLImportItemMapper& GetTableItemMapper() const; inline SvXMLImportItemMapper& GetTableItemMapper(); - SvXMLImportContext *CreateTableItemImportContext( sal_uInt16 nPrefix, - const OUString& rLocalName, - const css::uno::Reference< css::xml::sax::XAttributeList > & xAttrList, + SvXMLImportContext *CreateTableItemImportContext( sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList > & xAttrList, XmlStyleFamily nSubFamily, SfxItemSet& rItemSet ); const SvXMLTokenMap& GetDocElemTokenMap(); diff --git a/sw/source/filter/xml/xmlimpit.cxx b/sw/source/filter/xml/xmlimpit.cxx index 543d3ba90c59..023eae8dc25b 100644 --- a/sw/source/filter/xml/xmlimpit.cxx +++ b/sw/source/filter/xml/xmlimpit.cxx @@ -48,6 +48,8 @@ #include <xmloff/prhdlfac.hxx> #include <xmloff/xmltypes.hxx> #include <xmloff/xmlprhdl.hxx> +#include <xmloff/xmlimp.hxx> +#include <xmloff/xmlnamespace.hxx> #include "xmlithlp.hxx" #include <com/sun/star/uno/Any.hxx> @@ -76,27 +78,25 @@ SvXMLImportItemMapper::setMapEntries( SvXMLItemMapEntriesRef rMapEntries ) // fills the given itemset with the attributes in the given list void SvXMLImportItemMapper::importXML( SfxItemSet& rSet, - uno::Reference< xml::sax::XAttributeList > const & xAttrList, + uno::Reference< xml::sax::XFastAttributeList > const & xAttrList, const SvXMLUnitConverter& rUnitConverter, const SvXMLNamespaceMap& rNamespaceMap ) { - sal_Int16 nAttr = xAttrList->getLength(); - std::unique_ptr<SvXMLAttrContainerItem> pUnknownItem; - for( sal_Int16 i=0; i < nAttr; i++ ) + for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList )) { - const OUString& rAttrName = xAttrList->getNameByIndex( i ); - OUString aLocalName, aPrefix, aNamespace; - sal_uInt16 nPrefix = - rNamespaceMap.GetKeyByAttrName( rAttrName, &aPrefix, &aLocalName, - &aNamespace ); - if( XML_NAMESPACE_XMLNS == nPrefix ) + if( IsTokenInNamespace(aIter.getToken(), XML_NAMESPACE_XMLNS) ) continue; - const OUString& rValue = xAttrList->getValueByIndex( i ); + sal_Int32 nToken = aIter.getToken(); + const OUString sValue = aIter.toString(); // find a map entry for this attribute - SvXMLItemMapEntry const * pEntry = mrMapEntries->getByName( nPrefix, aLocalName ); + sal_Int32 nLookupToken = nToken; + // compatiblity namespaces need to be tranformed into current namespace before looking up + if (IsTokenInNamespace(nLookupToken, XML_NAMESPACE_FO_COMPAT)) + nLookupToken = XML_ELEMENT(FO, (nLookupToken & TOKEN_MASK)); + SvXMLItemMapEntry const * pEntry = mrMapEntries->getByName( nLookupToken ); if( pEntry ) { @@ -121,7 +121,7 @@ void SvXMLImportItemMapper::importXML( SfxItemSet& rSet, if( 0 == (pEntry->nMemberId&MID_SW_FLAG_SPECIAL_ITEM_IMPORT) ) { - bPut = PutXMLValue( *pNewItem, rValue, + bPut = PutXMLValue( *pNewItem, sValue, static_cast<sal_uInt16>( pEntry->nMemberId & MID_SW_FLAG_MASK ), rUnitConverter ); @@ -129,7 +129,7 @@ void SvXMLImportItemMapper::importXML( SfxItemSet& rSet, else { bPut = handleSpecialItem( *pEntry, *pNewItem, rSet, - rValue, rUnitConverter ); + sValue, rUnitConverter ); } if( bPut ) @@ -142,11 +142,11 @@ void SvXMLImportItemMapper::importXML( SfxItemSet& rSet, } else if( 0 != (pEntry->nMemberId & MID_SW_FLAG_NO_ITEM_IMPORT) ) { - handleNoItem( *pEntry, rSet, rValue, rUnitConverter, + handleNoItem( *pEntry, rSet, sValue, rUnitConverter, rNamespaceMap ); } } - else if (!aLocalName.isEmpty()) + else { if( !pUnknownItem ) { @@ -163,11 +163,63 @@ void SvXMLImportItemMapper::importXML( SfxItemSet& rSet, } if( pUnknownItem ) { - if( XML_NAMESPACE_NONE == nPrefix ) - pUnknownItem->AddAttr( aLocalName, rValue ); + if( IsTokenInNamespace(nToken, XML_NAMESPACE_NONE) ) + pUnknownItem->AddAttr( SvXMLImport::getNameFromToken( nToken ), sValue ); else - pUnknownItem->AddAttr( aPrefix, aNamespace, aLocalName, - rValue ); + { + const OUString& rAttrNamespacePrefix = SvXMLImport::getNamespacePrefixFromToken(nToken, &rNamespaceMap); + OUString sAttrName = SvXMLImport::getNameFromToken( nToken ); + if ( !rAttrNamespacePrefix.isEmpty() ) + sAttrName = rAttrNamespacePrefix + SvXMLImport::aNamespaceSeparator + sAttrName; + OUString aLocalName, aPrefix, aNamespace; + rNamespaceMap.GetKeyByAttrName( sAttrName, &aPrefix, &aLocalName, + &aNamespace ); + pUnknownItem->AddAttr( rAttrNamespacePrefix, aNamespace, aLocalName, + sValue ); + } + } + } + } + + importXMLUnknownAttributes(rSet, xAttrList, rUnitConverter, pUnknownItem); + + if( pUnknownItem ) + { + rSet.Put( *pUnknownItem ); + } + + finished(rSet, rUnitConverter); +} + +void SvXMLImportItemMapper::importXMLUnknownAttributes( SfxItemSet& rSet, + uno::Reference< xml::sax::XFastAttributeList > const & xAttrList, + const SvXMLUnitConverter& rUnitConverter, + std::unique_ptr<SvXMLAttrContainerItem>& pUnknownItem) +{ + const css::uno::Sequence< css::xml::Attribute > unknownAttributes = xAttrList->getUnknownAttributes(); + for (const auto & rAttribute : unknownAttributes) + { + if( !pUnknownItem ) + { + const SfxPoolItem* pItem = nullptr; + if( SfxItemState::SET == rSet.GetItemState( nUnknownWhich, true, + &pItem ) ) + { + pUnknownItem.reset( static_cast<SvXMLAttrContainerItem*>( pItem->Clone() ) ); + } + else + { + pUnknownItem.reset( new SvXMLAttrContainerItem( nUnknownWhich ) ); + } + } + if( pUnknownItem ) + { + if( rAttribute.NamespaceURL.isEmpty() ) + pUnknownItem->AddAttr( rAttribute.Name, rAttribute.Value ); + else + { + pUnknownItem->AddAttr( rAttribute.Name, rAttribute.NamespaceURL, rAttribute.Name, + rAttribute.Value ); } } } diff --git a/sw/source/filter/xml/xmlimpit.hxx b/sw/source/filter/xml/xmlimpit.hxx index ff6920faac17..8c95459fe9e6 100644 --- a/sw/source/filter/xml/xmlimpit.hxx +++ b/sw/source/filter/xml/xmlimpit.hxx @@ -27,6 +27,7 @@ class SfxPoolItem; class SfxItemSet; class SvXMLNamespaceMap; struct SvXMLItemMapEntry; +class SvXMLAttrContainerItem; class SvXMLImportItemMapper { @@ -39,7 +40,7 @@ public: /** fills the given itemset with the attributes in the given list */ void importXML( SfxItemSet& rSet, - css::uno::Reference< css::xml::sax::XAttributeList > const & xAttrList, + css::uno::Reference< css::xml::sax::XFastAttributeList > const & xAttrList, const SvXMLUnitConverter& rUnitConverter, const SvXMLNamespaceMap& rNamespaceMap ); @@ -74,6 +75,12 @@ public: const OUString& rValue, sal_uInt16 nMemberId, const SvXMLUnitConverter& rUnitConverter ); +private: + void importXMLUnknownAttributes( SfxItemSet& rSet, + css::uno::Reference< css::xml::sax::XFastAttributeList > const & xAttrList, + const SvXMLUnitConverter& rUnitConverter, + std::unique_ptr<SvXMLAttrContainerItem>& pUnknownItem ); + }; inline const SvXMLItemMapEntriesRef& diff --git a/sw/source/filter/xml/xmlitem.cxx b/sw/source/filter/xml/xmlitem.cxx index 4b22cd5044d8..bfc287a45109 100644 --- a/sw/source/filter/xml/xmlitem.cxx +++ b/sw/source/filter/xml/xmlitem.cxx @@ -18,6 +18,7 @@ */ #include <editeng/brushitem.hxx> +#include <sal/log.hxx> #include <xmloff/xmlimp.hxx> #include "xmlimpit.hxx" #include "xmlitem.hxx" @@ -26,13 +27,12 @@ using namespace ::com::sun::star; -SwXMLItemSetContext::SwXMLItemSetContext( SvXMLImport& rImp, sal_uInt16 nPrfx, - const OUString& rLName, - const uno::Reference< xml::sax::XAttributeList >& xAttrList, +SwXMLItemSetContext::SwXMLItemSetContext( SvXMLImport& rImp, sal_Int32 /*nElement*/, + const uno::Reference< xml::sax::XFastAttributeList >& xAttrList, SfxItemSet& rISet, SvXMLImportItemMapper& rIMap, const SvXMLUnitConverter& rUnitConverter ): - SvXMLImportContext( rImp, nPrfx, rLName ), + SvXMLImportContext( rImp ), rItemSet( rISet ), rIMapper( rIMap ), rUnitConv( rUnitConverter ) @@ -51,18 +51,19 @@ SwXMLItemSetContext::~SwXMLItemSetContext() } } -SvXMLImportContextRef SwXMLItemSetContext::CreateChildContext( sal_uInt16 nPrefix, - const OUString& rLocalName, - const uno::Reference< xml::sax::XAttributeList >& xAttrList ) +css::uno::Reference< css::xml::sax::XFastContextHandler > SwXMLItemSetContext::createFastChildContext( + sal_Int32 nElement, + const uno::Reference< xml::sax::XFastAttributeList >& xAttrList ) { SvXMLItemMapEntriesRef xMapEntries = rIMapper.getMapEntries(); - SvXMLItemMapEntry const * pEntry = xMapEntries->getByName( nPrefix, rLocalName ); + SvXMLItemMapEntry const * pEntry = xMapEntries->getByName( nElement ); if( pEntry && 0 != (pEntry->nMemberId & MID_SW_FLAG_ELEMENT_ITEM_IMPORT) ) { - return CreateChildContext( nPrefix, rLocalName, xAttrList, - *pEntry ); + return createFastChildContext( nElement, xAttrList, *pEntry ).get(); } + else + SAL_WARN("sw", "unknown element " << SvXMLImport::getPrefixAndNameFromToken(nElement)); return nullptr; } @@ -70,9 +71,8 @@ SvXMLImportContextRef SwXMLItemSetContext::CreateChildContext( sal_uInt16 nPrefi CreateChildContext if the element matches an entry in the SvXMLImportItemMapper with the mid flag MID_SW_FLAG_ELEMENT */ -SvXMLImportContextRef SwXMLItemSetContext::CreateChildContext( sal_uInt16 nPrefix, - const OUString& rLocalName, - const uno::Reference< xml::sax::XAttributeList >& xAttrList, +SvXMLImportContextRef SwXMLItemSetContext::createFastChildContext( sal_Int32 nElement, + const uno::Reference< xml::sax::XFastAttributeList >& xAttrList, const SvXMLItemMapEntry& rEntry ) { SvXMLImportContextRef xContext; @@ -86,13 +86,13 @@ SvXMLImportContextRef SwXMLItemSetContext::CreateChildContext( sal_uInt16 nPrefi false, &pItem ) ) { xContext = new SwXMLBrushItemImportContext( - GetImport(), nPrefix, rLocalName, xAttrList, + GetImport(), nElement, xAttrList, rUnitConv, *static_cast<const SvxBrushItem *>(pItem) ); } else { xContext = new SwXMLBrushItemImportContext( - GetImport(), nPrefix, rLocalName, xAttrList, + GetImport(), nElement, xAttrList, rUnitConv, RES_BACKGROUND ); } xBackground = xContext; diff --git a/sw/source/filter/xml/xmlitem.hxx b/sw/source/filter/xml/xmlitem.hxx index b8678ebe1a68..55971f339a0d 100644 --- a/sw/source/filter/xml/xmlitem.hxx +++ b/sw/source/filter/xml/xmlitem.hxx @@ -38,26 +38,26 @@ class SwXMLItemSetContext final : public SvXMLImportContext public: - SwXMLItemSetContext( SvXMLImport& rImport, sal_uInt16 nPrfx, - const OUString& rLName, - const css::uno::Reference< css::xml::sax::XAttributeList >& xAttrList, + SwXMLItemSetContext( SvXMLImport& rImport, sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList, SfxItemSet& rItemSet, SvXMLImportItemMapper& rIMap, const SvXMLUnitConverter& rUnitConv ); virtual ~SwXMLItemSetContext() override; - virtual SvXMLImportContextRef CreateChildContext( sal_uInt16 nPrefix, - const OUString& rLocalName, - const css::uno::Reference< css::xml::sax::XAttributeList >& xAttrList ) override; + virtual void SAL_CALL startFastElement( sal_Int32 /*nElement*/, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& ) 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; private: // This method is called from this instance implementation of - // CreateChildContext if the element matches an entry in the + // createFastChildContext if the element matches an entry in the // SvXMLImportItemMapper with the mid flag MID_SW_FLAG_ELEMENT_ITEM_IMPORT - SvXMLImportContextRef CreateChildContext( sal_uInt16 nPrefix, - const OUString& rLocalName, - const css::uno::Reference< css::xml::sax::XAttributeList >& xAttrList, + SvXMLImportContextRef createFastChildContext( sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList, const SvXMLItemMapEntry& rEntry ); }; diff --git a/sw/source/filter/xml/xmlitemi.cxx b/sw/source/filter/xml/xmlitemi.cxx index 7c9ffcc2c3d6..54eed769a945 100644 --- a/sw/source/filter/xml/xmlitemi.cxx +++ b/sw/source/filter/xml/xmlitemi.cxx @@ -244,9 +244,8 @@ void SwXMLImport::FinitItemImport() } SvXMLImportContext *SwXMLImport::CreateTableItemImportContext( - sal_uInt16 nPrefix, - const OUString& rLocalName, - const Reference< xml::sax::XAttributeList > & xAttrList, + sal_Int32 nElement, + const Reference< xml::sax::XFastAttributeList > & xAttrList, XmlStyleFamily nFamily, SfxItemSet& rItemSet ) { @@ -271,10 +270,10 @@ SvXMLImportContext *SwXMLImport::CreateTableItemImportContext( m_pTableItemMapper->setMapEntries( xItemMap ); - return new SwXMLItemSetContext( *this, nPrefix, rLocalName, - xAttrList, rItemSet, - GetTableItemMapper(), - *m_pTwipUnitConv ); + return new SwXMLItemSetContext( *this, nElement, + xAttrList, rItemSet, + GetTableItemMapper(), + *m_pTwipUnitConv ); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/filter/xml/xmlitmap.hxx b/sw/source/filter/xml/xmlitmap.hxx index af4c12ebd129..8d5adb4af4f9 100644 --- a/sw/source/filter/xml/xmlitmap.hxx +++ b/sw/source/filter/xml/xmlitmap.hxx @@ -70,8 +70,7 @@ public: explicit SvXMLItemMapEntries(SvXMLItemMapEntry const * pEntrys); virtual ~SvXMLItemMapEntries() override; - SvXMLItemMapEntry const * getByName( sal_uInt16 nNameSpace, - const OUString& rString ) const; + SvXMLItemMapEntry const * getByName( sal_Int32 nElement ) const; SvXMLItemMapEntry const & getByIndex( sal_uInt16 nIndex ) const; sal_uInt16 getCount() const; diff --git a/sw/source/filter/xml/xmlitmpr.cxx b/sw/source/filter/xml/xmlitmpr.cxx index 100fc7636564..366bcc10f53f 100644 --- a/sw/source/filter/xml/xmlitmpr.cxx +++ b/sw/source/filter/xml/xmlitmpr.cxx @@ -19,6 +19,7 @@ #include <rtl/ustring.hxx> #include "xmlitmap.hxx" +#include <xmloff/xmlimp.hxx> using ::xmloff::token::IsXMLToken; using ::xmloff::token::XML_TOKEN_INVALID; @@ -48,14 +49,13 @@ SvXMLItemMapEntries::~SvXMLItemMapEntries() { } -SvXMLItemMapEntry const * SvXMLItemMapEntries::getByName( sal_uInt16 nNameSpace, - const OUString& rString ) const +SvXMLItemMapEntry const * SvXMLItemMapEntries::getByName( sal_Int32 nElement ) const { SvXMLItemMapEntry const * pMap = mpImpl->mpEntries; while( pMap && (pMap->eLocalName != XML_TOKEN_INVALID) ) { - if( pMap->nNameSpace == nNameSpace && - IsXMLToken( rString, pMap->eLocalName ) ) + if( IsTokenInNamespace(nElement, pMap->nNameSpace) && + (nElement & TOKEN_MASK) == pMap->eLocalName ) break; pMap++; } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits