summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/xmloff/xmlictxt.hxx5
-rw-r--r--sc/source/filter/xml/XMLTrackedChangesContext.cxx84
-rw-r--r--xmloff/source/core/xmlictxt.cxx39
3 files changed, 82 insertions, 46 deletions
diff --git a/include/xmloff/xmlictxt.hxx b/include/xmloff/xmlictxt.hxx
index 82f4c11632f1..c0d484844faf 100644
--- a/include/xmloff/xmlictxt.hxx
+++ b/include/xmloff/xmlictxt.hxx
@@ -107,6 +107,11 @@ public:
virtual css::uno::Reference< XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 Element,
const css::uno::Reference<css::xml::sax::XFastAttributeList>& Attribs) override;
+ /**
+ * temporary method to forward call to CreateChildContext, for use during slow-to-fastparser transition
+ */
+ css::uno::Reference< XFastContextHandler > createFastChildContextFallback(sal_Int32 Element,
+ const css::uno::Reference<css::xml::sax::XFastAttributeList>& Attribs);
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createUnknownChildContext(
const OUString & Namespace, const OUString & Name,
diff --git a/sc/source/filter/xml/XMLTrackedChangesContext.cxx b/sc/source/filter/xml/XMLTrackedChangesContext.cxx
index 7a6f7a0a7e56..3467c1eb9c7f 100644
--- a/sc/source/filter/xml/XMLTrackedChangesContext.cxx
+++ b/sc/source/filter/xml/XMLTrackedChangesContext.cxx
@@ -142,24 +142,21 @@ class ScXMLChangeCellContext;
class ScXMLChangeTextPContext : public ScXMLImportContext
{
- css::uno::Reference< css::xml::sax::XAttributeList> xAttrList;
- OUString sLName;
+ css::uno::Reference< css::xml::sax::XFastAttributeList> mxAttrList;
+ sal_Int32 mnElement;
OUStringBuffer sText;
ScXMLChangeCellContext* pChangeCellContext;
rtl::Reference<SvXMLImportContext>
pTextPContext;
- sal_uInt16 nPrefix;
public:
- ScXMLChangeTextPContext( ScXMLImport& rImport, sal_uInt16 nPrfx,
- const OUString& rLName,
- const css::uno::Reference<css::xml::sax::XAttributeList>& xAttrList,
+ ScXMLChangeTextPContext( ScXMLImport& rImport, sal_Int32 nElement,
+ const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttrList,
ScXMLChangeCellContext* pChangeCellContext);
- 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;
virtual void SAL_CALL characters( const OUString& rChars ) override;
@@ -189,12 +186,8 @@ public:
OUString& rInputString, double& fValue, sal_uInt16& nType,
ScMatrixMode& nMatrixFlag, sal_Int32& nMatrixCols, sal_Int32& nMatrixRows);
- 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; }
+ sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList ) override;
void CreateTextPContext(bool bIsNewParagraph);
bool IsEditCell() const { return mpEditTextObj.is(); }
@@ -649,39 +642,35 @@ uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLDeletionsContext::
}
ScXMLChangeTextPContext::ScXMLChangeTextPContext( ScXMLImport& rImport,
- sal_uInt16 nPrfx,
- const OUString& rLName,
- const css::uno::Reference<css::xml::sax::XAttributeList>& xTempAttrList,
+ sal_Int32 nElement,
+ const css::uno::Reference<css::xml::sax::XFastAttributeList>& xAttrList,
ScXMLChangeCellContext* pTempChangeCellContext) :
- ScXMLImportContext( rImport, nPrfx, rLName ),
- xAttrList(xTempAttrList),
- sLName(rLName),
+ ScXMLImportContext( rImport ),
+ mxAttrList(xAttrList),
+ mnElement(nElement),
sText(),
- pChangeCellContext(pTempChangeCellContext),
- nPrefix(nPrfx)
+ pChangeCellContext(pTempChangeCellContext)
{
// here are no attributes
}
-SvXMLImportContextRef ScXMLChangeTextPContext::CreateChildContext( sal_uInt16 nTempPrefix,
- const OUString& rLName,
- const css::uno::Reference<css::xml::sax::XAttributeList>& xTempAttrList )
+uno::Reference< xml::sax::XFastContextHandler > SAL_CALL ScXMLChangeTextPContext::createFastChildContext(
+ sal_Int32 nElement,
+ const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
{
- SvXMLImportContextRef xContext;
-
- if ((nPrefix == XML_NAMESPACE_TEXT) && (IsXMLToken(rLName, XML_S)) && !pTextPContext)
+ uno::Reference< xml::sax::XFastContextHandler > xContext;
+ if (IsTokenInNamespace(mnElement, XML_NAMESPACE_TEXT)
+ && (nElement & TOKEN_MASK) == XML_S
+ && !pTextPContext)
{
sal_Int32 nRepeat(0);
- sal_Int16 nAttrCount(xAttrList.is() ? xAttrList->getLength() : 0);
- for( sal_Int16 i=0; i < nAttrCount; ++i )
+ for( auto& aIter : sax_fastparser::castToFastAttributeList(mxAttrList) )
{
- const OUString& sAttrName(xAttrList->getNameByIndex( i ));
- const OUString& sValue(xAttrList->getValueByIndex( i ));
- OUString aLocalName;
- sal_uInt16 nPrfx(GetScImport().GetNamespaceMap().GetKeyByAttrName(
- sAttrName, &aLocalName ));
- if ((nPrfx == XML_NAMESPACE_TEXT) && (IsXMLToken(aLocalName, XML_C)))
+ const OUString sValue = aIter.toString();
+ if (aIter.getToken() == XML_ELEMENT(TEXT, XML_C))
nRepeat = sValue.toInt32();
+ else
+ XMLOFF_WARN_UNKNOWN("sc", aIter);
}
if (nRepeat)
for (sal_Int32 j = 0; j < nRepeat; ++j)
@@ -697,14 +686,16 @@ SvXMLImportContextRef ScXMLChangeTextPContext::CreateChildContext( sal_uInt16 nT
if (!pTextPContext)
{
bWasContext = false;
- pTextPContext= GetScImport().GetTextImport()->CreateTextChildContext(
- GetScImport(), nPrefix, sLName, xAttrList);
+ pTextPContext = GetScImport().GetTextImport()->CreateTextChildContext(
+ GetScImport(), mnElement, mxAttrList);
}
if (pTextPContext)
{
if (!bWasContext)
pTextPContext->characters(sText.makeStringAndClear());
- xContext = pTextPContext->CreateChildContext(nTempPrefix, rLName, xTempAttrList);
+ xContext = pTextPContext->createFastChildContext(nElement, xAttrList);
+ if (!xContext)
+ xContext = pTextPContext->createFastChildContextFallback(nElement, xAttrList);
}
}
@@ -719,7 +710,7 @@ void ScXMLChangeTextPContext::characters( const OUString& rChars )
pTextPContext->characters(rChars);
}
-void ScXMLChangeTextPContext::endFastElement(sal_Int32 )
+void ScXMLChangeTextPContext::endFastElement(sal_Int32 /*nElement*/)
{
if (!pTextPContext)
pChangeCellContext->SetText(sText.makeStringAndClear());
@@ -807,18 +798,17 @@ ScXMLChangeCellContext::ScXMLChangeCellContext( ScXMLImport& rImport,
nMatrixFlag = ScMatrixMode::Formula;
}
-SvXMLImportContextRef ScXMLChangeCellContext::CreateChildContext( sal_uInt16 nPrefix,
- const OUString& rLocalName,
- const css::uno::Reference<css::xml::sax::XAttributeList>& xAttrList )
+uno::Reference< xml::sax::XFastContextHandler > ScXMLChangeCellContext::createFastChildContext(
+ sal_Int32 nElement, const uno::Reference< xml::sax::XFastAttributeList >& xAttrList )
{
SvXMLImportContext *pContext(nullptr);
- if ((nPrefix == XML_NAMESPACE_TEXT) && (IsXMLToken(rLocalName, XML_P)))
+ if (nElement == XML_ELEMENT(TEXT, XML_P))
{
bEmpty = false;
if (bFirstParagraph)
{
- pContext = new ScXMLChangeTextPContext(GetScImport(), nPrefix, rLocalName, xAttrList, this);
+ pContext = new ScXMLChangeTextPContext(GetScImport(), nElement, xAttrList, this);
bFirstParagraph = false;
}
else
@@ -826,9 +816,11 @@ SvXMLImportContextRef ScXMLChangeCellContext::CreateChildContext( sal_uInt16 nPr
if (!mpEditTextObj.is())
CreateTextPContext(true);
pContext = GetScImport().GetTextImport()->CreateTextChildContext(
- GetScImport(), nPrefix, rLocalName, xAttrList);
+ GetScImport(), nElement, xAttrList);
}
}
+ else
+ XMLOFF_WARN_UNKNOWN_ELEMENT("sc", nElement);
return pContext;
}
diff --git a/xmloff/source/core/xmlictxt.cxx b/xmloff/source/core/xmlictxt.cxx
index 175adf28c876..0074ee886089 100644
--- a/xmloff/source/core/xmlictxt.cxx
+++ b/xmloff/source/core/xmlictxt.cxx
@@ -110,6 +110,45 @@ uno::Reference< xml::sax::XFastContextHandler > SAL_CALL SvXMLImportContext::cre
return nullptr;
}
+css::uno::Reference< css::xml::sax::XFastContextHandler > SvXMLImportContext::createFastChildContextFallback(sal_Int32 Element, const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
+{
+ // fall back to slow-parser path
+ const OUString& rPrefix = SvXMLImport::getNamespacePrefixFromToken(Element, &mrImport.GetNamespaceMap());
+ const OUString& rLocalName = SvXMLImport::getNameFromToken( Element );
+ OUString aName = rPrefix.isEmpty() ? rLocalName : rPrefix + SvXMLImport::aNamespaceSeparator + rLocalName;
+ OUString aLocalName;
+ sal_uInt16 nPrefix =
+ mrImport.mpNamespaceMap->GetKeyByAttrName( aName, &aLocalName );
+
+ mrImport.maAttrList->Clear();
+
+ if ( Attribs.is() )
+ {
+ for( auto &it : sax_fastparser::castToFastAttributeList( Attribs ) )
+ {
+ sal_Int32 nToken = it.getToken();
+ const OUString& rAttrNamespacePrefix = SvXMLImport::getNamespacePrefixFromToken(nToken, &mrImport.GetNamespaceMap());
+ OUString sAttrName = SvXMLImport::getNameFromToken( nToken );
+ if ( !rAttrNamespacePrefix.isEmpty() )
+ sAttrName = rAttrNamespacePrefix + SvXMLImport::aNamespaceSeparator + sAttrName;
+
+ mrImport.maAttrList->AddAttribute( sAttrName, "CDATA", it.toString() );
+ }
+
+ const uno::Sequence< xml::Attribute > unknownAttribs = Attribs->getUnknownAttributes();
+ for ( const auto& rUnknownAttrib : unknownAttribs )
+ {
+ const OUString& rAttrValue = rUnknownAttrib.Value;
+ const OUString& rAttrName = rUnknownAttrib.Name;
+ // note: rAttrName is expected to be namespace-prefixed here
+ mrImport.maAttrList->AddAttribute( rAttrName, "CDATA", rAttrValue );
+ }
+ }
+
+ SAL_INFO("xmloff.core", "calling CreateChildContext on " << typeid(*this).name());
+ return CreateChildContext(nPrefix, aLocalName, mrImport.maAttrList.get() ).get();
+}
+
uno::Reference< xml::sax::XFastContextHandler > SAL_CALL SvXMLImportContext::createUnknownChildContext
(const OUString & /*rNamespace*/, const OUString & /*rName*/, const uno::Reference< xml::sax::XFastAttributeList > & /*Attribs*/)
{