From 267c6f2ac71f92999e969232431ba04678e7437e Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 15 Apr 2024 07:54:39 +0200 Subject: Adding upstream version 4:24.2.0. Signed-off-by: Daniel Baumann --- include/xmloff/XMLEventExport.hxx | 128 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 include/xmloff/XMLEventExport.hxx (limited to 'include/xmloff/XMLEventExport.hxx') diff --git a/include/xmloff/XMLEventExport.hxx b/include/xmloff/XMLEventExport.hxx new file mode 100644 index 0000000000..53864b9e5e --- /dev/null +++ b/include/xmloff/XMLEventExport.hxx @@ -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 . + */ + +#ifndef INCLUDED_XMLOFF_XMLEVENTEXPORT_HXX +#define INCLUDED_XMLOFF_XMLEVENTEXPORT_HXX + +#include +#include +#include +#include +#include + +#include +#include + +class SvXMLExport; +namespace com::sun::star { + namespace document { class XEventsSupplier; } + namespace container { class XNameReplace; } + namespace container { class XNameAccess; } + namespace beans { struct PropertyValue; } +} + +namespace com::sun::star::uno { template class Reference; } +namespace com::sun::star::uno { template class Sequence; } + +typedef ::std::map< OUString, std::unique_ptr > HandlerMap; +typedef ::std::map< OUString, XMLEventName > NameMap; + +/** + * Export instances of EventsSupplier services. To use this class you + * must fulfill two conditions: + * + * 1) provide a translation from the API event names to XML event + * names + * 2) Register XMLEventExportHandler instances for all script types + * that you would like to export. + * + * The Export()-Methods all have a bUseWhitespace parameter that + * causes the exported elements to be surrounded by whitespace, which + * in turn causes the elements to be indented properly. By default, + * whitespace is used, but it may not be called for in all cases (e.g + * events attached to hyperlink within a paragraph.) + */ +class XMLOFF_DLLPUBLIC XMLEventExport +{ + SvXMLExport& m_rExport; + + HandlerMap m_aHandlerMap; + NameMap m_aNameTranslationMap; + + bool m_bExtNamespace; + +public: + XMLEventExport(SvXMLExport& rExport); + ~XMLEventExport(); + + XMLEventExport& operator=( XMLEventExport const & ) = delete; // MSVC2017 workaround + XMLEventExport( XMLEventExport const & ) = delete; // MSVC2017 workaround + + /// register an EventExportHandler for a particular script type + /// + /// The handlers will be deleted when the object is destroyed, hence + /// no pointers to a handler registered with AddHandler() should be + /// held by anyone. + void AddHandler( const OUString& rName, + std::unique_ptr pHandler ); + + /// register additional event names + void AddTranslationTable( const XMLEventNameTranslation* pTransTable ); + + /// export the events (calls EventExport::Export(Reference) ) + void Export( css::uno::Reference const & xAccess, + bool bUseWhitespace = true); + + /// export the events (calls EventExport::Export(Reference) ) + void Export( css::uno::Reference const & xAccess, + bool bUseWhitespace = true); + + /// export the events (writes element) + void Export( css::uno::Reference const & xAccess, + bool bUseWhitespace = true); + + /// export the events, but write element + /// (for new file format additions) + void ExportExt( css::uno::Reference const & xAccess); + + /// export a single event (writes element) + void ExportSingleEvent( + const css::uno::Sequence& rEventValues, + const OUString& rApiEventName, + bool bUseWhitespace = true ); + +private: + + /// export one event (start container-element if necessary) + SAL_DLLPRIVATE void ExportEvent( + const css::uno::Sequence& rEventValues, + const XMLEventName& rXmlEventName, + bool bUseWhitespace, + bool& rExported); + + /// export the start element + SAL_DLLPRIVATE void StartElement(bool bUseWhitespace); + + /// export the end element + SAL_DLLPRIVATE void EndElement(bool bUseWhitespace); +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3