1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef DOM_ELEMENT_HXX 25 #define DOM_ELEMENT_HXX 26 27 #include <libxml/tree.h> 28 29 #include <com/sun/star/uno/Reference.h> 30 #include <com/sun/star/xml/dom/XNode.hpp> 31 #include <com/sun/star/xml/dom/XNodeList.hpp> 32 #include <com/sun/star/xml/dom/XNamedNodeMap.hpp> 33 #include <com/sun/star/xml/dom/NodeType.hpp> 34 35 #include <node.hxx> 36 37 38 using ::rtl::OUString; 39 using namespace com::sun::star::uno; 40 using namespace com::sun::star::xml::dom; 41 42 namespace DOM 43 { 44 typedef ::cppu::ImplInheritanceHelper1<CNode, XElement > CElement_Base; 45 46 class CElement 47 : public CElement_Base 48 { 49 private: 50 friend class CDocument; 51 52 Reference< XAttr > setAttributeNode_Impl_Lock( 53 Reference< XAttr > const& xNewAttr, bool const bNS); 54 55 protected: 56 CElement(CDocument const& rDocument, ::osl::Mutex const& rMutex, 57 xmlNodePtr const pNode); 58 59 public: 60 61 virtual void saxify(const Reference< XDocumentHandler >& i_xHandler); 62 63 virtual void fastSaxify( Context& i_rContext ); 64 65 virtual bool IsChildTypeAllowed(NodeType const nodeType); 66 67 /** 68 Retrieves an attribute value by name. 69 */ 70 virtual OUString SAL_CALL getAttribute(const OUString& name); 71 72 /** 73 Retrieves an attribute node by name. 74 */ 75 virtual Reference< XAttr > SAL_CALL getAttributeNode(const OUString& name); 76 77 /** 78 Retrieves an Attr node by local name and namespace URI. 79 */ 80 virtual Reference< XAttr > SAL_CALL getAttributeNodeNS(const OUString& namespaceURI, const OUString& localName); 81 82 /** 83 Retrieves an attribute value by local name and namespace URI. 84 */ 85 virtual OUString SAL_CALL getAttributeNS(const OUString& namespaceURI, const OUString& localName); 86 87 /** 88 Returns a NodeList of all descendant Elements with a given tag name, 89 in the order in which they are 90 encountered in a preorder traversal of this Element tree. 91 */ 92 virtual Reference< XNodeList > SAL_CALL getElementsByTagName(const OUString& name); 93 94 /** 95 Returns a NodeList of all the descendant Elements with a given local 96 name and namespace URI in the order in which they are encountered in 97 a preorder traversal of this Element tree. 98 */ 99 virtual Reference< XNodeList > SAL_CALL getElementsByTagNameNS(const OUString& namespaceURI, 100 const OUString& localName); 101 102 /** 103 The name of the element. 104 */ 105 virtual OUString SAL_CALL getTagName(); 106 107 /** 108 Returns true when an attribute with a given name is specified on this 109 element or has a default value, false otherwise. 110 */ 111 virtual sal_Bool SAL_CALL hasAttribute(const OUString& name); 112 113 /** 114 Returns true when an attribute with a given local name and namespace 115 URI is specified on this element or has a default value, false otherwise. 116 */ 117 virtual sal_Bool SAL_CALL hasAttributeNS(const OUString& namespaceURI, const OUString& localName); 118 119 /** 120 Removes an attribute by name. 121 */ 122 virtual void SAL_CALL removeAttribute(const OUString& name); 123 124 /** 125 Removes the specified attribute node. 126 */ 127 virtual Reference< XAttr > SAL_CALL removeAttributeNode(const Reference< XAttr >& oldAttr); 128 129 /** 130 Removes an attribute by local name and namespace URI. 131 */ 132 virtual void SAL_CALL removeAttributeNS(const OUString& namespaceURI, const OUString& localName); 133 134 /** 135 Adds a new attribute. 136 */ 137 virtual void SAL_CALL setAttribute(const OUString& name, const OUString& value); 138 139 /** 140 Adds a new attribute node. 141 */ 142 virtual Reference< XAttr > SAL_CALL setAttributeNode(const Reference< XAttr >& newAttr); 143 144 /** 145 Adds a new attribute. 146 */ 147 virtual Reference< XAttr > SAL_CALL setAttributeNodeNS(const Reference< XAttr >& newAttr); 148 149 /** 150 Adds a new attribute. 151 */ 152 virtual void SAL_CALL setAttributeNS( 153 const OUString& namespaceURI, const OUString& qualifiedName, const OUString& value); 154 155 /** 156 sets the element name 157 */ 158 virtual void SAL_CALL setElementName(const OUString& elementName); 159 160 // overrides for XNode base 161 virtual OUString SAL_CALL getNodeName(); 162 virtual OUString SAL_CALL getNodeValue(); 163 virtual Reference< XNamedNodeMap > SAL_CALL getAttributes(); 164 virtual OUString SAL_CALL getLocalName(); 165 166 // resolve uno inheritance problems... 167 // --- delegation for XNde base. appendChild(const Reference<XNode> & newChild)168 virtual Reference< XNode > SAL_CALL appendChild(const Reference< XNode >& newChild) 169 { 170 return CNode::appendChild(newChild); 171 } cloneNode(sal_Bool deep)172 virtual Reference< XNode > SAL_CALL cloneNode(sal_Bool deep) 173 { 174 return CNode::cloneNode(deep); 175 } getChildNodes()176 virtual Reference< XNodeList > SAL_CALL getChildNodes() 177 { 178 return CNode::getChildNodes(); 179 } getFirstChild()180 virtual Reference< XNode > SAL_CALL getFirstChild() 181 { 182 return CNode::getFirstChild(); 183 } getLastChild()184 virtual Reference< XNode > SAL_CALL getLastChild() 185 { 186 return CNode::getLastChild(); 187 } getNamespaceURI()188 virtual OUString SAL_CALL getNamespaceURI() 189 { 190 return CNode::getNamespaceURI(); 191 } getNextSibling()192 virtual Reference< XNode > SAL_CALL getNextSibling() 193 { 194 return CNode::getNextSibling(); 195 } getNodeType()196 virtual NodeType SAL_CALL getNodeType() 197 { 198 return CNode::getNodeType(); 199 } getOwnerDocument()200 virtual Reference< XDocument > SAL_CALL getOwnerDocument() 201 { 202 return CNode::getOwnerDocument(); 203 } getParentNode()204 virtual Reference< XNode > SAL_CALL getParentNode() 205 { 206 return CNode::getParentNode(); 207 } getPrefix()208 virtual OUString SAL_CALL getPrefix() 209 { 210 return CNode::getPrefix(); 211 } getPreviousSibling()212 virtual Reference< XNode > SAL_CALL getPreviousSibling() 213 { 214 return CNode::getPreviousSibling(); 215 } hasAttributes()216 virtual sal_Bool SAL_CALL hasAttributes() 217 { 218 return CNode::hasAttributes(); 219 } hasChildNodes()220 virtual sal_Bool SAL_CALL hasChildNodes() 221 { 222 return CNode::hasChildNodes(); 223 } insertBefore(const Reference<XNode> & newChild,const Reference<XNode> & refChild)224 virtual Reference< XNode > SAL_CALL insertBefore( 225 const Reference< XNode >& newChild, const Reference< XNode >& refChild) 226 { 227 return CNode::insertBefore(newChild, refChild); 228 } isSupported(const OUString & feature,const OUString & ver)229 virtual sal_Bool SAL_CALL isSupported(const OUString& feature, const OUString& ver) 230 { 231 return CNode::isSupported(feature, ver); 232 } normalize()233 virtual void SAL_CALL normalize() 234 { 235 CNode::normalize(); 236 } removeChild(const Reference<XNode> & oldChild)237 virtual Reference< XNode > SAL_CALL removeChild(const Reference< XNode >& oldChild) 238 { 239 return CNode::removeChild(oldChild); 240 } replaceChild(const Reference<XNode> & newChild,const Reference<XNode> & oldChild)241 virtual Reference< XNode > SAL_CALL replaceChild( 242 const Reference< XNode >& newChild, const Reference< XNode >& oldChild) 243 { 244 return CNode::replaceChild(newChild, oldChild); 245 } setNodeValue(const OUString & nodeValue)246 virtual void SAL_CALL setNodeValue(const OUString& nodeValue) 247 { 248 return CNode::setNodeValue(nodeValue); 249 } setPrefix(const OUString & prefix)250 virtual void SAL_CALL setPrefix(const OUString& prefix) 251 { 252 return CNode::setPrefix(prefix); 253 } 254 255 }; 256 257 } 258 259 #endif 260