diff options
author | Noel <noelgrandin@gmail.com> | 2020-12-03 11:33:25 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-12-03 17:48:21 +0100 |
commit | e65b31244fa7d2f9bfffb7e7b9567e623a4cbf0b (patch) | |
tree | 795ba0107c806c1da61491ab27ce89cd687724c6 /xmloff | |
parent | d0fa04b4111d8b43d4249aeae96bb0f6fcd35e8e (diff) |
fastparser in XMLCellImportContext
Change-Id: I62d5953d26ea37ba2c40ed1b778f71b85c304b9d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/107147
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'xmloff')
-rw-r--r-- | xmloff/source/table/XMLTableImport.cxx | 97 |
1 files changed, 60 insertions, 37 deletions
diff --git a/xmloff/source/table/XMLTableImport.cxx b/xmloff/source/table/XMLTableImport.cxx index aa89732a4c81..af931822cbe6 100644 --- a/xmloff/source/table/XMLTableImport.cxx +++ b/xmloff/source/table/XMLTableImport.cxx @@ -74,6 +74,9 @@ public: virtual SvXMLImportContextRef CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const Reference< 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; + private: SvXMLImportContextRef mxParent; }; @@ -98,6 +101,9 @@ class XMLTableImportContext : public SvXMLImportContext public: XMLTableImportContext( const rtl::Reference< XMLTableImport >& xThis, Reference< XColumnRowRange > const & xColumnRowRange ); + 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 Reference< XAttributeList >& xAttrList ) override; virtual void SAL_CALL endFastElement(sal_Int32 nElement) override; @@ -106,7 +112,7 @@ public: SvXMLImportContextRef ImportColumn( const Reference< XAttributeList >& xAttrList ); SvXMLImportContext * ImportRow( sal_uInt16 nPrefix, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList ); - SvXMLImportContextRef ImportCell( sal_uInt16 nPrefix, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList ); + SvXMLImportContextRef ImportCell( sal_Int32 nElement, const Reference< XFastAttributeList >& xAttrList ); OUString GetDefaultCellStyleName() const; @@ -132,10 +138,12 @@ public: XMLCellImportContext( SvXMLImport& rImport, const Reference< XMergeableCell >& xCell, const OUString& sDefaultCellStyleName, - 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 ); - virtual SvXMLImportContextRef CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const Reference< 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 >& xAttrList ) override; virtual void SAL_CALL endFastElement(sal_Int32 nElement) override; @@ -188,6 +196,13 @@ SvXMLImportContextRef XMLProxyContext::CreateChildContext( sal_uInt16 nPrefix, c return nullptr; } + css::uno::Reference< css::xml::sax::XFastContextHandler > XMLProxyContext::createFastChildContext( sal_Int32 nElement, const Reference< XFastAttributeList >& xAttrList ) +{ + if( mxParent.is() ) + return mxParent->createFastChildContext( nElement, xAttrList ); + return nullptr; +} + XMLTableImport::XMLTableImport( SvXMLImport& rImport, const rtl::Reference< XMLPropertySetMapper >& xCellPropertySetMapper, const rtl::Reference< XMLPropertyHandlerFactory >& xFactoryRef ) : mrImport( rImport ) @@ -533,7 +548,7 @@ SvXMLImportContext * XMLTableImportContext::ImportRow( sal_uInt16 nPrefix, const return new XMLProxyContext( GetImport(), xThis, nPrefix, rLocalName ); } -SvXMLImportContextRef XMLTableImportContext::ImportCell( sal_uInt16 nPrefix, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList ) +SvXMLImportContextRef XMLTableImportContext::ImportCell( sal_Int32 nElement, const Reference< XFastAttributeList >& xAttrList ) { mnCurrentColumn++; if( mxColumns.is() ) try @@ -542,7 +557,7 @@ SvXMLImportContextRef XMLTableImportContext::ImportCell( sal_uInt16 nPrefix, con mxColumns->insertByIndex( mxColumns->getCount(), mnCurrentColumn - mxColumns->getCount() + 1 ); Reference< XMergeableCell > xCell( mxTable->getCellByPosition( mnCurrentColumn, mnCurrentRow ), UNO_QUERY_THROW ); - XMLCellImportContext* pCellContext = new XMLCellImportContext( GetImport(), xCell, GetDefaultCellStyleName(), nPrefix, rLocalName, xAttrList ); + XMLCellImportContext* pCellContext = new XMLCellImportContext( GetImport(), xCell, GetDefaultCellStyleName(), nElement, xAttrList ); const sal_Int32 nColumnSpan = pCellContext->getColumnSpan(); const sal_Int32 nRowSpan = pCellContext->getRowSpan(); @@ -566,6 +581,16 @@ SvXMLImportContextRef XMLTableImportContext::ImportCell( sal_uInt16 nPrefix, con return nullptr; } +css::uno::Reference< css::xml::sax::XFastContextHandler > XMLTableImportContext::createFastChildContext( + sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) +{ + if( nElement == XML_ELEMENT(TABLE, XML_TABLE_CELL) || + nElement == XML_ELEMENT(TABLE, XML_COVERED_TABLE_CELL) ) + return ImportCell( nElement, xAttrList ).get(); + return nullptr; +} + SvXMLImportContextRef XMLTableImportContext::CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList ) { if( nPrefix == XML_NAMESPACE_TABLE ) @@ -574,15 +599,13 @@ SvXMLImportContextRef XMLTableImportContext::CreateChildContext( sal_uInt16 nPre return ImportColumn( xAttrList ); else if( IsXMLToken( rLocalName, XML_TABLE_ROW ) ) return ImportRow( nPrefix, rLocalName, xAttrList ); - else if( IsXMLToken( rLocalName, XML_TABLE_CELL ) || IsXMLToken( rLocalName, XML_COVERED_TABLE_CELL ) ) - return ImportCell( nPrefix, rLocalName, xAttrList ); else if( IsXMLToken( rLocalName, XML_TABLE_COLUMNS ) || IsXMLToken( rLocalName, XML_TABLE_ROWS ) ) { SvXMLImportContextRef xThis( this ); return new XMLProxyContext( GetImport(), xThis, nPrefix, rLocalName ); } } - + SAL_WARN("xmloff", "unknown element"); return nullptr; } @@ -616,8 +639,12 @@ OUString XMLTableImportContext::GetDefaultCellStyleName() const // XMLCellImportContext -XMLCellImportContext::XMLCellImportContext( SvXMLImport& rImport, const Reference< XMergeableCell >& xCell, const OUString& sDefaultCellStyleName, sal_uInt16 nPrfx, const OUString& rLName, const css::uno::Reference< css::xml::sax::XAttributeList >& xAttrList ) -: SvXMLImportContext( rImport, nPrfx, rLName ) +XMLCellImportContext::XMLCellImportContext( SvXMLImport& rImport, + const Reference< XMergeableCell >& xCell, + const OUString& sDefaultCellStyleName, + sal_Int32 /*nElement*/, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) +: SvXMLImportContext( rImport ) , mxCell( xCell ) , mbListContextPushed( false ) , mnColSpan( 1 ) @@ -627,39 +654,31 @@ XMLCellImportContext::XMLCellImportContext( SvXMLImport& rImport, const Referenc OUString sStyleName; // read attributes for the table-cell - 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 sAttrName( xAttrList->getNameByIndex( i ) ); - const OUString sValue( xAttrList->getValueByIndex( i ) ); - OUString aLocalName; + const OUString sValue = aIter.toString(); - sal_uInt16 nPrefix2 = GetImport().GetNamespaceMap().GetKeyByAttrName( sAttrName, &aLocalName ); - if( XML_NAMESPACE_TABLE == nPrefix2 ) + switch (aIter.getToken()) { - if( IsXMLToken( aLocalName, XML_NUMBER_COLUMNS_REPEATED ) ) - { + case XML_ELEMENT(TABLE, XML_NUMBER_COLUMNS_REPEATED): mnRepeated = sValue.toInt32(); - } - else if( IsXMLToken( aLocalName, XML_NUMBER_COLUMNS_SPANNED ) ) - { + break; + case XML_ELEMENT(TABLE, XML_NUMBER_COLUMNS_SPANNED): mnColSpan = sValue.toInt32(); - } - else if( IsXMLToken( aLocalName, XML_NUMBER_ROWS_SPANNED ) ) - { + break; + case XML_ELEMENT(TABLE, XML_NUMBER_ROWS_SPANNED): mnRowSpan = sValue.toInt32(); - } - else if( IsXMLToken( aLocalName, XML_STYLE_NAME ) ) - { + break; + case XML_ELEMENT(TABLE, XML_STYLE_NAME): sStyleName = sValue; - } - } - else if ( (XML_NAMESPACE_XML == nPrefix2) && - IsXMLToken(aLocalName, XML_ID) ) - { + break; + case XML_ELEMENT(XML, XML_ID): //FIXME: TODO - } + break; //FIXME: RDFa (table:table-cell) + default: + XMLOFF_WARN_UNKNOWN("xmloff", aIter); + } } // if there is no style name at the cell, try default style name from row @@ -685,7 +704,9 @@ XMLCellImportContext::XMLCellImportContext( SvXMLImport& rImport, const Referenc } } -SvXMLImportContextRef XMLCellImportContext::CreateChildContext( sal_uInt16 nPrefix, const OUString& rLocalName, const Reference< XAttributeList >& xAttrList ) +css::uno::Reference< css::xml::sax::XFastContextHandler > XMLCellImportContext::createFastChildContext( + sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) { // create text cursor on demand if( !mxCursor.is() ) @@ -711,9 +732,11 @@ SvXMLImportContextRef XMLCellImportContext::CreateChildContext( sal_uInt16 nPref // if we have a text cursor, lets try to import some text if( mxCursor.is() ) { - pContext = GetImport().GetTextImport()->CreateTextChildContext( GetImport(), nPrefix, rLocalName, xAttrList ); + pContext = GetImport().GetTextImport()->CreateTextChildContext( GetImport(), nElement, xAttrList ); } + if (!pContext) + XMLOFF_WARN_UNKNOWN_ELEMENT("xmloff", nElement); return pContext; } |