1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef _XMLOFF_XMLEVENTEXPORT_HXX
25 #define _XMLOFF_XMLEVENTEXPORT_HXX
26 
27 #include "sal/config.h"
28 #include "xmloff/dllapi.h"
29 #include "sal/types.h"
30 #include <com/sun/star/uno/Sequence.hxx>
31 #include <com/sun/star/uno/Reference.hxx>
32 #include <rtl/ustring.hxx>
33 #include <xmloff/xmlevent.hxx>
34 
35 #include <map>
36 
37 class SvXMLExport;
38 namespace com { namespace sun { namespace star {
39 	namespace document { class XEventsSupplier; }
40 	namespace container { class XNameReplace; }
41 	namespace container { class XNameAccess; }
42 	namespace beans { struct PropertyValue; }
43 } } }
44 
45 typedef ::std::map< ::rtl::OUString, XMLEventExportHandler* > HandlerMap;
46 typedef ::std::map< ::rtl::OUString, XMLEventName > NameMap;
47 
48 /**
49  * Export instances of EventsSupplier services. To use this class you
50  * must fulfill two conditions:
51  *
52  * 1) provide a translation from the API event names to XML event
53  * names
54  * 2) Register XMLEventExportHandler instances for all script types
55  * that you would like to export.
56  *
57  * The Export()-Methods all have a bUseWhitespace parameter that
58  * causes the exported elements to be surrounded by whitespace, which
59  * in turn causes the elements to be indented properly. By default,
60  * whitespace is used, but it may not be called for in all cases (e.g
61  * events attached to hyperlink within a paragraph.)
62  */
63 class XMLOFF_DLLPUBLIC XMLEventExport
64 {
65 	const ::rtl::OUString sEventType;
66 
67 	SvXMLExport& rExport;
68 
69 	HandlerMap aHandlerMap;
70 	NameMap aNameTranslationMap;
71 
72     bool bExtNamespace;
73 
74 public:
75 	XMLEventExport(SvXMLExport& rExport,
76 				   const XMLEventNameTranslation* pTranslationTable = NULL);
77 	~XMLEventExport();
78 
79 	/// register an EventExportHandler for a particular script type
80 	///
81 	/// The handlers will be deleted when the object is destroyed, hence
82 	/// no pointers to a handler registered with AddHandler() should be
83 	/// held by anyone.
84 	void AddHandler( const ::rtl::OUString& rName,
85 					 XMLEventExportHandler* rHandler );
86 
87 	/// register additional event names
88 	void AddTranslationTable( const XMLEventNameTranslation* pTransTable );
89 
90 	/// export the events (calls EventExport::Export(Reference<XNameAcess>) )
91 	void Export( ::com::sun::star::uno::Reference<
92 					 ::com::sun::star::document::XEventsSupplier> & xAccess,
93 				sal_Bool bUseWhitespace = sal_True);
94 
95 	/// export the events (calls EventExport::Export(Reference<XNameAcess>) )
96 	void Export( ::com::sun::star::uno::Reference<
97 					 ::com::sun::star::container::XNameReplace> & xAccess,
98 				sal_Bool bUseWhitespace = sal_True);
99 
100 	/// export the events (writes <office:events> element)
101 	void Export( ::com::sun::star::uno::Reference<
102 					 ::com::sun::star::container::XNameAccess> & xAccess,
103 				sal_Bool bUseWhitespace = sal_True);
104 
105     /// export the events, but write <officeooo:events> element
106     /// (for new file format additions)
107     void ExportExt( ::com::sun::star::uno::Reference<
108                      ::com::sun::star::container::XNameAccess> & xAccess,
109                 sal_Bool bUseWhitespace = sal_True);
110 
111     /// export a single event (writes <office:events> element)
112     void ExportSingleEvent(
113         ::com::sun::star::uno::Sequence<
114             ::com::sun::star::beans::PropertyValue>& rEventValues,
115         const ::rtl::OUString& rApiEventName,
116         sal_Bool bUseWhitespace = sal_True );
117 
118 private:
119 
120     /// export one event (start container-element if necessary)
121     SAL_DLLPRIVATE void ExportEvent(
122         ::com::sun::star::uno::Sequence<
123             ::com::sun::star::beans::PropertyValue>& rEventValues,
124     	const XMLEventName& rXmlEventName,
125         sal_Bool bUseWhitespace,
126         sal_Bool& rExported);
127 
128 	/// export the start element
129 	SAL_DLLPRIVATE void StartElement(sal_Bool bUseWhitespace);
130 
131 	/// export the end element
132 	SAL_DLLPRIVATE void EndElement(sal_Bool bUseWhitespace);
133 };
134 
135 #endif
136