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 virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName); 95 virtual Sequence< OUString > SAL_CALL getSupportedServiceNames (); 96 97 /** 98 Obtain an instance of a DOMImplementation object. 99 */ 100 virtual Reference< XDOMImplementation > SAL_CALL getDOMImplementation(); 101 102 /** 103 Indicates whether or not this parser is configured to understand 104 namespaces. 105 */ 106 virtual sal_Bool SAL_CALL isNamespaceAware(); 107 108 /** 109 Indicates whether or not this parser is configured to validate XML 110 documents. 111 */ 112 virtual sal_Bool SAL_CALL isValidating(); 113 114 /** 115 Obtain a new instance of a DOM Document object to build a DOM tree 116 with. 117 */ 118 virtual Reference< XDocument > SAL_CALL newDocument(); 119 120 /** 121 Parse the content of the given InputStream as an XML document and 122 return a new DOM Document object. 123 */ 124 virtual Reference< XDocument > SAL_CALL parse(const Reference< XInputStream >& is); 125 126 /** 127 Parse the content of the given URI as an XML document and return 128 a new DOM Document object. 129 */ 130 virtual Reference< XDocument > SAL_CALL parseURI(const OUString& uri); 131 132 /** 133 Specify the EntityResolver to be used to resolve entities present 134 in the XML document to be parsed. 135 */ 136 virtual void SAL_CALL setEntityResolver(const Reference< XEntityResolver >& er); 137 138 virtual Reference< XEntityResolver > SAL_CALL getEntityResolver(); 139 140 141 /** 142 Specify the ErrorHandler to be used to report errors present in 143 the XML document to be parsed. 144 */ 145 virtual void SAL_CALL setErrorHandler(const Reference< XErrorHandler >& eh); 146 }; 147 } 148 149 #endif 150