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