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_ACCELERATORCONFIGURATIONREADER_HXX_
25 #define _FRAMEWORK_XML_ACCELERATORCONFIGURATIONREADER_HXX_
26 
27 //_______________________________________________
28 // own includes
29 
30 #include <accelerators/acceleratorcache.hxx>
31 #include <accelerators/keymapping.hxx>
32 #include <macros/xinterface.hxx>
33 #include <threadhelp/threadhelpbase.hxx>
34 #include <general.h>
35 
36 //_______________________________________________
37 // interface includes
38 
39 #ifndef __COM_SUN_STAR_XML_SAX_XDOCUMENTHANDLER_HPP_
40 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
41 #endif
42 
43 #ifndef __COM_SUN_STAR_XML_SAX_XLOCATOR_HPP_
44 #include <com/sun/star/xml/sax/XLocator.hpp>
45 #endif
46 
47 //_______________________________________________
48 // other includes
49 #include <salhelper/singletonref.hxx>
50 #include <cppuhelper/weak.hxx>
51 #include <rtl/ustring.hxx>
52 
53 namespace framework{
54 
55 class AcceleratorConfigurationReader : public  css::xml::sax::XDocumentHandler
56                                      , private ThreadHelpBase
57                                      , public  ::cppu::OWeakObject
58 {
59     //-------------------------------------------
60     // const, types
61 
62     private:
63 
64         //---------------------------------------
65         /** @short  classification of XML elements. */
66 		enum EXMLElement
67 		{
68 			E_ELEMENT_ACCELERATORLIST,
69 			E_ELEMENT_ITEM
70         };
71 
72         //---------------------------------------
73         /** @short  classification of XML attributes. */
74         enum EXMLAttribute
75         {
76 			E_ATTRIBUTE_KEYCODE,
77 			E_ATTRIBUTE_MOD_SHIFT,
78 			E_ATTRIBUTE_MOD_MOD1,
79 			E_ATTRIBUTE_MOD_MOD2,
80                         E_ATTRIBUTE_MOD_MOD3,
81 			E_ATTRIBUTE_URL
82 		};
83 
84         //---------------------------------------
85         /** @short  some namespace defines */
86 		enum EAcceleratorXMLNamespace
87 		{
88 			E_NAMESPACE_ACCEL,
89 			E_NAMESPACE_XLINK
90 		};
91 
92     //-------------------------------------------
93     // member
94 
95     private:
96 
97         //---------------------------------------
98         /** @short  needed to read the xml configuration. */
99         css::uno::Reference< css::xml::sax::XDocumentHandler > m_xReader;
100 
101         //---------------------------------------
102         /** @short  reference to the outside container, where this
103                     reader/writer must work on. */
104         AcceleratorCache& m_rContainer;
105 
106         //---------------------------------------
107         /** @short  used to detect if an accelerator list
108                     occures recursive inside xml. */
109 		sal_Bool m_bInsideAcceleratorList;
110 
111         //---------------------------------------
112         /** @short  used to detect if an accelerator item
113                     occures recursive inside xml. */
114 		sal_Bool m_bInsideAcceleratorItem;
115 
116         //---------------------------------------
117         /** @short  is used to map key codes to its
118                     string representation.
119 
120             @descr  To perform this operatio is
121                     created only one times and holded
122                     alive forever ...*/
123         ::salhelper::SingletonRef< KeyMapping > m_rKeyMapping;
124 
125         //---------------------------------------
126         /** @short  provide informations abou the parsing state.
127 
128             @descr  We use it to find out the line and column, where
129                     an error occure.
130           */
131 		css::uno::Reference< css::xml::sax::XLocator > m_xLocator;
132 
133 /*        SfxAcceleratorItemList& m_aReadAcceleratorList;
134 */
135 
136     //-------------------------------------------
137     // interface
138 
139 	public:
140 
141         //---------------------------------------
142         /** @short  connect this new reader/writer instance
143                     to an outside container, which should be used
144                     flushed to the underlying XML configuration or
145                     filled from there.
146 
147             @param  rContainer
148                     a reference to the outside container.
149           */
150         AcceleratorConfigurationReader(AcceleratorCache& rContainer);
151 
152         //---------------------------------------
153         /** @short  does nothing real ... */
154 		virtual ~AcceleratorConfigurationReader();
155 
156         //---------------------------------------
157         // XInterface
158         FWK_DECLARE_XINTERFACE
159 
160         //---------------------------------------
161 		// XDocumentHandler
162 		virtual void SAL_CALL startDocument()
163 			throw(css::xml::sax::SAXException,
164                   css::uno::RuntimeException );
165 
166 		virtual void SAL_CALL endDocument()
167 			throw(css::xml::sax::SAXException,
168                   css::uno::RuntimeException );
169 
170 		virtual void SAL_CALL startElement(const ::rtl::OUString&                                      sElement      ,
171 			                               const css::uno::Reference< css::xml::sax::XAttributeList >& xAttributeList)
172 			throw(css::xml::sax::SAXException,
173                   css::uno::RuntimeException );
174 
175 		virtual void SAL_CALL endElement(const ::rtl::OUString& sElement)
176             throw(css::xml::sax::SAXException,
177                   css::uno::RuntimeException );
178 
179 		virtual void SAL_CALL characters(const ::rtl::OUString& sChars)
180 			throw(css::xml::sax::SAXException,
181                   css::uno::RuntimeException );
182 
183 		virtual void SAL_CALL ignorableWhitespace(const ::rtl::OUString& sWhitespaces)
184 			throw(css::xml::sax::SAXException,
185                   css::uno::RuntimeException );
186 
187 		virtual void SAL_CALL processingInstruction(const ::rtl::OUString& sTarget,
188                                                     const ::rtl::OUString& sData  )
189 			throw(css::xml::sax::SAXException,
190                   css::uno::RuntimeException );
191 
192 		virtual void SAL_CALL setDocumentLocator(const css::uno::Reference< css::xml::sax::XLocator >& xLocator)
193 			throw(css::xml::sax::SAXException,
194                   css::uno::RuntimeException );
195 
196     //-------------------------------------------
197     // helper
198 
199     private:
200 
201         //---------------------------------------
202         /** TODO document me */
203 		static EXMLElement implst_classifyElement(const ::rtl::OUString& sElement);
204 
205         //---------------------------------------
206         /** TODO document me */
207 		static EXMLAttribute implst_classifyAttribute(const ::rtl::OUString& sAttribute);
208 
209         //---------------------------------------
210         /** TODO document me */
211 		::rtl::OUString implts_getErrorLineString();
212 };
213 
214 } // namespace framework
215 
216 #endif // _FRAMEWORK_XML_ACCELERATORCONFIGURATIONREADER_HXX_
217