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

version 1.28, 2002/01/21 13:04:02 version 1.35, 2002/01/28 10:50:03
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 396  static void _selectX(Request& r, const S Line 397  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 426  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 442  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: 

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


E-mail: