From d3a59629f79da913b4a3ee367cdf70d0f5167416 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=C5=BE=20Vajngerl?= Date: Sat, 16 Aug 2014 20:30:18 +0200 Subject: XmlWriter: simplify and take SvStream* as input Change-Id: I56b2fa6887f7971604a2dcf34497ecda9cea8937 --- include/test/xmlwriter.hxx | 5 ++++- test/source/mtfxmldump.cxx | 18 +----------------- test/source/xmlwriter.cxx | 32 ++++++++++++++++++++++++++++---- 3 files changed, 33 insertions(+), 22 deletions(-) diff --git a/include/test/xmlwriter.hxx b/include/test/xmlwriter.hxx index b640639041f3..243b7fc0b869 100644 --- a/include/test/xmlwriter.hxx +++ b/include/test/xmlwriter.hxx @@ -16,13 +16,16 @@ #include #include +#include + class OOO_DLLPUBLIC_TEST XmlWriter { private: + SvStream* mpStream; xmlTextWriterPtr mpWriter; public: - XmlWriter(xmlTextWriterPtr pWriter); + XmlWriter(SvStream* pStream); virtual ~XmlWriter(); void startDocument(); diff --git a/test/source/mtfxmldump.cxx b/test/source/mtfxmldump.cxx index f50a5ed9d408..1a12912307cc 100644 --- a/test/source/mtfxmldump.cxx +++ b/test/source/mtfxmldump.cxx @@ -22,19 +22,6 @@ namespace const size_t constMaxActionType = 513; -int lclWriteCallback(void* pContext, const char* sBuffer, int nLen) -{ - SvStream* pStream = static_cast(pContext); - return (int) pStream->Write(sBuffer, nLen); -} - -int lclCloseCallback(void* pContext) -{ - SvStream* pStream = static_cast(pContext); - pStream->Flush(); - return 0; // 0 or -1 in case of error -} - OUString flagToString(sal_uInt16 nFlag) { if (nFlag & PUSH_LINECOLOR) @@ -253,10 +240,7 @@ xmlDocPtr MetafileXmlDump::dumpAndParse(GDIMetaFile& rMetaFile, const OUString& else pStream.reset(new SvFileStream(rTempStreamName, STREAM_STD_READWRITE | STREAM_TRUNC)); - xmlOutputBufferPtr xmlOutBuffer = xmlOutputBufferCreateIO(lclWriteCallback, lclCloseCallback, pStream.get(), NULL); - xmlTextWriterPtr xmlWriter = xmlNewTextWriter(xmlOutBuffer); - - XmlWriter aWriter(xmlWriter); + XmlWriter aWriter(pStream.get()); aWriter.startDocument(); aWriter.startElement("metafile"); 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 #include -XmlWriter::XmlWriter(xmlTextWriterPtr pWriter) : - mpWriter(pWriter) +namespace +{ + +int lclWriteCallback(void* pContext, const char* sBuffer, int nLen) +{ + SvStream* pStream = static_cast(pContext); + return (int) pStream->Write(sBuffer, nLen); +} + +int lclCloseCallback(void* pContext) +{ + SvStream* pStream = static_cast(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() -- cgit v1.2.1