Annotation of parser3/src/classes/dnode.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:
! 6: Author: Alexander Petrosyan <paf@design.ru> (http://design.ru/paf)
! 7: */
! 8: static const char *RCSId="$Id: dom.C,v 1.22 2001/09/15 14:22:47 parser Exp $";
! 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"
! 18: #include "dnode.h"
! 19:
! 20: #include <util/XMLString.hpp>
! 21: //#include <XalanSourceTree/XalanSourceTreeInit.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:
! 34: static void _xpath(Request& r, const String& method_name, MethodParams *params) {
! 35: // _asm int 3;
! 36: Pool& pool=r.pool();
! 37: VDnode& vdnode=*static_cast<VDnode *>(r.self);
! 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,
! 53: &vdnode.get_node(pool, &method_name),
! 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) {
! 70: _throw(pool, &expression, e);
! 71: }
! 72: }
! 73:
! 74: // constructor
! 75:
! 76: MDnode::MDnode(Pool& apool) : Methoded(apool) {
! 77: set_name(*NEW String(pool(), DNODE_CLASS_NAME));
! 78:
! 79: // ^node.xpath[/some/xpath/query]
! 80: add_native_method("xpath", Method::CT_DYNAMIC, _xpath, 1, 1);
! 81:
! 82: }
! 83: // global variable
! 84:
! 85: Methoded *Dnode_class;
! 86:
! 87: // creator
! 88:
! 89: Methoded *MDnode_create(Pool& pool) {
! 90: return Dnode_class=new(pool) MDnode(pool);
! 91: }
E-mail: