Annotation of parser3/src/classes/dnode.C, revision 1.4

1.1       parser      1: /** @file
                      2:        Parser: @b dom parser class.
                      3: 
                      4:        Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com)
                      5: 
                      6:        Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
                      7: */
1.4     ! parser      8: static const char *RCSId="$Id: dnode.C,v 1.3 2001/09/20 07:31:51 parser Exp $"; 
1.1       parser      9: 
                     10: #if _MSC_VER
                     11: #      pragma warning(disable:4291)   // disable warning 
                     12: //     "no matching operator delete found; memory will not be freed if initialization throws an exception
                     13: #endif
                     14: 
                     15: #include "classes.h"
                     16: #include "pa_request.h"
                     17: #include "pa_vdnode.h"
1.2       parser     18: 
1.1       parser     19: #include "dnode.h"
                     20: 
                     21: #include <util/XMLString.hpp>
                     22: #include <XalanSourceTree/XalanSourceTreeDOMSupport.hpp>
                     23: #include <XPath/XPathEvaluator.hpp>
                     24: #include <XPath/NodeRefList.hpp>
                     25: 
                     26: // defines
                     27: 
                     28: #define DNODE_CLASS_NAME "dnode"
                     29: 
                     30: // class
                     31: 
                     32: // methods
                     33: 
1.3       parser     34: static void _select(Request& r, const String& method_name, MethodParams *params) {
1.1       parser     35: //     _asm int 3;
                     36:        Pool& pool=r.pool();
1.2       parser     37:        VDnode& vnode=*static_cast<VDnode *>(r.self);
1.1       parser     38: 
                     39:        // expression
                     40:        const String& expression=params->as_string(0, "expression must not be code");
                     41:        const char *expression_cstr=expression.cstr(String::UL_AS_IS);
                     42:        XalanDOMString dstring(expression_cstr);
                     43:        const XalanDOMChar *expression_dcstr=dstring.c_str();
                     44: 
                     45:        XPathEvaluator evaluator;
                     46:        // Initialize the XalanSourceTree subsystem...
                     47: //     XalanSourceTreeInit             theSourceTreeInit;
                     48:        // We'll use these to parse the XML file.
                     49:        XalanSourceTreeDOMSupport dom_support;
                     50: 
                     51:        try {
                     52:                NodeRefList list=evaluator.selectNodeList(dom_support, 
1.2       parser     53:                        &vnode.get_node(pool, &method_name), 
1.1       parser     54:                        expression_dcstr);
                     55: 
                     56:                VHash& result=*new(pool) VHash(pool);
                     57:                for(int i=0; i<list.getLength(); i++) {
                     58:                        String& skey=*new(pool) String(pool);
                     59:                        {
                     60:                                char *buf=(char *)pool.malloc(MAX_NUMBER);
                     61:                                snprintf(buf, MAX_NUMBER, "%d", i);
                     62:                                skey << buf;
                     63:                        }
                     64: 
                     65:                        result.hash().put(skey, new(pool) VDnode(pool, list.item(i)));
                     66:                }
                     67:                result.set_name(method_name);
                     68:                r.write_no_lang(result);
                     69:        } catch(const XSLException& e) {
1.4     ! parser     70:                r._throw(&expression, e);
1.1       parser     71:        }
                     72: }
                     73: 
1.3       parser     74: static void _select_single(Request& r, const String& method_name, MethodParams *params) {
                     75: //     _asm int 3;
                     76:        Pool& pool=r.pool();
                     77:        VDnode& vnode=*static_cast<VDnode *>(r.self);
                     78: 
                     79:        // expression
                     80:        const String& expression=params->as_string(0, "expression must not be code");
                     81:        const char *expression_cstr=expression.cstr(String::UL_AS_IS);
                     82:        XalanDOMString dstring(expression_cstr);
                     83:        const XalanDOMChar *expression_dcstr=dstring.c_str();
                     84: 
                     85:        XPathEvaluator evaluator;
                     86:        // Initialize the XalanSourceTree subsystem...
                     87: //     XalanSourceTreeInit             theSourceTreeInit;
                     88:        // We'll use these to parse the XML file.
                     89:        XalanSourceTreeDOMSupport dom_support;
                     90: 
                     91:        try {
                     92:                 if(XalanNode *node=evaluator.selectSingleNode(dom_support, 
                     93:                        &vnode.get_node(pool, &method_name), 
                     94:                        expression_dcstr)) {
                     95: 
                     96:                        VDnode& result=*new(pool) VDnode(pool, node);
                     97:                        result.set_name(method_name);
                     98:                        r.write_no_lang(result);
                     99:                }
                    100:        } catch(const XSLException& e) {
1.4     ! parser    101:                r._throw(&expression, e);
1.3       parser    102:        }
                    103: }
                    104: 
1.1       parser    105: // constructor
                    106: 
                    107: MDnode::MDnode(Pool& apool) : Methoded(apool) {
                    108:        set_name(*NEW String(pool(), DNODE_CLASS_NAME));
1.2       parser    109: 
1.3       parser    110:        // ^node.select[/some/xpath/query] = hash $.#[dnode]
                    111:        add_native_method("select", Method::CT_DYNAMIC, _select, 1, 1);
1.1       parser    112: 
1.3       parser    113:        // ^node.select-single[/some/xpath/query] = first dnode
                    114:        add_native_method("select-single", Method::CT_DYNAMIC, _select_single, 1, 1);
1.1       parser    115: 
                    116: }
                    117: // global variable
                    118: 
                    119: Methoded *Dnode_class;
                    120: 
                    121: // creator
                    122: 
                    123: Methoded *MDnode_create(Pool& pool) {
                    124:        return Dnode_class=new(pool) MDnode(pool);
                    125: }

E-mail: