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_STATUSBARDOCUMENTHANDLER_HXX_
25 #define __FRAMEWORK_XML_STATUSBARDOCUMENTHANDLER_HXX_
26 
27 #ifndef __FRAMEWORK_XML_STATUSBARCONFIGURATION_HXX_
28 #include <framework/statusbarconfiguration.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 #include <framework/fwedllapi.h>
49 
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 OReadStatusBarDocumentHandler :	private ThreadHelpBase,	// Struct for right initialization of lock member! Must be first of baseclasses.
60 										public ::cppu::WeakImplHelper1< ::com::sun::star::xml::sax::XDocumentHandler >
61 {
62 	public:
63 		enum StatusBar_XML_Entry
64 		{
65 			SB_ELEMENT_STATUSBAR,
66 			SB_ELEMENT_STATUSBARITEM,
67 			SB_ATTRIBUTE_URL,
68 			SB_ATTRIBUTE_ALIGN,
69 			SB_ATTRIBUTE_STYLE,
70 			SB_ATTRIBUTE_AUTOSIZE,
71 			SB_ATTRIBUTE_OWNERDRAW,
72 			SB_ATTRIBUTE_WIDTH,
73 			SB_ATTRIBUTE_OFFSET,
74             SB_ATTRIBUTE_HELPURL,
75 			SB_XML_ENTRY_COUNT
76 		};
77 
78 		enum StatusBar_XML_Namespace
79 		{
80 			SB_NS_STATUSBAR,
81 			SB_NS_XLINK,
82 			SB_XML_NAMESPACES_COUNT
83 		};
84 
85         OReadStatusBarDocumentHandler( const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer >& aStatusBarItems );
86 		virtual ~OReadStatusBarDocumentHandler();
87 
88 		// XDocumentHandler
89 		virtual void SAL_CALL startDocument(void)
90 		throw (	::com::sun::star::xml::sax::SAXException,
91 				::com::sun::star::uno::RuntimeException );
92 
93 		virtual void SAL_CALL endDocument(void)
94 		throw(	::com::sun::star::xml::sax::SAXException,
95 				::com::sun::star::uno::RuntimeException );
96 
97 		virtual void SAL_CALL startElement(
98 			const rtl::OUString& aName,
99 			const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > &xAttribs)
100 		throw(	::com::sun::star::xml::sax::SAXException,
101 				::com::sun::star::uno::RuntimeException );
102 
103 		virtual void SAL_CALL endElement(const rtl::OUString& aName)
104 		throw(	::com::sun::star::xml::sax::SAXException,
105 				::com::sun::star::uno::RuntimeException );
106 
107 		virtual void SAL_CALL characters(const rtl::OUString& aChars)
108 		throw(	::com::sun::star::xml::sax::SAXException,
109 				::com::sun::star::uno::RuntimeException );
110 
111 		virtual void SAL_CALL ignorableWhitespace(const rtl::OUString& aWhitespaces)
112 		throw(	::com::sun::star::xml::sax::SAXException,
113 				::com::sun::star::uno::RuntimeException );
114 
115 		virtual void SAL_CALL processingInstruction(const rtl::OUString& aTarget,
116 													const rtl::OUString& aData)
117 		throw(	::com::sun::star::xml::sax::SAXException,
118 				::com::sun::star::uno::RuntimeException );
119 
120 		virtual void SAL_CALL setDocumentLocator(
121 			const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator > &xLocator)
122 		throw(	::com::sun::star::xml::sax::SAXException,
123 				::com::sun::star::uno::RuntimeException );
124 
125 	private:
126 		::rtl::OUString getErrorLineString();
127 
128 		class StatusBarHashMap : public ::std::hash_map< ::rtl::OUString				,
129 														 StatusBar_XML_Entry			,
130 														 rtl::OUStringHash,
131 														 ::std::equal_to< ::rtl::OUString >	>
132 		{
133 			public:
free()134 				inline void free()
135 				{
136 					StatusBarHashMap().swap( *this );
137 				}
138 		};
139 
140 		sal_Bool																	        m_bStatusBarStartFound;
141 		sal_Bool																	        m_bStatusBarEndFound;
142 		sal_Bool																	        m_bStatusBarItemStartFound;
143 		StatusBarHashMap															        m_aStatusBarMap;
144         ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexContainer >    m_aStatusBarItems;
145 		::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator >	        m_xLocator;
146 };
147 
148 class FWE_DLLPUBLIC OWriteStatusBarDocumentHandler : private ThreadHelpBase // Struct for right initialization of lock member! Must be first of baseclasses.
149 {
150 	public:
151 		OWriteStatusBarDocumentHandler(
152             const ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >& rStatusBarItems,
153 			const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler >& rWriteDocHandler );
154 		virtual ~OWriteStatusBarDocumentHandler();
155 
156 		void WriteStatusBarDocument() throw
157 			( ::com::sun::star::xml::sax::SAXException,
158 			  ::com::sun::star::uno::RuntimeException );
159 
160 	protected:
161         virtual void WriteStatusBarItem(
162             const rtl::OUString& rCommandURL,
163             const rtl::OUString& rHelpURL,
164             sal_Int16            nOffset,
165             sal_Int16            nStyle,
166             sal_Int16            nWidth ) throw
167 			( ::com::sun::star::xml::sax::SAXException,
168 			  ::com::sun::star::uno::RuntimeException );
169 
170         ::com::sun::star::uno::Reference< ::com::sun::star::container::XIndexAccess >       m_aStatusBarItems;
171 		::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler >	m_xWriteDocumentHandler;
172 		::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >		m_xEmptyList;
173 		::rtl::OUString																		m_aXMLStatusBarNS;
174 		::rtl::OUString																		m_aXMLXlinkNS;
175 		::rtl::OUString																		m_aAttributeType;
176 		::rtl::OUString																		m_aAttributeURL;
177 };
178 
179 } // namespace framework
180 
181 #endif
182