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 DOM_SAXBUILDER_HXX 29 #define DOM_SAXBUILDER_HXX 30 31 #include <stack> 32 #include <map> 33 34 #include <sal/types.h> 35 #include <osl/mutex.hxx> 36 #include <cppuhelper/implbase3.hxx> 37 #include <com/sun/star/uno/Reference.h> 38 #include <com/sun/star/uno/Sequence.h> 39 40 #include <com/sun/star/uno/XInterface.hpp> 41 #include <com/sun/star/uno/Exception.hpp> 42 #include <com/sun/star/xml/dom/XSAXDocumentBuilder.hpp> 43 #include <com/sun/star/xml/dom/SAXDocumentBuilderState.hpp> 44 #include <com/sun/star/xml/dom/XDocument.hpp> 45 #include <com/sun/star/xml/dom/XDocumentFragment.hpp> 46 #include <com/sun/star/xml/sax/XDocumentHandler.hpp> 47 #include <com/sun/star/xml/sax/XLocator.hpp> 48 #include <com/sun/star/xml/sax/XAttributeList.hpp> 49 #include <com/sun/star/lang/XServiceInfo.hpp> 50 #include <com/sun/star/lang/XSingleServiceFactory.hpp> 51 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 52 53 using ::rtl::OUString; 54 using namespace com::sun::star::uno; 55 using namespace com::sun::star::xml::dom; 56 using namespace com::sun::star::xml::sax; 57 58 using com::sun::star::lang::XServiceInfo; 59 using com::sun::star::lang::XSingleServiceFactory; 60 using com::sun::star::lang::XMultiServiceFactory; 61 62 namespace DOM 63 { 64 65 typedef std::stack< Reference< XNode > > NodeStack; 66 typedef std::map< OUString, OUString > NSMap; 67 typedef std::map< OUString, OUString > AttrMap; 68 typedef std::stack< NSMap > NSStack; 69 70 class CSAXDocumentBuilder 71 : public ::cppu::WeakImplHelper3< XDocumentHandler, XSAXDocumentBuilder, XServiceInfo > 72 { 73 74 private: 75 ::osl::Mutex m_Mutex; 76 const Reference< XMultiServiceFactory > m_aServiceManager; 77 78 SAXDocumentBuilderState m_aState; 79 NodeStack m_aNodeStack; 80 NSStack m_aNSStack; 81 82 OUString resolvePrefix(const OUString& aPrefix); 83 84 Reference< XDocument > m_aDocument; 85 Reference< XDocumentFragment > m_aFragment; 86 Reference< XLocator > m_aLocator; 87 88 89 public: 90 91 // call for factory 92 static Reference< XInterface > getInstance(const Reference < XMultiServiceFactory >& xFactory); 93 94 // static helpers for service info and component management 95 static const char* aImplementationName; 96 static const char* aSupportedServiceNames[]; 97 static OUString _getImplementationName(); 98 static Sequence< OUString > _getSupportedServiceNames(); 99 static Reference< XInterface > _getInstance(const Reference< XMultiServiceFactory >& rSMgr); 100 101 CSAXDocumentBuilder(const Reference< XMultiServiceFactory >& mgr); 102 103 // XServiceInfo 104 virtual OUString SAL_CALL getImplementationName() 105 throw (RuntimeException); 106 virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) 107 throw (RuntimeException); 108 virtual Sequence< OUString > SAL_CALL getSupportedServiceNames () 109 throw (RuntimeException); 110 111 // XDocumentHandler 112 virtual void SAL_CALL startDocument() 113 throw( RuntimeException, com::sun::star::xml::sax::SAXException ); 114 virtual void SAL_CALL endDocument() 115 throw( RuntimeException, com::sun::star::xml::sax::SAXException ); 116 virtual void SAL_CALL startElement( const OUString& aName, 117 const Reference< XAttributeList >& xAttribs ) 118 throw( RuntimeException, com::sun::star::xml::sax::SAXException ); 119 virtual void SAL_CALL endElement( const OUString& aName ) 120 throw( RuntimeException, com::sun::star::xml::sax::SAXException ); 121 virtual void SAL_CALL characters( const OUString& aChars ) 122 throw( RuntimeException, com::sun::star::xml::sax::SAXException ); 123 virtual void SAL_CALL ignorableWhitespace( const OUString& aWhitespaces ) 124 throw( RuntimeException, com::sun::star::xml::sax::SAXException ); 125 virtual void SAL_CALL processingInstruction( const OUString& aTarget, 126 const OUString& aData ) 127 throw( RuntimeException, com::sun::star::xml::sax::SAXException ); 128 virtual void SAL_CALL setDocumentLocator( const Reference< XLocator >& xLocator ) 129 throw( RuntimeException, com::sun::star::xml::sax::SAXException ); 130 131 132 // XSAXDocumentBuilder 133 virtual SAXDocumentBuilderState SAL_CALL getState() 134 throw (RuntimeException); 135 virtual void SAL_CALL reset() 136 throw (RuntimeException); 137 virtual Reference< XDocument > SAL_CALL getDocument() 138 throw (RuntimeException); 139 virtual Reference< XDocumentFragment > SAL_CALL getDocumentFragment() 140 throw (RuntimeException); 141 virtual void SAL_CALL startDocumentFragment(const Reference< XDocument >& ownerDoc) 142 throw (RuntimeException); 143 virtual void SAL_CALL endDocumentFragment() 144 throw (RuntimeException); 145 146 147 }; 148 } 149 150 #endif 151