diff options
-rw-r--r-- | include/test/mtfxmldump.hxx | 6 | ||||
-rw-r--r-- | include/test/primitive2dxmldump.hxx | 7 | ||||
-rw-r--r-- | include/test/xmlwriter.hxx | 49 | ||||
-rw-r--r-- | include/tools/XmlWriter.hxx | 2 | ||||
-rw-r--r-- | test/Library_test.mk | 1 | ||||
-rw-r--r-- | test/source/mtfxmldump.cxx | 18 | ||||
-rw-r--r-- | test/source/primitive2dxmldump.cxx | 7 | ||||
-rw-r--r-- | test/source/xmlwriter.cxx | 117 | ||||
-rw-r--r-- | tools/source/xml/XmlWriter.cxx | 6 |
9 files changed, 26 insertions, 187 deletions
diff --git a/include/test/mtfxmldump.hxx b/include/test/mtfxmldump.hxx index 38087d6f8f3a..b55de95258db 100644 --- a/include/test/mtfxmldump.hxx +++ b/include/test/mtfxmldump.hxx @@ -12,20 +12,20 @@ #include <sal/config.h> #include <test/testdllapi.hxx> - #include <libxml/tree.h> #include <vcl/gdimtf.hxx> #include <vcl/metaactiontypes.hxx> #include <o3tl/enumarray.hxx> -class XmlWriter; +namespace tools { class XmlWriter; } + enum class MetaActionType; class OOO_DLLPUBLIC_TEST MetafileXmlDump final { o3tl::enumarray<MetaActionType, bool> maFilter; - void writeXml(const GDIMetaFile& rMetaFile, XmlWriter& rWriter); + void writeXml(const GDIMetaFile& rMetaFile, tools::XmlWriter& rWriter); public: MetafileXmlDump(); diff --git a/include/test/primitive2dxmldump.hxx b/include/test/primitive2dxmldump.hxx index 80ef271ee720..5acf69999ecd 100644 --- a/include/test/primitive2dxmldump.hxx +++ b/include/test/primitive2dxmldump.hxx @@ -12,18 +12,17 @@ #include <sal/config.h> #include <test/testdllapi.hxx> -#include <test/xmlwriter.hxx> - #include <libxml/tree.h> #include <drawinglayer/primitive2d/baseprimitive2d.hxx> - #include <vector> +namespace tools { class XmlWriter; } + class OOO_DLLPUBLIC_TEST Primitive2dXmlDump final { private: std::vector<bool> maFilter; - void decomposeAndWrite(const drawinglayer::primitive2d::Primitive2DContainer& rPrimitive2DSequence, XmlWriter& rWriter); + void decomposeAndWrite(const drawinglayer::primitive2d::Primitive2DContainer& rPrimitive2DSequence, tools::XmlWriter& rWriter); public: Primitive2dXmlDump(); diff --git a/include/test/xmlwriter.hxx b/include/test/xmlwriter.hxx deleted file mode 100644 index 96a5314d8d48..000000000000 --- a/include/test/xmlwriter.hxx +++ /dev/null @@ -1,49 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -#ifndef INCLUDED_TEST_XMLWRITER_HXX -#define INCLUDED_TEST_XMLWRITER_HXX - -#include <test/testdllapi.hxx> - -#include <libxml/xmlwriter.h> -#include <rtl/ustring.hxx> -#include <rtl/string.hxx> - -class SvStream; - -class OOO_DLLPUBLIC_TEST XmlWriter final -{ -private: - SvStream* mpStream; - xmlTextWriterPtr mpWriter; - -public: - XmlWriter(SvStream* pStream); - ~XmlWriter(); - - void startDocument(); - void endDocument(); - - void element(const OString& sTagName); - - void startElement(const OString& sTagName); - 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 content(const OString& aValue); - void content(const OUString& aValue); -}; - -#endif // INCLUDED_TEST_XMLWRITER_HXX - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/tools/XmlWriter.hxx b/include/tools/XmlWriter.hxx index 15a3a0013912..8224df417f1b 100644 --- a/include/tools/XmlWriter.hxx +++ b/include/tools/XmlWriter.hxx @@ -49,6 +49,8 @@ public: void content(const OString& sValue); void content(const OUString& sValue); + + void element(const OString& sName); }; } // end tools namespace diff --git a/test/Library_test.mk b/test/Library_test.mk index 957ffc0d97e0..c3fcdd020f1b 100644 --- a/test/Library_test.mk +++ b/test/Library_test.mk @@ -45,7 +45,6 @@ $(eval $(call gb_Library_add_exception_objects,test,\ test/source/xmltesttools \ test/source/htmltesttools \ test/source/mtfxmldump \ - test/source/xmlwriter \ test/source/primitive2dxmldump \ test/source/screenshot_test \ )) diff --git a/test/source/mtfxmldump.cxx b/test/source/mtfxmldump.cxx index 5cb4402ee4d8..cd21df3ff71e 100644 --- a/test/source/mtfxmldump.cxx +++ b/test/source/mtfxmldump.cxx @@ -9,7 +9,7 @@ #include <test/mtfxmldump.hxx> #include <test/xmltesttools.hxx> -#include <test/xmlwriter.hxx> +#include <tools/XmlWriter.hxx> #include <vcl/metaact.hxx> #include <rtl/string.hxx> @@ -350,31 +350,31 @@ OUString hex32(sal_uInt32 nNumber) return OUString::createFromAscii(ss.str().c_str()); } -void writePoint(XmlWriter& rWriter, Point const& rPoint) +void writePoint(tools::XmlWriter& rWriter, Point const& rPoint) { rWriter.attribute("x", rPoint.X()); rWriter.attribute("y", rPoint.Y()); } -void writeStartPoint(XmlWriter& rWriter, Point const& rPoint) +void writeStartPoint(tools::XmlWriter& rWriter, Point const& rPoint) { rWriter.attribute("startx", rPoint.X()); rWriter.attribute("starty", rPoint.Y()); } -void writeEndPoint(XmlWriter& rWriter, Point const& rPoint) +void writeEndPoint(tools::XmlWriter& rWriter, Point const& rPoint) { rWriter.attribute("endx", rPoint.X()); rWriter.attribute("endy", rPoint.Y()); } -void writeSize(XmlWriter& rWriter, Size const& rSize) +void writeSize(tools::XmlWriter& rWriter, Size const& rSize) { rWriter.attribute("width", rSize.Width()); rWriter.attribute("height", rSize.Height()); } -void writeRectangle(XmlWriter& rWriter, tools::Rectangle const& rRectangle) +void writeRectangle(tools::XmlWriter& rWriter, tools::Rectangle const& rRectangle) { rWriter.attribute("left", rRectangle.Left()); rWriter.attribute("top", rRectangle.Top()); @@ -382,7 +382,7 @@ void writeRectangle(XmlWriter& rWriter, tools::Rectangle const& rRectangle) rWriter.attribute("bottom", rRectangle.Bottom()); } -void writeLineInfo(XmlWriter& rWriter, LineInfo const& rLineInfo) +void writeLineInfo(tools::XmlWriter& rWriter, LineInfo const& rLineInfo) { rWriter.attribute("style", convertLineStyleToString(rLineInfo.GetStyle())); rWriter.attribute("width", rLineInfo.GetWidth()); @@ -424,7 +424,7 @@ xmlDocPtr MetafileXmlDump::dumpAndParse(const GDIMetaFile& rMetaFile, const OUSt else pStream.reset(new SvFileStream(rTempStreamName, StreamMode::STD_READWRITE | StreamMode::TRUNC)); - XmlWriter aWriter(pStream.get()); + tools::XmlWriter aWriter(pStream.get()); aWriter.startDocument(); aWriter.startElement("metafile"); @@ -440,7 +440,7 @@ xmlDocPtr MetafileXmlDump::dumpAndParse(const GDIMetaFile& rMetaFile, const OUSt return pDoc; } -void MetafileXmlDump::writeXml(const GDIMetaFile& rMetaFile, XmlWriter& rWriter) +void MetafileXmlDump::writeXml(const GDIMetaFile& rMetaFile, tools::XmlWriter& rWriter) { for(size_t nAction = 0; nAction < rMetaFile.GetActionSize(); ++nAction) { diff --git a/test/source/primitive2dxmldump.cxx b/test/source/primitive2dxmldump.cxx index a9304b89ad07..4f5c63ed54a9 100644 --- a/test/source/primitive2dxmldump.cxx +++ b/test/source/primitive2dxmldump.cxx @@ -9,6 +9,7 @@ #include <test/primitive2dxmldump.hxx> #include <test/xmltesttools.hxx> +#include <tools/XmlWriter.hxx> #include <vcl/metaact.hxx> #include <rtl/string.hxx> @@ -28,8 +29,6 @@ #include <drawinglayer/primitive2d/svggradientprimitive2d.hxx> #include <drawinglayer/primitive2d/metafileprimitive2d.hxx> #include <drawinglayer/geometry/viewinformation2d.hxx> - - #include <drawinglayer/attribute/lineattribute.hxx> #include <drawinglayer/attribute/fontattribute.hxx> @@ -70,7 +69,7 @@ xmlDocPtr Primitive2dXmlDump::dumpAndParse( else pStream.reset(new SvFileStream(rTempStreamName, StreamMode::STD_READWRITE | StreamMode::TRUNC)); - XmlWriter aWriter(pStream.get()); + tools::XmlWriter aWriter(pStream.get()); aWriter.startDocument(); aWriter.startElement("primitive2D"); @@ -88,7 +87,7 @@ xmlDocPtr Primitive2dXmlDump::dumpAndParse( void Primitive2dXmlDump::decomposeAndWrite( const drawinglayer::primitive2d::Primitive2DContainer& rPrimitive2DSequence, - XmlWriter& rWriter) + tools::XmlWriter& rWriter) { for (size_t i = 0; i < rPrimitive2DSequence.size(); i++) { diff --git a/test/source/xmlwriter.cxx b/test/source/xmlwriter.cxx deleted file mode 100644 index f363378d57a1..000000000000 --- a/test/source/xmlwriter.cxx +++ /dev/null @@ -1,117 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include <libxml/xmlstring.h> -#include <tools/stream.hxx> -#include <test/xmlwriter.hxx> - -namespace -{ - -int lclWriteCallback(void* pContext, const char* sBuffer, int nLen) -{ - SvStream* pStream = static_cast<SvStream*>(pContext); - return static_cast<int>(pStream->WriteBytes(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(nullptr) -{} - -XmlWriter::~XmlWriter() -{} - -void XmlWriter::startDocument() -{ - if (mpWriter == nullptr && mpStream != nullptr) - { - xmlOutputBufferPtr xmlOutBuffer = xmlOutputBufferCreateIO(lclWriteCallback, lclCloseCallback, mpStream, nullptr); - mpWriter = xmlNewTextWriter(xmlOutBuffer); - xmlTextWriterSetIndent(mpWriter, 1); - xmlTextWriterStartDocument(mpWriter, nullptr, "UTF-8", nullptr); - } -} - -void XmlWriter::endDocument() -{ - xmlTextWriterEndDocument(mpWriter); - xmlFreeTextWriter(mpWriter); - mpWriter = nullptr; -} - -void XmlWriter::element(const OString& name) -{ - startElement(name); - endElement(); -} - -void XmlWriter::startElement(const OString& name) -{ - xmlChar* xmlName = xmlCharStrdup(name.getStr()); - xmlTextWriterStartElement(mpWriter, xmlName); - xmlFree(xmlName); -} - -void XmlWriter::attribute(const OString& name, const OString & value) -{ - xmlChar* xmlName = xmlCharStrdup(name.getStr()); - xmlChar* xmlValue = xmlCharStrdup(value.getStr()); - xmlTextWriterWriteAttribute(mpWriter, xmlName, xmlValue); - xmlFree(xmlValue); - xmlFree(xmlName); -} - -void XmlWriter::attribute(const OString& name, const OUString& value) -{ - attribute(name, OUStringToOString(value, RTL_TEXTENCODING_UTF8).getStr()); -} - -void XmlWriter::attribute(const OString& name, const sal_Int32 aNumber) -{ - attribute(name, OUString::number(aNumber)); -} - -void XmlWriter::content(const OUString& aValue) -{ - content(OUStringToOString(aValue, RTL_TEXTENCODING_UTF8)); -} - -void XmlWriter::content(const OString& aValue) -{ - xmlChar* xmlValue = xmlCharStrdup(aValue.getStr()); - xmlTextWriterWriteString(mpWriter, xmlValue); - xmlFree(xmlValue); -} - -void XmlWriter::endElement() -{ - xmlTextWriterEndElement(mpWriter); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/tools/source/xml/XmlWriter.cxx b/tools/source/xml/XmlWriter.cxx index 5952dde13c96..ba2c3936f51b 100644 --- a/tools/source/xml/XmlWriter.cxx +++ b/tools/source/xml/XmlWriter.cxx @@ -113,6 +113,12 @@ void XmlWriter::content(const OUString& sValue) content(OUStringToOString(sValue, RTL_TEXTENCODING_UTF8)); } +void XmlWriter::element(const OString& sName) +{ + startElement(sName); + endElement(); +} + } // end tools namespace /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |