summaryrefslogtreecommitdiff
path: root/test/source/xmlwriter.cxx
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.com>2014-08-16 20:30:18 +0200
committerTomaž Vajngerl <tomaz.vajngerl@collabora.com>2014-08-16 20:49:20 +0200
commitd3a59629f79da913b4a3ee367cdf70d0f5167416 (patch)
tree44979202a3012247bebec5c3dab9b31275609602 /test/source/xmlwriter.cxx
parent8a3a2e888bf805c602c217733510114e0521eedf (diff)
XmlWriter: simplify and take SvStream* as input
Change-Id: I56b2fa6887f7971604a2dcf34497ecda9cea8937
Diffstat (limited to 'test/source/xmlwriter.cxx')
-rw-r--r--test/source/xmlwriter.cxx32
1 files changed, 28 insertions, 4 deletions
diff --git a/test/source/xmlwriter.cxx b/test/source/xmlwriter.cxx
index c3ac40ec4a2a..de3b901902ec 100644
--- a/test/source/xmlwriter.cxx
+++ b/test/source/xmlwriter.cxx
@@ -20,8 +20,27 @@
#include <libxml/xmlstring.h>
#include <test/xmlwriter.hxx>
-XmlWriter::XmlWriter(xmlTextWriterPtr pWriter) :
- mpWriter(pWriter)
+namespace
+{
+
+int lclWriteCallback(void* pContext, const char* sBuffer, int nLen)
+{
+ SvStream* pStream = static_cast<SvStream*>(pContext);
+ return (int) pStream->Write(sBuffer, nLen);
+}
+
+int lclCloseCallback(void* pContext)
+{
+ SvStream* pStream = static_cast<SvStream*>(pContext);
+ pStream->Flush();
+ return 0; // 0 or -1 in case of error
+}
+
+} // anonymous namespace
+
+XmlWriter::XmlWriter(SvStream* pStream) :
+ mpStream(pStream),
+ mpWriter(NULL)
{}
XmlWriter::~XmlWriter()
@@ -29,8 +48,13 @@ XmlWriter::~XmlWriter()
void XmlWriter::startDocument()
{
- xmlTextWriterSetIndent(mpWriter, 1);
- xmlTextWriterStartDocument(mpWriter, NULL, "UTF-8", NULL);
+ if (mpWriter == NULL && mpStream != NULL)
+ {
+ xmlOutputBufferPtr xmlOutBuffer = xmlOutputBufferCreateIO(lclWriteCallback, lclCloseCallback, mpStream, NULL);
+ mpWriter = xmlNewTextWriter(xmlOutBuffer);
+ xmlTextWriterSetIndent(mpWriter, 1);
+ xmlTextWriterStartDocument(mpWriter, NULL, "UTF-8", NULL);
+ }
}
void XmlWriter::endDocument()