1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _FRAMEWORK_XML_ACCELERATORCONFIGURATIONREADER_HXX_
29 #define _FRAMEWORK_XML_ACCELERATORCONFIGURATIONREADER_HXX_
30 
31 //_______________________________________________
32 // own includes
33 
34 #include <accelerators/acceleratorcache.hxx>
35 #include <accelerators/keymapping.hxx>
36 #include <macros/xinterface.hxx>
37 #include <threadhelp/threadhelpbase.hxx>
38 #include <general.h>
39 
40 //_______________________________________________
41 // interface includes
42 
43 #ifndef __COM_SUN_STAR_XML_SAX_XDOCUMENTHANDLER_HPP_
44 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
45 #endif
46 
47 #ifndef __COM_SUN_STAR_XML_SAX_XLOCATOR_HPP_
48 #include <com/sun/star/xml/sax/XLocator.hpp>
49 #endif
50 
51 //_______________________________________________
52 // other includes
53 #include <salhelper/singletonref.hxx>
54 #include <cppuhelper/weak.hxx>
55 #include <rtl/ustring.hxx>
56 
57 namespace framework{
58 
59 class AcceleratorConfigurationReader : public  css::xml::sax::XDocumentHandler
60                                      , private ThreadHelpBase
61                                      , public  ::cppu::OWeakObject
62 {
63     //-------------------------------------------
64     // const, types
65 
66     private:
67 
68         //---------------------------------------
69         /** @short  classification of XML elements. */
70 		enum EXMLElement
71 		{
72 			E_ELEMENT_ACCELERATORLIST,
73 			E_ELEMENT_ITEM
74         };
75 
76         //---------------------------------------
77         /** @short  classification of XML attributes. */
78         enum EXMLAttribute
79         {
80 			E_ATTRIBUTE_KEYCODE,
81 			E_ATTRIBUTE_MOD_SHIFT,
82 			E_ATTRIBUTE_MOD_MOD1,
83 			E_ATTRIBUTE_MOD_MOD2,
84                         E_ATTRIBUTE_MOD_MOD3,
85 			E_ATTRIBUTE_URL
86 		};
87 
88         //---------------------------------------
89         /** @short  some namespace defines */
90 		enum EAcceleratorXMLNamespace
91 		{
92 			E_NAMESPACE_ACCEL,
93 			E_NAMESPACE_XLINK
94 		};
95 
96     //-------------------------------------------
97     // member
98 
99     private:
100 
101         //---------------------------------------
102         /** @short  needed to read the xml configuration. */
103         css::uno::Reference< css::xml::sax::XDocumentHandler > m_xReader;
104 
105         //---------------------------------------
106         /** @short  reference to the outside container, where this
107                     reader/writer must work on. */
108         AcceleratorCache& m_rContainer;
109 
110         //---------------------------------------
111         /** @short  used to detect if an accelerator list
112                     occures recursive inside xml. */
113 		sal_Bool m_bInsideAcceleratorList;
114 
115         //---------------------------------------
116         /** @short  used to detect if an accelerator item
117                     occures recursive inside xml. */
118 		sal_Bool m_bInsideAcceleratorItem;
119 
120         //---------------------------------------
121         /** @short  is used to map key codes to its
122                     string representation.
123 
124             @descr  To perform this operatio is
125                     created only one times and holded
126                     alive forever ...*/
127         ::salhelper::SingletonRef< KeyMapping > m_rKeyMapping;
128 
129         //---------------------------------------
130         /** @short  provide informations abou the parsing state.
131 
132             @descr  We use it to find out the line and column, where
133                     an error occure.
134           */
135 		css::uno::Reference< css::xml::sax::XLocator > m_xLocator;
136 
137 /*        SfxAcceleratorItemList& m_aReadAcceleratorList;
138 */
139 
140     //-------------------------------------------
141     // interface
142 
143 	public:
144 
145         //---------------------------------------
146         /** @short  connect this new reader/writer instance
147                     to an outside container, which should be used
148                     flushed to the underlying XML configuration or
149                     filled from there.
150 
151             @param  rContainer
152                     a reference to the outside container.
153           */
154         AcceleratorConfigurationReader(AcceleratorCache& rContainer);
155 
156         //---------------------------------------
157         /** @short  does nothing real ... */
158 		virtual ~AcceleratorConfigurationReader();
159 
160         //---------------------------------------
161         // XInterface
162         FWK_DECLARE_XINTERFACE
163 
164         //---------------------------------------
165 		// XDocumentHandler
166 		virtual void SAL_CALL startDocument()
167 			throw(css::xml::sax::SAXException,
168                   css::uno::RuntimeException );
169 
170 		virtual void SAL_CALL endDocument()
171 			throw(css::xml::sax::SAXException,
172                   css::uno::RuntimeException );
173 
174 		virtual void SAL_CALL startElement(const ::rtl::OUString&                                      sElement      ,
175 			                               const css::uno::Reference< css::xml::sax::XAttributeList >& xAttributeList)
176 			throw(css::xml::sax::SAXException,
177                   css::uno::RuntimeException );
178 
179 		virtual void SAL_CALL endElement(const ::rtl::OUString& sElement)
180             throw(css::xml::sax::SAXException,
181                   css::uno::RuntimeException );
182 
183 		virtual void SAL_CALL characters(const ::rtl::OUString& sChars)
184 			throw(css::xml::sax::SAXException,
185                   css::uno::RuntimeException );
186 
187 		virtual void SAL_CALL ignorableWhitespace(const ::rtl::OUString& sWhitespaces)
188 			throw(css::xml::sax::SAXException,
189                   css::uno::RuntimeException );
190 
191 		virtual void SAL_CALL processingInstruction(const ::rtl::OUString& sTarget,
192                                                     const ::rtl::OUString& sData  )
193 			throw(css::xml::sax::SAXException,
194                   css::uno::RuntimeException );
195 
196 		virtual void SAL_CALL setDocumentLocator(const css::uno::Reference< css::xml::sax::XLocator >& xLocator)
197 			throw(css::xml::sax::SAXException,
198                   css::uno::RuntimeException );
199 
200     //-------------------------------------------
201     // helper
202 
203     private:
204 
205         //---------------------------------------
206         /** TODO document me */
207 		static EXMLElement implst_classifyElement(const ::rtl::OUString& sElement);
208 
209         //---------------------------------------
210         /** TODO document me */
211 		static EXMLAttribute implst_classifyAttribute(const ::rtl::OUString& sAttribute);
212 
213         //---------------------------------------
214         /** TODO document me */
215 		::rtl::OUString implts_getErrorLineString();
216 };
217 
218 } // namespace framework
219 
220 #endif // _FRAMEWORK_XML_ACCELERATORCONFIGURATIONREADER_HXX_
221