xref: /aoo4110/main/xmloff/inc/xmloff/xmlevent.hxx (revision b1cdbd2c)
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_XMLEVENT_HXX
25 #define _XMLOFF_XMLEVENT_HXX
26 
27 #include <com/sun/star/uno/Sequence.hxx>
28 #include <com/sun/star/uno/Reference.hxx>
29 
30 
31 /**
32  * @#file
33  *
34  * Several definition used in im- and export of events
35  */
36 
37 namespace com { namespace sun { namespace star {
38 	namespace xml { namespace sax { class XAttributeList; } }
39 	namespace beans { struct PropertyValue; }
40 } } }
41 namespace rtl { class OUString; }
42 
43 class SvXMLExport;
44 class SvXMLImportContext;
45 class SvXMLImport;
46 class XMLEventsImportContext;
47 
48 
49 struct XMLEventName
50 {
51 	sal_uInt16 m_nPrefix;
52 	::rtl::OUString m_aName;
53 
XMLEventNameXMLEventName54 	XMLEventName() : m_nPrefix( 0 ) {}
XMLEventNameXMLEventName55 	XMLEventName( sal_uInt16 n, const sal_Char *p ) :
56 		m_nPrefix( n ),
57 		m_aName( ::rtl::OUString::createFromAscii(p) )
58    	{}
59 
XMLEventNameXMLEventName60 	XMLEventName( sal_uInt16 n, const ::rtl::OUString& r ) :
61 		m_nPrefix( n ),
62 		m_aName( r )
63    	{}
64 
operator <XMLEventName65 	bool operator<( const XMLEventName& r ) const
66 	{
67 		return m_nPrefix < r.m_nPrefix ||
68 			   (m_nPrefix == r.m_nPrefix && m_aName < r.m_aName );
69 	}
70 
71 };
72 
73 /**
74  * XMLEventNameTranslation: define tables that translate between event names
75  * as used in the XML file format and in the StarOffice API.
76  * The last entry in the table must be { NULL, 0, NULL }.
77  */
78 struct XMLEventNameTranslation
79 {
80 	const sal_Char* sAPIName;
81 	sal_uInt16		nPrefix;	// namespace prefix
82 	const sal_Char* sXMLName;
83 };
84 
85 /// a translation table for the events defined in the XEventsSupplier service
86 /// (implemented in XMLEventExport.cxx)
87 extern const XMLEventNameTranslation aStandardEventTable[];
88 
89 
90 /**
91  * Handle export of an event for a certain event type (event type as
92  * defined by the PropertyValue "EventType" in API).
93  *
94  * The Handler has to generate the full <script:event> element.
95  */
96 class XMLEventExportHandler
97 {
98 public:
~XMLEventExportHandler()99     virtual ~XMLEventExportHandler() {};
100 
101 	virtual void Export(
102 		SvXMLExport& rExport,					/// the current XML export
103 		const ::rtl::OUString& rEventQName,		/// the XML name of the event
104 		::com::sun::star::uno::Sequence<		/// the values for the event
105 			::com::sun::star::beans::PropertyValue> & rValues,
106 	 	sal_Bool bUseWhitespace) = 0;	/// create whitespace around elements?
107 };
108 
109 
110 /**
111  * Handle import of an event for a certain event type (as defined by
112  * the PropertyValue "EventType" in the API).
113  *
114  * EventContextFactories must be registered with the EventImportHelper
115  * that is attached to the SvXMLImport.
116  *
117  * The factory has to create an import context for a <script:event>
118  * element.  The context has to call the
119  * EventsImportContext::AddEventValues() method to fave its event
120  * registered with the enclosing element. For events consisting only
121  * of attributes (and an empty element) an easy solution is to handle
122  * all attributes in the CreateContext()-method and return a default
123  * context.
124  *
125  * EventContextFactory objects have to be registered with the
126  * EventsImportHelper.
127  */
128 class XMLEventContextFactory
129 {
130 public:
~XMLEventContextFactory()131     virtual ~XMLEventContextFactory() {};
132 
133 	virtual SvXMLImportContext* CreateContext(
134 		SvXMLImport& rImport,				/// import context
135 		sal_uInt16 nPrefix,					/// element: namespace prefix
136 		const ::rtl::OUString& rLocalName,	/// element: local name
137 		const ::com::sun::star::uno::Reference< 	/// attribute list
138 			::com::sun::star::xml::sax::XAttributeList> & xAttrList,
139 		/// the context for the enclosing <script:events> element
140 		XMLEventsImportContext* rEvents,
141 		/// the event name (as understood by the API)
142 		const ::rtl::OUString& rApiEventName,
143 		/// the event type name (as registered)
144 		const ::rtl::OUString& rApiLanguage) = 0;
145 };
146 
147 
148 #endif
149