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