xref: /AOO41X/main/framework/inc/xml/eventsdocumenthandler.hxx (revision 5758ad8ce74c9f4c352d679950be760456f756ea)
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 __FRAMEWORK_XML_EVENTSDOCUMENTHANDLER_HXX_
25 #define __FRAMEWORK_XML_EVENTSDOCUMENTHANDLER_HXX_
26 
27 #ifndef __FRAMEWORK_XML_TOOLBOXCONFIGURATION_HXX_
28 #include <framework/eventsconfiguration.hxx>
29 #endif
30 
31 //_________________________________________________________________________________________________________________
32 //  interface includes
33 //_________________________________________________________________________________________________________________
34 
35 #ifndef __COM_SUN_STAR_XML_SAX_XDOCUMENTHANDLER_HPP_
36 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
37 #endif
38 
39 //_________________________________________________________________________________________________________________
40 //  other includes
41 //_________________________________________________________________________________________________________________
42 #include <threadhelp/threadhelpbase.hxx>
43 #include <rtl/ustring.hxx>
44 #include <cppuhelper/implbase1.hxx>
45 
46 #include <hash_map>
47 #include <stdtypes.h>
48 
49 #include <framework/fwedllapi.h>
50 //_________________________________________________________________________________________________________________
51 //  namespace
52 //_________________________________________________________________________________________________________________
53 
54 namespace framework{
55 
56 //*****************************************************************************************************************
57 // Hash code function for using in all hash maps of follow implementation.
58 
59 class FWE_DLLPUBLIC OReadEventsDocumentHandler :    private ThreadHelpBase, // Struct for right initalization of lock member! Must be first of baseclasses.
60                                     public ::cppu::WeakImplHelper1< ::com::sun::star::xml::sax::XDocumentHandler >
61 {
62     public:
63         enum Events_XML_Entry
64         {
65             EV_ELEMENT_EVENTS,
66             EV_ELEMENT_EVENT,
67             EV_ATTRIBUTE_TYPE,
68             EV_ATTRIBUTE_NAME,
69             XL_ATTRIBUTE_HREF,
70             XL_ATTRIBUTE_TYPE,
71             EV_ATTRIBUTE_MACRONAME,
72             EV_ATTRIBUTE_LIBRARY,
73             EV_XML_ENTRY_COUNT
74         };
75 
76         enum Event_XML_Namespace
77         {
78             EV_NS_EVENT,
79             EV_NS_XLINK,
80             EV_XML_NAMESPACES_COUNT
81         };
82 
83         OReadEventsDocumentHandler( EventsConfig& aItems );
84 
85 
86         // XDocumentHandler
87         virtual void SAL_CALL startDocument(void)
88         throw ( ::com::sun::star::xml::sax::SAXException,
89                 ::com::sun::star::uno::RuntimeException );
90 
91         virtual void SAL_CALL endDocument(void)
92         throw(  ::com::sun::star::xml::sax::SAXException,
93                 ::com::sun::star::uno::RuntimeException );
94 
95         virtual void SAL_CALL startElement(
96             const rtl::OUString& aName,
97             const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > &xAttribs)
98         throw(  ::com::sun::star::xml::sax::SAXException,
99                 ::com::sun::star::uno::RuntimeException );
100 
101         virtual void SAL_CALL endElement(const rtl::OUString& aName)
102         throw(  ::com::sun::star::xml::sax::SAXException,
103                 ::com::sun::star::uno::RuntimeException );
104 
105         virtual void SAL_CALL characters(const rtl::OUString& aChars)
106         throw(  ::com::sun::star::xml::sax::SAXException,
107                 ::com::sun::star::uno::RuntimeException );
108 
109         virtual void SAL_CALL ignorableWhitespace(const rtl::OUString& aWhitespaces)
110         throw(  ::com::sun::star::xml::sax::SAXException,
111                 ::com::sun::star::uno::RuntimeException );
112 
113         virtual void SAL_CALL processingInstruction(const rtl::OUString& aTarget,
114                                                     const rtl::OUString& aData)
115         throw(  ::com::sun::star::xml::sax::SAXException,
116                 ::com::sun::star::uno::RuntimeException );
117 
118         virtual void SAL_CALL setDocumentLocator(
119             const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator > &xLocator)
120         throw(  ::com::sun::star::xml::sax::SAXException,
121                 ::com::sun::star::uno::RuntimeException );
122 
123     protected:
124         virtual ~OReadEventsDocumentHandler();
125 
126     private:
127         ::rtl::OUString getErrorLineString();
128 
129         class EventsHashMap : public ::std::hash_map<   ::rtl::OUString                 ,
130                                                         Events_XML_Entry                ,
131                                                         rtl::OUStringHash,
132                                                         ::std::equal_to< ::rtl::OUString >  >
133         {
134             public:
free()135                 inline void free()
136                 {
137                     EventsHashMap().swap( *this );
138                 }
139         };
140 
141         sal_Bool                                                                    m_bEventsStartFound;
142         sal_Bool                                                                    m_bEventsEndFound;
143         sal_Bool                                                                    m_bEventStartFound;
144         EventsHashMap                                                               m_aEventsMap;
145         EventsConfig&                                                               m_aEventItems;
146         ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator >    m_xLocator;
147 };
148 
149 class FWE_DLLPUBLIC OWriteEventsDocumentHandler : private ThreadHelpBase // Struct for right initalization of lock member! Must be first of baseclasses.
150 {
151     public:
152         OWriteEventsDocumentHandler(
153             const EventsConfig& aItems,
154             ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > );
155         virtual ~OWriteEventsDocumentHandler();
156 
157         void WriteEventsDocument() throw
158             ( ::com::sun::star::xml::sax::SAXException,
159               ::com::sun::star::uno::RuntimeException );
160 
161     protected:
162         virtual void WriteEvent(
163                 const ::rtl::OUString& aEventName,
164                 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aPropertyValue ) throw
165             ( ::com::sun::star::xml::sax::SAXException,
166               ::com::sun::star::uno::RuntimeException );
167 
168         const EventsConfig&                                                                 m_aItems;
169         ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler >    m_xWriteDocumentHandler;
170         ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >      m_xEmptyList;
171         ::rtl::OUString                                                                     m_aXMLEventNS;
172         ::rtl::OUString                                                                     m_aXMLXlinkNS;
173         ::rtl::OUString                                                                     m_aAttributeType;
174         ::rtl::OUString                                                                     m_aAttributeURL;
175         ::rtl::OUString                                                                     m_aAttributeLanguage;
176         ::rtl::OUString                                                                     m_aAttributeLinkType;
177         ::rtl::OUString                                                                     m_aAttributeMacroName;
178         ::rtl::OUString                                                                     m_aAttributeLibrary;
179         ::rtl::OUString                                                                     m_aAttributeName;
180 };
181 
182 } // namespace framework
183 
184 #endif
185