Diff for /parser3/src/classes/xnode.C between versions 1.72 and 1.78

version 1.72, 2005/12/16 10:15:12 version 1.78, 2007/08/20 08:56:46
Line 17  static const char * const IDENT_XNODE_C= Line 17  static const char * const IDENT_XNODE_C=
 #include "pa_vxdoc.h"  #include "pa_vxdoc.h"
 #include "pa_vvoid.h"  #include "pa_vvoid.h"
 #include "pa_xml_exception.h"  #include "pa_xml_exception.h"
   #include "pa_vbool.h"
   
 #include "xnode.h"  #include "xnode.h"
 #include "libxml/xpath.h"  #include "libxml/xpath.h"
Line 101  xmlNode& as_node(MethodParams& params, i Line 102  xmlNode& as_node(MethodParams& params, i
         if(Value* vxnode=value.as(VXNODE_TYPE, false))          if(Value* vxnode=value.as(VXNODE_TYPE, false))
                 return static_cast<VXnode*>(vxnode)->get_xmlnode();                  return static_cast<VXnode*>(vxnode)->get_xmlnode();
         else          else
                 throw Exception("parser.runtime",                  throw Exception(PARSER_RUNTIME,
                         0,                          0,
                         msg);                          msg);
 }  }
Line 113  xmlChar* as_xmlchar(Request& r, MethodPa Line 114  xmlChar* as_xmlchar(Request& r, MethodPa
 xmlAttr& as_attr(MethodParams& params, int index, const char* msg) {  xmlAttr& as_attr(MethodParams& params, int index, const char* msg) {
         xmlNode& xmlnode=as_node(params, index, msg);          xmlNode& xmlnode=as_node(params, index, msg);
         if(xmlnode.type!=XML_ATTRIBUTE_NODE)          if(xmlnode.type!=XML_ATTRIBUTE_NODE)
                 throw Exception("parser.runtime",                  throw Exception(PARSER_RUNTIME,
                         0,                          0,
                         msg);                          msg);
   
Line 121  xmlAttr& as_attr(MethodParams& params, i Line 122  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)          if(!node|| xmlHaveGenericErrors())
                 throw XmlException(0); // OOM, bad name, things like that                  throw XmlException(0); // OOM, bad name, things like that
   
         // write out result          // write out result
Line 170  xmlNs& pa_xmlMapNs(xmlDoc& doc, const xm Line 171  xmlNs& pa_xmlMapNs(xmlDoc& doc, const xm
 static void pa_addAttributeNode(xmlNode& selfNode, xmlAttr& attrNode)   static void pa_addAttributeNode(xmlNode& selfNode, xmlAttr& attrNode) 
 {  {
         if(attrNode.type!=XML_ATTRIBUTE_NODE)          if(attrNode.type!=XML_ATTRIBUTE_NODE)
                 throw Exception("xml",                  throw Exception(PARSER_RUNTIME,
                         0,                          0,
                         "must be ATTRIBUTE_NODE");                          "must be ATTRIBUTE_NODE");
   
Line 265  static void _replaceChild(Request& r, Me Line 266  static void _replaceChild(Request& r, Me
         xmlDoc& xmldoc=vxdoc.get_xmldoc();          xmlDoc& xmldoc=vxdoc.get_xmldoc();
         xmlNode& selfNode=vnode.get_xmlnode();          xmlNode& selfNode=vnode.get_xmlnode();
         xmlNode& newChild=as_node(params, 0, "newChild must be node");          xmlNode& newChild=as_node(params, 0, "newChild must be node");
         xmlNode& oldChild=as_node(params, 1, "refChild must be node");          xmlNode& oldChild=as_node(params, 1, "oldChild must be node");
   
         if(newChild.doc!=&xmldoc)          if(newChild.doc!=&xmldoc)
                 throw Exception("xml",                  throw Exception("xml.dom",
                         0,                          0,
                         "WRONG_DOCUMENT_ERR");                          "WRONG_DOCUMENT_ERR");
         if(oldChild.doc!=&xmldoc)          if(oldChild.doc!=&xmldoc)
                 throw Exception("xml",                  throw Exception("xml.dom",
                         0,                          0,
                         "WRONG_DOCUMENT_ERR");                          "WRONG_DOCUMENT_ERR");
   
           if(oldChild.parent!=&selfNode)
                   throw Exception("xml.dom",
                           0,
                           "NOT_FOUND_ERR");
   
         xmlNode* refChild=oldChild.next;          xmlNode* refChild=oldChild.next;
         xmlUnlinkNode(&oldChild);          xmlUnlinkNode(&oldChild);
         xmlNode* retNode;          xmlNode* retNode;
Line 297  static void _removeChild(Request& r, Met Line 303  static void _removeChild(Request& r, Met
         xmlNode& oldChild=as_node(params, 0, "refChild must be node");          xmlNode& oldChild=as_node(params, 0, "refChild must be node");
                   
         if(oldChild.doc!=&xmldoc)          if(oldChild.doc!=&xmldoc)
                 throw Exception("xml",                  throw Exception("xml.dom",
                         0,                          0,
                         "WRONG_DOCUMENT_ERR");                          "WRONG_DOCUMENT_ERR");
   
Line 348  xmlNode& get_self_element(VXnode& vnode) Line 354  xmlNode& get_self_element(VXnode& vnode)
         xmlNode& node=vnode.get_xmlnode();          xmlNode& node=vnode.get_xmlnode();
   
         if(node.type!=XML_ELEMENT_NODE)          if(node.type!=XML_ELEMENT_NODE)
                 throw Exception("parser.runtime",                  throw Exception(PARSER_RUNTIME,
                         0,                          0,
                         "method can only be called on nodes of ELEMENT type");                          "method can only be called on nodes of ELEMENT type");
   
Line 412  static void _setAttributeNode(Request& r Line 418  static void _setAttributeNode(Request& r
         xmlAttr& newAttr=as_attr(params, 0, "newAttr must be ATTRIBUTE node");          xmlAttr& newAttr=as_attr(params, 0, "newAttr must be ATTRIBUTE node");
   
         if(newAttr.doc!=&xmldoc)          if(newAttr.doc!=&xmldoc)
                 throw Exception("xml",                  throw Exception("xml.dom",
                         0,                          0,
                         "WRONG_DOCUMENT_ERR");                          "WRONG_DOCUMENT_ERR");
   
         if(newAttr.parent)          if(newAttr.parent)
                 throw Exception("xml",                  throw Exception("xml.dom",
                         0,                          0,
                         "INUSE_ATTRIBUTE_ERR");                          "INUSE_ATTRIBUTE_ERR");
                   
Line 438  static void _removeAttributeNode(Request Line 444  static void _removeAttributeNode(Request
         xmlAttr& oldAttr=as_attr(params, 0, "oldAttr must be ATTRIBUTE node");          xmlAttr& oldAttr=as_attr(params, 0, "oldAttr must be ATTRIBUTE node");
   
         if(oldAttr.parent!=&element)          if(oldAttr.parent!=&element)
                 throw Exception("xml",                  throw Exception("xml.dom",
                         0,                          0,
                         "NOT_FOUND_ERR");                          "NOT_FOUND_ERR");
   
Line 570  static void _hasAttributeNS(Request& r, Line 576  static void _hasAttributeNS(Request& r,
         r.write_no_lang(*new VBool(prop!=0));          r.write_no_lang(*new VBool(prop!=0));
 }  }
   
   // boolean hasAttributes
   static void _hasAttributes(Request& r, MethodParams&) {
           VXnode& vnode=GET_SELF(r, VXnode);
           xmlNode& element=get_self_element(vnode);
   
           // write out result
           r.write_no_lang(*new VBool(element.properties!=0));
   }
   
 static void _getElementsByTagNameNS(Request& r, MethodParams& params) {  static void _getElementsByTagNameNS(Request& r, MethodParams& params) {
         VXnode& vnode=GET_SELF(r, VXnode);          VXnode& vnode=GET_SELF(r, VXnode);
         VXdoc& vdoc=vnode.get_vxdoc();          VXdoc& vdoc=vnode.get_vxdoc();
Line 619  static void register_one_ns( Line 634  static void register_one_ns(
                         info->r->transcode(key),                           info->r->transcode(key), 
                         info->r->transcode(*svalue));                          info->r->transcode(*svalue));
         else          else
                 throw Exception("parser.runtime",                  throw Exception(PARSER_RUNTIME,
                         new String(key, String::L_TAINTED),                          new String(key, String::L_TAINTED),
                         "value is %s, must be string or number", value->type());                          "value is %s, must be string or number", value->type());
 }  }
Line 631  static void _selectX(Request& r, MethodP Line 646  static void _selectX(Request& r, MethodP
                                                           Value*& result))                                                             Value*& result)) 
 {  {
         VXnode& vnode=GET_SELF(r, VXnode);          VXnode& vnode=GET_SELF(r, VXnode);
         xmlNode& element=get_self_element(vnode);          xmlNode& xmlnode=vnode.get_xmlnode();
         VXdoc& vdoc=vnode.get_vxdoc();          VXdoc& vdoc=vnode.get_vxdoc();
         xmlDoc& xmldoc=vdoc.get_xmldoc();          xmlDoc& xmldoc=vdoc.get_xmldoc();
   
Line 640  static void _selectX(Request& r, MethodP Line 655  static void _selectX(Request& r, MethodP
         xmlXPathContext_auto_ptr ctxt(xmlXPathNewContext(&xmldoc));          xmlXPathContext_auto_ptr ctxt(xmlXPathNewContext(&xmldoc));
         {          {
                 Register_one_ns_info info={&r, ctxt.get()};                  Register_one_ns_info info={&r, ctxt.get()};
                 vdoc.search_namespaces.hash().for_each(register_one_ns, &info);                  vdoc.search_namespaces.hash().for_each<Register_one_ns_info*>(register_one_ns, &info);
         }          }
         ctxt->node=&element;          ctxt->node=&xmlnode;
         /*error to stderr for now*/          /*error to stderr for now*/
         xmlXPathObject_auto_ptr res(          xmlXPathObject_auto_ptr res(
                 xmlXPathEvalExpression(r.transcode(expression), ctxt.get()));                  xmlXPathEvalExpression(r.transcode(expression), ctxt.get()));
Line 677  static void selectNodesHandler(Request&, Line 692  static void selectNodesHandler(Request&,
                         }                          }
                 break;                  break;
         default:           default: 
                 throw Exception(0,                  throw Exception(PARSER_RUNTIME,
                         &expression,                          &expression,
                         "wrong xmlXPathEvalExpression result type (%d)", res->type);                          "wrong xmlXPathEvalExpression result type (%d)", res->type);
                 break; // never                  break; // never
Line 695  static void selectNodeHandler(Request& r Line 710  static void selectNodeHandler(Request& r
         case XPATH_NODESET:           case XPATH_NODESET: 
                 if(res->nodesetval && res->nodesetval->nodeNr) { // empty result strangly has NODESET  res->type                  if(res->nodesetval && res->nodesetval->nodeNr) { // empty result strangly has NODESET  res->type
                         if(res->nodesetval->nodeNr>1)                          if(res->nodesetval->nodeNr>1)
                                 throw Exception("parser.runtime",                                  throw Exception(PARSER_RUNTIME,
                                         &expression,                                          &expression,
                                         "resulted not in a single node (%d)", res->nodesetval->nodeNr);                                          "resulted not in a single node (%d)", res->nodesetval->nodeNr);
                                                   
Line 712  static void selectNodeHandler(Request& r Line 727  static void selectNodeHandler(Request& r
                 result=new VString(r.transcode((xmlChar*)res->stringval));                  result=new VString(r.transcode((xmlChar*)res->stringval));
                 break;                  break;
         default:           default: 
                 throw Exception("parser.runtime",                  throw Exception(PARSER_RUNTIME,
                         &expression,                          &expression,
                         "wrong xmlXPathEvalExpression result type (%d)", res->type);                          "wrong xmlXPathEvalExpression result type (%d)", res->type);
         }          }
Line 732  static void selectBoolHandler(Request&, Line 747  static void selectBoolHandler(Request&,
                         break;                          break;
                 // else[nodeset] fall down to default                  // else[nodeset] fall down to default
         default:           default: 
                 throw Exception("parser.runtime",                  throw Exception(PARSER_RUNTIME,
                         &expression,                          &expression,
                         "wrong xmlXPathEvalExpression result type (%d)", res->type);                          "wrong xmlXPathEvalExpression result type (%d)", res->type);
                 break; // never                  break; // never
Line 753  static void selectNumberHandler(Request& Line 768  static void selectNumberHandler(Request&
                         break;                          break;
                 // else[nodeset] fall down to default                  // else[nodeset] fall down to default
         default:           default: 
                 throw Exception("parser.runtime",                  throw Exception(PARSER_RUNTIME,
                         &expression,                          &expression,
                         "wrong xmlXPathEvalExpression result type (%d)", res->type);                          "wrong xmlXPathEvalExpression result type (%d)", res->type);
                 break; // never                  break; // never
Line 776  static void selectStringHandler(Request& Line 791  static void selectStringHandler(Request&
                         break;                          break;
                 // else[nodeset] fall down to default                  // else[nodeset] fall down to default
         default:           default: 
                 throw Exception("parser.runtime",                  throw Exception(PARSER_RUNTIME,
                         &expression,                          &expression,
                         "wrong xmlXPathEvalExpression result type (%d)", res->type);                          "wrong xmlXPathEvalExpression result type (%d)", res->type);
                 break; // never                  break; // never
Line 866  MXnode::MXnode(const char* aname, VState Line 881  MXnode::MXnode(const char* aname, VState
         add_native_method("hasAttribute", Method::CT_DYNAMIC, _hasAttribute, 1, 1);          add_native_method("hasAttribute", Method::CT_DYNAMIC, _hasAttribute, 1, 1);
         // boolean hasAttributeNS(in DOMString namespaceURI, in DOMString localName) raises(DOMException);          // boolean hasAttributeNS(in DOMString namespaceURI, in DOMString localName) raises(DOMException);
         add_native_method("hasAttributeNS", Method::CT_DYNAMIC, _hasAttributeNS, 2, 2);          add_native_method("hasAttributeNS", Method::CT_DYNAMIC, _hasAttributeNS, 2, 2);
           // boolean hasAttributes
           add_native_method("hasAttributes", Method::CT_DYNAMIC, _hasAttributes, 0, 0);
           
   
         /// parser          /// parser
         // ^node.select[/some/xpath/query] = hash $.#[dnode]          // ^node.select[/some/xpath/query] = hash $.#[dnode]

Removed from v.1.72  
changed lines
  Added in v.1.78


E-mail: