home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / modules / rdf / src / xmlglue.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  7.6 KB  |  309 lines

  1. /* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. /* 
  20.    This is some glue code for a "stop-gap" xml parser that is being shipped with the free
  21.    source. A real xml parser from James Clark will replace this 
  22.    within the next few weeks.
  23.  
  24.    For more information on this file, contact rjc or guha 
  25.    For more information on RDF, look at the RDF section of www.mozilla.org
  26.    For more info on XML in navigator, look at the XML section
  27.    of www.mozilla.org.
  28. */
  29.  
  30. #include "xmlglue.h"
  31. #include "xmlparse.h"
  32. #include "xmlss.h"
  33.  
  34.  
  35.  
  36. unsigned int
  37. xml_write_ready(NET_StreamClass *stream)
  38. {
  39.    return XML_LINE_SIZE;
  40.  
  41. }
  42.  
  43.  
  44.  
  45. void
  46. xml_abort(NET_StreamClass *stream, int status)
  47. {
  48.     void *obj=stream->data_object;
  49.   freeMem(((XMLFile)obj)->holdOver);
  50.   freeMem(((XMLFile)obj)->line);
  51.   ((XMLFile)obj)->line = ((XMLFile)obj)->holdOver = NULL;
  52. }
  53.  
  54.  
  55.  
  56. void
  57. xml_complete (NET_StreamClass *stream)
  58. {
  59.   NET_StreamClass *newstream;
  60.   void *obj=stream->data_object;
  61.   URL_Struct *urls = ((XMLFile)obj)->urls;
  62.   freeMem(((XMLFile)obj)->holdOver);
  63.   freeMem(((XMLFile)obj)->line);
  64.   ((XMLFile)obj)->line = ((XMLFile)obj)->holdOver = NULL; 
  65.   ((XMLFile)obj)->numOpenStreams--;
  66.   if (((XMLFile)obj)->numOpenStreams < 1) {
  67.   /* direct the stream to the html parser */
  68.     URL_Struct *nurls =   NET_CreateURLStruct(copyString(urls->address), NET_DONT_RELOAD);
  69.     StrAllocCopy(nurls->content_type, TEXT_HTML);
  70.  
  71.     newstream = NET_StreamBuilder(1,  nurls, (MWContext*) ((XMLFile)obj)->mwcontext);
  72.     ((XMLFile)obj)->stream = newstream;
  73.     convertToHTML(((XMLFile)obj));
  74.     newstream->complete(newstream);
  75.     NET_FreeURLStruct(nurls); 
  76.   }
  77. }
  78.  
  79.  
  80.  
  81. void
  82. outputToStream (XMLFile f, char* s)
  83. {
  84.   int ans = 0;
  85.   NET_StreamClass *stream = (NET_StreamClass*) f->stream;
  86. #ifdef DEBUG
  87. /*  FE_Trace(s); */
  88. #endif
  89.   (*(stream->put_block))(stream, s, strlen(s)); 
  90. }
  91.  
  92.  
  93.  
  94. #ifdef    XP_MAC
  95. PR_PUBLIC_API(NET_StreamClass *)
  96. #else
  97. PUBLIC NET_StreamClass *
  98. #endif
  99.  
  100. XML_XMLConverter(FO_Present_Types  format_out, void *data_object, URL_Struct *URL_s, MWContext  *window_id)
  101. {
  102.     NET_StreamClass* stream;
  103.     XMLFile  xmlf;
  104.     TRACEMSG(("Setting up display stream. Have URL: %s\n", URL_s->address));
  105.  
  106.     xmlf = (XMLFile) getMem(sizeof(XMLFileStruct));
  107.     xmlf->holdOver = getMem(XML_BUF_SIZE);
  108.     xmlf->lineSize = XML_LINE_SIZE;
  109.     xmlf->line     = (char*)getMem(XML_LINE_SIZE);
  110.     xmlf->urls = URL_s;
  111.     xmlf->address = copyString(URL_s->address);
  112.     xmlf->mwcontext = window_id;
  113.     xmlf->numOpenStreams = 1;
  114.     /*    URL_s->fedata = xmlf; */
  115.     stream = NET_NewStream("XML", (MKStreamWriteFunc)parseNextXMLBlob, 
  116.                (MKStreamCompleteFunc)xml_complete,
  117.                (MKStreamAbortFunc)xml_abort, 
  118.                (MKStreamWriteReadyFunc)xml_write_ready, xmlf, window_id);
  119.     if (stream == NULL) freeMem(xmlf);
  120.     
  121.     return(stream);
  122. }
  123.  
  124.  
  125.  
  126. /* XML-CSS stuff */
  127.  
  128.  
  129.  
  130. unsigned int
  131. xmlcss_write_ready(NET_StreamClass *stream)
  132. {
  133.    return XML_LINE_SIZE;
  134.  
  135. }
  136.  
  137.  
  138.  
  139. void
  140. xmlcss_abort(NET_StreamClass *stream, int status)
  141. {
  142.   StyleSheet obj=stream->data_object;
  143.   XMLFile xml = obj->xmlFile;
  144.   xml->numOpenStreams--;
  145.   freeMem(obj->holdOver);
  146.   freeMem(obj->line);
  147.   obj->line = obj->holdOver = NULL;
  148. }
  149.  
  150.  
  151.  
  152. void
  153. xmlcss_complete  (NET_StreamClass *stream)
  154. {
  155.   StyleSheet ss =stream->data_object;
  156.   URL_Struct *urls = ss->urls;
  157.   XMLFile xml = ss->xmlFile;
  158.   freeMem(ss->holdOver);
  159.   freeMem(ss->line);
  160.   ss->line = ss->holdOver = NULL; 
  161.   xml->numOpenStreams--;
  162.   if (xml->numOpenStreams == 0) { 
  163.   /* direct the stream to the html parser */
  164.     NET_StreamClass *newstream;
  165.     URL_Struct *nurls =   NET_CreateURLStruct(copyString(xml->address), NET_DONT_RELOAD);
  166.     StrAllocCopy(nurls->content_type, TEXT_HTML);
  167.     newstream = NET_StreamBuilder(1,  nurls, (MWContext*) xml->mwcontext);
  168.     xml->stream = newstream;
  169.     convertToHTML(xml);
  170.     newstream->complete(newstream);
  171.     NET_FreeURLStruct(nurls); 
  172.   }     
  173. }
  174.  
  175.  
  176.  
  177. #ifdef    XP_MAC
  178. PR_PUBLIC_API(NET_StreamClass *)
  179. #else
  180. PUBLIC NET_StreamClass *
  181. #endif
  182.  
  183. XML_CSSConverter(FO_Present_Types  format_out, void *data_object, URL_Struct *URL_s, MWContext  *window_id)
  184. {
  185.     StyleSheet  ss = (StyleSheet) URL_s->fe_data;
  186.     TRACEMSG(("Setting up style sheet stream. Have URL: %s\n", URL_s->address));
  187.  
  188.     return NET_NewStream("XML-CSS", (MKStreamWriteFunc)parseNextXMLCSSBlob, 
  189.                (MKStreamCompleteFunc)xmlcss_complete,
  190.                (MKStreamAbortFunc)xmlcss_abort, 
  191.                (MKStreamWriteReadyFunc)xmlcss_write_ready, ss, window_id);
  192. }
  193.  
  194.  
  195.  
  196. void
  197. xmlcss_GetUrlExitFunc (URL_Struct *urls, int status, MWContext *cx)
  198. {
  199.  
  200. }
  201.  
  202.  
  203.  
  204. void
  205. readCSS (StyleSheet ss)
  206. {
  207.   URL_Struct                      *urls;
  208.   urls = NET_CreateURLStruct(ss->address, NET_DONT_RELOAD);
  209.   if (urls == NULL)  {
  210.     ss->xmlFile->numOpenStreams--;
  211.     return;
  212.   }
  213.   urls->fe_data = ss;
  214.   NET_GetURL(urls, FO_CACHE_AND_XMLCSS, ss->xmlFile->mwcontext, xmlcss_GetUrlExitFunc);
  215. }
  216.  
  217.  
  218.  
  219. int
  220. xmlhtml_write(NET_StreamClass *stream, const char *str, int32 len)
  221. {
  222.   XMLHTMLInclusion obj=stream->data_object;
  223.   char* newStr;
  224.   if (obj == NULL  || len < 0) {
  225.       return MK_INTERRUPTED;
  226.   }
  227.  newStr = getMem(len+1);
  228.  memcpy(newStr, str, len);
  229.  *(obj->content + obj->n++) = newStr;
  230.  return (len);
  231. }
  232.  
  233.  
  234.  
  235. unsigned int
  236. xmlhtml_write_ready(NET_StreamClass *stream)
  237. {
  238.    return XML_LINE_SIZE;
  239.  
  240. }
  241.  
  242.  
  243.  
  244. void
  245. xmlhtml_abort(NET_StreamClass *stream, int status)
  246. {
  247. }
  248.  
  249.  
  250.  
  251. void
  252. xmlhtml_complete  (NET_StreamClass *stream)
  253. {
  254.   XMLHTMLInclusion ss =stream->data_object;
  255.   XMLFile xml = ss->xml;
  256.   xml->numOpenStreams--;
  257.   if (xml->numOpenStreams == 0) { 
  258.   /* direct the stream to the html parser */
  259.     NET_StreamClass *newstream;
  260.     URL_Struct *nurls =   NET_CreateURLStruct(copyString(xml->address), NET_DONT_RELOAD);
  261.     StrAllocCopy(nurls->content_type, TEXT_HTML);
  262.     newstream = NET_StreamBuilder(1,  nurls, (MWContext*) xml->mwcontext);
  263.     xml->stream = newstream;
  264.     convertToHTML(xml);
  265.     newstream->complete(newstream);
  266.     NET_FreeURLStruct(nurls); 
  267.   }     
  268. }
  269.  
  270.  
  271.  
  272. #ifdef    XP_MAC
  273. PR_PUBLIC_API(NET_StreamClass *)
  274. #else
  275. PUBLIC NET_StreamClass *
  276. #endif
  277.  
  278. XML_HTMLConverter(FO_Present_Types  format_out, void *data_object, URL_Struct *URL_s, MWContext  *window_id)
  279. {
  280.     XMLHTMLInclusion  ss = (XMLHTMLInclusion) URL_s->fe_data;
  281.  
  282.     return NET_NewStream("XML-HTML", (MKStreamWriteFunc)xmlhtml_write, 
  283.                (MKStreamCompleteFunc)xmlhtml_complete,
  284.                (MKStreamAbortFunc)xmlhtml_abort, 
  285.                (MKStreamWriteReadyFunc)xmlhtml_write_ready, ss, window_id);
  286. }
  287.  
  288.  
  289.  
  290. void
  291. xmlhtml_GetUrlExitFunc (URL_Struct *urls, int status, MWContext *cx)
  292. {
  293. }
  294.  
  295.  
  296.  
  297. void
  298. readHTML (char* url, XMLHTMLInclusion ss)
  299. {
  300.   URL_Struct                      *urls;
  301.   urls = NET_CreateURLStruct(url, NET_DONT_RELOAD);
  302.   if (urls == NULL)  {
  303.     ss->xml->numOpenStreams--;
  304.     return;
  305.   }
  306.   urls->fe_data = ss;
  307.   NET_GetURL(urls, FO_CACHE_AND_XMLHTML, ss->xml->mwcontext, xmlhtml_GetUrlExitFunc);
  308. }
  309.