diff options
-rw-r--r-- | include/tools/XmlWriter.hxx | 10 | ||||
-rw-r--r-- | tools/source/xml/XmlWriter.cxx | 39 |
2 files changed, 44 insertions, 5 deletions
diff --git a/include/tools/XmlWriter.hxx b/include/tools/XmlWriter.hxx index 8224df417f1b..6095d1379bfe 100644 --- a/include/tools/XmlWriter.hxx +++ b/include/tools/XmlWriter.hxx @@ -13,6 +13,7 @@ #include <tools/toolsdllapi.h> #include <tools/stream.hxx> #include <memory> +#include <vector> namespace tools { @@ -23,8 +24,8 @@ struct XmlWriterImpl; * all the internal libxml2 workings and uses types that are native for LO * development. * - * The codepage used for XML is always "utf-8" and the output is indented so it - * is easier to read. + * The codepage used for XML is always "utf-8" and the output is indented by + * default so it is easier to read. * */ class TOOLS_DLLPUBLIC XmlWriter final @@ -37,15 +38,18 @@ public: ~XmlWriter(); - bool startDocument(); + bool startDocument(sal_Int32 nIndent = 2); void endDocument(); void startElement(const OString& sName); + void startElement(const OString& sPrefix, const OString& sName, const OString& sNamespaceUri); void endElement(); void attribute(const OString& sTagName, const OString& aValue); void attribute(const OString& sTagName, const OUString& aValue); void attribute(const OString& sTagName, sal_Int32 aNumber); + void attributeBase64(const OString& sTagName, std::vector<sal_uInt8> const& rValueInBytes); + void attributeBase64(const OString& sTagName, std::vector<char> const& rValueInBytes); void content(const OString& sValue); void content(const OUString& sValue); diff --git a/tools/source/xml/XmlWriter.cxx b/tools/source/xml/XmlWriter.cxx index ba2c3936f51b..8895e92064db 100644 --- a/tools/source/xml/XmlWriter.cxx +++ b/tools/source/xml/XmlWriter.cxx @@ -54,14 +54,14 @@ XmlWriter::~XmlWriter() endDocument(); } -bool XmlWriter::startDocument() +bool XmlWriter::startDocument(sal_Int32 nIndent) { xmlOutputBufferPtr xmlOutBuffer = xmlOutputBufferCreateIO(funcWriteCallback, funcCloseCallback, mpImpl->mpStream, nullptr); mpImpl->mpWriter = xmlNewTextWriter(xmlOutBuffer); if (mpImpl->mpWriter == nullptr) return false; - xmlTextWriterSetIndent(mpImpl->mpWriter, 1); + xmlTextWriterSetIndent(mpImpl->mpWriter, nIndent); xmlTextWriterStartDocument(mpImpl->mpWriter, nullptr, "UTF-8", nullptr); return true; } @@ -73,6 +73,26 @@ void XmlWriter::endDocument() mpImpl->mpWriter = nullptr; } +void XmlWriter::startElement(const OString& sPrefix, const OString& sName, + const OString& sNamespaceUri) +{ + xmlChar* xmlName = xmlCharStrdup(sName.getStr()); + xmlChar* xmlPrefix = nullptr; + xmlChar* xmlNamespaceUri = nullptr; + if (!sPrefix.isEmpty()) + xmlPrefix = xmlCharStrdup(sPrefix.getStr()); + if (!sNamespaceUri.isEmpty()) + xmlNamespaceUri = xmlCharStrdup(sNamespaceUri.getStr()); + + xmlTextWriterStartElementNS(mpImpl->mpWriter, xmlPrefix, xmlName, xmlNamespaceUri); + + xmlFree(xmlName); + if (!sPrefix.isEmpty()) + xmlFree(xmlPrefix); + if (!sNamespaceUri.isEmpty()) + xmlFree(xmlNamespaceUri); +} + void XmlWriter::startElement(const OString& sName) { xmlChar* xmlName = xmlCharStrdup(sName.getStr()); @@ -82,6 +102,21 @@ void XmlWriter::startElement(const OString& sName) void XmlWriter::endElement() { xmlTextWriterEndElement(mpImpl->mpWriter); } +void XmlWriter::attributeBase64(const OString& rsName, std::vector<sal_uInt8> const& rValueInBytes) +{ + std::vector<char> aSignedBytes(rValueInBytes.begin(), rValueInBytes.end()); + attributeBase64(rsName, aSignedBytes); +} + +void XmlWriter::attributeBase64(const OString& rsName, std::vector<char> const& rValueInBytes) +{ + xmlChar* xmlName = xmlCharStrdup(rsName.getStr()); + xmlTextWriterStartAttribute(mpImpl->mpWriter, xmlName); + xmlTextWriterWriteBase64(mpImpl->mpWriter, rValueInBytes.data(), 0, rValueInBytes.size()); + xmlTextWriterEndAttribute(mpImpl->mpWriter); + xmlFree(xmlName); +} + void XmlWriter::attribute(const OString& name, const OString& value) { xmlChar* xmlName = xmlCharStrdup(name.getStr()); |