--- parser3/src/classes/xdoc.C 2002/06/27 08:32:18 1.94 +++ parser3/src/classes/xdoc.C 2002/08/19 09:48:39 1.99 @@ -3,12 +3,13 @@ Copyright (c) 2001, 2002 ArtLebedev Group (http://www.artlebedev.com) Author: Alexandr Petrosian (http://paf.design.ru) - - $Id: xdoc.C,v 1.94 2002/06/27 08:32:18 paf Exp $ */ + #include "classes.h" #ifdef XML +static const char* IDENT_XDOC_C="$Date: 2002/08/19 09:48:39 $"; + #include "pa_stylesheet_connection.h" #include "pa_request.h" #include "pa_vxdoc.h" @@ -285,6 +286,73 @@ 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.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.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); @@ -332,15 +400,13 @@ GdomeElement *gdome_doc_createElementNS GdomeAttr *gdome_doc_createAttributeNS (GdomeDocument *self, GdomeDOMString *namespaceURI, GdomeDOMString *qualifiedName, GdomeException *exc); */ - static void _create(Request& r, const String& method_name, MethodParams *params) { - //_asm int 3; Pool& pool=r.pool(); VXdoc& vdoc=*static_cast(r.self); - Value& param=params->get(0); + Value& param=params->get(params->size()-1); GdomeDocument *document; - if(param.get_junction()) { // {} + if(param.get_junction()) { // {...} Temp_lang temp_lang(r, String::UL_XML); const String& xml=r.process_to_string(param); @@ -383,6 +449,18 @@ static void _create(Request& r, const St /// +xalan createXMLDecl ? } + + // URI + const char *URI_cstr; + if(params->size()>1) { // absolute(param) + const String& URI=params->as_string(0, "URI must be string"); + URI_cstr=r.absolute(URI).cstr(); + } else // default = disk path to requested document + URI_cstr=r.info.path_translated; + xmlDoc *doc=gdome_xml_doc_get_xmlDoc(document); + if(URI_cstr) + doc->URL=pool.transcode_buf2xchar(URI_cstr, strlen(URI_cstr)); + // replace any previous parsed source vdoc.set_document(document); } @@ -716,9 +794,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 @@ -776,6 +854,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 @@ -785,11 +865,15 @@ 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} - // ^xdoc::_create[xml] - add_native_method("create", Method::CT_DYNAMIC, _create, 1, 1); + // ^xdoc::create[xml] + // ^xdoc::create[URI][xml] + add_native_method("create", Method::CT_DYNAMIC, _create, 1, 2); // for backward compatibility with <=v 1.82 2002/01/31 11:51:46 paf add_native_method("set", Method::CT_DYNAMIC, _create, 1, 1); @@ -808,8 +892,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); }