summaryrefslogtreecommitdiff
path: root/sax
diff options
context:
space:
mode:
authordante <dante19031999@gmail.com>2020-12-26 18:53:18 +0100
committerNoel Grandin <noel.grandin@collabora.co.uk>2020-12-27 08:29:27 +0100
commit78552cb9b167a677952bf80eb0c7af62baaf015a (patch)
treef3f6a0fcd8168fc44091d258ec1b821fc017d4c8 /sax
parenta26504cb5790eff1ca8b932382f73ff3baaec50a (diff)
Preparations for customized xml entities on export
Change-Id: I8ad4af7e27ae5f8908f4c932242cb96abbf3de90 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108354 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sax')
-rw-r--r--sax/source/expatwrap/saxwriter.cxx44
1 files changed, 42 insertions, 2 deletions
diff --git a/sax/source/expatwrap/saxwriter.cxx b/sax/source/expatwrap/saxwriter.cxx
index 8566cab2b7e6..03ca1f765d82 100644
--- a/sax/source/expatwrap/saxwriter.cxx
+++ b/sax/source/expatwrap/saxwriter.cxx
@@ -22,6 +22,7 @@
#include <cassert>
#include <set>
#include <stack>
+#include <vector>
#include <com/sun/star/io/IOException.hpp>
#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
@@ -72,6 +73,17 @@ enum SaxInvalidCharacterError
SAX_ERROR
};
+// Stuff for custom entity names
+struct ReplacementPair
+{
+ OUString name;
+ OUString replacement;
+};
+inline bool operator<(const ReplacementPair& lhs, const ReplacementPair& rhs)
+{
+ return lhs.replacement.compareTo(rhs.replacement) < 0;
+}
+
class SaxWriterHelper
{
#ifdef DBG_UTIL
@@ -88,6 +100,8 @@ private:
sal_uInt32 nCurrentPos;
bool m_bStartElementFinished;
+ std::vector<ReplacementPair> m_Replacements;
+
/// @throws SAXException
sal_uInt32 writeSequence();
@@ -175,6 +189,10 @@ public:
/// @throws SAXException
void clearBuffer();
+
+ // Use custom entity names
+ void setCustomEntityNames(
+ const ::css::uno::Sequence<::css::beans::Pair<::rtl::OUString, ::rtl::OUString>>& replacements);
};
const bool g_bValidCharsBelow32[32] =
@@ -239,6 +257,19 @@ void SaxWriterHelper::AddBytes(sal_Int8* pTarget, sal_uInt32& rPos,
AddBytes(pTarget, rPos, &pBytes[nCount], nRestCount);
}
+void SaxWriterHelper::setCustomEntityNames(
+ const ::css::uno::Sequence<::css::beans::Pair<::rtl::OUString, ::rtl::OUString>>& replacements)
+{
+ m_Replacements.resize(replacements.size());
+ for (size_t i = 0; i < replacements.size(); ++i)
+ {
+ m_Replacements[i].name = replacements[i].First;
+ m_Replacements[i].replacement = replacements[i].Second;
+ }
+ if (replacements.size() > 1)
+ std::sort(m_Replacements.begin(), m_Replacements.end());
+}
+
/** Converts a UTF-16 string to UTF-8 and does XML normalization
@param pTarget
@@ -300,7 +331,7 @@ bool SaxWriterHelper::convertToXML( const sal_Unicode * pStr,
}
}
break;
- case 39: // 39 == '''
+ case '\'':
{
if ((rPos + 6) > SEQUENCESIZE)
AddBytes(pTarget, rPos, reinterpret_cast<sal_Int8 const *>("&apos;"), 6);
@@ -855,7 +886,7 @@ sal_Int32 calcXMLByteLength( const OUString& rStr,
case '>': // &gt;
nOutputLength +=4;
break;
- case 39: // 39 == ''', &apos;
+ case '\'': // &apos;
case '"': // &quot;
case 13: // &#x0d;
nOutputLength += 6;
@@ -988,6 +1019,9 @@ public: // XDocumentHandler
virtual void SAL_CALL processingInstruction(const OUString& aTarget,
const OUString& aData) override;
virtual void SAL_CALL setDocumentLocator(const Reference< XLocator > & xLocator) override;
+ virtual void SAL_CALL setCustomEntityNames(
+ const ::css::uno::Sequence<::css::beans::Pair<::rtl::OUString, ::rtl::OUString>>& replacements)
+ override;
public: // XExtendedDocumentHandler
virtual void SAL_CALL startCDATA() override;
@@ -1304,6 +1338,12 @@ void SAXWriter::setDocumentLocator(const Reference< XLocator >&)
}
+void SAXWriter::setCustomEntityNames(
+ const ::css::uno::Sequence<::css::beans::Pair<::rtl::OUString, ::rtl::OUString>>& replacements)
+{
+ m_pSaxWriterHelper->setCustomEntityNames(replacements);
+}
+
void SAXWriter::startCDATA()
{
if( ! m_bDocStarted || m_bIsCDATA)