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_XMLEVENTSIMPORTCONTEXT_HXX
25 #define _XMLOFF_XMLEVENTSIMPORTCONTEXT_HXX
26 
27 #include "sal/config.h"
28 #include "xmloff/dllapi.h"
29 #include <com/sun/star/uno/Reference.hxx>
30 #include <com/sun/star/uno/Sequence.hxx>
31 #include <xmloff/xmlictxt.hxx>
32 #include <xmloff/xmlevent.hxx>
33 
34 #include <map>
35 #include <vector>
36 
37 namespace com { namespace sun { namespace star {
38 	namespace xml { namespace sax {	class XAttributeList; } }
39 	namespace beans { struct PropertyValue;	}
40 	namespace container { class XNameReplace; }
41 	namespace document { class XEventsSupplier; }
42 } } }
43 namespace rtl {	class OUString; }
44 
45 typedef ::std::pair<
46 			::rtl::OUString,
47 			::com::sun::star::uno::Sequence<
48 				::com::sun::star::beans::PropertyValue> > EventNameValuesPair;
49 
50 typedef ::std::vector< EventNameValuesPair > EventsVector;
51 
52 /**
53  * Import <script:events> element.
54  *
55  * The import context usually sets the events immediately at the event
56  * XNameReplace. If none was given on construction, it operates in
57  * delayed mode: All events are collected and may then be set
58  * with the setEvents() method.
59  */
60 class XMLOFF_DLLPUBLIC XMLEventsImportContext : public SvXMLImportContext
61 {
62 protected:
63 	// the event XNameReplace; may be empty
64 	::com::sun::star::uno::Reference<
65 		::com::sun::star::container::XNameReplace> xEvents;
66 
67 	// if no XNameReplace is given, use this vector to collect events
68 	EventsVector aCollectEvents;
69 
70 public:
71 
72 	TYPEINFO();
73 
74 	XMLEventsImportContext(
75 		SvXMLImport& rImport,
76 		sal_uInt16 nPrfx,
77 		const ::rtl::OUString& rLocalName);
78 
79 	XMLEventsImportContext(
80 		SvXMLImport& rImport,
81 		sal_uInt16 nPrfx,
82 		const ::rtl::OUString& rLocalName,
83 		const ::com::sun::star::uno::Reference<
84 			::com::sun::star::document::XEventsSupplier> & xEventsSupplier);
85 
86 	XMLEventsImportContext(
87 		SvXMLImport& rImport,
88 		sal_uInt16 nPrfx,
89 		const ::rtl::OUString& rLocalName,
90 		const ::com::sun::star::uno::Reference<
91 			::com::sun::star::container::XNameReplace> & xNameRepl);
92 
93 	~XMLEventsImportContext();
94 
95 	void AddEventValues(
96 		const ::rtl::OUString& rEventName,
97 		const ::com::sun::star::uno::Sequence<
98 			::com::sun::star::beans::PropertyValue> & rValues);
99 
100     /// if the import operates in delayed mode, you can use this method
101     /// to set all events that have been read on the XEventsSupplier
102 	void SetEvents(
103 		const ::com::sun::star::uno::Reference<
104 			::com::sun::star::document::XEventsSupplier> & xEventsSupplier);
105 
106     /// if the import operates in delayed mode, you can use this method
107     /// to set all events that have been read on the XNameReplace
108 	void SetEvents(
109 		const ::com::sun::star::uno::Reference<
110 			::com::sun::star::container::XNameReplace> & xNameRepl);
111 
112     /// if the import operates indelayed mode, you can use this method
113     /// to obtain the value sequence for a specific event
114     sal_Bool GetEventSequence(
115         const ::rtl::OUString& rName,
116         ::com::sun::star::uno::Sequence<
117         ::com::sun::star::beans::PropertyValue> & rSequence );
118 
119 protected:
120 
121 	virtual void StartElement(
122 		const ::com::sun::star::uno::Reference<
123 			::com::sun::star::xml::sax::XAttributeList> & xAttrList);
124 
125 	virtual void EndElement();
126 
127 	virtual SvXMLImportContext *CreateChildContext(
128 		sal_uInt16 nPrefix,
129 		const ::rtl::OUString& rLocalName,
130 		const ::com::sun::star::uno::Reference<
131 			::com::sun::star::xml::sax::XAttributeList> & xAttrList );
132 };
133 
134 #endif
135