Branch libreoffice-5-0-4
[LibreOffice.git] / include / xmloff / XMLEventExport.hxx
bloba65aa5d60a8742b84bc1710e9bb9bc778aae2167
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_XMLOFF_XMLEVENTEXPORT_HXX
21 #define INCLUDED_XMLOFF_XMLEVENTEXPORT_HXX
23 #include <sal/config.h>
24 #include <xmloff/dllapi.h>
25 #include <sal/types.h>
26 #include <com/sun/star/uno/Sequence.hxx>
27 #include <com/sun/star/uno/Reference.hxx>
28 #include <rtl/ustring.hxx>
29 #include <xmloff/xmlevent.hxx>
31 #include <map>
33 class SvXMLExport;
34 namespace com { namespace sun { namespace star {
35 namespace document { class XEventsSupplier; }
36 namespace container { class XNameReplace; }
37 namespace container { class XNameAccess; }
38 namespace beans { struct PropertyValue; }
39 } } }
41 typedef ::std::map< OUString, XMLEventExportHandler* > HandlerMap;
42 typedef ::std::map< OUString, XMLEventName > NameMap;
44 /**
45 * Export instances of EventsSupplier services. To use this class you
46 * must fulfill two conditions:
48 * 1) provide a translation from the API event names to XML event
49 * names
50 * 2) Register XMLEventExportHandler instances for all script types
51 * that you would like to export.
53 * The Export()-Methods all have a bUseWhitespace parameter that
54 * causes the exported elements to be surrounded by whitespace, which
55 * in turn causes the elements to be indented properly. By default,
56 * whitespace is used, but it may not be called for in all cases (e.g
57 * events attached to hyperlink within a paragraph.)
59 class XMLOFF_DLLPUBLIC XMLEventExport
61 const OUString sEventType;
63 SvXMLExport& rExport;
65 HandlerMap aHandlerMap;
66 NameMap aNameTranslationMap;
68 bool bExtNamespace;
70 public:
71 XMLEventExport(SvXMLExport& rExport,
72 const XMLEventNameTranslation* pTranslationTable = NULL);
73 ~XMLEventExport();
75 /// register an EventExportHandler for a particular script type
76 ///
77 /// The handlers will be deleted when the object is destroyed, hence
78 /// no pointers to a handler registered with AddHandler() should be
79 /// held by anyone.
80 void AddHandler( const OUString& rName,
81 XMLEventExportHandler* rHandler );
83 /// register additional event names
84 void AddTranslationTable( const XMLEventNameTranslation* pTransTable );
86 /// export the events (calls EventExport::Export(Reference<XNameAcess>) )
87 void Export( ::com::sun::star::uno::Reference<
88 ::com::sun::star::document::XEventsSupplier> & xAccess,
89 bool bUseWhitespace = true);
91 /// export the events (calls EventExport::Export(Reference<XNameAcess>) )
92 void Export( ::com::sun::star::uno::Reference<
93 ::com::sun::star::container::XNameReplace> & xAccess,
94 bool bUseWhitespace = true);
96 /// export the events (writes <office:events> element)
97 void Export( ::com::sun::star::uno::Reference<
98 ::com::sun::star::container::XNameAccess> & xAccess,
99 bool bUseWhitespace = true);
101 /// export the events, but write <officeooo:events> element
102 /// (for new file format additions)
103 void ExportExt( ::com::sun::star::uno::Reference<
104 ::com::sun::star::container::XNameAccess> & xAccess,
105 bool bUseWhitespace = true);
107 /// export a single event (writes <office:events> element)
108 void ExportSingleEvent(
109 ::com::sun::star::uno::Sequence<
110 ::com::sun::star::beans::PropertyValue>& rEventValues,
111 const OUString& rApiEventName,
112 bool bUseWhitespace = true );
114 private:
116 /// export one event (start container-element if necessary)
117 SAL_DLLPRIVATE void ExportEvent(
118 ::com::sun::star::uno::Sequence<
119 ::com::sun::star::beans::PropertyValue>& rEventValues,
120 const XMLEventName& rXmlEventName,
121 bool bUseWhitespace,
122 bool& rExported);
124 /// export the start element
125 SAL_DLLPRIVATE void StartElement(bool bUseWhitespace);
127 /// export the end element
128 SAL_DLLPRIVATE void EndElement(bool bUseWhitespace);
131 #endif
133 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */