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_DOCUMENTBUILDER_HXX 25 #define DOM_DOCUMENTBUILDER_HXX 26 27 #include <sal/types.h> 28 29 #include <cppuhelper/implbase2.hxx> 30 31 #include <com/sun/star/uno/Reference.h> 32 #include <com/sun/star/uno/Sequence.h> 33 34 #include <com/sun/star/uno/XInterface.hpp> 35 #include <com/sun/star/xml/dom/XDocumentBuilder.hpp> 36 #include <com/sun/star/xml/dom/XDocument.hpp> 37 #include <com/sun/star/xml/dom/XDOMImplementation.hpp> 38 #include <com/sun/star/xml/sax/XEntityResolver.hpp> 39 #include <com/sun/star/xml/sax/XErrorHandler.hpp> 40 #include <com/sun/star/xml/sax/SAXParseException.hpp> 41 #include <com/sun/star/io/XInputStream.hpp> 42 #include <com/sun/star/io/IOException.hpp> 43 #include <com/sun/star/lang/XServiceInfo.hpp> 44 #include <com/sun/star/lang/XMultiServiceFactory.hpp> 45 46 47 using ::rtl::OUString; 48 using namespace com::sun::star::uno; 49 using namespace com::sun::star::lang; 50 using namespace com::sun::star::xml::dom; 51 using namespace com::sun::star::xml::sax; 52 using namespace com::sun::star::io; 53 54 namespace DOM 55 { 56 typedef ::cppu::WeakImplHelper2 57 < XDocumentBuilder 58 , ::com::sun::star::lang::XServiceInfo 59 > CDocumentBuilder_Base; 60 61 class CDocumentBuilder 62 : public CDocumentBuilder_Base 63 { 64 private: 65 ::osl::Mutex m_Mutex; 66 Reference< ::com::sun::star::lang::XMultiServiceFactory > const 67 m_xFactory; 68 Reference< XEntityResolver > m_xEntityResolver; 69 Reference< XErrorHandler > m_xErrorHandler; 70 71 public: 72 73 // ctor 74 CDocumentBuilder( 75 Reference< ::com::sun::star::lang::XMultiServiceFactory > const& 76 xFactory); 77 78 // call for factory 79 static Reference< XInterface > getInstance( 80 Reference< ::com::sun::star::lang::XMultiServiceFactory > const& 81 xFactory); 82 83 // static helpers for service info and component management 84 static const char* aImplementationName; 85 static const char* aSupportedServiceNames[]; 86 static OUString _getImplementationName(); 87 static Sequence< OUString > _getSupportedServiceNames(); 88 static Reference< XInterface > _getInstance( 89 Reference< ::com::sun::star::lang::XMultiServiceFactory > const& 90 rSMgr); 91 92 // XServiceInfo 93 virtual OUString SAL_CALL getImplementationName() 94 throw (RuntimeException); 95 virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) 96 throw (RuntimeException); 97 virtual Sequence< OUString > SAL_CALL getSupportedServiceNames () 98 throw (RuntimeException); 99 100 /** 101 Obtain an instance of a DOMImplementation object. 102 */ 103 virtual Reference< XDOMImplementation > SAL_CALL getDOMImplementation() 104 throw (RuntimeException); 105 106 /** 107 Indicates whether or not this parser is configured to understand 108 namespaces. 109 */ 110 virtual sal_Bool SAL_CALL isNamespaceAware() 111 throw (RuntimeException); 112 113 /** 114 Indicates whether or not this parser is configured to validate XML 115 documents. 116 */ 117 virtual sal_Bool SAL_CALL isValidating() 118 throw (RuntimeException); 119 120 /** 121 Obtain a new instance of a DOM Document object to build a DOM tree 122 with. 123 */ 124 virtual Reference< XDocument > SAL_CALL newDocument() 125 throw (RuntimeException); 126 127 /** 128 Parse the content of the given InputStream as an XML document and 129 return a new DOM Document object. 130 */ 131 virtual Reference< XDocument > SAL_CALL parse(const Reference< XInputStream >& is) 132 throw (RuntimeException, SAXParseException, IOException); 133 134 /** 135 Parse the content of the given URI as an XML document and return 136 a new DOM Document object. 137 */ 138 virtual Reference< XDocument > SAL_CALL parseURI(const OUString& uri) 139 throw (RuntimeException, SAXParseException, IOException); 140 141 /** 142 Specify the EntityResolver to be used to resolve entities present 143 in the XML document to be parsed. 144 */ 145 virtual void SAL_CALL setEntityResolver(const Reference< XEntityResolver >& er) 146 throw (RuntimeException); 147 148 virtual Reference< XEntityResolver > SAL_CALL getEntityResolver() 149 throw (RuntimeException); 150 151 152 /** 153 Specify the ErrorHandler to be used to report errors present in 154 the XML document to be parsed. 155 */ 156 virtual void SAL_CALL setErrorHandler(const Reference< XErrorHandler >& eh) 157 throw (RuntimeException); 158 }; 159 } 160 161 #endif 162