Diff for /parser3/src/classes/xdoc.C between versions 1.169 and 1.200

version 1.169, 2011/05/27 06:55:47 version 1.200, 2020/12/15 17:10:29
Line 1 Line 1
 /** @file  /** @file
         Parser: @b xdoc parser class.          Parser: @b xdoc parser class.
   
         Copyright (c) 2001-2009 ArtLebedev Group (http://www.artlebedev.com)          Copyright (c) 2001-2020 Art. Lebedev Studio (http://www.artlebedev.com)
         Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)          Author: Alexandr Petrosian <paf@design.ru> (http://paf.design.ru)
 */  */
   
Line 9 Line 9
   
 #ifdef XML  #ifdef XML
   
 static const char * const IDENT_XDOC_C="$Date$";  
   
 #include "libxml/tree.h"  #include "libxml/tree.h"
 #include "libxml/HTMLtree.h"  #include "libxml/HTMLtree.h"
 #include "libxslt/xsltInternals.h"  #include "libxslt/xsltInternals.h"
Line 28  static const char * const IDENT_XDOC_C=" Line 26  static const char * const IDENT_XDOC_C="
 #include "pa_vfile.h"  #include "pa_vfile.h"
 #include "pa_xml_exception.h"  #include "pa_xml_exception.h"
 #include "xnode.h"  #include "xnode.h"
   #include "pa_charsets.h"
   
   volatile const char * IDENT_XDOC_C="$Id$";
   
 // defines  // defines
   
Line 46  public: Line 47  public:
   
 // global variable  // global variable
   
 DECLARE_CLASS_VAR(xdoc, new MXdoc, 0);  DECLARE_CLASS_VAR(xnode, new MXnode); // must be here as Xdoc is inherited from Xnode and should be inited before
   DECLARE_CLASS_VAR(xdoc, new MXdoc);
   
 // helper classes  // helper classes
   
Line 116  private: Line 118  private:
         xsltTransformContext *_Ptr;          xsltTransformContext *_Ptr;
 };  };
   
 class xsltStylesheet_auto_ptr {  
 public:  
         explicit xsltStylesheet_auto_ptr(xsltStylesheet *_APtr = 0)   
                 : _Owns(_APtr != 0), _Ptr(_APtr) {}  
         xsltStylesheet_auto_ptr(const xsltStylesheet_auto_ptr& _Y)   
                 : _Owns(_Y._Owns), _Ptr(_Y.release()) {}  
         xsltStylesheet_auto_ptr& operator=(const xsltStylesheet_auto_ptr& _Y)   
                 {if (this != &_Y)  
                         {if (_Ptr != _Y.get())  
                                 {if (_Owns && _Ptr)  
                                         xsltFreeStylesheet(_Ptr);  
                                 _Owns = _Y._Owns; }  
                         else if (_Y._Owns)  
                                 _Owns = true;  
                         _Ptr = _Y.release(); }  
                 return (*this); }  
         ~xsltStylesheet_auto_ptr()  
                 {if (_Owns && _Ptr)  
                         xsltFreeStylesheet(_Ptr); }  
         xsltStylesheet& operator*() const   
                 {return (*get()); }  
         xsltStylesheet *operator->() const   
                 {return (get()); }  
         xsltStylesheet *get() const   
                 {return (_Ptr); }  
         xsltStylesheet *release() const   
                 {((xsltStylesheet_auto_ptr *)this)->_Owns = false;  
                 return (_Ptr); }  
 private:  
         bool _Owns;  
         xsltStylesheet *_Ptr;  
 };  
   
 // methods  // methods
   
 static void writeNode(Request& r, VXdoc& xdoc, xmlNode* node) {  static void writeNode(Request& r, VXdoc& xdoc, xmlNode* node) {
Line 158  static void writeNode(Request& r, VXdoc& Line 127  static void writeNode(Request& r, VXdoc&
                         "error creating node"); // OOM, bad name, things like that                          "error creating node"); // OOM, bad name, things like that
   
         // write out result          // write out result
         r.write_no_lang(xdoc.wrap(*node));          r.write(xdoc.wrap(*node));
 }  }
   
 struct IdsIteratorInfo {  struct IdsIteratorInfo {
Line 166  struct IdsIteratorInfo { Line 135  struct IdsIteratorInfo {
         xmlNode *element;          xmlNode *element;
 };  };
   
 /* Hash Scanner function for pa_getElementById */  /* switching to calling convetion of libxml */
 extern "C" void // switching to calling convetion of libxml  extern "C" void idsHashScanner (void *payload, void *data, const xmlChar *name) {
 idsHashScanner (void *payload, void *data, xmlChar *name) {  
         IdsIteratorInfo *priv = (IdsIteratorInfo *)data;          IdsIteratorInfo *priv = (IdsIteratorInfo *)data;
   
         if (priv->element == NULL && xmlStrEqual (name, priv->elementId))          if (priv->element == NULL && xmlStrEqual (name, priv->elementId))
Line 179  idsHashScanner (void *payload, void *dat Line 147  idsHashScanner (void *payload, void *dat
         }          }
 }  }
   
 static xmlNode*  static xmlNode* pa_getElementById(xmlDoc& xmldoc, xmlChar* elementId) {
 pa_getElementById(xmlDoc& xmldoc, xmlChar* elementId) {  
         xmlHashTable *ids = (xmlHashTable *)xmldoc.ids;          xmlHashTable *ids = (xmlHashTable *)xmldoc.ids;
         IdsIteratorInfo iter={elementId, NULL};          IdsIteratorInfo iter={elementId, NULL};
         xmlHashScan(ids, idsHashScanner, &iter);          xmlHashScan(ids, (xmlHashScanner)idsHashScanner, &iter);
         return iter.element;          return iter.element;
 }  }
   
Line 364  static void _importNode(Request& r, Meth Line 331  static void _importNode(Request& r, Meth
         writeNode(r, vdoc, node);          writeNode(r, vdoc, node);
 }  }
   
 /*  #define XML_PARSE_OPTIONS (XML_PARSE_DTDLOAD | XML_PARSE_NOENT | XML_PARSE_HUGE)
 GdomeElement *gdome_doc_createElementNS (GdomeDocument *self, GdomeDOMString *namespaceURI, GdomeDOMString *qualifiedName, GdomeException *exc);  
 GdomeAttr *gdome_doc_createAttributeNS (GdomeDocument *self, GdomeDOMString *namespaceURI, GdomeDOMString *qualifiedName, GdomeException *exc);  
 */  
   
 static void _create(Request& r, MethodParams& params) {  static void _create(Request& r, MethodParams& params) {
         Charset& source_charset=r.charsets.source();          Charset& source_charset=r.charsets.source();
Line 377  static void _create(Request& r, MethodPa Line 341  static void _create(Request& r, MethodPa
         xmlDoc* xmldoc;          xmlDoc* xmldoc;
         bool set_encoding=false;          bool set_encoding=false;
         if(param.get_junction()) { // {<?xml?>...}          if(param.get_junction()) { // {<?xml?>...}
                 Temp_lang temp_lang(r, String::L_XML);  
                 const String& xml=r.process_to_string(param);                  const String& xml=r.process_to_string(param);
                   String::Body sbody=xml.cstr_to_string_body_untaint(String::L_XML, r.connection(false), &r.charsets);
   
                 String::Body sbody=xml.cstr_to_string_body_untaint(r.flang, 0, &r.charsets);                  xmldoc=xmlReadMemory(sbody.cstr(), sbody.length(), NULL, NULL, XML_PARSE_OPTIONS);
                 xmldoc=xmlParseMemory(sbody.cstr(), sbody.length());  
   
                 //printf("document=0x%p\n", document);  
                 if(!xmldoc || xmlHaveGenericErrors())                  if(!xmldoc || xmlHaveGenericErrors())
                         throw XmlException(0);                          throw XmlException(0, r);
   
                 // must be last action in if, see after if}                  // must be last action in if, see after if}
         } else { // [localName]          } else { // [localName]
Line 394  static void _create(Request& r, MethodPa Line 357  static void _create(Request& r, MethodPa
                         if(xmlValidateNCName(localName, 0) != 0)                          if(xmlValidateNCName(localName, 0) != 0)
                                 throw XmlException(0, XML_INVALID_LOCAL_NAME, localName);                                  throw XmlException(0, XML_INVALID_LOCAL_NAME, localName);
   
 #if 0  
                         GdomeDocumentType *documentType=gdome_di_createDocumentType (  
                                 docimpl,   
                                 r.transcode(qualifiedName),   
                                 0/*publicId*/,   
                                 0/*systemId*/,   
                                 &exc);  
                         if(!documentType || exc || xmlHaveGenericErrors())  
                                 throw Exception(  
                                         method_name,   
                                         exc);  
                         /// +xalan createXMLDecl ?  
 #endif  
                         xmldoc=xmlNewDoc(0);                          xmldoc=xmlNewDoc(0);
                         if(!xmldoc || xmlHaveGenericErrors())                          if(!xmldoc || xmlHaveGenericErrors())
                                 throw XmlException(0);                                  throw XmlException(0, r);
   
                         xmlNode* node=xmlNewChild((xmlNode*)xmldoc, NULL, localName, NULL);                          xmlNode* node=xmlNewChild((xmlNode*)xmldoc, NULL, localName, NULL);
                         if(!node || xmlHaveGenericErrors())                          if(!node || xmlHaveGenericErrors())
                                 throw XmlException(0);                                  throw XmlException(0, r);
   
                         set_encoding=true;                          set_encoding=true;
                         // must be last action in if, see after if}                          // must be last action in if, see after if}
                 } else {                  } else {
                         VFile* vfile=param.as_vfile(String::L_AS_IS);                          VFile* vfile=param.as_vfile(String::L_AS_IS);
                         xmldoc=xmlParseMemory(vfile->value_ptr(), vfile->value_size());                          xmldoc=xmlReadMemory(vfile->value_ptr(), vfile->value_size(), NULL, NULL, XML_PARSE_OPTIONS);
                         if(!xmldoc || xmlHaveGenericErrors())                          if(!xmldoc || xmlHaveGenericErrors())
                                 throw XmlException(0);                                  throw XmlException(0, r);
                 }                  }
         }          }
         // must be first action after if}          // must be first action after if}
Line 432  static void _create(Request& r, MethodPa Line 382  static void _create(Request& r, MethodPa
         const char* URI_cstr;          const char* URI_cstr;
         if(params.count()>1) { // absolute(param)          if(params.count()>1) { // absolute(param)
                 const String& URI=params.as_string(0, "URI must be string");                  const String& URI=params.as_string(0, "URI must be string");
                 URI_cstr=r.absolute(URI).cstr();                  URI_cstr=r.full_disk_path(URI).cstr();
         } else // default = disk path to requested document          } else // default = disk path to requested document
                 URI_cstr=r.request_info.path_translated;                  URI_cstr=r.request_info.path_translated;
         if(URI_cstr)          if(URI_cstr)
Line 451  static void _load(Request& r, MethodPara Line 401  static void _load(Request& r, MethodPara
         const String* uri=&params.as_string(0, "URI must be string");          const String* uri=&params.as_string(0, "URI must be string");
         const char* uri_cstr;          const char* uri_cstr;
         if(uri->pos("://")==STRING_NOT_FOUND) // disk path          if(uri->pos("://")==STRING_NOT_FOUND) // disk path
                 uri_cstr=r.absolute(*uri).taint_cstr(String::L_FILE_SPEC);                  uri_cstr=r.full_disk_path(*uri).taint_cstr(String::L_FILE_SPEC);
         else // xxx://           else // xxx:// 
                 uri_cstr=uri->taint_cstr(String::L_AS_IS); // leave as-is for xmlParseFile to handle                  uri_cstr=uri->taint_cstr(String::L_AS_IS); // leave as-is for xmlParseFile to handle
   
         /// @todo!! add SAFE MODE!!          /// @todo!! add SAFE MODE!!
         xmlDoc* xmldoc=xmlParseFile(uri_cstr);          xmlDoc* xmldoc=xmlReadFile(uri_cstr, NULL, XML_PARSE_OPTIONS);
         if(!xmldoc || xmlHaveGenericErrors())          if(!xmldoc || xmlHaveGenericErrors())
                 throw XmlException(uri);                  throw XmlException(uri, r);
                   
         // must be first action after if}          // must be first action after if}
         // replace any previous parsed source          // replace any previous parsed source
Line 469  String::C xdoc2buf(Request& r, VXdoc& vd Line 419  String::C xdoc2buf(Request& r, VXdoc& vd
                                         XDocOutputOptions& oo,                                          XDocOutputOptions& oo,
                                         const String* file_spec,                                          const String* file_spec,
                                         bool use_source_charset_to_render_and_client_charset_to_write_to_header=false) {                                          bool use_source_charset_to_render_and_client_charset_to_write_to_header=false) {
         const char* render_encoding;          Charset* render=0;
         const char* header_encoding;          Charset* header=0;
         if(use_source_charset_to_render_and_client_charset_to_write_to_header) {          if(use_source_charset_to_render_and_client_charset_to_write_to_header) {
                 render_encoding=r.charsets.source().NAME_CSTR();                  render=&r.charsets.source();
                 header_encoding=r.charsets.client().NAME_CSTR();                  header=&r.charsets.client();
         } else {          } else {
                 header_encoding=render_encoding=oo.encoding->cstr();                  header=render=&pa_charsets.get(*oo.encoding);
         }          }
           const char* render_encoding=render->NAME_CSTR();
           const char* header_encoding=header->NAME_CSTR();
   
         xmlCharEncodingHandler *renderer=xmlFindCharEncodingHandler(render_encoding);          xmlCharEncodingHandler *renderer=xmlFindCharEncodingHandler(render_encoding);
         if(!renderer)  
                 throw Exception(PARSER_RUNTIME,  
                         0,  
                         "encoding '%s' not supported", render_encoding);  
         // UTF-8 renderer contains empty input/output converters,           // UTF-8 renderer contains empty input/output converters, 
         // which is wrong for xmlOutputBufferCreateIO          // which is wrong for xmlOutputBufferCreateIO
         // while zero renderer goes perfectly           // while zero renderer goes perfectly 
         if(strcmp(render_encoding, "UTF-8")==0)          if(render->isUTF8())
                 renderer=0;                  renderer=0;
   
         xmlOutputBuffer_auto_ptr outputBuffer(xmlAllocOutputBuffer(renderer));          xmlOutputBuffer_auto_ptr outputBuffer(xmlAllocOutputBuffer(renderer));
   
         xsltStylesheet_auto_ptr stylesheet(xsltNewStylesheet());          xsltStylesheet *stylesheet = xsltNewStylesheet();
         if(!stylesheet.get())          if(!stylesheet)
                 throw Exception(0,                  throw Exception(0, 0, "xsltNewStylesheet failed");
                         0,  
                         "xsltNewStylesheet failed");  
   
         #define OOSTRING2STYLE(name) \          #define OOSTRING2STYLE(name) \
                 stylesheet->name=oo.name?BAD_CAST xmlMemStrdup((const char*)r.transcode(*oo.name)):0                  stylesheet->name=oo.name?BAD_CAST xmlMemStrdup((const char*)r.transcode(*oo.name)):0
Line 516  String::C xdoc2buf(Request& r, VXdoc& vd Line 462  String::C xdoc2buf(Request& r, VXdoc& vd
         xmldoc.encoding=BAD_CAST xmlMemStrdup(render_encoding);          xmldoc.encoding=BAD_CAST xmlMemStrdup(render_encoding);
         if(header_encoding)          if(header_encoding)
                 stylesheet->encoding=BAD_CAST xmlMemStrdup(header_encoding);                  stylesheet->encoding=BAD_CAST xmlMemStrdup(header_encoding);
         if(xsltSaveResultTo(outputBuffer.get(), &xmldoc, stylesheet.get())<0          if(xsltSaveResultTo(outputBuffer.get(), &xmldoc, stylesheet)<0
                 || xmlHaveGenericErrors())                  || xmlHaveGenericErrors())
                 throw XmlException(0);                  throw XmlException(0, r);
   
         // write out result          // write out result
         char *gnome_str;          char *gnome_str;
         size_t gnome_length;          size_t gnome_length;
   #ifdef LIBXML2_NEW_BUFFER
           if(outputBuffer->conv) {
                   gnome_length=xmlBufUse(outputBuffer->conv);
                   gnome_str=(char *)xmlBufContent(outputBuffer->conv);
           } else {
                   gnome_length=xmlOutputBufferGetSize(&(*outputBuffer));
                   gnome_str=(char *)xmlOutputBufferGetContent(&(*outputBuffer));
           }
   #else
         if(outputBuffer->conv) {          if(outputBuffer->conv) {
                 gnome_length=outputBuffer->conv->use;                  gnome_length=outputBuffer->conv->use;
                 gnome_str=(char *)outputBuffer->conv->content;                  gnome_str=(char *)outputBuffer->conv->content;
Line 530  String::C xdoc2buf(Request& r, VXdoc& vd Line 485  String::C xdoc2buf(Request& r, VXdoc& vd
                 gnome_length=outputBuffer->buffer->use;                  gnome_length=outputBuffer->buffer->use;
                 gnome_str=(char *)outputBuffer->buffer->content;                  gnome_str=(char *)outputBuffer->buffer->content;
         }          }
   #endif
   
         if(file_spec){          if(file_spec){
                 file_write(r.charsets,                  file_write(r.charsets,
Line 549  inline HashStringValue* get_options(Meth Line 505  inline HashStringValue* get_options(Meth
 static void _file(Request& r, MethodParams& params) {  static void _file(Request& r, MethodParams& params) {
         VXdoc& vdoc=GET_SELF(r, VXdoc);          VXdoc& vdoc=GET_SELF(r, VXdoc);
   
         XDocOutputOptions oo(r, get_options(params, 0));          XDocOutputOptions oo(vdoc.output_options);
           oo.append(r, get_options(params, 0), true/* $.name[filename] could be specified by user */);
         String::C buf=xdoc2buf(r, vdoc, oo, 0/*file_name. not to file, to memory*/);          String::C buf=xdoc2buf(r, vdoc, oo, 0/*file_name. not to file, to memory*/);
   
         VFile& vfile=*new VFile;          VFile& vfile=*new VFile;
         VHash& vhcontent_type=*new VHash;          VHash& vhcontent_type=*new VHash;
         vhcontent_type.hash().put(          vhcontent_type.hash().put(value_name, new VString(*oo.mediaType));
                 value_name,           vhcontent_type.hash().put("charset", new VString(*oo.encoding));
                 new VString(*oo.mediaType));  
         vhcontent_type.hash().put(  
                 String::Body("charset"),   
                 new VString(*oo.encoding));  
   
         vfile.set(false/*tainted*/, buf.str?buf.str:""/*to distinguish from stat-ed file*/, buf.length,           vfile.set_binary(false/*not tainted*/, buf.str?buf.str:""/*to distinguish from stat-ed file*/, buf.length, oo.filename, &vhcontent_type);
                 0/*file_name*/, &vhcontent_type);  
   
         vfile.set_mode(true/*text*/);  
   
         // write out result          // write out result
         r.write_no_lang(vfile);          r.write(vfile);
 }  }
   
 static void _save(Request& r, MethodParams& params) {  static void _save(Request& r, MethodParams& params) {
         VXdoc& vdoc=GET_SELF(r, VXdoc);          VXdoc& vdoc=GET_SELF(r, VXdoc);
   
         const String& file_spec=r.absolute(params.as_string(0, FILE_NAME_MUST_BE_STRING));          const String& file_spec=r.full_disk_path(params.as_string(0, FILE_NAME_MUST_BE_STRING));
                   
         XDocOutputOptions oo(r, get_options(params, 1));          XDocOutputOptions oo(vdoc.output_options);
           oo.append(r, get_options(params, 1));
         xdoc2buf(r, vdoc, oo, &file_spec);          xdoc2buf(r, vdoc, oo, &file_spec);
 }  }
   
 static void _string(Request& r, MethodParams& params) {  static void _string(Request& r, MethodParams& params) {
         VXdoc& vdoc=GET_SELF(r, VXdoc);          VXdoc& vdoc=GET_SELF(r, VXdoc);
   
         XDocOutputOptions oo(r, get_options(params, 0));          XDocOutputOptions oo(vdoc.output_options);
           oo.append(r, get_options(params, 0));
         String::C buf=xdoc2buf(r, vdoc, oo,          String::C buf=xdoc2buf(r, vdoc, oo,
                 0/*file_name. not to file, to memory*/,                  0/*file_name. not to file, to memory*/,
                 true/*use source charset to render, client charset to put to header*/);                  true/*use source charset to render, client charset to put to header*/);
   
         // write out result          // write out result
         r.write_no_lang(String(buf, String::L_AS_IS));          r.write(String(buf, String::L_AS_IS));
 }  }
   
 #ifndef DOXYGEN  #ifndef DOXYGEN
Line 607  static void add_xslt_param( Line 559  static void add_xslt_param(
         *info->current_transform_param++=(s=info->r->transcode(meaning->as_string())); *info->strings+=s;          *info->current_transform_param++=(s=info->r->transcode(meaning->as_string())); *info->strings+=s;
 }  }
   
 static VXdoc& _transform(Request& r, const String* stylesheet_source,   static VXdoc& _transform(Request& r, const String* stylesheet_source, VXdoc& vdoc, xsltStylesheetPtr stylesheet, const xmlChar** transform_params) 
                                                    VXdoc& vdoc, xsltStylesheetPtr stylesheet, const xmlChar** transform_params)   
 {  {
         xmlDoc& xmldoc=vdoc.get_xmldoc();          xmlDoc& xmldoc=vdoc.get_xmldoc();
   
Line 627  static VXdoc& _transform(Request& r, con Line 578  static VXdoc& _transform(Request& r, con
                 0/*FILE *profile*/,                  0/*FILE *profile*/,
                 transformContext.get());                  transformContext.get());
         if(!transformed || xmlHaveGenericErrors())          if(!transformed || xmlHaveGenericErrors())
                 throw XmlException(stylesheet_source);                  throw XmlException(stylesheet_source, r);
   
         //gdome_xml_doc_mkref dislikes XML_HTML_DOCUMENT_NODE  type, fixing          //gdome_xml_doc_mkref dislikes XML_HTML_DOCUMENT_NODE  type, fixing
         transformed->type=XML_DOCUMENT_NODE;          transformed->type=XML_DOCUMENT_NODE;
   
         // constructing result          // constructing result
         return *new VXdoc(r.charsets, *transformed);          VXdoc& result=*new VXdoc(r.charsets, *transformed);
           /* grabbing options
   
                   <xsl:output
                   !method = "xml" | "html" | "text"
                           X| qname-but-not-ncname 
                   !version = nmtoken 
                   !encoding = string 
                   !omit-xml-declaration = "yes" | "no"
                   !standalone = "yes" | "no"
                   !doctype-public = string 
                   !doctype-system = string 
                   Xcdata-section-elements = qnames 
                   !indent = "yes" | "no"
                   !media-type = string /> 
           */
           XDocOutputOptions& oo=result.output_options;
   
           oo.method=stylesheet->method?&r.transcode(stylesheet->method):0;
           oo.encoding=stylesheet->encoding?&r.transcode(stylesheet->encoding):0;
           oo.mediaType=stylesheet->mediaType?&r.transcode(stylesheet->mediaType):0;
           oo.indent=stylesheet->indent;
           oo.version=stylesheet->version?&r.transcode(stylesheet->version):0;
           oo.standalone=stylesheet->standalone;
           oo.omitXmlDeclaration=stylesheet->omitXmlDeclaration;
   
           // return
           return result;
 }  }
 static void _transform(Request& r, MethodParams& params) {  static void _transform(Request& r, MethodParams& params) {
         VXdoc& vdoc=GET_SELF(r, VXdoc);          VXdoc& vdoc=GET_SELF(r, VXdoc);
Line 642  static void _transform(Request& r, Metho Line 619  static void _transform(Request& r, Metho
         Array<const xmlChar*> transform_strings;          Array<const xmlChar*> transform_strings;
         const xmlChar** transform_params=0;          const xmlChar** transform_params=0;
         if(params.count()>1)          if(params.count()>1)
                 if(HashStringValue* hash=params.as_hash(1)) {                  if(HashStringValue* hash=params.as_hash(1, "transform options")) {
                         transform_params=new(UseGC) const xmlChar*[hash->count()*2+1];                          transform_params=new(PointerGC) const xmlChar*[hash->count()*2+1];
                         Add_xslt_param_info info={                          Add_xslt_param_info info={
                                 &r,                                   &r, 
                                 &transform_strings,                                  &transform_strings,
Line 655  static void _transform(Request& r, Metho Line 632  static void _transform(Request& r, Metho
   
         VXdoc* result;          VXdoc* result;
         if(Value *vxdoc=params[0].as(VXDOC_TYPE)) { // stylesheet (xdoc)          if(Value *vxdoc=params[0].as(VXDOC_TYPE)) { // stylesheet (xdoc)
                 xmlDoc& stylesheetdoc=static_cast<VXdoc *>(vxdoc)->get_xmldoc();                  VXdoc& vstylesheet=static_cast<VXdoc &>(*vxdoc);
                   xmlDoc& stylesheetdoc=vstylesheet.get_xmldoc();
   
                 // compile xdoc stylesheet                  // compile xdoc stylesheet
                 xsltStylesheet_auto_ptr stylesheet_ptr(xsltParseStylesheetDoc(&stylesheetdoc));                   xsltStylesheet *stylesheet=xsltParseStylesheetDoc(&stylesheetdoc);
                 if(xmlHaveGenericErrors())                  if(xmlHaveGenericErrors())
                         throw XmlException(0);                          throw XmlException(0, r);
                 if(!stylesheet_ptr.get())                  if(!stylesheet)
                         throw Exception("xml",                          throw Exception("xml", 0, "stylesheet failed to compile");
                                 0,  
                                 "stylesheet failed to compile");  
                 // strange thing - xsltParseStylesheetDoc records document and destroys it in stylesheet destructor  
                 // we don't need that  
                 stylesheet_ptr->doc=0;  
   
                 // transform!                  // transform!
                 result=&_transform(r, 0,                  result=&_transform(r, 0, vdoc, stylesheet, transform_params);
                         vdoc, stylesheet_ptr.get(),  
                         transform_params);  
         } else { // stylesheet (file name)          } else { // stylesheet (file name)
                 // extablish stylesheet connection                  // extablish stylesheet connection
                 const String& stylesheet_filespec=                  const String& stylesheet_filespec=r.full_disk_path(params.as_string(0, "stylesheet must be file name (string) or DOM document (xdoc)"));
                         r.absolute(params.as_string(0, "stylesheet must be file name (string) or DOM document (xdoc)"));                  Stylesheet_connection_ptr connection(stylesheet_manager->get_connection(stylesheet_filespec));
                 Stylesheet_connection_ptr connection=stylesheet_manager->get_connection(stylesheet_filespec);  
   
                 // load and compile file to stylesheet [or get cached if any]                  // load and compile file to stylesheet [or get cached if any]
                 // transform!                  // transform!
                 result=&_transform(r, &stylesheet_filespec, vdoc, connection->stylesheet(),                  result=&_transform(r, &stylesheet_filespec, vdoc, connection->stylesheet(), transform_params);
                         transform_params);  
         }          }
   
         // write out result          // write out result
         r.write_no_lang(*result);          r.write(*result);
 }  }
   
 // constructor  // constructor
   
 /// @test how to create empty type html?  /// @test how to create empty type html?
 MXdoc::MXdoc(): MXnode(XDOC_CLASS_NAME, xnode_class) {  MXdoc::MXdoc(): MXnode(XDOC_CLASS_NAME) {
           set_base(xnode_class);
   
         /// DOM1          /// DOM1
   
         // Element createElement(in DOMString tagName) raises(DOMException);          // Element createElement(in DOMString tagName) raises(DOMException);
Line 761  MXdoc::MXdoc(): MXnode(XDOC_CLASS_NAME, Line 733  MXdoc::MXdoc(): MXnode(XDOC_CLASS_NAME,
   
 // global variable  // global variable
   
 DECLARE_CLASS_VAR(xdoc, 0, 0); // fictive  DECLARE_CLASS_VAR(xnode, 0); // fictive
   DECLARE_CLASS_VAR(xdoc, 0); // fictive
   
 #endif  #endif

Removed from v.1.169  
changed lines
  Added in v.1.200


E-mail: