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_EVENTSDOCUMENTHANDLER_HXX_ 29 #define __FRAMEWORK_XML_EVENTSDOCUMENTHANDLER_HXX_ 30 31 #ifndef __FRAMEWORK_XML_TOOLBOXCONFIGURATION_HXX_ 32 #include <framework/eventsconfiguration.hxx> 33 #endif 34 35 //_________________________________________________________________________________________________________________ 36 // interface includes 37 //_________________________________________________________________________________________________________________ 38 39 #ifndef __COM_SUN_STAR_XML_SAX_XDOCUMENTHANDLER_HPP_ 40 #include <com/sun/star/xml/sax/XDocumentHandler.hpp> 41 #endif 42 43 //_________________________________________________________________________________________________________________ 44 // other includes 45 //_________________________________________________________________________________________________________________ 46 #include <threadhelp/threadhelpbase.hxx> 47 #include <rtl/ustring.hxx> 48 #include <cppuhelper/implbase1.hxx> 49 50 #include <hash_map> 51 #include <stdtypes.h> 52 53 #include <framework/fwedllapi.h> 54 //_________________________________________________________________________________________________________________ 55 // namespace 56 //_________________________________________________________________________________________________________________ 57 58 namespace framework{ 59 60 //***************************************************************************************************************** 61 // Hash code function for using in all hash maps of follow implementation. 62 63 class FWE_DLLPUBLIC OReadEventsDocumentHandler : private ThreadHelpBase, // Struct for right initalization of lock member! Must be first of baseclasses. 64 public ::cppu::WeakImplHelper1< ::com::sun::star::xml::sax::XDocumentHandler > 65 { 66 public: 67 enum Events_XML_Entry 68 { 69 EV_ELEMENT_EVENTS, 70 EV_ELEMENT_EVENT, 71 EV_ATTRIBUTE_TYPE, 72 EV_ATTRIBUTE_NAME, 73 XL_ATTRIBUTE_HREF, 74 XL_ATTRIBUTE_TYPE, 75 EV_ATTRIBUTE_MACRONAME, 76 EV_ATTRIBUTE_LIBRARY, 77 EV_XML_ENTRY_COUNT 78 }; 79 80 enum Event_XML_Namespace 81 { 82 EV_NS_EVENT, 83 EV_NS_XLINK, 84 EV_XML_NAMESPACES_COUNT 85 }; 86 87 OReadEventsDocumentHandler( EventsConfig& aItems ); 88 89 90 // XDocumentHandler 91 virtual void SAL_CALL startDocument(void) 92 throw ( ::com::sun::star::xml::sax::SAXException, 93 ::com::sun::star::uno::RuntimeException ); 94 95 virtual void SAL_CALL endDocument(void) 96 throw( ::com::sun::star::xml::sax::SAXException, 97 ::com::sun::star::uno::RuntimeException ); 98 99 virtual void SAL_CALL startElement( 100 const rtl::OUString& aName, 101 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > &xAttribs) 102 throw( ::com::sun::star::xml::sax::SAXException, 103 ::com::sun::star::uno::RuntimeException ); 104 105 virtual void SAL_CALL endElement(const rtl::OUString& aName) 106 throw( ::com::sun::star::xml::sax::SAXException, 107 ::com::sun::star::uno::RuntimeException ); 108 109 virtual void SAL_CALL characters(const rtl::OUString& aChars) 110 throw( ::com::sun::star::xml::sax::SAXException, 111 ::com::sun::star::uno::RuntimeException ); 112 113 virtual void SAL_CALL ignorableWhitespace(const rtl::OUString& aWhitespaces) 114 throw( ::com::sun::star::xml::sax::SAXException, 115 ::com::sun::star::uno::RuntimeException ); 116 117 virtual void SAL_CALL processingInstruction(const rtl::OUString& aTarget, 118 const rtl::OUString& aData) 119 throw( ::com::sun::star::xml::sax::SAXException, 120 ::com::sun::star::uno::RuntimeException ); 121 122 virtual void SAL_CALL setDocumentLocator( 123 const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator > &xLocator) 124 throw( ::com::sun::star::xml::sax::SAXException, 125 ::com::sun::star::uno::RuntimeException ); 126 127 protected: 128 virtual ~OReadEventsDocumentHandler(); 129 130 private: 131 ::rtl::OUString getErrorLineString(); 132 133 class EventsHashMap : public ::std::hash_map< ::rtl::OUString , 134 Events_XML_Entry , 135 OUStringHashCode , 136 ::std::equal_to< ::rtl::OUString > > 137 { 138 public: 139 inline void free() 140 { 141 EventsHashMap().swap( *this ); 142 } 143 }; 144 145 sal_Bool m_bEventsStartFound; 146 sal_Bool m_bEventsEndFound; 147 sal_Bool m_bEventStartFound; 148 EventsHashMap m_aEventsMap; 149 EventsConfig& m_aEventItems; 150 ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XLocator > m_xLocator; 151 }; 152 153 class FWE_DLLPUBLIC OWriteEventsDocumentHandler : private ThreadHelpBase // Struct for right initalization of lock member! Must be first of baseclasses. 154 { 155 public: 156 OWriteEventsDocumentHandler( 157 const EventsConfig& aItems, 158 ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > ); 159 virtual ~OWriteEventsDocumentHandler(); 160 161 void WriteEventsDocument() throw 162 ( ::com::sun::star::xml::sax::SAXException, 163 ::com::sun::star::uno::RuntimeException ); 164 165 protected: 166 virtual void WriteEvent( 167 const ::rtl::OUString& aEventName, 168 const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aPropertyValue ) throw 169 ( ::com::sun::star::xml::sax::SAXException, 170 ::com::sun::star::uno::RuntimeException ); 171 172 const EventsConfig& m_aItems; 173 ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XDocumentHandler > m_xWriteDocumentHandler; 174 ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XAttributeList > m_xEmptyList; 175 ::rtl::OUString m_aXMLEventNS; 176 ::rtl::OUString m_aXMLXlinkNS; 177 ::rtl::OUString m_aAttributeType; 178 ::rtl::OUString m_aAttributeURL; 179 ::rtl::OUString m_aAttributeLanguage; 180 ::rtl::OUString m_aAttributeLinkType; 181 ::rtl::OUString m_aAttributeMacroName; 182 ::rtl::OUString m_aAttributeLibrary; 183 ::rtl::OUString m_aAttributeName; 184 }; 185 186 } // namespace framework 187 188 #endif 189