diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-08-16 20:30:18 +0200 |
---|---|---|
committer | Tomaž Vajngerl <tomaz.vajngerl@collabora.com> | 2014-08-16 20:49:20 +0200 |
commit | d3a59629f79da913b4a3ee367cdf70d0f5167416 (patch) | |
tree | 44979202a3012247bebec5c3dab9b31275609602 /test | |
parent | 8a3a2e888bf805c602c217733510114e0521eedf (diff) |
XmlWriter: simplify and take SvStream* as input
Change-Id: I56b2fa6887f7971604a2dcf34497ecda9cea8937
Diffstat (limited to 'test')
-rw-r--r-- | test/source/mtfxmldump.cxx | 18 | ||||
-rw-r--r-- | test/source/xmlwriter.cxx | 32 |
2 files changed, 29 insertions, 21 deletions
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<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 -} - 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 <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() |