|
|
| version 1.87, 2012/03/16 09:24:08 | version 1.97, 2020/12/15 17:10:29 |
|---|---|
| Line 1 | Line 1 |
| /** @file | /** @file |
| Parser: @b dom parser class. | Parser: @b dom parser class. |
| Copyright (c) 2001-2012 Art. Lebedev Studio (http://www.artlebedev.com) | Copyright (c) 2001-2020 Art. Lebedev Studio (http://www.artlebedev.com) |
| Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) | Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru) |
| */ | */ |
| #include "classes.h" | #include "classes.h" |
| Line 23 | Line 23 |
| volatile const char * IDENT_XNODE_C="$Id$" IDENT_XNODE_H; | volatile const char * IDENT_XNODE_C="$Id$" IDENT_XNODE_H; |
| // global variable | |
| DECLARE_CLASS_VAR(xnode, new MXnode, 0); | |
| // classes | // classes |
| class xmlXPathObject_auto_ptr { | class xmlXPathObject_auto_ptr { |
| Line 148 xmlAttr& as_attr(MethodParams& params, i | Line 144 xmlAttr& as_attr(MethodParams& params, i |
| static void writeNode(Request& r, VXdoc& xdoc, xmlNode* node) { | static void writeNode(Request& r, VXdoc& xdoc, xmlNode* node) { |
| if(!node|| xmlHaveGenericErrors()) | if(!node|| xmlHaveGenericErrors()) |
| throw XmlException(0); // OOM, bad name, things like that | throw XmlException(0, r); // OOM, bad name, things like that |
| // write out result | // write out result |
| r.write_no_lang(xdoc.wrap(*node)); | r.write(xdoc.wrap(*node)); |
| } | } |
| static xmlNode* pa_getAttributeNodeNS(xmlNode& selfNode, | static xmlNode* pa_getAttributeNodeNS(xmlNode& selfNode, |
| Line 162 static xmlNode* pa_getAttributeNodeNS(xm | Line 158 static xmlNode* pa_getAttributeNodeNS(xm |
| currentNode; | currentNode; |
| currentNode=currentNode->next) | currentNode=currentNode->next) |
| { | { |
| if(!namespaceURI || currentNode->ns && xmlStrEqual(currentNode->ns->href, namespaceURI)) | if(!namespaceURI || (currentNode->ns && xmlStrEqual(currentNode->ns->href, namespaceURI)) ) |
| if(!localName || xmlStrEqual(currentNode->name, localName)) | if(!localName || xmlStrEqual(currentNode->name, localName)) |
| return currentNode; | return currentNode; |
| } | } |
| Line 184 xmlNs& pa_xmlMapNs(xmlDoc& doc, const xm | Line 180 xmlNs& pa_xmlMapNs(xmlDoc& doc, const xm |
| if (cur == NULL) { | if (cur == NULL) { |
| cur = xmlNewNs (NULL, href, prefix); | cur = xmlNewNs (NULL, href, prefix); |
| if(!cur || xmlHaveGenericErrors()) | if(!cur || xmlHaveGenericErrors()) |
| throw XmlException(0); | throw XmlException(); |
| cur->next = doc.oldNs; | cur->next = doc.oldNs; |
| doc.oldNs = cur; | doc.oldNs = cur; |
| } | } |
| Line 359 static void _hasChildNodes(Request& r, M | Line 355 static void _hasChildNodes(Request& r, M |
| xmlNode& node=vnode.get_xmlnode(); | xmlNode& node=vnode.get_xmlnode(); |
| // write out result | // write out result |
| r.write_no_lang(VBool::get(node.children!=0)); | r.write(VBool::get(node.children!=0)); |
| } | } |
| // Node cloneNode(in boolean deep); | // Node cloneNode(in boolean deep); |
| Line 399 static void _getAttribute(Request& r, Me | Line 395 static void _getAttribute(Request& r, Me |
| // @todo: when name="xmlns" | // @todo: when name="xmlns" |
| xmlChar* attribute_value=xmlGetProp(&element, name); | xmlChar* attribute_value=xmlGetProp(&element, name); |
| // write out result | // write out result |
| r.write_pass_lang(r.transcode(attribute_value)); | r.write(r.transcode(attribute_value)); |
| } | } |
| // void setAttribute(in DOMString name, in DOMString value) raises(DOMException); | // void setAttribute(in DOMString name, in DOMString value) raises(DOMException); |
| Line 412 static void _setAttribute(Request& r, Me | Line 408 static void _setAttribute(Request& r, Me |
| // @todo: when name="xmlns" | // @todo: when name="xmlns" |
| if(!xmlSetProp(&element, name, attribute_value)) | if(!xmlSetProp(&element, name, attribute_value)) |
| throw XmlException(0); | throw XmlException(0, r); |
| } | } |
| // void removeAttribute(in DOMString name) raises(DOMException); | // void removeAttribute(in DOMString name) raises(DOMException); |
| Line 508 static void _getElementsByTagName(Reques | Line 504 static void _getElementsByTagName(Reques |
| &info); | &info); |
| // write out result | // write out result |
| r.write_no_lang(result); | r.write(result); |
| } | } |
| // DOM 2 | // DOM 2 |
| Line 524 static void _getAttributeNS(Request& r, | Line 520 static void _getAttributeNS(Request& r, |
| // todo: when name="xmlns" | // todo: when name="xmlns" |
| xmlChar* attribute_value=xmlGetNsProp(&element, localName, namespaceURI); | xmlChar* attribute_value=xmlGetNsProp(&element, localName, namespaceURI); |
| // write out result | // write out result |
| r.write_pass_lang(r.transcode(attribute_value)); | r.write(r.transcode(attribute_value)); |
| } | } |
| Line 557 static void _setAttributeNS(Request& r, | Line 553 static void _setAttributeNS(Request& r, |
| } | } |
| if(!attrNode) | if(!attrNode) |
| throw XmlException(0); | throw XmlException(0, r); |
| } | } |
| // void removeAttributeNS(in DOMString namespaceURI, in DOMString localName) raises(DOMException); | // void removeAttributeNS(in DOMString namespaceURI, in DOMString localName) raises(DOMException); |
| Line 599 static void _hasAttribute(Request& r, Me | Line 595 static void _hasAttribute(Request& r, Me |
| // @todo: when name="xmlns" | // @todo: when name="xmlns" |
| // write out result | // write out result |
| r.write_no_lang(VBool::get(xmlHasProp(&element, name)!=0)); | r.write(VBool::get(xmlHasProp(&element, name)!=0)); |
| } | } |
| // boolean hasAttributeNS(n DOMString namespaceURI, in DOMString localName) raises(DOMException); | // boolean hasAttributeNS(n DOMString namespaceURI, in DOMString localName) raises(DOMException); |
| Line 611 static void _hasAttributeNS(Request& r, | Line 607 static void _hasAttributeNS(Request& r, |
| xmlNode& element=get_self_element(vnode); | xmlNode& element=get_self_element(vnode); |
| // write out result | // write out result |
| r.write_no_lang(VBool::get(xmlHasNsProp(&element, localName, namespaceURI)!=0)); | r.write(VBool::get(xmlHasNsProp(&element, localName, namespaceURI)!=0)); |
| } | } |
| // boolean hasAttributes | // boolean hasAttributes |
| Line 620 static void _hasAttributes(Request& r, M | Line 616 static void _hasAttributes(Request& r, M |
| xmlNode& element=get_self_element(vnode); | xmlNode& element=get_self_element(vnode); |
| // write out result | // write out result |
| r.write_no_lang(VBool::get(element.properties!=0)); | r.write(VBool::get(element.properties!=0)); |
| } | } |
| // NodeList getElementsByTagNameNS(in DOMString namespaceURI, in DOMString localName); | // NodeList getElementsByTagNameNS(in DOMString namespaceURI, in DOMString localName); |
| Line 646 static void _getElementsByTagNameNS(Requ | Line 642 static void _getElementsByTagNameNS(Requ |
| &info); | &info); |
| // write out result | // write out result |
| r.write_no_lang(result); | r.write(result); |
| } | } |
| Line 706 static void _selectX(Request& r, MethodP | Line 702 static void _selectX(Request& r, MethodP |
| xmlXPathEvalExpression(r.transcode(expression), ctxt.get())); | xmlXPathEvalExpression(r.transcode(expression), ctxt.get())); |
| if(xmlHaveGenericErrors()) | if(xmlHaveGenericErrors()) |
| throw XmlException(0); | throw XmlException(0, r); |
| Value* result=0; | Value* result=0; |
| if(res.get()) | if(res.get()) |
| handler(r, expression, res, vdoc, result); | handler(r, expression, res, vdoc, result); |
| if(result) | if(result) |
| r.write_no_lang(*result); | r.write(*result); |
| } | } |
| static void selectNodesHandler(Request&, | static void selectNodesHandler(Request&, |
| Line 869 static void _selectString(Request& r, Me | Line 865 static void _selectString(Request& r, Me |
| // constructor | // constructor |
| /// @bug one can change const and ruin other's work, we need unchangable VIntConst class | /// @bug one can change const and ruin other's work, we need unchangable VIntConst class |
| MXnode::MXnode(const char* aname, VStateless_class *abase): | MXnode::MXnode(const char* aname): Methoded(aname?aname:"xnode") { |
| Methoded(aname?aname:"xnode", abase) | |
| { | |
| /// DOM1 node | /// DOM1 node |
| // Node insertBefore(in Node newChild,in Node refChild) raises(DOMException); | // Node insertBefore(in Node newChild,in Node refChild) raises(DOMException); |
| Line 943 MXnode::MXnode(const char* aname, VState | Line 937 MXnode::MXnode(const char* aname, VState |
| // consts | // consts |
| #define CONST(name) \ | #define CONST(name) consts.put(#name, new VInt(XML_##name)) |
| consts.put(String::Body(#name), new VInt(XML_##name)) | #define CONST2(name, value) consts.put(#name, new VInt(value)) |
| #define CONST2(name, value) \ | |
| consts.put(String::Body(#name), new VInt(value)) | |
| CONST(ELEMENT_NODE); | CONST(ELEMENT_NODE); |
| CONST(ATTRIBUTE_NODE); | CONST(ATTRIBUTE_NODE); |
| Line 962 MXnode::MXnode(const char* aname, VState | Line 954 MXnode::MXnode(const char* aname, VState |
| CONST(NOTATION_NODE); | CONST(NOTATION_NODE); |
| } | } |
| #else | |
| // global variable | |
| DECLARE_CLASS_VAR(xnode, 0, 0); // fictive | |
| #endif | #endif |