LibreOffice Module unoxml (master) 1
node.hxx
Go to the documentation of this file.
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#pragma once
21
22#include <libxml/tree.h>
23
24#include <sal/types.h>
25#include <rtl/ref.hxx>
26#include <rtl/string.hxx>
27#include <rtl/ustring.hxx>
28
30
31#include <sax/fastattribs.hxx>
32
33#include <com/sun/star/uno/Reference.h>
34#include <com/sun/star/uno/Sequence.h>
35#include <com/sun/star/xml/dom/XNode.hpp>
36#include <com/sun/star/xml/dom/XNodeList.hpp>
37#include <com/sun/star/xml/dom/XNamedNodeMap.hpp>
38#include <com/sun/star/xml/dom/NodeType.hpp>
39#include <com/sun/star/xml/dom/events/XEventTarget.hpp>
40#include <com/sun/star/xml/dom/events/XEvent.hpp>
41#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
42#include <com/sun/star/xml/sax/XFastDocumentHandler.hpp>
43
44#include <unordered_map>
45
46namespace DOM
47{
48 struct Context
49 {
50 Context( const css::uno::Reference< css::xml::sax::XFastDocumentHandler >& i_xHandler,
52 maNamespaces( 1, std::vector<Namespace>() ),
53 maNamespaceMap(101),
54 mxAttribList(new sax_fastparser::FastAttributeList(pTokenHandler)),
55 mxCurrentHandler(i_xHandler),
56 mxDocHandler(i_xHandler),
57 mxTokenHandler(pTokenHandler)
58 {}
59
60 struct Namespace
61 {
62 OString maPrefix;
63 sal_Int32 mnToken;
64
65 const OString& getPrefix() const { return maPrefix; }
66 };
67
68 typedef std::vector< std::vector<Namespace> > NamespaceVectorType;
69 typedef std::unordered_map< OUString, sal_Int32 > NamespaceMapType;
70
75 css::uno::Reference<css::xml::sax::XFastContextHandler> mxCurrentHandler;
76 css::uno::Reference<css::xml::sax::XFastDocumentHandler> mxDocHandler;
78 };
79
80 void pushContext(Context& io_rContext);
81 void popContext(Context& io_rContext);
82
83 sal_Int32 getTokenWithPrefix( const Context& rContext, const char* xPrefix, const char* xName );
84 sal_Int32 getToken( const Context& rContext, const char* xName );
85
87 void addNamespaces(Context& io_rContext, xmlNodePtr pNode);
88
89 class CDocument;
90
91 class SAL_LOPLUGIN_ANNOTATE("crosscast") CNode
92 : public cppu::WeakImplHelper< css::xml::dom::XNode, css::xml::dom::events::XEventTarget >
93 {
94 friend class CDocument;
95 friend class CElement;
96 friend class CAttributesMap;
97
98 private:
99 bool m_bUnlinked;
100
101 protected:
102 css::xml::dom::NodeType const m_aNodeType;
104 xmlNodePtr m_aNodePtr;
105
107 ::osl::Mutex & m_rMutex;
108
109 // for initialization by classes derived through ImplInheritanceHelper
110 CNode(CDocument const& rDocument, ::osl::Mutex const& rMutex,
111 css::xml::dom::NodeType const& reNodeType, xmlNodePtr const& rpNode);
112 void invalidate();
113
114 void dispatchSubtreeModified();
115
116 void checkNoParent(css::uno::Reference< css::xml::dom::XNode >const& xNode);
117
118 static void checkNoParent(const xmlNodePtr pNode);
119
120 void checkSameOwner(css::uno::Reference< css::xml::dom::XNode >const& xNode);
121
122 public:
123
124 virtual ~CNode() override;
125
126 xmlNodePtr GetNodePtr() { return m_aNodePtr; }
127
128 virtual CDocument & GetOwnerDocument();
129
130 // recursively create SAX events
131 virtual void saxify(const css::uno::Reference< css::xml::sax::XDocumentHandler >& i_xHandler);
132
133 // recursively create SAX events
134 virtual void fastSaxify( Context& io_rContext );
135
136 // constrains child relationship between nodes based on type
137 virtual bool IsChildTypeAllowed(css::xml::dom::NodeType nodeType,
138 css::xml::dom::NodeType const* pReplacedNodeType);
139
140 // ---- DOM interfaces
141
145 virtual css::uno::Reference< css::xml::dom::XNode > SAL_CALL
146 appendChild(css::uno::Reference< css::xml::dom::XNode > const& xNewChild) override;
147
152 virtual css::uno::Reference< css::xml::dom::XNode > SAL_CALL cloneNode(sal_Bool deep) override;
153
158 virtual css::uno::Reference< css::xml::dom::XNamedNodeMap > SAL_CALL getAttributes() override;
159
163 virtual css::uno::Reference< css::xml::dom::XNodeList > SAL_CALL getChildNodes() override;
164
168 virtual css::uno::Reference< css::xml::dom::XNode > SAL_CALL getFirstChild() override;
169
173 virtual css::uno::Reference< css::xml::dom::XNode > SAL_CALL getLastChild() override;
174
178 virtual OUString SAL_CALL getLocalName() override;
179
183 virtual OUString SAL_CALL getNamespaceURI() override;
184
188 virtual css::uno::Reference< css::xml::dom::XNode > SAL_CALL getNextSibling() override;
189
194 virtual OUString SAL_CALL getNodeName() override;
195
199 virtual css::xml::dom::NodeType SAL_CALL getNodeType() override;
200
205 virtual OUString SAL_CALL getNodeValue() override;
206
210 virtual css::uno::Reference< css::xml::dom::XDocument > SAL_CALL getOwnerDocument() override;
211
215 virtual css::uno::Reference< css::xml::dom::XNode > SAL_CALL getParentNode() override;
216
220 virtual OUString SAL_CALL getPrefix() override;
221
225 virtual css::uno::Reference< css::xml::dom::XNode > SAL_CALL getPreviousSibling() override;
226
230 virtual sal_Bool SAL_CALL hasAttributes() override;
231
235 virtual sal_Bool SAL_CALL hasChildNodes() override;
236
240 virtual css::uno::Reference< css::xml::dom::XNode > SAL_CALL insertBefore(
241 const css::uno::Reference< css::xml::dom::XNode >& newChild, const css::uno::Reference< css::xml::dom::XNode >& refChild) override;
242
247 virtual sal_Bool SAL_CALL isSupported(const OUString& feature, const OUString& ver) override;
248
256 virtual void SAL_CALL normalize() override;
257
262 virtual css::uno::Reference< css::xml::dom::XNode > SAL_CALL removeChild(const css::uno::Reference< css::xml::dom::XNode >& oldChild) override;
263
268 virtual css::uno::Reference< css::xml::dom::XNode > SAL_CALL replaceChild(
269 const css::uno::Reference< css::xml::dom::XNode >& newChild, const css::uno::Reference< css::xml::dom::XNode >& oldChild) override;
270
274 virtual void SAL_CALL setNodeValue(const OUString& nodeValue) override;
275
279 virtual void SAL_CALL setPrefix(const OUString& prefix) override;
280
281
282 // --- XEventTarget
283 virtual void SAL_CALL addEventListener(const OUString& eventType,
284 const css::uno::Reference< css::xml::dom::events::XEventListener >& listener,
285 sal_Bool useCapture) override;
286
287 virtual void SAL_CALL removeEventListener(const OUString& eventType,
288 const css::uno::Reference< css::xml::dom::events::XEventListener >& listener,
289 sal_Bool useCapture) override;
290
291 virtual sal_Bool SAL_CALL dispatchEvent(const css::uno::Reference< css::xml::dom::events::XEvent >& evt) override;
292 };
293
295 void nscleanup(const xmlNodePtr aNode, const xmlNodePtr aParent);
296}
297
298/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
class SAL_WARN_UNUSED SAL_LOPLUGIN_ANNOTATE("crosscast") SwContentIndexReg
::osl::Mutex & m_rMutex
Reference< XOfficeDatabaseDocument > m_xDocument
Definition: attr.cxx:38
void nscleanup(const xmlNodePtr aNode, const xmlNodePtr aParent)
eliminate redundant namespace declarations
Definition: node.cxx:195
void popContext(Context &io_rContext)
Definition: node.cxx:61
void pushContext(Context &io_rContext)
Definition: node.cxx:52
sal_Int32 getTokenWithPrefix(const Context &rContext, const char *pPrefix, const char *pName)
Definition: node.cxx:100
sal_Int32 getToken(const Context &rContext, const char *pToken)
Definition: node.cxx:94
void addNamespaces(Context &io_rContext, xmlNodePtr pNode)
add namespaces on this node to context
Definition: node.cxx:66
bool normalize(sal_uInt16 &rDay, sal_uInt16 &rMonth, sal_Int16 &rYear)
sal_Int32 mnToken
Definition: node.hxx:63
const OString & getPrefix() const
Definition: node.hxx:65
rtl::Reference< sax_fastparser::FastTokenHandlerBase > mxTokenHandler
Definition: node.hxx:77
NamespaceVectorType maNamespaces
outer vector: xml context; inner vector: current NS
Definition: node.hxx:72
std::unordered_map< OUString, sal_Int32 > NamespaceMapType
Definition: node.hxx:69
css::uno::Reference< css::xml::sax::XFastContextHandler > mxCurrentHandler
Definition: node.hxx:75
Context(const css::uno::Reference< css::xml::sax::XFastDocumentHandler > &i_xHandler, sax_fastparser::FastTokenHandlerBase *pTokenHandler)
Definition: node.hxx:50
std::vector< std::vector< Namespace > > NamespaceVectorType
Definition: node.hxx:68
css::uno::Reference< css::xml::sax::XFastDocumentHandler > mxDocHandler
Definition: node.hxx:76
NamespaceMapType maNamespaceMap
Definition: node.hxx:73
::rtl::Reference< sax_fastparser::FastAttributeList > mxAttribList
Definition: node.hxx:74
unsigned char sal_Bool