summaryrefslogtreecommitdiff
path: root/xmloff/source/core
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2020-04-30 08:37:51 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2020-04-30 09:43:10 +0200
commite4da8ae4bef37f5450dcf34d9f06b68e3b901c01 (patch)
tree5ce67402f1bc237745046e43caf096896f3a92d2 /xmloff/source/core
parent315d56582f8a56d8f2d3ea6cda63ea4832249608 (diff)
Revert "Convert TokenContext to fastparser APIs"
This reverts commit b7bfe6ae08f5b214f2d03d70a40b66c894c0b659. Reason for revert: I missed some call-sites which means this is not going to work properly, which also means we don't have any tests for this functionality :-( Change-Id: Ie340a5e2331609258e79176c3dd12249ad46ba7b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93134 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'xmloff/source/core')
-rw-r--r--xmloff/source/core/DomBuilderContext.cxx77
-rw-r--r--xmloff/source/core/xmlimp.cxx1
2 files changed, 45 insertions, 33 deletions
diff --git a/xmloff/source/core/DomBuilderContext.cxx b/xmloff/source/core/DomBuilderContext.cxx
index d6f01954f14b..9f893d710ae0 100644
--- a/xmloff/source/core/DomBuilderContext.cxx
+++ b/xmloff/source/core/DomBuilderContext.cxx
@@ -55,13 +55,17 @@ using com::sun::star::xml::dom::NodeType_ELEMENT_NODE;
// helper functions; implemented below
static Reference<XNode> lcl_createDomInstance();
static Reference<XNode> lcl_createElement( SvXMLImport& rImport,
- sal_Int32 nElement,
+ sal_uInt16 nPrefix,
+ const OUString& rLocalName,
const Reference<XNode>& xParent);
-DomBuilderContext::DomBuilderContext( SvXMLImport& rImport, sal_Int32 nElement ) :
- SvXMLImportContext( rImport ),
- mxNode( lcl_createElement( rImport, nElement, lcl_createDomInstance() ) )
+DomBuilderContext::DomBuilderContext( SvXMLImport& rImport,
+ sal_uInt16 nPrefix,
+ const OUString& rLocalName ) :
+ SvXMLImportContext( rImport, nPrefix, rLocalName ),
+ mxNode( lcl_createElement( rImport, nPrefix, rLocalName,
+ lcl_createDomInstance() ) )
{
SAL_WARN_IF( !mxNode.is(), "xmloff", "empty XNode not allowed" );
SAL_WARN_IF( !Reference<XElement>( mxNode, UNO_QUERY ).is(), "xmloff", "need element" );
@@ -69,10 +73,11 @@ DomBuilderContext::DomBuilderContext( SvXMLImport& rImport, sal_Int32 nElement )
}
DomBuilderContext::DomBuilderContext( SvXMLImport& rImport,
- sal_Int32 nElement,
+ sal_uInt16 nPrefix,
+ const OUString& rLocalName,
Reference<XNode> const & xParent ) :
- SvXMLImportContext( rImport ),
- mxNode( lcl_createElement( rImport, nElement, xParent ) )
+ SvXMLImportContext( rImport, nPrefix, rLocalName ),
+ mxNode( lcl_createElement( rImport, nPrefix, rLocalName, xParent ) )
{
SAL_WARN_IF( !mxNode.is(), "xmloff", "empty XNode not allowed" );
SAL_WARN_IF( !Reference<XElement>( mxNode, UNO_QUERY ).is(), "xmloff", "need element" );
@@ -89,39 +94,43 @@ Reference<XDocument> DomBuilderContext::getTree()
return mxNode->getOwnerDocument();
}
-css::uno::Reference< css::xml::sax::XFastContextHandler > DomBuilderContext::createFastChildContext(
- sal_Int32 nElement,
- const css::uno::Reference< css::xml::sax::XFastAttributeList >& )
+SvXMLImportContextRef DomBuilderContext::CreateChildContext(
+ sal_uInt16 nPrefix,
+ const OUString& rLocalName,
+ const Reference<XAttributeList>& )
{
// create DomBuilder for subtree
- return new DomBuilderContext( GetImport(), nElement, mxNode );
+ return new DomBuilderContext( GetImport(), nPrefix, rLocalName, mxNode );
}
-void DomBuilderContext::startFastElement(
- sal_Int32 /*nElement*/,
- const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
+void DomBuilderContext::StartElement(
+ const Reference<XAttributeList>& 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
- for (auto &aIter : sax_fastparser::castToFastAttributeList( xAttrList ))
+ sal_Int16 nAttributeCount = xAttrList->getLength();
+ for( sal_Int16 i = 0; i < nAttributeCount; i++ )
{
// get name & value for attribute
- OUString aName = SvXMLImport::getNameFromToken(aIter.getToken());
- OUString aValue = aIter.toString();
+ const OUString& rName = xAttrList->getNameByIndex( i );
+ const OUString& rValue = xAttrList->getValueByIndex( i );
// namespace handling: determine namespace & namespace key
- sal_Int32 nNamespacePrefix = (( aIter.getToken() & NMSP_MASK ) >> NMSP_SHIFT) - 1;
+ OUString sNamespace;
+ sal_uInt16 nNamespaceKey =
+ GetImport().GetNamespaceMap().GetKeyByAttrName(
+ rName, nullptr, nullptr, &sNamespace);
// create attribute node and set value
Reference<XElement> xElement( mxNode, UNO_QUERY_THROW );
- switch( nNamespacePrefix )
+ switch( nNamespaceKey )
{
case XML_NAMESPACE_NONE:
// no namespace: create a non-namespaced attribute
- xElement->setAttribute( aName, aValue );
+ xElement->setAttribute( rName, rValue );
break;
case XML_NAMESPACE_XMLNS:
// namespace declaration: ignore, since the DOM tree handles these
@@ -131,20 +140,25 @@ void DomBuilderContext::startFastElement(
// unknown namespace: illegal input. Raise Warning.
{
Sequence<OUString> aSeq(2);
- aSeq[0] = aName;
- aSeq[1] = aValue;
+ aSeq[0] = rName;
+ aSeq[1] = rValue;
GetImport().SetError(
XMLERROR_FLAG_WARNING | XMLERROR_NAMESPACE_TROUBLE, aSeq );
}
break;
default:
// a real and proper namespace: create namespaced attribute
- xElement->setAttributeNS( SvXMLImport::getNamespaceURIFromToken(aIter.getToken()), aName, aValue );
+ xElement->setAttributeNS( sNamespace, rName, rValue );
break;
}
}
}
+void DomBuilderContext::EndElement()
+{
+ // nothing to be done!
+}
+
void DomBuilderContext::Characters( const OUString& rCharacters )
{
SAL_WARN_IF( !mxNode.is(), "xmloff", "empty XNode not allowed" );
@@ -175,7 +189,8 @@ static Reference<XNode> lcl_createDomInstance()
}
static Reference<XNode> lcl_createElement( SvXMLImport& rImport,
- sal_Int32 nElement,
+ sal_uInt16 nPrefix,
+ const OUString& rLocalName,
const Reference<XNode>& xParent)
{
SAL_WARN_IF( !xParent.is(), "xmloff", "need parent node" );
@@ -188,20 +203,18 @@ static Reference<XNode> lcl_createElement( SvXMLImport& rImport,
// multiple prefixes for the same namespace. Fortunately, those are rare.
Reference<XElement> xElement;
- sal_Int32 nNamespacePrefix = (( nElement & NMSP_MASK ) >> NMSP_SHIFT) - 1;
- OUString aLocalName = SvXMLImport::getNameFromToken(nElement);
- switch( nNamespacePrefix )
+ switch( nPrefix )
{
case XML_NAMESPACE_NONE:
// no namespace: use local name
- xElement = xDocument->createElement( aLocalName );
+ xElement = xDocument->createElement( rLocalName );
break;
case XML_NAMESPACE_XMLNS:
case XML_NAMESPACE_UNKNOWN:
// both cases are illegal; raise warning (and use only local name)
- xElement = xDocument->createElement( aLocalName );
+ xElement = xDocument->createElement( rLocalName );
{
- Sequence<OUString> aSeq { aLocalName };
+ Sequence<OUString> aSeq { rLocalName };
rImport.SetError(
XMLERROR_FLAG_WARNING | XMLERROR_NAMESPACE_TROUBLE, aSeq );
}
@@ -212,8 +225,8 @@ static Reference<XNode> lcl_createElement( SvXMLImport& rImport,
// this is a bug, since this will fail for multiple prefixes used for
// the same namespace.
xElement = xDocument->createElementNS(
- rImport.GetNamespaceMap().GetNameByKey( nNamespacePrefix ),
- rImport.GetNamespaceMap().GetQNameByKey( nNamespacePrefix, aLocalName ) );
+ rImport.GetNamespaceMap().GetNameByKey( nPrefix ),
+ rImport.GetNamespaceMap().GetQNameByKey( nPrefix, rLocalName ) );
break;
}
SAL_WARN_IF( !xElement.is(), "xmloff", "can't create element" );
diff --git a/xmloff/source/core/xmlimp.cxx b/xmloff/source/core/xmlimp.cxx
index 99be12818ea8..cc515c645a23 100644
--- a/xmloff/source/core/xmlimp.cxx
+++ b/xmloff/source/core/xmlimp.cxx
@@ -2254,7 +2254,6 @@ void SAL_CALL SvXMLLegacyToFastDocHandler::startElement( const OUString& rName,
const OUString& rAttrValue = xAttrList->getValueByIndex( i );
sal_uInt16 const nAttrPrefix(mrImport->mpNamespaceMap->GetKeyByAttrName(
rAttrName, nullptr, &aLocalAttrName, &aNamespace));
- SAL_WARN("xmloff", "nAttrPrefix=" << nAttrPrefix);
if( XML_NAMESPACE_XMLNS != nAttrPrefix )
{
Sequence< sal_Int8 > aAttrSeq( reinterpret_cast<sal_Int8 const *>(