Annotation of parser3/src/classes/xnode.C, revision 1.1

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

E-mail: