diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-01-20 16:14:07 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-01-21 08:21:29 +0100 |
commit | 5a73d3908c30c898a0f21208810332d36657adee (patch) | |
tree | 7d1272ebb7af29a0773a06ddf4ea092e87860c49 /xmloff | |
parent | acb8d7d0568352bb34e869880c6ef44336f63b6f (diff) |
use FastParser in XMLScriptContext
Change-Id: I7c5f5b77a78307c556ee5718480346ed3dd159fc
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87075
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'xmloff')
-rw-r--r-- | xmloff/source/draw/sdxmlimp.cxx | 23 | ||||
-rw-r--r-- | xmloff/source/script/xmlscripti.cxx | 69 |
2 files changed, 47 insertions, 45 deletions
diff --git a/xmloff/source/draw/sdxmlimp.cxx b/xmloff/source/draw/sdxmlimp.cxx index 66f6643d6215..98a4ebccbbd3 100644 --- a/xmloff/source/draw/sdxmlimp.cxx +++ b/xmloff/source/draw/sdxmlimp.cxx @@ -173,15 +173,6 @@ SvXMLImportContextRef SdXMLDocContext_Impl::CreateChildContext( SAL_INFO("xmloff.draw", "XML_TOK_DOC_META: should not have come here, maybe document is invalid?"); break; } - case XML_TOK_DOC_SCRIPT: - { - if( GetImport().getImportFlags() & SvXMLImportFlags::SCRIPTS ) - { - // office:script inside office:document - xContext = new XMLScriptContext( GetSdImport(), rLocalName, GetSdImport().GetModel() ); - } - break; - } case XML_TOK_DOC_BODY: { if( GetImport().getImportFlags() & SvXMLImportFlags::CONTENT ) @@ -198,8 +189,20 @@ SvXMLImportContextRef SdXMLDocContext_Impl::CreateChildContext( } uno::Reference< xml::sax::XFastContextHandler > SAL_CALL SdXMLDocContext_Impl::createFastChildContext( - sal_Int32 /*nElement*/, const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ ) + sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& /*xAttrList*/ ) { + switch (nElement) + { + case XML_ELEMENT(OFFICE, XML_SCRIPTS): + { + if( GetImport().getImportFlags() & SvXMLImportFlags::SCRIPTS ) + { + // office:script inside office:document + return new XMLScriptContext( GetSdImport(), GetSdImport().GetModel() ); + } + break; + } + } return nullptr; } diff --git a/xmloff/source/script/xmlscripti.cxx b/xmloff/source/script/xmlscripti.cxx index e038515ed5f9..1cee9101a080 100644 --- a/xmloff/source/script/xmlscripti.cxx +++ b/xmloff/source/script/xmlscripti.cxx @@ -48,21 +48,25 @@ private: OUString const m_aLanguage; public: - XMLScriptChildContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName, + XMLScriptChildContext( SvXMLImport& rImport, const css::uno::Reference< css::frame::XModel>& rxModel, const OUString& rLanguage ); 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 >& /*xAttrList*/ ) override + { return nullptr; } - virtual void EndElement() override; + virtual void SAL_CALL startFastElement( sal_Int32 /*nElement*/, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& ) override {} }; } -XMLScriptChildContext::XMLScriptChildContext( SvXMLImport& rImport, sal_uInt16 nPrfx, const OUString& rLName, +XMLScriptChildContext::XMLScriptChildContext( SvXMLImport& rImport, const Reference< frame::XModel >& rxModel, const OUString& rLanguage ) - :SvXMLImportContext( rImport, nPrfx, rLName ) + :SvXMLImportContext( rImport ) ,m_xModel( rxModel ) ,m_xDocumentScripts( rxModel, UNO_QUERY ) ,m_aLanguage( rLanguage ) @@ -74,7 +78,6 @@ SvXMLImportContextRef XMLScriptChildContext::CreateChildContext( const Reference< xml::sax::XAttributeList >& /*xAttrList*/ ) { SvXMLImportContextRef xContext; - if ( m_xDocumentScripts.is() ) { // document supports embedding scripts/macros OUString aBasic( GetImport().GetNamespaceMap().GetPrefixByKey( XML_NAMESPACE_OOO ) + ":Basic" ); @@ -86,15 +89,11 @@ SvXMLImportContextRef XMLScriptChildContext::CreateChildContext( return xContext; } -void XMLScriptChildContext::EndElement() -{ -} - // XMLScriptContext: context for <office:scripts> element -XMLScriptContext::XMLScriptContext( SvXMLImport& rImport, const OUString& rLName, +XMLScriptContext::XMLScriptContext( SvXMLImport& rImport, const Reference<XModel>& rDocModel ) - :SvXMLImportContext( rImport, XML_NAMESPACE_OFFICE, rLName ) + :SvXMLImportContext( rImport ) ,m_xModel( rDocModel ) { } @@ -103,9 +102,32 @@ XMLScriptContext::~XMLScriptContext() { } +css::uno::Reference< css::xml::sax::XFastContextHandler > XMLScriptContext::createFastChildContext( + sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) +{ + if ( nElement == XML_ELEMENT(OFFICE, XML_SCRIPT) ) + { + if ( m_xModel.is() ) + { + OUString aLanguage = xAttrList->getValue( XML_ELEMENT(SCRIPT, XML_LANGUAGE) ); + + uno::Sequence< beans::PropertyValue > aMedDescr = m_xModel->getArgs(); + sal_Int32 nNewLen = aMedDescr.getLength() + 1; + aMedDescr.realloc( nNewLen ); + aMedDescr[nNewLen-1].Name = "BreakMacroSignature"; + aMedDescr[nNewLen-1].Value <<= true; + m_xModel->attachResource( m_xModel->getURL(), aMedDescr ); + + return new XMLScriptChildContext( GetImport(), m_xModel, aLanguage ); + } + } + return nullptr; +} + SvXMLImportContextRef XMLScriptContext::CreateChildContext( sal_uInt16 nPrefix, const OUString& rLName, - const Reference<XAttributeList>& xAttrList ) + const Reference<XAttributeList>& /*xAttrList*/ ) { SvXMLImportContextRef xContext; @@ -116,33 +138,10 @@ SvXMLImportContextRef XMLScriptContext::CreateChildContext( Reference< XEventsSupplier> xSupplier( GetImport().GetModel(), UNO_QUERY ); xContext = new XMLEventsImportContext( GetImport(), nPrefix, rLName, xSupplier ); } - else if ( IsXMLToken( rLName, XML_SCRIPT ) ) - { - OUString aAttrName( GetImport().GetNamespaceMap().GetPrefixByKey( XML_NAMESPACE_SCRIPT ) + ":language" ); - if ( xAttrList.is() ) - { - OUString aLanguage = xAttrList->getValueByName( aAttrName ); - - if ( m_xModel.is() ) - { - uno::Sequence< beans::PropertyValue > aMedDescr = m_xModel->getArgs(); - sal_Int32 nNewLen = aMedDescr.getLength() + 1; - aMedDescr.realloc( nNewLen ); - aMedDescr[nNewLen-1].Name = "BreakMacroSignature"; - aMedDescr[nNewLen-1].Value <<= true; - m_xModel->attachResource( m_xModel->getURL(), aMedDescr ); - - xContext = new XMLScriptChildContext( GetImport(), nPrefix, rLName, m_xModel, aLanguage ); - } - } - } } return xContext; } -void XMLScriptContext::EndElement() -{ -} /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |