--- parser3/src/classes/Attic/dom.C 2001/09/20 07:31:51 1.26 +++ parser3/src/classes/Attic/dom.C 2001/09/21 09:04:18 1.32 @@ -5,12 +5,7 @@ Author: Alexander Petrosyan (http://design.ru/paf) */ -static const char *RCSId="$Id: dom.C,v 1.26 2001/09/20 07:31:51 parser Exp $"; - -#if _MSC_VER -# pragma warning(disable:4291) // disable warning -// "no matching operator delete found; memory will not be freed if initialization throws an exception -#endif +static const char *RCSId="$Id: dom.C,v 1.32 2001/09/21 09:04:18 parser Exp $"; #include "classes.h" #include "pa_request.h" @@ -86,30 +81,33 @@ static void create_optioned_listener( const char *& content_type, const char *& charset, FormatterListener *& listener, Pool& pool, const String& method_name, MethodParams *params, int index, Writer& writer) { - charset=0; + // default encoding from pool + const String *scharset=&pool.get_charset(); const String *method=0; XalanDOMString xalan_encoding; - Value& voptions=params->as_no_junction(index, "options must not be code"); - if(voptions.is_defined()) { - if(Hash *options=voptions.get_hash()) { - // $.method[xml|html|text] - if(Value *vmethod=static_cast(options->get(*new(pool) - String(pool, DOM_OUTPUT_METHOD_OPTION_NAME)))) - method=&vmethod->as_string(); - - // $.encoding[windows-1251|...] - if(Value *vencoding=static_cast(options->get(*new(pool) - String(pool, DOM_OUTPUT_ENCODING_OPTION_NAME)))) { - charset=vencoding->as_string().cstr(); - xalan_encoding.append(charset, strlen(charset)); - } - } else - PTHROW(0, 0, - &method_name, - "options must be hash"); + if(params->size()>index) { + Value& voptions=params->as_no_junction(index, "options must not be code"); + if(voptions.is_defined()) { + if(Hash *options=voptions.get_hash()) { + // $.method[xml|html|text] + if(Value *vmethod=static_cast(options->get(*new(pool) + String(pool, DOM_OUTPUT_METHOD_OPTION_NAME)))) + method=&vmethod->as_string(); + + // $.encoding[windows-1251|...] + if(Value *vencoding=static_cast(options->get(*new(pool) + String(pool, DOM_OUTPUT_ENCODING_OPTION_NAME)))) { + scharset=&vencoding->as_string(); + } + } else + PTHROW(0, 0, + &method_name, + "options must be hash"); + } } + xalan_encoding.append(charset=scharset->cstr()); if(!method/*default='xml'*/ || *method == DOM_OUTPUT_METHOD_OPTION_VALUE_XML) { content_type="text/xml"; listener=new FormatterToXML(writer, @@ -149,7 +147,7 @@ static void _save(Request& r, const Stri VDnode& vnode=*static_cast(r.self); // filespec - const String& file_name=params->as_string(1, "file name must not be code"); + const String& file_name=params->as_string(0, "file name must not be code"); const char *filespec=r.absolute(file_name).cstr(String::UL_FILE_SPEC); // node @@ -161,11 +159,11 @@ static void _save(Request& r, const Stri const char *content_type, *charset; FormatterListener *formatterListener; create_optioned_listener(content_type, charset, formatterListener, - pool, method_name, params, 0, writer); + pool, method_name, params, 1, writer); FormatterTreeWalker treeWalker(*formatterListener); treeWalker.traverse(&node); // Walk that node and produce the XML... } catch(const XSLException& e) { - _throw(pool, &method_name, e); + r._throw(&method_name, e); } } @@ -190,7 +188,7 @@ static void _string(Request& r, const St // write out result r.write_no_lang(parserString); } catch(const XSLException& e) { - _throw(pool, &method_name, e); + r._throw(&method_name, e); } } @@ -229,7 +227,7 @@ static void _file(Request& r, const Stri vfile.set(false/*tainted*/, cstr, strlen(cstr), 0/*file_name*/, vcontent_type); r.write_no_lang(vfile); } catch(const XSLException& e) { - _throw(pool, &method_name, e); + r._throw(&method_name, e); } } @@ -335,14 +333,17 @@ static void _xslt(Request& r, const Stri MDom::MDom(Pool& apool) : MDnode(apool) { set_name(*NEW String(pool(), DOM_CLASS_NAME)); - // ^dom.save[options hash;some.xml] - add_native_method("save", Method::CT_DYNAMIC, _save, 2, 2); + // ^dom.save[some.xml] + // ^dom.save[some.xml;options hash] + add_native_method("save", Method::CT_DYNAMIC, _save, 1, 2); + // ^dom.string[] // ^dom.string[options hash] - add_native_method("string", Method::CT_DYNAMIC, _string, 1, 1); + add_native_method("string", Method::CT_DYNAMIC, _string, 0, 1); + // ^dom.file[] file with "" // ^dom.file[options hash] file with "" - add_native_method("file", Method::CT_DYNAMIC, _file, 1, 1); + add_native_method("file", Method::CT_DYNAMIC, _file, 0, 1); // ^dom::set[xml] add_native_method("set", Method::CT_DYNAMIC, _set, 1, 1);