1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 /* 3 * This file is part of the LibreOffice project. 4 * 5 * This Source Code Form is subject to the terms of the Mozilla Public 6 * License, v. 2.0. If a copy of the MPL was not distributed with this 7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 8 * 9 * This file incorporates work covered by the following license notice: 10 * 11 * Licensed to the Apache Software Foundation (ASF) under one or more 12 * contributor license agreements. See the NOTICE file distributed 13 * with this work for additional information regarding copyright 14 * ownership. The ASF licenses this file to you under the Apache 15 * License, Version 2.0 (the "License"); you may not use this file 16 * except in compliance with the License. You may obtain a copy of 17 * the License at http://www.apache.org/licenses/LICENSE-2.0 . 18 */ 19 20 #ifndef INCLUDED_XMLOFF_XMLEVENTEXPORT_HXX 21 #define INCLUDED_XMLOFF_XMLEVENTEXPORT_HXX 22 23 #include <sal/config.h> 24 #include <xmloff/dllapi.h> 25 #include <sal/types.h> 26 #include <rtl/ustring.hxx> 27 #include <xmloff/xmlevent.hxx> 28 29 #include <map> 30 #include <memory> 31 32 class SvXMLExport; 33 namespace com::sun::star { 34 namespace document { class XEventsSupplier; } 35 namespace container { class XNameReplace; } 36 namespace container { class XNameAccess; } 37 namespace beans { struct PropertyValue; } 38 } 39 40 namespace com::sun::star::uno { template <class interface_type> class Reference; } 41 namespace com::sun::star::uno { template <typename > class Sequence; } 42 43 typedef ::std::map< OUString, std::unique_ptr<XMLEventExportHandler> > HandlerMap; 44 typedef ::std::map< OUString, XMLEventName > NameMap; 45 46 /** 47 * Export instances of EventsSupplier services. To use this class you 48 * must fulfill two conditions: 49 * 50 * 1) provide a translation from the API event names to XML event 51 * names 52 * 2) Register XMLEventExportHandler instances for all script types 53 * that you would like to export. 54 * 55 * The Export()-Methods all have a bUseWhitespace parameter that 56 * causes the exported elements to be surrounded by whitespace, which 57 * in turn causes the elements to be indented properly. By default, 58 * whitespace is used, but it may not be called for in all cases (e.g 59 * events attached to hyperlink within a paragraph.) 60 */ 61 class XMLOFF_DLLPUBLIC XMLEventExport 62 { 63 SvXMLExport& rExport; 64 65 HandlerMap aHandlerMap; 66 NameMap aNameTranslationMap; 67 68 bool bExtNamespace; 69 70 public: 71 XMLEventExport(SvXMLExport& rExport); 72 ~XMLEventExport(); 73 74 XMLEventExport& operator=( XMLEventExport const & ) = delete; // MSVC2017 workaround 75 XMLEventExport( XMLEventExport const & ) = delete; // MSVC2017 workaround 76 77 /// register an EventExportHandler for a particular script type 78 /// 79 /// The handlers will be deleted when the object is destroyed, hence 80 /// no pointers to a handler registered with AddHandler() should be 81 /// held by anyone. 82 void AddHandler( const OUString& rName, 83 std::unique_ptr<XMLEventExportHandler> pHandler ); 84 85 /// register additional event names 86 void AddTranslationTable( const XMLEventNameTranslation* pTransTable ); 87 88 /// export the events (calls EventExport::Export(Reference<XNameAccess>) ) 89 void Export( css::uno::Reference<css::document::XEventsSupplier> const & xAccess, 90 bool bUseWhitespace = true); 91 92 /// export the events (calls EventExport::Export(Reference<XNameAccess>) ) 93 void Export( css::uno::Reference<css::container::XNameReplace> const & xAccess, 94 bool bUseWhitespace = true); 95 96 /// export the events (writes <office:events> element) 97 void Export( css::uno::Reference<css::container::XNameAccess> const & xAccess, 98 bool bUseWhitespace = true); 99 100 /// export the events, but write <officeooo:events> element 101 /// (for new file format additions) 102 void ExportExt( css::uno::Reference<css::container::XNameAccess> const & xAccess); 103 104 /// export a single event (writes <office:events> element) 105 void ExportSingleEvent( 106 css::uno::Sequence<css::beans::PropertyValue>& rEventValues, 107 const OUString& rApiEventName, 108 bool bUseWhitespace = true ); 109 110 private: 111 112 /// export one event (start container-element if necessary) 113 SAL_DLLPRIVATE void ExportEvent( 114 css::uno::Sequence<css::beans::PropertyValue>& rEventValues, 115 const XMLEventName& rXmlEventName, 116 bool bUseWhitespace, 117 bool& rExported); 118 119 /// export the start element 120 SAL_DLLPRIVATE void StartElement(bool bUseWhitespace); 121 122 /// export the end element 123 SAL_DLLPRIVATE void EndElement(bool bUseWhitespace); 124 }; 125 126 #endif 127 128 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 129