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_TOOLBOXDOCUMENTHANDLER_HXX_
29 #define __FRAMEWORK_XML_TOOLBOXDOCUMENTHANDLER_HXX_
30 
31 #include <framework/toolboxconfiguration.hxx>
32 
33 //_________________________________________________________________________________________________________________
34 //  interface includes
35 //_________________________________________________________________________________________________________________
36 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
37 #include <com/sun/star/beans/PropertyValue.hpp>
38 
39 //_________________________________________________________________________________________________________________
40 //  other includes
41 //_________________________________________________________________________________________________________________
42 #include <threadhelp/threadhelpbase.hxx>
43 #include <rtl/ustring.hxx>
44 #include <cppuhelper/implbase1.hxx>
45 #include <stdtypes.h>
46 #include <framework/fwedllapi.h>
47 
48 //_________________________________________________________________________________________________________________
49 //  namespace
50 //_________________________________________________________________________________________________________________
51 
52 namespace framework{
53 
54 //*****************************************************************************************************************
55 // Hash code function for using in all hash maps of follow implementation.
56 
57 class FWE_DLLPUBLIC OReadToolBoxDocumentHandler : private ThreadHelpBase,   // Struct for right initalization of lock member! Must be first of baseclasses.
58                                     public ::cppu::WeakImplHelper1< ::com::sun::star::xml::sax::XDocumentHandler >
59 {
60     public:
61         enum ToolBox_XML_Entry
62         {
63             TB_ELEMENT_TOOLBAR,
64             TB_ELEMENT_TOOLBARITEM,
65             TB_ELEMENT_TOOLBARSPACE,
66             TB_ELEMENT_TOOLBARBREAK,
67             TB_ELEMENT_TOOLBARSEPARATOR,
68             TB_ATTRIBUTE_TEXT,
69             TB_ATTRIBUTE_BITMAP,
70             TB_ATTRIBUTE_URL,
71             TB_ATTRIBUTE_ITEMBITS,
72             TB_ATTRIBUTE_VISIBLE,
73             TB_ATTRIBUTE_WIDTH,
74             TB_ATTRIBUTE_USER,
75             TB_ATTRIBUTE_HELPID,
76             TB_ATTRIBUTE_STYLE,
77             TB_ATTRIBUTE_UINAME,
78             TB_ATTRIBUTE_TOOLTIP,
79 			TB_XML_ENTRY_COUNT
80 		};
81 
82         enum ToolBox_XML_Namespace
83         {
84             TB_NS_TOOLBAR,
85             TB_NS_XLINK,
86             TB_XML_NAMESPACES_COUNT
87         };
88 
89         OReadToolBoxDocumentHandler( const ::com::sun::star::uno::Reference< com::sun::star::container::XIndexContainer >& rItemContainer );
90         virtual ~OReadToolBoxDocumentHandler();
91 
92         // XDocumentHandler
93         virtual void SAL_CALL startDocument(void)
94         throw ( ::com::sun::star::xml::sax::SAXException,
95                 ::com::sun::star::uno::RuntimeException );
96 
97         virtual void SAL_CALL endDocument(void)
98         throw(  ::com::sun::star::xml::sax::SAXException,
99                 ::com::sun::star::uno::RuntimeException );
100 
101         virtual void SAL_CALL startElement(
102             const rtl::OUString& aName,
103             const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > &xAttribs)
104         throw(  ::com::sun::star::xml::sax::SAXException,
105                 ::com::sun::star::uno::RuntimeException );
106 
107         virtual void SAL_CALL endElement(const rtl::OUString& aName)
108         throw(  ::com::sun::star::xml::sax::SAXException,
109                 ::com::sun::star::uno::RuntimeException );
110 
111         virtual void SAL_CALL characters(const rtl::OUString& aChars)
112         throw(  ::com::sun::star::xml::sax::SAXException,
113                 ::com::sun::star::uno::RuntimeException );
114 
115         virtual void SAL_CALL ignorableWhitespace(const rtl::OUString& aWhitespaces)
116         throw(  ::com::sun::star::xml::sax::SAXException,
117                 ::com::sun::star::uno::RuntimeException );
118 
119         virtual void SAL_CALL processingInstruction(const rtl::OUString& aTarget,
120                                                     const rtl::OUString& aData)
121         throw(  ::com::sun::star::xml::sax::SAXException,
122                 ::com::sun::star::uno::RuntimeException );
123 
124         virtual void SAL_CALL setDocumentLocator(
125             const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator > &xLocator)
126         throw(  ::com::sun::star::xml::sax::SAXException,
127                 ::com::sun::star::uno::RuntimeException );
128 
129     private:
130         ::rtl::OUString getErrorLineString();
131 
132         class ToolBoxHashMap : public ::std::hash_map<  ::rtl::OUString                 ,
133                                                         ToolBox_XML_Entry               ,
134                                                         OUStringHashCode                ,
135                                                         ::std::equal_to< ::rtl::OUString >  >
136         {
137             public:
138                 inline void free()
139                 {
140                     ToolBoxHashMap().swap( *this );
141                 }
142         };
143 
144         sal_Bool                                                                        m_bToolBarStartFound : 1;
145         sal_Bool                                                                        m_bToolBarEndFound : 1;
146         sal_Bool                                                                        m_bToolBarItemStartFound : 1;
147         sal_Bool                                                                        m_bToolBarSpaceStartFound : 1;
148         sal_Bool                                                                        m_bToolBarBreakStartFound : 1;
149         sal_Bool                                                                        m_bToolBarSeparatorStartFound : 1;
150         ToolBoxHashMap                                                                  m_aToolBoxMap;
151         com::sun::star::uno::Reference< com::sun::star::container::XIndexContainer >    m_rItemContainer;
152         ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator >        m_xLocator;
153 
154         sal_Int32                                                                       m_nHashCode_Style_Radio;
155         sal_Int32                                                                       m_nHashCode_Style_Auto;
156         sal_Int32                                                                       m_nHashCode_Style_Left;
157         sal_Int32                                                                       m_nHashCode_Style_AutoSize;
158         sal_Int32                                                                       m_nHashCode_Style_DropDown;
159         sal_Int32                                                                       m_nHashCode_Style_Repeat;
160         sal_Int32                                                                       m_nHashCode_Style_DropDownOnly;
161         sal_Int32                                                                       m_nHashCode_Style_Text;
162         sal_Int32                                                                       m_nHashCode_Style_Image;
163 		rtl::OUString                                                                   m_aType;
164 		rtl::OUString                                                                   m_aLabel;
165 		rtl::OUString                                                                   m_aStyle;
166 		rtl::OUString                                                                   m_aHelpURL;
167         rtl::OUString                                                                   m_aTooltip;
168 		rtl::OUString                                                                   m_aIsVisible;
169 		rtl::OUString                                                                   m_aCommandURL;
170 };
171 
172 
173 class FWE_DLLPUBLIC OWriteToolBoxDocumentHandler : private ThreadHelpBase   // Struct for right initalization of lock member! Must be first of baseclasses.
174 {
175     public:
176             OWriteToolBoxDocumentHandler(
177             const ::com::sun::star::uno::Reference< com::sun::star::container::XIndexAccess >& rItemAccess,
178             ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler >& rDocumentHandler );
179         virtual ~OWriteToolBoxDocumentHandler();
180 
181         void WriteToolBoxDocument() throw
182 			( ::com::sun::star::xml::sax::SAXException,
183 			  ::com::sun::star::uno::RuntimeException );
184 
185 	protected:
186         virtual void WriteToolBoxItem( const rtl::OUString& aCommandURL, const rtl::OUString& aLabel, const rtl::OUString& aHelpURL, const rtl::OUString& aTooltip, sal_Int16 nStyle,
187                                        sal_Int16 nWidth, sal_Bool bVisible ) throw
188             ( ::com::sun::star::xml::sax::SAXException,
189               ::com::sun::star::uno::RuntimeException );
190 
191         virtual void WriteToolBoxSpace() throw
192             ( ::com::sun::star::xml::sax::SAXException,
193               ::com::sun::star::uno::RuntimeException );
194 
195         virtual void WriteToolBoxBreak() throw
196             ( ::com::sun::star::xml::sax::SAXException,
197               ::com::sun::star::uno::RuntimeException );
198 
199         virtual void WriteToolBoxSeparator() throw
200             ( ::com::sun::star::xml::sax::SAXException,
201               ::com::sun::star::uno::RuntimeException );
202 
203         ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler >    m_xWriteDocumentHandler;
204         ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList >      m_xEmptyList;
205         com::sun::star::uno::Reference< com::sun::star::container::XIndexAccess >           m_rItemAccess;
206         ::rtl::OUString                                                                     m_aXMLToolbarNS;
207         ::rtl::OUString                                                                     m_aXMLXlinkNS;
208         ::rtl::OUString                                                                     m_aAttributeType;
209         ::rtl::OUString                                                                     m_aAttributeURL;
210 };
211 
212 } // namespace framework
213 
214 #endif
215