Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : : #ifndef DOM_DOCUMENT_HXX
21 : : #define DOM_DOCUMENT_HXX
22 : :
23 : : #include <set>
24 : : #include <memory>
25 : :
26 : : #include <libxml/tree.h>
27 : :
28 : : #include <sal/types.h>
29 : :
30 : : #include <cppuhelper/implbase6.hxx>
31 : :
32 : : #include <com/sun/star/uno/Reference.h>
33 : : #include <com/sun/star/beans/StringPair.hpp>
34 : : #include <com/sun/star/xml/dom/XNode.hpp>
35 : : #include <com/sun/star/xml/dom/XAttr.hpp>
36 : : #include <com/sun/star/xml/dom/XElement.hpp>
37 : : #include <com/sun/star/xml/dom/XDOMImplementation.hpp>
38 : : #include <com/sun/star/xml/dom/events/XDocumentEvent.hpp>
39 : : #include <com/sun/star/xml/dom/events/XEvent.hpp>
40 : : #include <com/sun/star/xml/sax/XSAXSerializable.hpp>
41 : : #include <com/sun/star/xml/sax/XFastSAXSerializable.hpp>
42 : : #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
43 : : #include <com/sun/star/xml/sax/XFastDocumentHandler.hpp>
44 : : #include <com/sun/star/io/XActiveDataSource.hpp>
45 : : #include <com/sun/star/io/XActiveDataControl.hpp>
46 : : #include <com/sun/star/io/XOutputStream.hpp>
47 : : #include <com/sun/star/io/XStreamListener.hpp>
48 : :
49 : : #include "node.hxx"
50 : :
51 : :
52 : : using namespace std;
53 : : using ::rtl::OUString;
54 : : using namespace com::sun::star;
55 : : using namespace com::sun::star::uno;
56 : : using namespace com::sun::star::xml::sax;
57 : : using namespace com::sun::star::io;
58 : : using namespace com::sun::star::xml::dom;
59 : : using namespace com::sun::star::xml::dom::events;
60 : :
61 : : namespace DOM
62 : : {
63 : : namespace events {
64 : : class CEventDispatcher;
65 : : }
66 : :
67 : : class CElement;
68 : :
69 : : typedef ::cppu::ImplInheritanceHelper6<
70 : : CNode, XDocument, XDocumentEvent,
71 : : XActiveDataControl, XActiveDataSource,
72 : : XSAXSerializable, XFastSAXSerializable>
73 : : CDocument_Base;
74 : :
75 : : class CDocument
76 : : : public CDocument_Base
77 : : {
78 : :
79 : : private:
80 : : /// this Mutex is used for synchronization of all UNO wrapper
81 : : /// objects that belong to this document
82 : : ::osl::Mutex m_Mutex;
83 : : /// the libxml document: freed in destructor
84 : : /// => all UNO wrapper objects must keep the CDocument alive
85 : : xmlDocPtr const m_aDocPtr;
86 : :
87 : : // datacontrol/source state
88 : : typedef set< Reference< XStreamListener > > listenerlist_t;
89 : : listenerlist_t m_streamListeners;
90 : : Reference< XOutputStream > m_rOutputStream;
91 : :
92 : : typedef std::map< const xmlNodePtr,
93 : : ::std::pair< WeakReference<XNode>, CNode* > > nodemap_t;
94 : : nodemap_t m_NodeMap;
95 : :
96 : : ::std::auto_ptr<events::CEventDispatcher> const m_pEventDispatcher;
97 : :
98 : : CDocument(xmlDocPtr const pDocPtr);
99 : :
100 : :
101 : : public:
102 : : /// factory: only way to create instance!
103 : : static ::rtl::Reference<CDocument>
104 : : CreateCDocument(xmlDocPtr const pDoc);
105 : :
106 : : virtual ~CDocument();
107 : :
108 : : // needed by CXPathAPI
109 : 192960 : ::osl::Mutex & GetMutex() { return m_Mutex; }
110 : :
111 : : events::CEventDispatcher & GetEventDispatcher();
112 : : ::rtl::Reference< CElement > GetDocumentElement();
113 : :
114 : : /// get UNO wrapper instance for a libxml node
115 : : ::rtl::Reference<CNode> GetCNode(
116 : : xmlNodePtr const pNode, bool const bCreate = true);
117 : : /// remove a UNO wrapper instance
118 : : void RemoveCNode(xmlNodePtr const pNode, CNode const*const pCNode);
119 : :
120 : : virtual CDocument & GetOwnerDocument();
121 : :
122 : : virtual void saxify(const Reference< XDocumentHandler >& i_xHandler);
123 : :
124 : : virtual void fastSaxify( Context& rContext );
125 : :
126 : : virtual bool IsChildTypeAllowed(NodeType const nodeType);
127 : :
128 : : /**
129 : : Creates an Attr of the given name.
130 : : */
131 : : virtual Reference< XAttr > SAL_CALL createAttribute(const OUString& name)
132 : : throw (RuntimeException, DOMException);
133 : :
134 : : /**
135 : : Creates an attribute of the given qualified name and namespace URI.
136 : : */
137 : : virtual Reference< XAttr > SAL_CALL createAttributeNS(const OUString& namespaceURI, const OUString& qualifiedName)
138 : : throw (RuntimeException, DOMException);
139 : :
140 : : /**
141 : : Creates a CDATASection node whose value is the specified string.
142 : : */
143 : : virtual Reference< XCDATASection > SAL_CALL createCDATASection(const OUString& data)
144 : : throw (RuntimeException);
145 : :
146 : : /**
147 : : Creates a Comment node given the specified string.
148 : : */
149 : : virtual Reference< XComment > SAL_CALL createComment(const OUString& data)
150 : : throw (RuntimeException);
151 : :
152 : : /**
153 : : Creates an empty DocumentFragment object.
154 : : */
155 : : virtual Reference< XDocumentFragment > SAL_CALL createDocumentFragment()
156 : : throw (RuntimeException);
157 : :
158 : : /**
159 : : Creates an element of the type specified.
160 : : */
161 : : virtual Reference< XElement > SAL_CALL createElement(const OUString& tagName)
162 : : throw (RuntimeException, DOMException);
163 : :
164 : : /**
165 : : Creates an element of the given qualified name and namespace URI.
166 : : */
167 : : virtual Reference< XElement > SAL_CALL createElementNS(const OUString& namespaceURI, const OUString& qualifiedName)
168 : : throw (RuntimeException, DOMException);
169 : :
170 : : /**
171 : : Creates an EntityReference object.
172 : : */
173 : : virtual Reference< XEntityReference > SAL_CALL createEntityReference(const OUString& name)
174 : : throw (RuntimeException, DOMException);
175 : :
176 : : /**
177 : : Creates a ProcessingInstruction node given the specified name and
178 : : data strings.
179 : : */
180 : : virtual Reference< XProcessingInstruction > SAL_CALL createProcessingInstruction(
181 : : const OUString& target, const OUString& data)
182 : : throw (RuntimeException, DOMException);
183 : :
184 : : /**
185 : : Creates a Text node given the specified string.
186 : : */
187 : : virtual Reference< XText > SAL_CALL createTextNode(const OUString& data)
188 : : throw (RuntimeException);
189 : :
190 : : /**
191 : : The Document Type Declaration (see DocumentType) associated with this
192 : : document.
193 : : */
194 : : virtual Reference< XDocumentType > SAL_CALL getDoctype()
195 : : throw (RuntimeException);
196 : :
197 : : /**
198 : : This is a convenience attribute that allows direct access to the child
199 : : node that is the root element of the document.
200 : : */
201 : : virtual Reference< XElement > SAL_CALL getDocumentElement()
202 : : throw (RuntimeException);
203 : :
204 : : /**
205 : : Returns the Element whose ID is given by elementId.
206 : : */
207 : : virtual Reference< XElement > SAL_CALL getElementById(const OUString& elementId)
208 : : throw (RuntimeException);
209 : :
210 : : /**
211 : : Returns a NodeList of all the Elements with a given tag name in the
212 : : order in which they are encountered in a preorder traversal of the
213 : : Document tree.
214 : : */
215 : : virtual Reference< XNodeList > SAL_CALL getElementsByTagName(const OUString& tagname)
216 : : throw (RuntimeException);
217 : :
218 : : /**
219 : : Returns a NodeList of all the Elements with a given local name and
220 : : namespace URI in the order in which they are encountered in a preorder
221 : : traversal of the Document tree.
222 : : */
223 : : virtual Reference< XNodeList > SAL_CALL getElementsByTagNameNS(const OUString& namespaceURI, const OUString& localName)
224 : : throw (RuntimeException);
225 : :
226 : : /**
227 : : The DOMImplementation object that handles this document.
228 : : */
229 : : virtual Reference< XDOMImplementation > SAL_CALL getImplementation()
230 : : throw (RuntimeException);
231 : :
232 : : /**
233 : : Imports a node from another document to this document.
234 : : */
235 : : virtual Reference< XNode > SAL_CALL importNode(const Reference< XNode >& importedNode, sal_Bool deep)
236 : : throw (RuntimeException, DOMException);
237 : :
238 : : // XDocumentEvent
239 : : virtual Reference< XEvent > SAL_CALL createEvent(const OUString& eventType) throw (RuntimeException);
240 : :
241 : : // XActiveDataControl,
242 : : // see http://api.libreoffice.org/docs/common/ref/com/sun/star/io/XActiveDataControl.html
243 : : virtual void SAL_CALL addListener(const Reference< XStreamListener >& aListener ) throw (RuntimeException);
244 : : virtual void SAL_CALL removeListener(const Reference< XStreamListener >& aListener ) throw (RuntimeException);
245 : : virtual void SAL_CALL start() throw (RuntimeException);
246 : : virtual void SAL_CALL terminate() throw (RuntimeException);
247 : :
248 : : // XActiveDataSource
249 : : // see http://api.libreoffice.org/docs/common/ref/com/sun/star/io/XActiveDataSource.html
250 : : virtual void SAL_CALL setOutputStream( const Reference< XOutputStream >& aStream ) throw (RuntimeException);
251 : : virtual Reference< XOutputStream > SAL_CALL getOutputStream() throw (RuntimeException);
252 : :
253 : : // ---- resolve uno inheritance problems...
254 : : // overrides for XNode base
255 : : virtual OUString SAL_CALL getNodeName()
256 : : throw (RuntimeException);
257 : : virtual OUString SAL_CALL getNodeValue()
258 : : throw (RuntimeException);
259 : : virtual Reference< XNode > SAL_CALL cloneNode(sal_Bool deep)
260 : : throw (RuntimeException);
261 : : // --- delegation for XNde base.
262 : 3634 : virtual Reference< XNode > SAL_CALL appendChild(const Reference< XNode >& newChild)
263 : : throw (RuntimeException, DOMException)
264 : : {
265 : 3634 : return CNode::appendChild(newChild);
266 : : }
267 : 2 : virtual Reference< XNamedNodeMap > SAL_CALL getAttributes()
268 : : throw (RuntimeException)
269 : : {
270 : 2 : return CNode::getAttributes();
271 : : }
272 : 2 : virtual Reference< XNodeList > SAL_CALL getChildNodes()
273 : : throw (RuntimeException)
274 : : {
275 : 2 : return CNode::getChildNodes();
276 : : }
277 : 22664 : virtual Reference< XNode > SAL_CALL getFirstChild()
278 : : throw (RuntimeException)
279 : : {
280 : 22664 : return CNode::getFirstChild();
281 : : }
282 : 8 : virtual Reference< XNode > SAL_CALL getLastChild()
283 : : throw (RuntimeException)
284 : : {
285 : 8 : return CNode::getLastChild();
286 : : }
287 : 2 : virtual OUString SAL_CALL getLocalName()
288 : : throw (RuntimeException)
289 : : {
290 : 2 : return CNode::getLocalName();
291 : : }
292 : 2 : virtual OUString SAL_CALL getNamespaceURI()
293 : : throw (RuntimeException)
294 : : {
295 : 2 : return CNode::getNamespaceURI();
296 : : }
297 : 2 : virtual Reference< XNode > SAL_CALL getNextSibling()
298 : : throw (RuntimeException)
299 : : {
300 : 2 : return CNode::getNextSibling();
301 : : }
302 : 199 : virtual NodeType SAL_CALL getNodeType()
303 : : throw (RuntimeException)
304 : : {
305 : 199 : return CNode::getNodeType();
306 : : }
307 : 10284 : virtual Reference< XDocument > SAL_CALL getOwnerDocument()
308 : : throw (RuntimeException)
309 : : {
310 : 10284 : return CNode::getOwnerDocument();
311 : : }
312 : 2 : virtual Reference< XNode > SAL_CALL getParentNode()
313 : : throw (RuntimeException)
314 : : {
315 : 2 : return CNode::getParentNode();
316 : : }
317 : 2 : virtual OUString SAL_CALL getPrefix()
318 : : throw (RuntimeException)
319 : : {
320 : 2 : return CNode::getPrefix();
321 : : }
322 : 2 : virtual Reference< XNode > SAL_CALL getPreviousSibling()
323 : : throw (RuntimeException)
324 : : {
325 : 2 : return CNode::getPreviousSibling();
326 : : }
327 : 2 : virtual sal_Bool SAL_CALL hasAttributes()
328 : : throw (RuntimeException)
329 : : {
330 : 2 : return CNode::hasAttributes();
331 : : }
332 : 8 : virtual sal_Bool SAL_CALL hasChildNodes()
333 : : throw (RuntimeException)
334 : : {
335 : 8 : return CNode::hasChildNodes();
336 : : }
337 : 8 : virtual Reference< XNode > SAL_CALL insertBefore(
338 : : const Reference< XNode >& newChild, const Reference< XNode >& refChild)
339 : : throw (RuntimeException, DOMException)
340 : : {
341 : 8 : return CNode::insertBefore(newChild, refChild);
342 : : }
343 : 2 : virtual sal_Bool SAL_CALL isSupported(const OUString& feature, const OUString& ver)
344 : : throw (RuntimeException)
345 : : {
346 : 2 : return CNode::isSupported(feature, ver);
347 : : }
348 : 2 : virtual void SAL_CALL normalize()
349 : : throw (RuntimeException)
350 : : {
351 : 2 : CNode::normalize();
352 : 2 : }
353 : 6 : virtual Reference< XNode > SAL_CALL removeChild(const Reference< XNode >& oldChild)
354 : : throw (RuntimeException, DOMException)
355 : : {
356 : 6 : return CNode::removeChild(oldChild);
357 : : }
358 : 10 : virtual Reference< XNode > SAL_CALL replaceChild(
359 : : const Reference< XNode >& newChild, const Reference< XNode >& oldChild)
360 : : throw (RuntimeException, DOMException)
361 : : {
362 : 10 : return CNode::replaceChild(newChild, oldChild);
363 : : }
364 : 2 : virtual void SAL_CALL setNodeValue(const OUString& nodeValue)
365 : : throw (RuntimeException, DOMException)
366 : : {
367 : 2 : return CNode::setNodeValue(nodeValue);
368 : : }
369 : 2 : virtual void SAL_CALL setPrefix(const OUString& prefix)
370 : : throw (RuntimeException, DOMException)
371 : : {
372 : 2 : return CNode::setPrefix(prefix);
373 : : }
374 : :
375 : : // ::com::sun::star::xml::sax::XSAXSerializable
376 : : virtual void SAL_CALL serialize(
377 : : const Reference< XDocumentHandler >& i_xHandler,
378 : : const Sequence< beans::StringPair >& i_rNamespaces)
379 : : throw (RuntimeException, SAXException);
380 : :
381 : : // ::com::sun::star::xml::sax::XFastSAXSerializable
382 : : virtual void SAL_CALL fastSerialize( const Reference< XFastDocumentHandler >& handler,
383 : : const Reference< XFastTokenHandler >& tokenHandler,
384 : : const Sequence< beans::StringPair >& i_rNamespaces,
385 : : const Sequence< beans::Pair< rtl::OUString, sal_Int32 > >& namespaces )
386 : : throw (SAXException, RuntimeException);
387 : : };
388 : : }
389 : :
390 : : #endif
391 : :
392 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|