--- parser3/src/classes/xdoc.C 2001/10/18 10:24:25 1.23 +++ parser3/src/classes/xdoc.C 2001/10/18 11:59:42 1.25 @@ -4,7 +4,7 @@ Copyright (c) 2001 ArtLebedev Group (http://www.artlebedev.com) Author: Alexander Petrosyan (http://design.ru/paf) - $Id: xdoc.C,v 1.23 2001/10/18 10:24:25 parser Exp $ + $Id: xdoc.C,v 1.25 2001/10/18 11:59:42 parser Exp $ */ #include "classes.h" #ifdef XML @@ -558,29 +558,24 @@ static void _set(Request& r, const Strin vdoc.set_parsed_source(*parsedSource); } -/// @test free dom_document, xalan_document static void _create(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); VXdoc& vdoc=*static_cast(r.self); - DOM_Document *dom_document=new DOM_Document(); - *dom_document=DOM_Document::createDocument(); - /* - const String& squalifiedName=params->as_string(0, "qualifiedName must be string"); + const char *qualifiedName= + params->as_string(0, "qualifiedName must be string").cstr(String::UL_XML); - /// +createXMLDecl ? - String xml(pool, "\n"); - xml << "<" << squalifiedName.cstr(String::UL_XML) << " />"; - */ - - XalanDocument& xalan_document=*new XercesDocumentBridge( - *dom_document, + XalanDocument& document=*new XercesDocumentBridge( + DOM_Document::createDocument(), 0, false /*threadSafe*/, false /*don' buildBridge -- too early, empty document*/); + /// +createXMLDecl ? + document.appendChild(document.createElement(XalanDOMString(qualifiedName))); + // replace any previous document - vdoc.set_document(xalan_document); + vdoc.set_document(document); } static void _load(Request& r, const String& method_name, MethodParams *params) { @@ -625,6 +620,7 @@ static void add_xslt_param(const Hash::K XalanDOMString(attribute_cstr), XalanDOMString(meaning_cstr)); } +/* static void _transform(Request& r, const String& method_name, MethodParams *params) { Pool& pool=r.pool(); VXdoc& vdoc=*static_cast(r.self); @@ -657,6 +653,68 @@ static void _transform(Request& r, const try { vdoc.transformer().transform2( parsed_source, + &connection.stylesheet(true/*nocache* /), + target); + } + catch (XSLException& e) { + connection.close(); + pool.exception()._throw(pool, &stylesheet_file_name, e); + } + catch (SAXParseException& e) { + connection.close(); + pool.exception()._throw(pool, &stylesheet_file_name, e); + } + catch (SAXException& e) { + connection.close(); + pool.exception()._throw(pool, &stylesheet_file_name, e); + } + catch (XMLException& e) { + connection.close(); + pool.exception()._throw(pool, &stylesheet_file_name, e); + } + catch(const XalanDOMException& e) { + connection.close(); + pool.exception()._throw(pool, &stylesheet_file_name, e); + } + + // write out result + VXdoc& result=*new(pool) VXdoc(pool); + result.set_document(*target); + r.write_no_lang(result); +} +*/ +static void _transform(Request& r, const String& method_name, MethodParams *params) { + Pool& pool=r.pool(); + VXdoc& vdoc=*static_cast(r.self); + + // params + if(params->size()>1) { + Value& vparams=params->as_no_junction(1, "transform parameters parameter must be string"); + if(vparams.is_defined()) + if(Hash *params=vparams.get_hash()) + params->for_each(add_xslt_param, &vdoc.transformer()); + else + PTHROW(0, 0, + &method_name, + "transform parameters parameter must be hash"); + } + + // source + XalanDocument &xalan_document=vdoc.get_document(pool, &method_name); + + // stylesheet + const String& stylesheet_file_name=params->as_string(0, "file name must be string"); + const String& stylesheet_filespec=r.absolute(stylesheet_file_name); + //_asm int 3; + Stylesheet_connection& connection=XSLT_stylesheet_manager->get_connection(stylesheet_filespec); + + // target + XalanDocument* target=vdoc.parser_liaison().createDocument(); + + // transform + try { + vdoc.transformer().transform2( + &xalan_document, &connection.stylesheet(true/*nocache*/), target); }