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