diff options
author | Noel <noelgrandin@gmail.com> | 2020-11-19 13:16:17 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-11-19 16:14:54 +0100 |
commit | 0c48c46d3ed5db39a0c0e6d0b35aab7506fb8772 (patch) | |
tree | cc9be16753c170e0ea220bd927a190261c762812 /xmloff | |
parent | 52f1115571469f210192cbce6b52e8b7d1d85dc0 (diff) |
fastparser in DomBuilderContext
Change-Id: I126db3987f491c1753ec6c169e42503137e4fa86
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/106152
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'xmloff')
-rw-r--r-- | xmloff/inc/DomBuilderContext.hxx | 5 | ||||
-rw-r--r-- | xmloff/source/core/DomBuilderContext.cxx | 37 |
2 files changed, 22 insertions, 20 deletions
diff --git a/xmloff/inc/DomBuilderContext.hxx b/xmloff/inc/DomBuilderContext.hxx index ef019030d831..4c216084d112 100644 --- a/xmloff/inc/DomBuilderContext.hxx +++ b/xmloff/inc/DomBuilderContext.hxx @@ -71,8 +71,9 @@ 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 void StartElement( - 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 >& xAttrList ) override; virtual void SAL_CALL characters( const OUString& rChars ) override; }; diff --git a/xmloff/source/core/DomBuilderContext.cxx b/xmloff/source/core/DomBuilderContext.cxx index 9c72ebfbf1eb..f24990c73c94 100644 --- a/xmloff/source/core/DomBuilderContext.cxx +++ b/xmloff/source/core/DomBuilderContext.cxx @@ -99,33 +99,30 @@ css::uno::Reference< css::xml::sax::XFastContextHandler > DomBuilderContext::cre } -void DomBuilderContext::StartElement( - const Reference<XAttributeList>& xAttrList ) +void SAL_CALL DomBuilderContext::startFastElement( + sal_Int32 nElement, + const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) { SAL_WARN_IF( !mxNode.is(), "xmloff", "empty XNode not allowed" ); SAL_WARN_IF( !mxNode->getOwnerDocument().is(), "xmloff", "XNode must have XDocument" ); // add attribute nodes to new node - sal_Int16 nAttributeCount = xAttrList->getLength(); - for( sal_Int16 i = 0; i < nAttributeCount; i++ ) + for( auto& aIter : sax_fastparser::castToFastAttributeList(xAttrList) ) { + sal_Int32 nAttrToken = aIter.getToken(); // get name & value for attribute - const OUString& rName = xAttrList->getNameByIndex( i ); - const OUString& rValue = xAttrList->getValueByIndex( i ); - - // namespace handling: determine namespace & namespace key - OUString sNamespace; - sal_uInt16 nNamespaceKey = - GetImport().GetNamespaceMap().GetKeyByAttrName( - rName, nullptr, nullptr, &sNamespace); + sal_uInt16 nNamespace = (nAttrToken >> NMSP_SHIFT) - 1; + const OUString& rPrefix = SvXMLImport::getNamespacePrefixFromToken(nAttrToken, &GetImport().GetNamespaceMap()); + const OUString& rLocalName = SvXMLImport::getNameFromToken( nAttrToken ); + OUString aValue = aIter.toString(); // create attribute node and set value Reference<XElement> xElement( mxNode, UNO_QUERY_THROW ); - switch( nNamespaceKey ) + switch( nNamespace ) { case XML_NAMESPACE_NONE: // no namespace: create a non-namespaced attribute - xElement->setAttribute( rName, rValue ); + xElement->setAttribute( rLocalName, aValue ); break; case XML_NAMESPACE_XMLNS: // namespace declaration: ignore, since the DOM tree handles these @@ -135,15 +132,19 @@ void DomBuilderContext::StartElement( // unknown namespace: illegal input. Raise Warning. { Sequence<OUString> aSeq(2); - aSeq[0] = rName; - aSeq[1] = rValue; + aSeq[0] = rLocalName; + aSeq[1] = aValue; GetImport().SetError( XMLERROR_FLAG_WARNING | XMLERROR_NAMESPACE_TROUBLE, aSeq ); } break; default: - // a real and proper namespace: create namespaced attribute - xElement->setAttributeNS( sNamespace, rName, rValue ); + { + // a real and proper namespace: create namespaced attribute + OUString namespaceURI = SvXMLImport::getNamespaceURIFromToken(nElement); + OUString qualifiedName = rPrefix.isEmpty() ? rLocalName : rPrefix + SvXMLImport::aNamespaceSeparator + rLocalName; + xElement->setAttributeNS( namespaceURI, qualifiedName, aValue ); + } break; } } |