bump product version to 4.1.6.2
[LibreOffice.git] / unoxml / source / dom / document.hxx
blob97c08cfafc2c759cbc2a3a54f6620565336cb4af
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef DOM_DOCUMENT_HXX
21 #define DOM_DOCUMENT_HXX
23 #include <set>
24 #include <memory>
26 #include <libxml/tree.h>
28 #include <sal/types.h>
30 #include <cppuhelper/implbase6.hxx>
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>
49 #include "node.hxx"
52 using namespace std;
53 using namespace com::sun::star;
54 using namespace com::sun::star::uno;
55 using namespace com::sun::star::xml::sax;
56 using namespace com::sun::star::io;
57 using namespace com::sun::star::xml::dom;
58 using namespace com::sun::star::xml::dom::events;
60 namespace DOM
62 namespace events {
63 class CEventDispatcher;
66 class CElement;
68 typedef ::cppu::ImplInheritanceHelper6<
69 CNode, XDocument, XDocumentEvent,
70 XActiveDataControl, XActiveDataSource,
71 XSAXSerializable, XFastSAXSerializable>
72 CDocument_Base;
74 class CDocument
75 : public CDocument_Base
78 private:
79 /// this Mutex is used for synchronization of all UNO wrapper
80 /// objects that belong to this document
81 ::osl::Mutex m_Mutex;
82 /// the libxml document: freed in destructor
83 /// => all UNO wrapper objects must keep the CDocument alive
84 xmlDocPtr const m_aDocPtr;
86 // datacontrol/source state
87 typedef set< Reference< XStreamListener > > listenerlist_t;
88 listenerlist_t m_streamListeners;
89 Reference< XOutputStream > m_rOutputStream;
91 typedef std::map< const xmlNodePtr,
92 ::std::pair< WeakReference<XNode>, CNode* > > nodemap_t;
93 nodemap_t m_NodeMap;
95 ::std::auto_ptr<events::CEventDispatcher> const m_pEventDispatcher;
97 CDocument(xmlDocPtr const pDocPtr);
100 public:
101 /// factory: only way to create instance!
102 static ::rtl::Reference<CDocument>
103 CreateCDocument(xmlDocPtr const pDoc);
105 virtual ~CDocument();
107 // needed by CXPathAPI
108 ::osl::Mutex & GetMutex() { return m_Mutex; }
110 events::CEventDispatcher & GetEventDispatcher();
111 ::rtl::Reference< CElement > GetDocumentElement();
113 /// get UNO wrapper instance for a libxml node
114 ::rtl::Reference<CNode> GetCNode(
115 xmlNodePtr const pNode, bool const bCreate = true);
116 /// remove a UNO wrapper instance
117 void RemoveCNode(xmlNodePtr const pNode, CNode const*const pCNode);
119 virtual CDocument & GetOwnerDocument();
121 virtual void saxify(const Reference< XDocumentHandler >& i_xHandler);
123 virtual void fastSaxify( Context& rContext );
125 virtual bool IsChildTypeAllowed(NodeType const nodeType);
128 Creates an Attr of the given name.
130 virtual Reference< XAttr > SAL_CALL createAttribute(const OUString& name)
131 throw (RuntimeException, DOMException);
134 Creates an attribute of the given qualified name and namespace URI.
136 virtual Reference< XAttr > SAL_CALL createAttributeNS(const OUString& namespaceURI, const OUString& qualifiedName)
137 throw (RuntimeException, DOMException);
140 Creates a CDATASection node whose value is the specified string.
142 virtual Reference< XCDATASection > SAL_CALL createCDATASection(const OUString& data)
143 throw (RuntimeException);
146 Creates a Comment node given the specified string.
148 virtual Reference< XComment > SAL_CALL createComment(const OUString& data)
149 throw (RuntimeException);
152 Creates an empty DocumentFragment object.
154 virtual Reference< XDocumentFragment > SAL_CALL createDocumentFragment()
155 throw (RuntimeException);
158 Creates an element of the type specified.
160 virtual Reference< XElement > SAL_CALL createElement(const OUString& tagName)
161 throw (RuntimeException, DOMException);
164 Creates an element of the given qualified name and namespace URI.
166 virtual Reference< XElement > SAL_CALL createElementNS(const OUString& namespaceURI, const OUString& qualifiedName)
167 throw (RuntimeException, DOMException);
170 Creates an EntityReference object.
172 virtual Reference< XEntityReference > SAL_CALL createEntityReference(const OUString& name)
173 throw (RuntimeException, DOMException);
176 Creates a ProcessingInstruction node given the specified name and
177 data strings.
179 virtual Reference< XProcessingInstruction > SAL_CALL createProcessingInstruction(
180 const OUString& target, const OUString& data)
181 throw (RuntimeException, DOMException);
184 Creates a Text node given the specified string.
186 virtual Reference< XText > SAL_CALL createTextNode(const OUString& data)
187 throw (RuntimeException);
190 The Document Type Declaration (see DocumentType) associated with this
191 document.
193 virtual Reference< XDocumentType > SAL_CALL getDoctype()
194 throw (RuntimeException);
197 This is a convenience attribute that allows direct access to the child
198 node that is the root element of the document.
200 virtual Reference< XElement > SAL_CALL getDocumentElement()
201 throw (RuntimeException);
204 Returns the Element whose ID is given by elementId.
206 virtual Reference< XElement > SAL_CALL getElementById(const OUString& elementId)
207 throw (RuntimeException);
210 Returns a NodeList of all the Elements with a given tag name in the
211 order in which they are encountered in a preorder traversal of the
212 Document tree.
214 virtual Reference< XNodeList > SAL_CALL getElementsByTagName(const OUString& tagname)
215 throw (RuntimeException);
218 Returns a NodeList of all the Elements with a given local name and
219 namespace URI in the order in which they are encountered in a preorder
220 traversal of the Document tree.
222 virtual Reference< XNodeList > SAL_CALL getElementsByTagNameNS(const OUString& namespaceURI, const OUString& localName)
223 throw (RuntimeException);
226 The DOMImplementation object that handles this document.
228 virtual Reference< XDOMImplementation > SAL_CALL getImplementation()
229 throw (RuntimeException);
232 Imports a node from another document to this document.
234 virtual Reference< XNode > SAL_CALL importNode(const Reference< XNode >& importedNode, sal_Bool deep)
235 throw (RuntimeException, DOMException);
237 // XDocumentEvent
238 virtual Reference< XEvent > SAL_CALL createEvent(const OUString& eventType) throw (RuntimeException);
240 // XActiveDataControl,
241 // see http://api.libreoffice.org/docs/common/ref/com/sun/star/io/XActiveDataControl.html
242 virtual void SAL_CALL addListener(const Reference< XStreamListener >& aListener ) throw (RuntimeException);
243 virtual void SAL_CALL removeListener(const Reference< XStreamListener >& aListener ) throw (RuntimeException);
244 virtual void SAL_CALL start() throw (RuntimeException);
245 virtual void SAL_CALL terminate() throw (RuntimeException);
247 // XActiveDataSource
248 // see http://api.libreoffice.org/docs/common/ref/com/sun/star/io/XActiveDataSource.html
249 virtual void SAL_CALL setOutputStream( const Reference< XOutputStream >& aStream ) throw (RuntimeException);
250 virtual Reference< XOutputStream > SAL_CALL getOutputStream() throw (RuntimeException);
252 // ---- resolve uno inheritance problems...
253 // overrides for XNode base
254 virtual OUString SAL_CALL getNodeName()
255 throw (RuntimeException);
256 virtual OUString SAL_CALL getNodeValue()
257 throw (RuntimeException);
258 virtual Reference< XNode > SAL_CALL cloneNode(sal_Bool deep)
259 throw (RuntimeException);
260 // --- delegation for XNde base.
261 virtual Reference< XNode > SAL_CALL appendChild(const Reference< XNode >& newChild)
262 throw (RuntimeException, DOMException)
264 return CNode::appendChild(newChild);
266 virtual Reference< XNamedNodeMap > SAL_CALL getAttributes()
267 throw (RuntimeException)
269 return CNode::getAttributes();
271 virtual Reference< XNodeList > SAL_CALL getChildNodes()
272 throw (RuntimeException)
274 return CNode::getChildNodes();
276 virtual Reference< XNode > SAL_CALL getFirstChild()
277 throw (RuntimeException)
279 return CNode::getFirstChild();
281 virtual Reference< XNode > SAL_CALL getLastChild()
282 throw (RuntimeException)
284 return CNode::getLastChild();
286 virtual OUString SAL_CALL getLocalName()
287 throw (RuntimeException)
289 return CNode::getLocalName();
291 virtual OUString SAL_CALL getNamespaceURI()
292 throw (RuntimeException)
294 return CNode::getNamespaceURI();
296 virtual Reference< XNode > SAL_CALL getNextSibling()
297 throw (RuntimeException)
299 return CNode::getNextSibling();
301 virtual NodeType SAL_CALL getNodeType()
302 throw (RuntimeException)
304 return CNode::getNodeType();
306 virtual Reference< XDocument > SAL_CALL getOwnerDocument()
307 throw (RuntimeException)
309 return CNode::getOwnerDocument();
311 virtual Reference< XNode > SAL_CALL getParentNode()
312 throw (RuntimeException)
314 return CNode::getParentNode();
316 virtual OUString SAL_CALL getPrefix()
317 throw (RuntimeException)
319 return CNode::getPrefix();
321 virtual Reference< XNode > SAL_CALL getPreviousSibling()
322 throw (RuntimeException)
324 return CNode::getPreviousSibling();
326 virtual sal_Bool SAL_CALL hasAttributes()
327 throw (RuntimeException)
329 return CNode::hasAttributes();
331 virtual sal_Bool SAL_CALL hasChildNodes()
332 throw (RuntimeException)
334 return CNode::hasChildNodes();
336 virtual Reference< XNode > SAL_CALL insertBefore(
337 const Reference< XNode >& newChild, const Reference< XNode >& refChild)
338 throw (RuntimeException, DOMException)
340 return CNode::insertBefore(newChild, refChild);
342 virtual sal_Bool SAL_CALL isSupported(const OUString& feature, const OUString& ver)
343 throw (RuntimeException)
345 return CNode::isSupported(feature, ver);
347 virtual void SAL_CALL normalize()
348 throw (RuntimeException)
350 CNode::normalize();
352 virtual Reference< XNode > SAL_CALL removeChild(const Reference< XNode >& oldChild)
353 throw (RuntimeException, DOMException)
355 return CNode::removeChild(oldChild);
357 virtual Reference< XNode > SAL_CALL replaceChild(
358 const Reference< XNode >& newChild, const Reference< XNode >& oldChild)
359 throw (RuntimeException, DOMException)
361 return CNode::replaceChild(newChild, oldChild);
363 virtual void SAL_CALL setNodeValue(const OUString& nodeValue)
364 throw (RuntimeException, DOMException)
366 return CNode::setNodeValue(nodeValue);
368 virtual void SAL_CALL setPrefix(const OUString& prefix)
369 throw (RuntimeException, DOMException)
371 return CNode::setPrefix(prefix);
374 // ::com::sun::star::xml::sax::XSAXSerializable
375 virtual void SAL_CALL serialize(
376 const Reference< XDocumentHandler >& i_xHandler,
377 const Sequence< beans::StringPair >& i_rNamespaces)
378 throw (RuntimeException, SAXException);
380 // ::com::sun::star::xml::sax::XFastSAXSerializable
381 virtual void SAL_CALL fastSerialize( const Reference< XFastDocumentHandler >& handler,
382 const Reference< XFastTokenHandler >& tokenHandler,
383 const Sequence< beans::StringPair >& i_rNamespaces,
384 const Sequence< beans::Pair< OUString, sal_Int32 > >& namespaces )
385 throw (SAXException, RuntimeException);
389 #endif
391 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */