diff options
author | Mohammed Abdul Azeem <azeemmysore@gmail.com> | 2016-09-02 01:18:53 +0530 |
---|---|---|
committer | Michael Meeks <michael.meeks@collabora.com> | 2016-09-05 16:24:59 +0000 |
commit | 67ef208b2b586603e205105a384231645d7f6712 (patch) | |
tree | 2f612397c3d5831b30cd49c393ce6e43a57856ac /xmloff | |
parent | 4e933ea84ec97ab5c4a353995c4c1ce7cdf54ea3 (diff) |
Fixes for migrating SvXMLImport to use FastParser:
These are necessary for implementing fast interfaces
for the contexts.
Change-Id: I37655c85c76b42782a49eeea3140490213047341
Reviewed-on: https://gerrit.libreoffice.org/28641
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Michael Meeks <michael.meeks@collabora.com>
Diffstat (limited to 'xmloff')
-rw-r--r-- | xmloff/source/core/xmlictxt.cxx | 60 | ||||
-rw-r--r-- | xmloff/source/core/xmlimp.cxx | 47 |
2 files changed, 76 insertions, 31 deletions
diff --git a/xmloff/source/core/xmlictxt.cxx b/xmloff/source/core/xmlictxt.cxx index f3e27e500aee..2fb80c5c89a5 100644 --- a/xmloff/source/core/xmlictxt.cxx +++ b/xmloff/source/core/xmlictxt.cxx @@ -25,6 +25,7 @@ #include <com/sun/star/xml/sax/XLocator.hpp> #include <xmloff/xmlimp.hxx> #include <xmloff/xmlictxt.hxx> +#include <sax/fastattribs.hxx> using namespace ::com::sun::star; @@ -69,6 +70,7 @@ void SvXMLImportContext::Characters( const OUString& ) void SAL_CALL SvXMLImportContext::startFastElement(sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList > & Attribs) throw (uno::RuntimeException, xml::sax::SAXException, std::exception) { + mrImport.isFastContext = false; startUnknownElement( mrImport.getNamespacePrefixFromToken( nElement ), mrImport.getNameFromToken( nElement ), Attribs ); } @@ -85,38 +87,47 @@ void SAL_CALL SvXMLImportContext::startUnknownElement(const OUString & rPrefix, else elementName = rLocalName; - uno::Sequence< xml::FastAttribute > fastAttribs = Attribs->getFastAttributes(); - sal_uInt16 len = fastAttribs.getLength(); - for (sal_uInt16 i = 0; i < len; i++) + if ( Attribs.is() ) { - OUString& rAttrValue = fastAttribs[i].Value; - sal_Int32 nToken = fastAttribs[i].Token; - const OUString& rAttrNamespacePrefix = mrImport.getNamespacePrefixFromToken( nToken ); - OUString sAttrName = mrImport.getNameFromToken( nToken ); - if ( !rAttrNamespacePrefix.isEmpty() ) - sAttrName = rAttrNamespacePrefix + ":" + sAttrName; - - rAttrList->AddAttribute( sAttrName, "CDATA", rAttrValue ); + sax_fastparser::FastAttributeList *pAttribList; + assert( dynamic_cast< sax_fastparser::FastAttributeList *>( Attribs.get() ) != nullptr ); + pAttribList = static_cast< sax_fastparser::FastAttributeList *>( Attribs.get() ); + + const std::vector< sal_Int32 >& rAttrTokenList = pAttribList->getFastAttributeTokens(); + for ( size_t i = 0; i < rAttrTokenList.size(); i++ ) + { + const OUString& rAttrValue = OUString(pAttribList->getFastAttributeValue(i), + pAttribList->AttributeValueLength(i), RTL_TEXTENCODING_UTF8); + sal_Int32 nToken = rAttrTokenList[ i ]; + const OUString& rAttrNamespacePrefix = mrImport.getNamespacePrefixFromToken( nToken ); + OUString sAttrName = mrImport.getNameFromToken( nToken ); + if ( !rAttrNamespacePrefix.isEmpty() ) + sAttrName = rAttrNamespacePrefix + ":" + sAttrName; + + rAttrList->AddAttribute( sAttrName, "CDATA", rAttrValue ); + } + + uno::Sequence< xml::Attribute > unknownAttribs = Attribs->getUnknownAttributes(); + sal_Int32 len = unknownAttribs.getLength(); + for ( sal_Int32 i = 0; i < len; i++ ) + { + const OUString& rAttrValue = unknownAttribs[i].Value; + OUString sAttrName = unknownAttribs[i].Name; + const OUString& rAttrNamespacePrefix = unknownAttribs[i].NamespaceURL; + if ( !rAttrNamespacePrefix.isEmpty() ) + sAttrName = rAttrNamespacePrefix + ":" + sAttrName; + + rAttrList->AddAttribute( sAttrName, "CDATA", rAttrValue ); + } } - uno::Sequence< xml::Attribute > unknownAttribs = Attribs->getUnknownAttributes(); - len = unknownAttribs.getLength(); - for ( sal_uInt16 i = 0; i < len; i++ ) - { - OUString& rAttrValue = unknownAttribs[i].Value; - OUString sAttrName = unknownAttribs[i].Name; - OUString& rAttrNamespacePrefix = unknownAttribs[i].NamespaceURL; - if ( !rAttrNamespacePrefix.isEmpty() ) - sAttrName = rAttrNamespacePrefix + ":" + sAttrName; - - rAttrList->AddAttribute( sAttrName, "CDATA", rAttrValue ); - } mrImport.startElement( elementName, rAttrList.get() ); } void SAL_CALL SvXMLImportContext::endFastElement(sal_Int32 nElement) throw (uno::RuntimeException, xml::sax::SAXException, std::exception) { + mrImport.isFastContext = false; endUnknownElement( mrImport.getNamespacePrefixFromToken( nElement ), mrImport.getNameFromToken( nElement ) ); } @@ -146,9 +157,10 @@ uno::Reference< xml::sax::XFastContextHandler > SAL_CALL SvXMLImportContext::cre return this; } -void SAL_CALL SvXMLImportContext::characters(const OUString &) +void SAL_CALL SvXMLImportContext::characters(const OUString &rChars) throw (uno::RuntimeException, xml::sax::SAXException, std::exception) { + mrImport.Characters( rChars ); } void SvXMLImportContext::onDemandRescueUsefulDataFromTemporary( const SvXMLImportContext& ) diff --git a/xmloff/source/core/xmlimp.cxx b/xmloff/source/core/xmlimp.cxx index f234cee2b194..7a1fd79164c5 100644 --- a/xmloff/source/core/xmlimp.cxx +++ b/xmloff/source/core/xmlimp.cxx @@ -435,6 +435,7 @@ SvXMLImport::SvXMLImport( mpXMLErrors( nullptr ), mnImportFlags( nImportFlags ), mnErrorFlags(SvXMLErrorFlags::NO), + isFastContext( false ), maNamespaceHandler( new SvXMLImportFastNamespaceHandler() ), mxTokenHandler( new FastTokenHandler() ), mbIsFormsSupported( true ), @@ -691,14 +692,9 @@ void SAL_CALL SvXMLImport::endDocument() } } -void SAL_CALL SvXMLImport::startElement( const OUString& rName, - const uno::Reference< xml::sax::XAttributeList >& xAttrList ) - throw(xml::sax::SAXException, uno::RuntimeException, std::exception) +void SvXMLImport::processNSAttributes( const uno::Reference< xml::sax::XAttributeList >& xAttrList, + SvXMLNamespaceMap *pRewindMap ) { - SvXMLNamespaceMap *pRewindMap = nullptr; - // SAL_INFO("svg", "startElement " << rName); - // Process namespace attributes. This must happen before creating the - // context, because namespace decaration apply to the element name itself. sal_Int16 nAttrCount = xAttrList.is() ? xAttrList->getLength() : 0; for( sal_Int16 i=0; i < nAttrCount; i++ ) { @@ -746,6 +742,17 @@ void SAL_CALL SvXMLImport::startElement( const OUString& rName, } } +} + +void SAL_CALL SvXMLImport::startElement( const OUString& rName, + const uno::Reference< xml::sax::XAttributeList >& xAttrList ) + throw(xml::sax::SAXException, uno::RuntimeException, std::exception) +{ + SvXMLNamespaceMap *pRewindMap = nullptr; + // SAL_INFO("svg", "startElement " << rName); + // Process namespace attributes. This must happen before creating the + // context, because namespace decaration apply to the element name itself. + processNSAttributes( xAttrList, pRewindMap ); // Get element's namespace and local name. OUString aLocalName; @@ -852,6 +859,14 @@ void SAL_CALL SvXMLImport::characters( const OUString& rChars ) } } +void SvXMLImport::Characters( const OUString& rChars ) +{ + if( !mpContexts->empty() ) + { + mpContexts->back()->Characters( rChars ); + } +} + void SAL_CALL SvXMLImport::ignorableWhitespace( const OUString& ) throw(xml::sax::SAXException, uno::RuntimeException, std::exception) { @@ -888,9 +903,23 @@ void SAL_CALL SvXMLImport::startFastElement (sal_Int32 Element, if ( !xContext.is() ) xContext.set( new SvXMLImportContext( *this ) ); + isFastContext = true; + // Call a startElement at the new context. xContext->startFastElement( Element, Attribs ); + if ( isFastContext ) + { + rtl::Reference < comphelper::AttributeList > rAttrList = new comphelper::AttributeList; + maNamespaceHandler->addNSDeclAttributes( rAttrList ); + SvXMLNamespaceMap *pRewindMap = nullptr; + processNSAttributes( rAttrList.get(), pRewindMap ); + SvXMLImportContext *pContext = dynamic_cast<SvXMLImportContext*>( xContext.get() ); + if( pContext && pRewindMap ) + pContext->PutRewindMap( pRewindMap ); + mpContexts->push_back( pContext ); + } + // Push context on stack. mpFastContexts->push_back( xContext ); } @@ -924,7 +953,11 @@ void SAL_CALL SvXMLImport::endFastElement (sal_Int32 Element) { uno::Reference< XFastContextHandler > xContext = mpFastContexts->back(); mpFastContexts->pop_back(); + isFastContext = true; xContext->endFastElement( Element ); + if ( isFastContext ) + mpContexts->pop_back(); + xContext = nullptr; } } |