summaryrefslogtreecommitdiffstats
path: root/filter/source/svg/test
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:06:44 +0000
commited5640d8b587fbcfed7dd7967f3de04b37a76f26 (patch)
tree7a5f7c6c9d02226d7471cb3cc8fbbf631b415303 /filter/source/svg/test
parentInitial commit. (diff)
downloadlibreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.tar.xz
libreoffice-ed5640d8b587fbcfed7dd7967f3de04b37a76f26.zip
Adding upstream version 4:7.4.7.upstream/4%7.4.7upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'filter/source/svg/test')
-rw-r--r--filter/source/svg/test/odfserializer.cxx128
-rw-r--r--filter/source/svg/test/odfserializer.hxx33
2 files changed, 161 insertions, 0 deletions
diff --git a/filter/source/svg/test/odfserializer.cxx b/filter/source/svg/test/odfserializer.cxx
new file mode 100644
index 000000000..cc3e7b30a
--- /dev/null
+++ b/filter/source/svg/test/odfserializer.cxx
@@ -0,0 +1,128 @@
+/* -*- 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 "odfserializer.hxx"
+#include <osl/diagnose.h>
+#include <rtl/ustrbuf.hxx>
+#include <cppuhelper/compbase.hxx>
+#include <cppuhelper/basemutex.hxx>
+#include <com/sun/star/uno/Sequence.hxx>
+
+using namespace ::com::sun::star;
+
+namespace svgi
+{
+
+typedef ::cppu::WeakComponentImplHelper<
+ css::xml::sax::XDocumentHandler> ODFSerializerBase;
+
+class ODFSerializer : private cppu::BaseMutex,
+ public ODFSerializerBase
+{
+public:
+ explicit ODFSerializer(const uno::Reference<io::XOutputStream>& xOut) :
+ ODFSerializerBase(m_aMutex),
+ m_xOutStream(xOut),
+ m_aLineFeed(1),
+ m_aBuf()
+ {
+ m_aLineFeed[0] = '\n';
+ }
+ ODFSerializer(const ODFSerializer&) = delete;
+ ODFSerializer& operator=(const ODFSerializer&) = delete;
+
+ virtual void SAL_CALL startDocument( ) override;
+ virtual void SAL_CALL endDocument( ) override;
+ virtual void SAL_CALL startElement( const OUString& aName, const uno::Reference< xml::sax::XAttributeList >& xAttribs ) override;
+ virtual void SAL_CALL endElement( const OUString& aName ) override;
+ virtual void SAL_CALL characters( const OUString& aChars ) override;
+ virtual void SAL_CALL ignorableWhitespace( const OUString& aWhitespaces ) override;
+ virtual void SAL_CALL processingInstruction( const OUString& aTarget, const OUString& aData ) override;
+ virtual void SAL_CALL setDocumentLocator( const uno::Reference< xml::sax::XLocator >& xLocator ) override;
+
+private:
+ uno::Reference<io::XOutputStream> m_xOutStream;
+ uno::Sequence<sal_Int8> m_aLineFeed;
+ uno::Sequence<sal_Int8> m_aBuf;
+};
+
+void SAL_CALL ODFSerializer::startDocument( )
+{
+ OSL_PRECOND(m_xOutStream.is(), "ODFSerializer(): invalid output stream");
+
+ OUStringBuffer aElement;
+ aElement.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
+ characters(aElement.makeStringAndClear());
+}
+
+void SAL_CALL ODFSerializer::endDocument()
+{}
+
+void SAL_CALL ODFSerializer::startElement( const OUString& aName,
+ const uno::Reference< xml::sax::XAttributeList >& xAttribs )
+{
+ OUStringBuffer aElement("<" + aName + " ");
+
+ const sal_Int16 nLen=xAttribs->getLength();
+ for( sal_Int16 i=0; i<nLen; ++i )
+ aElement.append(xAttribs->getNameByIndex(i) + "=\"" +
+ xAttribs->getValueByIndex(i) + "\" ");
+
+ characters(aElement.makeStringAndClear() + ">");
+}
+
+void SAL_CALL ODFSerializer::endElement( const OUString& aName )
+{
+ characters("</" + aName + ">");
+}
+
+void SAL_CALL ODFSerializer::characters( const OUString& aChars )
+{
+ const OString aStr = OUStringToOString(aChars, RTL_TEXTENCODING_UTF8);
+ const sal_Int32 nLen( aStr.getLength() );
+ m_aBuf.realloc( nLen );
+ const char* pStr = aStr.getStr();
+ std::copy(pStr,pStr+nLen,m_aBuf.getArray());
+
+ m_xOutStream->writeBytes(m_aBuf);
+ // TODO(F1): Make pretty printing configurable
+ m_xOutStream->writeBytes(m_aLineFeed);
+}
+
+void SAL_CALL ODFSerializer::ignorableWhitespace( const OUString& aWhitespaces )
+{
+ // TODO(F1): Make pretty printing configurable
+ characters(aWhitespaces);
+}
+
+void SAL_CALL ODFSerializer::processingInstruction( const OUString&,
+ const OUString& )
+{}
+
+void SAL_CALL ODFSerializer::setDocumentLocator( const uno::Reference< xml::sax::XLocator >& )
+{}
+
+uno::Reference< xml::sax::XDocumentHandler> createSerializer(const uno::Reference<io::XOutputStream>& xOut )
+{
+ return uno::Reference<xml::sax::XDocumentHandler>(new ODFSerializer(xOut));
+}
+
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/filter/source/svg/test/odfserializer.hxx b/filter/source/svg/test/odfserializer.hxx
new file mode 100644
index 000000000..2724c9f0a
--- /dev/null
+++ b/filter/source/svg/test/odfserializer.hxx
@@ -0,0 +1,33 @@
+/* -*- 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 .
+ */
+
+#pragma once
+
+#include <com/sun/star/uno/Reference.hxx>
+#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
+#include <com/sun/star/io/XOutputStream.hpp>
+
+namespace svgi
+{
+/// Creates a XDocumentHandler that serializes directly to an XOutputStream
+css::uno::Reference<css::xml::sax::XDocumentHandler>
+createSerializer(const css::uno::Reference<css::io::XOutputStream>&);
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */