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_EVENTIMPORTHELPER_HXX
25 #define _XMLOFF_EVENTIMPORTHELPER_HXX
26 
27 #include <com/sun/star/uno/Reference.hxx>
28 #include <xmloff/xmlevent.hxx>
29 
30 #include <map>
31 #include <list>
32 
33 
34 namespace com { namespace sun { namespace star {
35 	namespace xml { namespace sax {	class XAttributeList; } }
36 } } }
37 namespace rtl {	class OUString; }
38 class XMLEventContextFactory;
39 class XMLEventsImportContext;
40 struct XMLEventNameTranslation;
41 
42 typedef ::std::map< ::rtl::OUString, XMLEventContextFactory* > FactoryMap;
43 typedef ::std::map< XMLEventName, ::rtl::OUString > NameMap;
44 typedef ::std::list< NameMap* > NameMapList;
45 
46 
47 /**
48  * Helps the XMLEventsImportContext.
49  *
50  * This class stores
51  * a) the translation from XML event names to API event names, and
52  * b) a mapping from script language names to XMLEventContextFactory objects
53  *    (that handle particular languages).
54  *
55  * Event name translation tables may be added, i.e. they will be joined
56  * together. If different translations are needed (i.e., if the same XML name
57  * needs to be translated to different API names in different contexts), then
58  * translation tables may be saved on a translation table stack.
59  */
60 class XMLEventImportHelper
61 {
62 	/// map of XMLEventContextFactory objects
63 	FactoryMap aFactoryMap;
64 
65 	/// map from XML to API names
66 	NameMap* pEventNameMap;
67 
68 	/// stack of previous aEventNameMap
69 	NameMapList aEventNameMapList;
70 
71 public:
72 	XMLEventImportHelper();
73 
74 	~XMLEventImportHelper();
75 
76 	/// register a handler for a particular language type
77 	void RegisterFactory( const ::rtl::OUString& rLanguage,
78 						  XMLEventContextFactory* aFactory );
79 
80 	/// add event name translation to the internal table
81 	void AddTranslationTable( const XMLEventNameTranslation* pTransTable );
82 
83 	/// save the old translation table on a stack and install an empty table
84 	void PushTranslationTable();
85 
86 	/// recover the top-most previously saved translation table
87 	void PopTranslationTable();
88 
89 	/// create an appropriate import context for a particular event
90 	SvXMLImportContext* CreateContext(
91 		SvXMLImport& rImport,
92 		sal_uInt16 nPrefix,
93 		const ::rtl::OUString& rLocalName,
94 		const ::com::sun::star::uno::Reference<
95 			::com::sun::star::xml::sax::XAttributeList> & xAttrList,
96 		XMLEventsImportContext* rEvents,
97 		const ::rtl::OUString& rXmlEventName,
98 		const ::rtl::OUString& rLanguage);
99 
100 };
101 
102 #endif
103