1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: element.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 #include <com/sun/star/uno/Reference.h>
34 #include <com/sun/star/uno/Exception.hpp>
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 <libxml/tree.h>
42 using ::rtl::OUString
;
43 using namespace com::sun::star::uno
;
44 using namespace com::sun::star::xml::dom
;
48 class CElement
: public cppu::ImplInheritanceHelper1
<CNode
, XElement
>
52 Reference
< XAttr
> _setAttributeNode(const Reference
< XAttr
>& newAttr
, sal_Bool bNS
)
53 throw (RuntimeException
);
56 CElement(const xmlNodePtr aNodePtr
);
60 virtual void SAL_CALL
saxify(
61 const Reference
< XDocumentHandler
>& i_xHandler
);
63 virtual void SAL_CALL
fastSaxify( Context
& i_rContext
);
66 Retrieves an attribute value by name.
68 virtual OUString SAL_CALL
getAttribute(const OUString
& name
)
69 throw (RuntimeException
);
72 Retrieves an attribute node by name.
74 virtual Reference
< XAttr
> SAL_CALL
getAttributeNode(const OUString
& name
)
75 throw (RuntimeException
);
78 Retrieves an Attr node by local name and namespace URI.
80 virtual Reference
< XAttr
> SAL_CALL
getAttributeNodeNS(const OUString
& namespaceURI
, const OUString
& localName
)
81 throw (RuntimeException
);
84 Retrieves an attribute value by local name and namespace URI.
86 virtual OUString SAL_CALL
getAttributeNS(const OUString
& namespaceURI
, const OUString
& localName
)
87 throw (RuntimeException
);
90 Returns a NodeList of all descendant Elements with a given tag name,
91 in the order in which they are
92 encountered in a preorder traversal of this Element tree.
94 virtual Reference
< XNodeList
> SAL_CALL
getElementsByTagName(const OUString
& name
)
95 throw (RuntimeException
);
98 Returns a NodeList of all the descendant Elements with a given local
99 name and namespace URI in the order in which they are encountered in
100 a preorder traversal of this Element tree.
102 virtual Reference
< XNodeList
> SAL_CALL
getElementsByTagNameNS(const OUString
& namespaceURI
,
103 const OUString
& localName
)
104 throw (RuntimeException
);
107 The name of the element.
109 virtual OUString SAL_CALL
getTagName()
110 throw (RuntimeException
);
113 Returns true when an attribute with a given name is specified on this
114 element or has a default value, false otherwise.
116 virtual sal_Bool SAL_CALL
hasAttribute(const OUString
& name
)
117 throw (RuntimeException
);
120 Returns true when an attribute with a given local name and namespace
121 URI is specified on this element or has a default value, false otherwise.
123 virtual sal_Bool SAL_CALL
hasAttributeNS(const OUString
& namespaceURI
, const OUString
& localName
)
124 throw (RuntimeException
);
127 Removes an attribute by name.
129 virtual void SAL_CALL
removeAttribute(const OUString
& name
)
130 throw (RuntimeException
, DOMException
);
133 Removes the specified attribute node.
135 virtual Reference
< XAttr
> SAL_CALL
removeAttributeNode(const Reference
< XAttr
>& oldAttr
)
136 throw (RuntimeException
, DOMException
);
139 Removes an attribute by local name and namespace URI.
141 virtual void SAL_CALL
removeAttributeNS(const OUString
& namespaceURI
, const OUString
& localName
)
142 throw (RuntimeException
, DOMException
);
145 Adds a new attribute.
147 virtual void SAL_CALL
setAttribute(const OUString
& name
, const OUString
& value
)
148 throw (RuntimeException
, DOMException
);
151 Adds a new attribute node.
153 virtual Reference
< XAttr
> SAL_CALL
setAttributeNode(const Reference
< XAttr
>& newAttr
)
154 throw (RuntimeException
, DOMException
);
157 Adds a new attribute.
159 virtual Reference
< XAttr
> SAL_CALL
setAttributeNodeNS(const Reference
< XAttr
>& newAttr
)
160 throw (RuntimeException
, DOMException
);
163 Adds a new attribute.
165 virtual void SAL_CALL
setAttributeNS(
166 const OUString
& namespaceURI
, const OUString
& qualifiedName
, const OUString
& value
)
167 throw (RuntimeException
, DOMException
);
170 sets the element name
172 virtual void SAL_CALL
setElementName(const OUString
& elementName
)
173 throw (RuntimeException
, DOMException
);
175 // overrides for XNode base
176 virtual OUString SAL_CALL
getNodeName()
177 throw (RuntimeException
);
178 virtual OUString SAL_CALL
getNodeValue()
179 throw (RuntimeException
);
180 virtual Reference
< XNamedNodeMap
> SAL_CALL
getAttributes()
181 throw (RuntimeException
);
182 virtual OUString SAL_CALL
getLocalName()
183 throw (RuntimeException
);
185 // resolve uno inheritance problems...
186 // --- delegation for XNde base.
187 virtual Reference
< XNode
> SAL_CALL
appendChild(const Reference
< XNode
>& newChild
)
188 throw (RuntimeException
, DOMException
)
190 return CNode::appendChild(newChild
);
192 virtual Reference
< XNode
> SAL_CALL
cloneNode(sal_Bool deep
)
193 throw (RuntimeException
)
195 return CNode::cloneNode(deep
);
197 virtual Reference
< XNodeList
> SAL_CALL
getChildNodes()
198 throw (RuntimeException
)
200 return CNode::getChildNodes();
202 virtual Reference
< XNode
> SAL_CALL
getFirstChild()
203 throw (RuntimeException
)
205 return CNode::getFirstChild();
207 virtual Reference
< XNode
> SAL_CALL
getLastChild()
208 throw (RuntimeException
)
210 return CNode::getLastChild();
212 virtual OUString SAL_CALL
getNamespaceURI()
213 throw (RuntimeException
)
215 return CNode::getNamespaceURI();
217 virtual Reference
< XNode
> SAL_CALL
getNextSibling()
218 throw (RuntimeException
)
220 return CNode::getNextSibling();
222 virtual NodeType SAL_CALL
getNodeType()
223 throw (RuntimeException
)
225 return CNode::getNodeType();
227 virtual Reference
< XDocument
> SAL_CALL
getOwnerDocument()
228 throw (RuntimeException
)
230 return CNode::getOwnerDocument();
232 virtual Reference
< XNode
> SAL_CALL
getParentNode()
233 throw (RuntimeException
)
235 return CNode::getParentNode();
237 virtual OUString SAL_CALL
getPrefix()
238 throw (RuntimeException
)
240 return CNode::getPrefix();
242 virtual Reference
< XNode
> SAL_CALL
getPreviousSibling()
243 throw (RuntimeException
)
245 return CNode::getPreviousSibling();
247 virtual sal_Bool SAL_CALL
hasAttributes()
248 throw (RuntimeException
)
250 return CNode::hasAttributes();
252 virtual sal_Bool SAL_CALL
hasChildNodes()
253 throw (RuntimeException
)
255 return CNode::hasChildNodes();
257 virtual Reference
< XNode
> SAL_CALL
insertBefore(
258 const Reference
< XNode
>& newChild
, const Reference
< XNode
>& refChild
)
259 throw (RuntimeException
, DOMException
)
261 return CNode::insertBefore(newChild
, refChild
);
263 virtual sal_Bool SAL_CALL
isSupported(const OUString
& feature
, const OUString
& ver
)
264 throw (RuntimeException
)
266 return CNode::isSupported(feature
, ver
);
268 virtual void SAL_CALL
normalize()
269 throw (RuntimeException
)
273 virtual Reference
< XNode
> SAL_CALL
removeChild(const Reference
< XNode
>& oldChild
)
274 throw (RuntimeException
, DOMException
)
276 return CNode::removeChild(oldChild
);
278 virtual Reference
< XNode
> SAL_CALL
replaceChild(
279 const Reference
< XNode
>& newChild
, const Reference
< XNode
>& oldChild
)
280 throw (RuntimeException
, DOMException
)
282 return CNode::replaceChild(newChild
, oldChild
);
284 virtual void SAL_CALL
setNodeValue(const OUString
& nodeValue
)
285 throw (RuntimeException
, DOMException
)
287 return CNode::setNodeValue(nodeValue
);
289 virtual void SAL_CALL
setPrefix(const OUString
& prefix
)
290 throw (RuntimeException
, DOMException
)
292 return CNode::setPrefix(prefix
);