|
|
| version 1.1, 2001/09/18 12:25:06 | version 1.4, 2001/09/20 14:25:06 |
|---|---|
| Line 15 static const char *RCSId="$Id$"; | Line 15 static const char *RCSId="$Id$"; |
| #include "classes.h" | #include "classes.h" |
| #include "pa_request.h" | #include "pa_request.h" |
| #include "pa_vdnode.h" | #include "pa_vdnode.h" |
| #include "dnode.h" | #include "dnode.h" |
| #include <util/XMLString.hpp> | #include <util/XMLString.hpp> |
| //#include <XalanSourceTree/XalanSourceTreeInit.hpp> | |
| #include <XalanSourceTree/XalanSourceTreeDOMSupport.hpp> | #include <XalanSourceTree/XalanSourceTreeDOMSupport.hpp> |
| #include <XPath/XPathEvaluator.hpp> | #include <XPath/XPathEvaluator.hpp> |
| #include <XPath/NodeRefList.hpp> | #include <XPath/NodeRefList.hpp> |
| Line 31 static const char *RCSId="$Id$"; | Line 31 static const char *RCSId="$Id$"; |
| // methods | // methods |
| static void _xpath(Request& r, const String& method_name, MethodParams *params) { | static void _select(Request& r, const String& method_name, MethodParams *params) { |
| // _asm int 3; | // _asm int 3; |
| Pool& pool=r.pool(); | Pool& pool=r.pool(); |
| VDnode& vdnode=*static_cast<VDnode *>(r.self); | VDnode& vnode=*static_cast<VDnode *>(r.self); |
| // expression | // expression |
| const String& expression=params->as_string(0, "expression must not be code"); | const String& expression=params->as_string(0, "expression must not be code"); |
| Line 50 static void _xpath(Request& r, const Str | Line 50 static void _xpath(Request& r, const Str |
| try { | try { |
| NodeRefList list=evaluator.selectNodeList(dom_support, | NodeRefList list=evaluator.selectNodeList(dom_support, |
| &vdnode.get_node(pool, &method_name), | &vnode.get_node(pool, &method_name), |
| expression_dcstr); | expression_dcstr); |
| VHash& result=*new(pool) VHash(pool); | VHash& result=*new(pool) VHash(pool); |
| Line 67 static void _xpath(Request& r, const Str | Line 67 static void _xpath(Request& r, const Str |
| result.set_name(method_name); | result.set_name(method_name); |
| r.write_no_lang(result); | r.write_no_lang(result); |
| } catch(const XSLException& e) { | } catch(const XSLException& e) { |
| _throw(pool, &expression, e); | r._throw(&expression, e); |
| } | |
| } | |
| static void _select_single(Request& r, const String& method_name, MethodParams *params) { | |
| // _asm int 3; | |
| Pool& pool=r.pool(); | |
| VDnode& vnode=*static_cast<VDnode *>(r.self); | |
| // expression | |
| const String& expression=params->as_string(0, "expression must not be code"); | |
| const char *expression_cstr=expression.cstr(String::UL_AS_IS); | |
| XalanDOMString dstring(expression_cstr); | |
| const XalanDOMChar *expression_dcstr=dstring.c_str(); | |
| XPathEvaluator evaluator; | |
| // Initialize the XalanSourceTree subsystem... | |
| // XalanSourceTreeInit theSourceTreeInit; | |
| // We'll use these to parse the XML file. | |
| XalanSourceTreeDOMSupport dom_support; | |
| try { | |
| if(XalanNode *node=evaluator.selectSingleNode(dom_support, | |
| &vnode.get_node(pool, &method_name), | |
| expression_dcstr)) { | |
| VDnode& result=*new(pool) VDnode(pool, node); | |
| result.set_name(method_name); | |
| r.write_no_lang(result); | |
| } | |
| } catch(const XSLException& e) { | |
| r._throw(&expression, e); | |
| } | } |
| } | } |
| Line 76 static void _xpath(Request& r, const Str | Line 107 static void _xpath(Request& r, const Str |
| MDnode::MDnode(Pool& apool) : Methoded(apool) { | MDnode::MDnode(Pool& apool) : Methoded(apool) { |
| set_name(*NEW String(pool(), DNODE_CLASS_NAME)); | set_name(*NEW String(pool(), DNODE_CLASS_NAME)); |
| // ^node.xpath[/some/xpath/query] | // ^node.select[/some/xpath/query] = hash $.#[dnode] |
| add_native_method("xpath", Method::CT_DYNAMIC, _xpath, 1, 1); | add_native_method("select", Method::CT_DYNAMIC, _select, 1, 1); |
| // ^node.select-single[/some/xpath/query] = first dnode | |
| add_native_method("select-single", Method::CT_DYNAMIC, _select_single, 1, 1); | |
| } | } |
| // global variable | // global variable |