--- parser3/src/classes/xdoc.C 2002/08/01 11:41:13 1.97 +++ parser3/src/classes/xdoc.C 2002/09/20 13:09:49 1.103 @@ -8,7 +8,7 @@ #include "classes.h" #ifdef XML -static const char* IDENT_XDOC_C="$Date: 2002/08/01 11:41:13 $"; +static const char* IDENT_XDOC_C="$Date: 2002/09/20 13:09:49 $"; #include "pa_stylesheet_connection.h" #include "pa_request.h" @@ -170,7 +170,7 @@ static void writeNode(Request& r, const // Element createElement(in DOMString tagName) raises(DOMException); static void _createElement(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); - VXdoc& vdoc=*static_cast(r.self); + VXdoc& vdoc=*static_cast(r.get_self()); const String& tagName=params->as_string(0, "tagName must be string"); @@ -185,7 +185,7 @@ static void _createElement(Request& r, c // DocumentFragment createDocumentFragment() static void _createDocumentFragment(Request& r, const String& method_name, MethodParams *) { Pool& pool=r.pool(); - VXdoc& vdoc=*static_cast(r.self); + VXdoc& vdoc=*static_cast(r.get_self()); GdomeException exc; GdomeNode *node= @@ -198,7 +198,7 @@ static void _createDocumentFragment(Requ // Text createTextNode(in DOMString data); static void _createTextNode(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); - VXdoc& vdoc=*static_cast(r.self); + VXdoc& vdoc=*static_cast(r.get_self()); const String& data=params->as_string(0, "data must be string"); @@ -213,7 +213,7 @@ static void _createTextNode(Request& r, // Comment createComment(in DOMString data) static void _createComment(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); - VXdoc& vdoc=*static_cast(r.self); + VXdoc& vdoc=*static_cast(r.get_self()); const String& data=params->as_string(0, "data must be string"); @@ -228,7 +228,7 @@ static void _createComment(Request& r, c // CDATASection createCDATASection(in DOMString data) raises(DOMException); static void _createCDATASection(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); - VXdoc& vdoc=*static_cast(r.self); + VXdoc& vdoc=*static_cast(r.get_self()); const String& data=params->as_string(0, "data must be string"); @@ -243,7 +243,7 @@ static void _createCDATASection(Request& // ProcessingInstruction createProcessingInstruction(in DOMString target,in DOMString data) raises(DOMException); static void _createProcessingInstruction(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); - VXdoc& vdoc=*static_cast(r.self); + VXdoc& vdoc=*static_cast(r.get_self()); const String& target=params->as_string(0, "data must be string"); const String& data=params->as_string(1, "data must be string"); @@ -260,7 +260,7 @@ static void _createProcessingInstruction // Attr createAttribute(in DOMString name) raises(DOMException); static void _createAttribute(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); - VXdoc& vdoc=*static_cast(r.self); + VXdoc& vdoc=*static_cast(r.get_self()); const String& name=params->as_string(0, "name must be string"); @@ -274,7 +274,7 @@ static void _createAttribute(Request& r, // EntityReference createEntityReference(in DOMString name) raises(DOMException); static void _createEntityReference(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); - VXdoc& vdoc=*static_cast(r.self); + VXdoc& vdoc=*static_cast(r.get_self()); const String& name=params->as_string(0, "name must be string"); @@ -286,9 +286,76 @@ static void _createEntityReference(Reque writeNode(r, method_name, node, exc); } +// NodeList getElementsByTagName(in DOMString name); +static void _getElementsByTagName(Request& r, const String& method_name, MethodParams *params) { + Pool& pool=r.pool(); + VXdoc& vdoc=*static_cast(r.get_self()); + + const String& name=params->as_string(0, "name must be string"); + + VHash& result=*new(pool) VHash(pool); + GdomeException exc; + if(GdomeNodeList *nodes= + gdome_doc_getElementsByTagName( + vdoc.get_document(&method_name), + pool.transcode(name).get(), + &exc)) { + gulong length=gdome_nl_length(nodes, &exc); + for(gulong i=0; i(r.get_self()); + + // namespaceURI;localName + const String& namespaceURI=params->as_string(0, "namespaceURI must be string"); + const String& localName=params->as_string(1, "localName must be string"); + + GdomeException exc; + VHash& result=*new(pool) VHash(pool); + if(GdomeNodeList *nodes= + gdome_doc_getElementsByTagNameNS( + vdoc.get_document(&method_name), + pool.transcode(namespaceURI).get(), + pool.transcode(localName).get(), + &exc)) { + gulong length=gdome_nl_length(nodes, &exc); + for(gulong i=0; i(r.self); + VXdoc& vdoc=*static_cast(r.get_self()); // elementId const String& elementId=params->as_string(0, "elementID must be string"); @@ -309,7 +376,7 @@ static void _getElementById(Request& r, static void _importNode(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); - VXdoc& vdoc=*static_cast(r.self); + VXdoc& vdoc=*static_cast(r.get_self()); GdomeNode *importedNode= as_node(method_name, params, 0, "importedNode must be node"); @@ -335,7 +402,7 @@ GdomeAttr *gdome_doc_createAttributeNS ( static void _create(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); - VXdoc& vdoc=*static_cast(r.self); + VXdoc& vdoc=*static_cast(r.get_self()); Value& param=params->get(params->size()-1); GdomeDocument *document; @@ -380,6 +447,10 @@ static void _create(Request& r, const St &method_name, exc); + xmlDoc *doc=gdome_xml_doc_get_xmlDoc(document); + const char *source_charset_name=pool.get_source_charset().name().cstr(); + doc->encoding=pool.get_source_charset().transcode_buf2xchar(source_charset_name, strlen(source_charset_name)); + /// +xalan createXMLDecl ? } @@ -400,7 +471,7 @@ static void _create(Request& r, const St static void _load(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); - VXdoc& vdoc=*static_cast(r.self); + VXdoc& vdoc=*static_cast(r.get_self()); // filespec const String& file_name=params->as_string(0, "uri must be string"); @@ -443,6 +514,7 @@ static void param_option_over_output_opt } } +/// @test valid_options check static void prepare_output_options( Pool& pool, const String& method_name, MethodParams *params, int index, VXdoc::Output_options& oo) { @@ -581,7 +653,7 @@ static void xdoc2buf(Pool& pool, VXdoc& static void _file(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); - VXdoc& vdoc=*static_cast(r.self); + VXdoc& vdoc=*static_cast(r.get_self()); VXdoc::Output_options oo(vdoc.output_options); char *buf; size_t buf_size; xdoc2buf(pool, vdoc, method_name, params, 0, @@ -603,13 +675,14 @@ static void _file(Request& r, const Stri new(pool) VString(*oo.encoding)); vcontent_type=vhcontent_type; - vfile.set(false/*tainted*/, buf, buf_size, 0/*file_name*/, vcontent_type); + vfile.set(false/*tainted*/, buf?buf:""/*to distinguish from stat-ed file*/, buf_size, + 0/*file_name*/, vcontent_type); r.write_no_lang(vfile); } static void _save(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); - VXdoc& vdoc=*static_cast(r.self); + VXdoc& vdoc=*static_cast(r.get_self()); const String& file_spec=r.absolute(params->as_string(0, "file name must be string")); @@ -622,7 +695,7 @@ static void _save(Request& r, const Stri static void _string(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); - VXdoc& vdoc=*static_cast(r.self); + VXdoc& vdoc=*static_cast(r.get_self()); VXdoc::Output_options oo(vdoc.output_options); char *buf; size_t buf_size; xdoc2buf(pool, vdoc, method_name, params, 0, @@ -707,7 +780,7 @@ static VXdoc& _transform(Pool& pool, con } static void _transform(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); - VXdoc& vdoc=*static_cast(r.self); + VXdoc& vdoc=*static_cast(r.get_self()); // params const char **transform_params=0; @@ -727,9 +800,9 @@ static void _transform(Request& r, const VXdoc *result; Value& vmaybe_xdoc=params->get(0); - if(strcmp(vmaybe_xdoc.type(), VXDOC_TYPE)==0) { // stylesheet (xdoc) + if(Value *vxdoc=vmaybe_xdoc.as(VXDOC_TYPE, false)) { // stylesheet (xdoc) xmlDoc *document=gdome_xml_doc_get_xmlDoc( - static_cast(&vmaybe_xdoc)->get_document(&method_name)); + static_cast(vxdoc)->get_document(&method_name)); // compile xdoc stylesheet xsltStylesheet_auto_ptr stylesheet_ptr(xsltParseStylesheetDoc(document)); // strange thing - xsltParseStylesheetDoc records document and destroys it in stylesheet destructor @@ -787,6 +860,8 @@ MXdoc::MXdoc(Pool& apool) : MXnode(apool add_native_method("createAttribute", Method::CT_DYNAMIC, _createAttribute, 1, 1); // EntityReference createEntityReference(in DOMString name) raises(DOMException); add_native_method("createEntityReference", Method::CT_DYNAMIC, _createEntityReference, 1, 1); + // NodeList getElementsByTagName(in DOMString name); + add_native_method("getElementsByTagName", Method::CT_DYNAMIC, _getElementsByTagName, 1, 1); /// DOM2 @@ -796,6 +871,9 @@ MXdoc::MXdoc(Pool& apool) : MXnode(apool // Node (in Node importedNode, in boolean deep) raises(DOMException) add_native_method("importNode", Method::CT_DYNAMIC, _importNode, 2, 2); + // NodeList getElementsByTagNameNS(in DOMString namespaceURI, in DOMString localName); + add_native_method("getElementsByTagNameNS", Method::CT_DYNAMIC, _getElementsByTagNameNS, 2, 2); + /// parser // ^xdoc::create{qualifiedName} @@ -820,8 +898,8 @@ MXdoc::MXdoc(Pool& apool) : MXnode(apool // ^xdoc.file[options hash] file with "" add_native_method("file", Method::CT_DYNAMIC, _file, 0, 1); - // ^xdoc.transform[stylesheet file_name] - // ^xdoc.transform[stylesheet file_name;params hash] + // ^xdoc.transform[stylesheet file_name/xdoc] + // ^xdoc.transform[stylesheet file_name/xdoc;params hash] add_native_method("transform", Method::CT_DYNAMIC, _transform, 1, 2); }