Diff for /parser3/src/classes/xnode.C between versions 1.28 and 1.39

version 1.28, 2002/01/21 13:04:02 version 1.39, 2002/02/19 15:03:10
Line 1 Line 1
 /** @file  /** @file
         Parser: @b dom parser class.          Parser: @b dom parser class.
   
         Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)          Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com)
         Author: Alexander Petrosyan <paf@design.ru> (http://paf.design.ru)          Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
   
         $Id$          $Id$
 */  */
Line 12 Line 12
 #include "pa_charset.h"  #include "pa_charset.h"
 #include "pa_request.h"  #include "pa_request.h"
 #include "pa_vxnode.h"  #include "pa_vxnode.h"
   #include "pa_vxdoc.h"
 #include "pa_vvoid.h"  #include "pa_vvoid.h"
   
 #include "xnode.h"  #include "xnode.h"
Line 23  extern "C" { Line 24  extern "C" {
 #include "gdome.h"  #include "gdome.h"
 #include "libxml/xpath.h"  #include "libxml/xpath.h"
   
   // defines 
   
   #define XNODE_CLASS_NAME "xnode"
   
 // classes  // classes
   
 class xmlXPathObject_auto_ptr {  class xmlXPathObject_auto_ptr {
 public:  public:
         explicit xmlXPathObject_auto_ptr(xmlXPathObject *_P = 0)           explicit xmlXPathObject_auto_ptr(xmlXPathObject *_APtr = 0) 
                 : _Owns(_P != 0), _Ptr(_P) {}                  : _Owns(_APtr != 0), _Ptr(_APtr) {}
         xmlXPathObject_auto_ptr(const xmlXPathObject_auto_ptr& _Y)           xmlXPathObject_auto_ptr(const xmlXPathObject_auto_ptr& _Y) 
                 : _Owns(_Y._Owns), _Ptr(_Y.release()) {}                  : _Owns(_Y._Owns), _Ptr(_Y.release()) {}
         xmlXPathObject_auto_ptr& operator=(const xmlXPathObject_auto_ptr& _Y)           xmlXPathObject_auto_ptr& operator=(const xmlXPathObject_auto_ptr& _Y) 
Line 60  private: Line 65  private:
   
 class xmlXPathContext_auto_ptr {  class xmlXPathContext_auto_ptr {
 public:  public:
         explicit xmlXPathContext_auto_ptr(xmlXPathContext *_P = 0)           explicit xmlXPathContext_auto_ptr(xmlXPathContext *_APtr = 0) 
                 : _Owns(_P != 0), _Ptr(_P) {}                  : _Owns(_APtr != 0), _Ptr(_APtr) {}
         xmlXPathContext_auto_ptr(const xmlXPathContext_auto_ptr& _Y)           xmlXPathContext_auto_ptr(const xmlXPathContext_auto_ptr& _Y) 
                 : _Owns(_Y._Owns), _Ptr(_Y.release()) {}                  : _Owns(_Y._Owns), _Ptr(_Y.release()) {}
         xmlXPathContext_auto_ptr& operator=(const xmlXPathContext_auto_ptr& _Y)           xmlXPathContext_auto_ptr& operator=(const xmlXPathContext_auto_ptr& _Y) 
Line 91  private: Line 96  private:
         xmlXPathContext *_Ptr;          xmlXPathContext *_Ptr;
 };  };
   
 // defines  
   
 #define XNODE_CLASS_NAME "xnode"  
   
 // helpers  // helpers
   
 GdomeNode *as_node(Pool& pool, const String& method_name, MethodParams *params,   GdomeNode *as_node(Pool& pool, const String& method_name, MethodParams *params, 
                                                 int index, const char *msg) {                                                  int index, const char *msg) {
         Value& value=params->as_no_junction(index, msg);          Value& value=params->as_no_junction(index, msg);
         if(strcmp(value.type(), VXNODE_TYPE)!=0)          if(!(strcmp(value.type(), VXNODE_TYPE)==0 
                   || strcmp(value.type(), VXDOC_TYPE)==0))
                 throw Exception(0, 0,                  throw Exception(0, 0,
                         &method_name,                          &method_name,
                         msg);                          msg);
Line 212  static void _hasChildNodes(Request& r, c Line 214  static void _hasChildNodes(Request& r, c
 }  }
   
 // Node cloneNode(in boolean deep);  // Node cloneNode(in boolean deep);
 /// @test ownerDocument=?  
 static void _cloneNode(Request& r, const String& method_name, MethodParams *params) {  static void _cloneNode(Request& r, const String& method_name, MethodParams *params) {
         Pool& pool=r.pool();          Pool& pool=r.pool();
         VXnode& vnode=*static_cast<VXnode *>(r.self);          VXnode& vnode=*static_cast<VXnode *>(r.self);
Line 367  static void _getElementsByTagName(Reques Line 368  static void _getElementsByTagName(Reques
         r.write_no_lang(result);          r.write_no_lang(result);
 }  }
   
   static void _getElementsByTagNameNS(Request& r, const String& method_name, MethodParams *params) {
           Pool& pool=r.pool();
           GdomeElement *element=get_self_element(r, method_name);
   
           // namespaceURI;localName
           const String& namespaceURI=params->as_string(0, "namespaceURI must be string");
           const String& localName=params->as_string(1, "localName must be string");
   
           GdomeException exc;
           VHash& result=*new(pool) VHash(pool);
           if(GdomeNodeList *nodes=
                   gdome_el_getElementsByTagNameNS(
                           element, 
                           pool.transcode(namespaceURI).get(),
                           pool.transcode(localName).get(),
                           &exc)) {
                   gulong length=gdome_nl_length(nodes, &exc);
                   for(gulong i=0; i<length; i++) {
                           String& skey=*new(pool) String(pool);
                           {
                                   char *buf=(char *)pool.malloc(MAX_NUMBER);
                                   snprintf(buf, MAX_NUMBER, "%d", i);
                                   skey << buf;
                           }
   
                           result.hash(0).put(skey, new(pool) VXnode(pool, gdome_nl_item(nodes, i, &exc)));
                   }
           }
   
           // write out result
           r.write_no_lang(result);
   }
   
 // void normalize();  // void normalize();
 static void _normalize(Request& r, const String& method_name, MethodParams *) {  static void _normalize(Request& r, const String& method_name, MethodParams *) {
         Pool& pool=r.pool();          Pool& pool=r.pool();
Line 396  static void _selectX(Request& r, const S Line 430  static void _selectX(Request& r, const S
         GdomeException exc;          GdomeException exc;
         GdomeNode *dome_node=vnode.get_node(&method_name);          GdomeNode *dome_node=vnode.get_node(&method_name);
         GdomeDocument *dome_document=gdome_n_ownerDocument(dome_node, &exc);          GdomeDocument *dome_document=gdome_n_ownerDocument(dome_node, &exc);
         if(!dome_document)          if(!dome_document) // document does not own itself, so ownerDocument = 0
                 dome_document=GDOME_DOC(dome_node);                  dome_document=GDOME_DOC(dome_node); // and we need downcast
         xmlDoc *xml_document=((_Gdome_xml_Document *)dome_document)->n;          xmlDoc *xml_document=gdome_xml_doc_get_xmlDoc(dome_document);
     xmlXPathContext_auto_ptr ctxt(xmlXPathNewContext(xml_document));      xmlXPathContext_auto_ptr ctxt(xmlXPathNewContext(xml_document));
         ctxt->node=xmlDocGetRootElement(xml_document);          ctxt->node=gdome_xml_n_get_xmlNode(dome_node);
         /*error to stderr for now*/          /*error to stderr for now*/
         xmlXPathObject_auto_ptr res(          xmlXPathObject_auto_ptr res(
                 xmlXPathEvalExpression(BAD_CAST pool.transcode(expression)->str, ctxt.get()));                  xmlXPathEvalExpression(BAD_CAST pool.transcode(expression)->str, ctxt.get()));
Line 425  static void selectNodesHandler(Pool& poo Line 459  static void selectNodesHandler(Pool& poo
                                                           const String& expression,                                                            const String& expression,
                                                           xmlXPathObject_auto_ptr res,                                                            xmlXPathObject_auto_ptr res,
                                                           Value *& result) {                                                            Value *& result) {
           VHash *vhash=new(pool) VHash(pool);  result=vhash;
         switch(res->type) {          switch(res->type) {
         case XPATH_UNDEFINED:           case XPATH_UNDEFINED: 
                 break;                  break;
         case XPATH_NODESET:          case XPATH_NODESET:
                 if(int size=res->nodesetval->nodeNr) {                  if(int size=res->nodesetval->nodeNr) {
                         VHash *vhash=new(pool) VHash(pool);  
                         Hash& hash=vhash->hash(0);                          Hash& hash=vhash->hash(0);
                         for(int i=0; i<size; i++) {                          for(int i=0; i<size; i++) {
                                 String& skey=*new(pool) String(pool);                                  String& skey=*new(pool) String(pool);
Line 441  static void selectNodesHandler(Pool& poo Line 475  static void selectNodesHandler(Pool& poo
                                 }                                  }
   
                                 hash.put(skey, new(pool) VXnode(pool,                                   hash.put(skey, new(pool) VXnode(pool, 
                                         gdome_xml_n_mkref(res->nodesetval->nodeTab[0])));                                          gdome_xml_n_mkref(res->nodesetval->nodeTab[i])));
                         }                          }
                         result=vhash;  
                 }                  }
                 break;                  break;
         default:           default: 
Line 618  MXnode::MXnode(Pool& apool) : Methoded(a Line 651  MXnode::MXnode(Pool& apool) : Methoded(a
         add_native_method("removeAttributeNode", Method::CT_DYNAMIC, _removeAttributeNode, 1, 1);          add_native_method("removeAttributeNode", Method::CT_DYNAMIC, _removeAttributeNode, 1, 1);
         // NodeList getElementsByTagName(in DOMString name);          // NodeList getElementsByTagName(in DOMString name);
         add_native_method("getElementsByTagName", Method::CT_DYNAMIC, _getElementsByTagName, 1, 1);          add_native_method("getElementsByTagName", Method::CT_DYNAMIC, _getElementsByTagName, 1, 1);
           // NodeList getElementsByTagNameNS(in DOMString namespaceURI, in DOMString localName);
           add_native_method("getElementsByTagNameNS", Method::CT_DYNAMIC, _getElementsByTagNameNS, 2, 2);
         // void normalize();          // void normalize();
         add_native_method("normalize", Method::CT_DYNAMIC, _normalize, 0, 0);          add_native_method("normalize", Method::CT_DYNAMIC, _normalize, 0, 0);
   

Removed from v.1.28  
changed lines
  Added in v.1.39


E-mail: