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_MENUDOCUMENTHANDLER_HXX_
25 #define __FRAMEWORK_XML_MENUDOCUMENTHANDLER_HXX_
26 
27 //_________________________________________________________________________________________________________________
28 //	interface includes
29 //_________________________________________________________________________________________________________________
30 
31 #ifndef __COM_SUN_STAR_XML_SAX_XDOCUMENTHANDLER_HPP_
32 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
33 #endif
34 #include <com/sun/star/container/XIndexContainer.hpp>
35 #include <com/sun/star/lang/XSingleComponentFactory.hpp>
36 #include <com/sun/star/beans/PropertyValue.hpp>
37 #include <com/sun/star/uno/Sequence.h>
38 #include <com/sun/star/uno/XComponentContext.hpp>
39 
40 //_________________________________________________________________________________________________________________
41 //	other includes
42 //_________________________________________________________________________________________________________________
43 #include <threadhelp/threadhelpbase.hxx>
44 #include <rtl/ustring.hxx>
45 #include <cppuhelper/implbase1.hxx>
46 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
47 #include <framework/fwedllapi.h>
48 
49 //_________________________________________________________________________________________________________________
50 //	namespace
51 //_________________________________________________________________________________________________________________
52 
53 namespace framework{
54 
55 class FWE_DLLPUBLIC ReadMenuDocumentHandlerBase : public ThreadHelpBase,	// Struct for right initalization of mutex member! Must be first of baseclasses.
56 									public ::cppu::WeakImplHelper1< ::com::sun::star::xml::sax::XDocumentHandler >
57 {
58 	public:
59 		ReadMenuDocumentHandlerBase();
60 		virtual ~ReadMenuDocumentHandlerBase();
61 
62 		// XDocumentHandler
63 		virtual void SAL_CALL startDocument(void)
64 		throw (	::com::sun::star::xml::sax::SAXException,
65 				::com::sun::star::uno::RuntimeException ) = 0;
66 
67 		virtual void SAL_CALL endDocument(void)
68 		throw(	::com::sun::star::xml::sax::SAXException,
69 				::com::sun::star::uno::RuntimeException ) = 0;
70 
71 		virtual void SAL_CALL startElement(
72 			const rtl::OUString& aName,
73 			const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > &xAttribs)
74 		throw(	::com::sun::star::xml::sax::SAXException,
75 				::com::sun::star::uno::RuntimeException ) = 0;
76 
77 		virtual void SAL_CALL endElement(const rtl::OUString& aName)
78 		throw(	::com::sun::star::xml::sax::SAXException,
79 				::com::sun::star::uno::RuntimeException ) = 0;
80 
81 		virtual void SAL_CALL characters(const rtl::OUString& aChars)
82 		throw(	::com::sun::star::xml::sax::SAXException,
83 				::com::sun::star::uno::RuntimeException ) = 0;
84 
85 		virtual void SAL_CALL ignorableWhitespace(const rtl::OUString& aWhitespaces)
86 		throw(	::com::sun::star::xml::sax::SAXException,
87 				::com::sun::star::uno::RuntimeException );
88 
89 		virtual void SAL_CALL processingInstruction(const rtl::OUString& aTarget,
90 													const rtl::OUString& aData)
91 		throw(	::com::sun::star::xml::sax::SAXException,
92 				::com::sun::star::uno::RuntimeException );
93 
94 		virtual void SAL_CALL setDocumentLocator(
95 			const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator > &xLocator)
96 		throw(	::com::sun::star::xml::sax::SAXException,
97 				::com::sun::star::uno::RuntimeException );
98 
99 	protected:
100 		::rtl::OUString getErrorLineString();
101 
102 		::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator > m_xLocator;
103 		::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler> m_xReader;
104 		void initPropertyCommon( com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > &rProps,
105 								 const rtl::OUString &rCommandURL, const rtl::OUString &rHelpId,
106                                  const rtl::OUString &rLabel, sal_Int16 nItemStyleBits );
107 	private:
108 		rtl::OUString m_aType;
109 		rtl::OUString m_aLabel;
110 		rtl::OUString m_aContainer;
111 		rtl::OUString m_aHelpURL;
112 		rtl::OUString m_aCommandURL;
113         rtl::OUString m_aStyle;
114 		::com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue > m_aItemProp;
115 };
116 
117 
118 class FWE_DLLPUBLIC OReadMenuDocumentHandler : public ReadMenuDocumentHandlerBase
119 {
120 	public:
121 		// #110897#
122         OReadMenuDocumentHandler(
123 			const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
124 			const com::sun::star::uno::Reference< com::sun::star::container::XIndexContainer >& rItemContainer );
125 		virtual ~OReadMenuDocumentHandler();
126 
127 		// #110897#
128 		const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& getServiceFactory();
129 
130 		// XDocumentHandler
131 		virtual void SAL_CALL startDocument(void)
132 		throw (	::com::sun::star::xml::sax::SAXException,
133 				::com::sun::star::uno::RuntimeException );
134 
135 		virtual void SAL_CALL endDocument(void)
136 		throw(	::com::sun::star::xml::sax::SAXException,
137 				::com::sun::star::uno::RuntimeException );
138 
139 		virtual void SAL_CALL startElement(
140 			const rtl::OUString& aName,
141 			const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > &xAttribs)
142 		throw(	::com::sun::star::xml::sax::SAXException,
143 				::com::sun::star::uno::RuntimeException );
144 
145 		virtual void SAL_CALL endElement(const rtl::OUString& aName)
146 		throw(	::com::sun::star::xml::sax::SAXException,
147 				::com::sun::star::uno::RuntimeException );
148 
149 		virtual void SAL_CALL characters(const rtl::OUString& aChars)
150 		throw(	::com::sun::star::xml::sax::SAXException,
151 				::com::sun::star::uno::RuntimeException );
152 
153 	private:
154           int		m_nElementDepth;
155           sal_Bool	m_bMenuBarMode;
156           com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer > m_xMenuBarContainer;
157           com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleComponentFactory > m_xContainerFactory;
158           const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& mxServiceFactory;
159 };	// OReadMenuDocumentHandler
160 
161 
162 class FWE_DLLPUBLIC OReadMenuBarHandler : public ReadMenuDocumentHandlerBase
163 {
164 	public:
165 		// #110897#
166 		OReadMenuBarHandler(
167 			const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xServiceFactory,
168 			const com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer >& rMenuBarContainer,
169             const com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleComponentFactory >& rContainerFactory );
170 		virtual ~OReadMenuBarHandler();
171 
172 		// #110897#
173 		const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& getServiceFactory();
174 
175 		// XDocumentHandler
176 		virtual void SAL_CALL startDocument(void)
177 		throw (	::com::sun::star::xml::sax::SAXException,
178 				::com::sun::star::uno::RuntimeException );
179 
180 		virtual void SAL_CALL endDocument(void)
181 		throw(	::com::sun::star::xml::sax::SAXException,
182 				::com::sun::star::uno::RuntimeException );
183 
184 		virtual void SAL_CALL startElement(
185 			const rtl::OUString& aName,
186 			const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > &xAttribs)
187 		throw(	::com::sun::star::xml::sax::SAXException,
188 				::com::sun::star::uno::RuntimeException );
189 
190 		virtual void SAL_CALL endElement(const rtl::OUString& aName)
191 		throw(	::com::sun::star::xml::sax::SAXException,
192 				::com::sun::star::uno::RuntimeException );
193 
194 		virtual void SAL_CALL characters(const rtl::OUString& aChars)
195 		throw(	::com::sun::star::xml::sax::SAXException,
196 				::com::sun::star::uno::RuntimeException );
197 
198 	private:
199 		int			m_nElementDepth;
200 		sal_Bool	m_bMenuMode;
201         com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer > m_xMenuBarContainer;
202         com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleComponentFactory > m_xContainerFactory;
203 
204 		// #110897#
205 		const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& mxServiceFactory;
206 };	// OReadMenuBarHandler
207 
208 
209 class FWE_DLLPUBLIC OReadMenuHandler : public ReadMenuDocumentHandlerBase
210 {
211 	public:
212 		OReadMenuHandler( const com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer >& rMenuContainer,
213                           const com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleComponentFactory >& rContainerFactory );
214 		virtual ~OReadMenuHandler();
215 
216 		// XDocumentHandler
217 		virtual void SAL_CALL startDocument(void)
218 		throw (	::com::sun::star::xml::sax::SAXException,
219 				::com::sun::star::uno::RuntimeException );
220 
221 		virtual void SAL_CALL endDocument(void)
222 		throw(	::com::sun::star::xml::sax::SAXException,
223 				::com::sun::star::uno::RuntimeException );
224 
225 		virtual void SAL_CALL startElement(
226 			const rtl::OUString& aName,
227 			const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > &xAttribs)
228 		throw(	::com::sun::star::xml::sax::SAXException,
229 				::com::sun::star::uno::RuntimeException );
230 
231 		virtual void SAL_CALL endElement(const rtl::OUString& aName)
232 		throw(	::com::sun::star::xml::sax::SAXException,
233 				::com::sun::star::uno::RuntimeException );
234 
235 		virtual void SAL_CALL characters(const rtl::OUString& aChars)
236 		throw(	::com::sun::star::xml::sax::SAXException,
237 				::com::sun::star::uno::RuntimeException );
238 
239 	private:
240 		int					m_nElementDepth;
241 		sal_Bool			m_bMenuPopupMode;
242         com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer > m_xMenuContainer;
243         com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleComponentFactory > m_xContainerFactory;
244 }; // OReadMenuHandler
245 
246 
247 class FWE_DLLPUBLIC OReadMenuPopupHandler : public ReadMenuDocumentHandlerBase
248 {
249 	public:
250 		OReadMenuPopupHandler( const com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer >& rMenuContainer,
251                                const com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleComponentFactory >& rContainerFactory );
252 		virtual ~OReadMenuPopupHandler();
253 
254 		// XDocumentHandler
255 		virtual void SAL_CALL startDocument(void)
256 			throw (	::com::sun::star::xml::sax::SAXException,
257 					::com::sun::star::uno::RuntimeException );
258 
259 		virtual void SAL_CALL endDocument(void)
260 			throw (	::com::sun::star::xml::sax::SAXException,
261 					::com::sun::star::uno::RuntimeException );
262 
263 		virtual void SAL_CALL startElement(
264 			const rtl::OUString& aName,
265 			const ::com::sun::star::uno::Reference<
266 				::com::sun::star::xml::sax::XAttributeList > &xAttribs)
267 			throw (	::com::sun::star::xml::sax::SAXException,
268 					::com::sun::star::uno::RuntimeException );
269 
270 		virtual void SAL_CALL endElement(const rtl::OUString& aName)
271 			throw (	::com::sun::star::xml::sax::SAXException,
272 					::com::sun::star::uno::RuntimeException );
273 
274 		virtual void SAL_CALL characters(const rtl::OUString& aChars)
275 			throw (	::com::sun::star::xml::sax::SAXException,
276 					::com::sun::star::uno::RuntimeException );
277 
278 	private:
279 		enum NextElementClose { ELEM_CLOSE_NONE, ELEM_CLOSE_MENUITEM, ELEM_CLOSE_MENUSEPARATOR };
280 
281 		int					m_nElementDepth;
282 		sal_Bool			m_bMenuMode;
283         com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer > m_xMenuContainer;
284         com::sun::star::uno::Reference< ::com::sun::star::lang::XSingleComponentFactory > m_xContainerFactory;
285         com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >     m_xComponentContext;
286 		NextElementClose	m_nNextElementExpected;
287 }; // OReadMenuPopupHandler
288 
289 
290 class FWE_DLLPUBLIC OWriteMenuDocumentHandler
291 {
292 	public:
293 		OWriteMenuDocumentHandler(
294             const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >& rMenuBarContainer,
295 			const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler >& rDocumentHandler );
296 		virtual ~OWriteMenuDocumentHandler();
297 
298 		void WriteMenuDocument() throw
299 			( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
300 	protected:
301 		virtual void WriteMenu( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >& rSubMenuContainer ) throw
302 			( ::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException );
303 
304         virtual void WriteMenuItem( const rtl::OUString& aCommandURL, const rtl::OUString& aLabel, const rtl::OUString& aHelpURL, sal_Int16 nStyle = 0 );
305 		virtual void WriteMenuSeparator();
306 
307         com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess > m_xMenuBarContainer;
308 		::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > m_xWriteDocumentHandler;
309 		::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > m_xEmptyList;
310 		::rtl::OUString m_aAttributeType;
311 };
312 
313 } // namespace framework
314 
315 #endif	// #ifndef __FRAMEWORK_XML_MENUDOCUMENTHANDLER_HXX_
316