[webkit-changes] cvs commit: WebCore/khtml/xsl xslt_processorimpl.cpp xslt_processorimpl.h

Adele adele at opensource.apple.com
Tue Aug 2 14:35:32 PDT 2005


adele       05/08/02 14:35:31

  Modified:    .        Tag: Safari-2-0-branch ChangeLog
               khtml/xsl Tag: Safari-2-0-branch xslt_processorimpl.cpp
                        xslt_processorimpl.h
  Log:
          Merged fix from TOT to Safari-2-0-branch
  
      2005-06-29  Anders Carlsson  <andersca at mac.com>
  
          Reviewed and landed by Darin Adler.
  
          - Fix <http://bugzilla.opendarwin.org/show_bug.cgi?id=3274>
          document() not supported
  
          Test cases added:
          * layout-tests/fast/xsl/document-function-expected.txt: Added.
          * layout-tests/fast/xsl/document-function.xml: Added.
          * layout-tests/fast/xsl/document-function.xsl: Added.
          * layout-tests/fast/xsl/resources/document-function-source.xml: Added.
  
          * khtml/xsl/xslt_processorimpl.cpp:
          (DOM::parseErrorFunc):
          Stub to prevent errors from getting written to the console.
  
          (DOM::stylesheetLoadFunc):
          Fetch and parse documents.
  
          (DOM::XSLTProcessorImpl::transformDocument):
          Use the processor as the global variable instead of the
          style sheet.
  
          * khtml/xsl/xslt_processorimpl.h:
          (DOM::XSLTProcessorImpl::stylesheet):
          (DOM::XSLTProcessorImpl::sourceDocument):
          Add accessors for source document and stylesheet.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.4104.2.82 +33 -0     WebCore/ChangeLog
  
  Index: ChangeLog
  ===================================================================
  RCS file: /cvs/root/WebCore/ChangeLog,v
  retrieving revision 1.4104.2.81
  retrieving revision 1.4104.2.82
  diff -u -r1.4104.2.81 -r1.4104.2.82
  --- ChangeLog	2 Aug 2005 21:26:03 -0000	1.4104.2.81
  +++ ChangeLog	2 Aug 2005 21:35:24 -0000	1.4104.2.82
  @@ -2,6 +2,39 @@
   
           Merged fix from TOT to Safari-2-0-branch
   
  +    2005-06-29  Anders Carlsson  <andersca at mac.com>
  +
  +        Reviewed and landed by Darin Adler.
  +
  +        - Fix <http://bugzilla.opendarwin.org/show_bug.cgi?id=3274>
  +        document() not supported
  +
  +        Test cases added:
  +        * layout-tests/fast/xsl/document-function-expected.txt: Added.
  +        * layout-tests/fast/xsl/document-function.xml: Added.
  +        * layout-tests/fast/xsl/document-function.xsl: Added.
  +        * layout-tests/fast/xsl/resources/document-function-source.xml: Added.
  +        
  +        * khtml/xsl/xslt_processorimpl.cpp:
  +        (DOM::parseErrorFunc):
  +        Stub to prevent errors from getting written to the console.
  +        
  +        (DOM::stylesheetLoadFunc):
  +        Fetch and parse documents.
  +        
  +        (DOM::XSLTProcessorImpl::transformDocument):
  +        Use the processor as the global variable instead of the 
  +        style sheet.
  +        
  +        * khtml/xsl/xslt_processorimpl.h:
  +        (DOM::XSLTProcessorImpl::stylesheet):
  +        (DOM::XSLTProcessorImpl::sourceDocument):
  +        Add accessors for source document and stylesheet.
  +
  +2005-08-02  Adele Peterson  <adele at apple.com>
  +
  +        Merged fix from TOT to Safari-2-0-branch
  +
       2005-07-03  Maciej Stachowiak  <mjs at apple.com>
   
   	Original patch from Mark Rowe <opendarwin.org at bdash.net.nz>, reviewed by me.
  
  
  
  No                   revision
  
  
  No                   revision
  
  
  1.4.10.2  +73 -27    WebCore/khtml/xsl/xslt_processorimpl.cpp
  
  Index: xslt_processorimpl.cpp
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/xsl/xslt_processorimpl.cpp,v
  retrieving revision 1.4.10.1
  retrieving revision 1.4.10.2
  diff -u -r1.4.10.1 -r1.4.10.2
  --- xslt_processorimpl.cpp	27 Jun 2005 23:51:49 -0000	1.4.10.1
  +++ xslt_processorimpl.cpp	2 Aug 2005 21:35:31 -0000	1.4.10.2
  @@ -27,6 +27,9 @@
   #include "loader.h"
   #include "khtmlview.h"
   #include "khtml_part.h"
  +#include "KWQLoader.h"
  +
  +#include <kio/job.h>
   
   #include <libxslt/xsltutils.h>
   #include <libxslt/documents.h>
  @@ -54,19 +57,49 @@
           m_sourceDocument->deref();
   }
   
  -static XSLStyleSheetImpl* globalSheet = 0;
  +static void parseErrorFunc(void *ctxt, const char *msg, ...)
  +{
  +    // FIXME: It would be nice to display error messages somewhere.
  +}
  +
  +static XSLTProcessorImpl *globalProcessor = 0;
   static xmlDocPtr stylesheetLoadFunc(const xmlChar* uri,
                                       xmlDictPtr dict,
                                       int options,
                                       void* ctxt,
                                       xsltLoadType type)
   {
  -    if (type != XSLT_LOAD_STYLESHEET)
  -        return NULL; // FIXME: Add support for XSLT_LOAD_DOCUMENT for the document() function.
  -    
  -    if (!globalSheet)
  +    if (!globalProcessor)
           return NULL;
  -    return globalSheet->locateStylesheetSubResource(((xsltStylesheetPtr)ctxt)->doc, uri);
  +    
  +    switch (type) {
  +        case XSLT_LOAD_DOCUMENT: {
  +            KURL url = KURL((char *)uri);
  +            KURL finalURL;
  +            KIO::TransferJob *job = KIO::get(url, true, false);
  +            QByteArray data;
  +            QString headers;
  +            xmlDocPtr doc;
  +            xmlGenericErrorFunc oldErrorFunc = xmlGenericError;
  +            void *oldErrorContext = xmlGenericErrorContext;
  +            
  +            data = KWQServeSynchronousRequest(khtml::Cache::loader(), 
  +                                              globalProcessor->sourceDocument()->docLoader(), job, finalURL, headers);
  +        
  +            xmlSetGenericErrorFunc(0, parseErrorFunc);
  +            // We don't specify an encoding here. Neither Gecko nor WinIE respects
  +            // the encoding specified in the HTTP headers.
  +            doc = xmlReadMemory(data.data(), data.size(), (const char *)uri, 0, options);
  +            xmlSetGenericErrorFunc(oldErrorContext, oldErrorFunc);
  +            return doc;
  +        }
  +        case XSLT_LOAD_STYLESHEET:
  +            return globalProcessor->stylesheet()->locateStylesheetSubResource(((xsltStylesheetPtr)ctxt)->doc, uri);
  +        default:
  +            break;
  +    }
  +    
  +    return NULL;
   }
   
   DocumentImpl* XSLTProcessorImpl::transformDocument(DocumentImpl* doc)
  @@ -77,20 +110,26 @@
   
       if (!m_stylesheet || !m_stylesheet->document()) return 0;
           
  -    globalSheet = m_stylesheet;
  +    globalProcessor = this;
       xsltSetLoaderFunc(stylesheetLoadFunc);
   
       xsltStylesheetPtr sheet = m_stylesheet->compileStyleSheet();
   
  -    globalSheet = 0;
  -    xsltSetLoaderFunc(0);
  -
  -    if (!sheet) return 0;
  +    if (!sheet) {
  +        globalProcessor = 0;
  +        xsltSetLoaderFunc(0);
  +        return 0;
  +    }
  +    
       m_stylesheet->clearDocuments();
     
       // Get the parsed source document.
       xmlDocPtr sourceDoc = (xmlDocPtr)doc->transformSource();
       xmlDocPtr resultDoc = xsltApplyStylesheet(sheet, sourceDoc, NULL);
  +    
  +    globalProcessor = 0;
  +    xsltSetLoaderFunc(0);
  +
       DocumentImpl* result = documentFromXMLDocPtr(resultDoc, sheet);
       xsltFreeStylesheet(sheet);
       return result;
  @@ -107,12 +146,14 @@
       m_resultOutput += QString(buffer, len);
   }
   
  -DocumentImpl* XSLTProcessorImpl::documentFromXMLDocPtr(xmlDocPtr resultDoc, xsltStylesheetPtr sheet)
  +DocumentImpl *XSLTProcessorImpl::documentFromXMLDocPtr(xmlDocPtr resultDoc, xsltStylesheetPtr sheet)
   {
  -    // FIXME: For now we serialize and then reparse.  It might be more optimal to write a DOM
  -    // converter.
  -    if (!resultDoc || !sheet) return 0;
  -    DocumentImpl* result = 0;
  +    // FIXME: For now we serialize and then reparse. It might be more optimal to write a DOM  converter.
  +
  +    if (!resultDoc || !sheet)
  +        return 0;
  +
  +    DocumentImpl *result = 0;
       xmlOutputBufferPtr outputBuf = xmlAllocOutputBuffer(NULL);
       if (outputBuf) {
           outputBuf->context = this;
  @@ -124,12 +165,12 @@
           // There are three types of output we need to be able to deal with:
           // HTML (create an HTML document), XML (create an XML document), and text (wrap in a <pre> and
           // make an XML document).
  -        KHTMLView* view = m_sourceDocument->view();
  -        const xmlChar* method;
  +        KHTMLView *view = m_sourceDocument->view();
  +        const xmlChar *method;
           XSLT_GET_IMPORT_PTR(method, sheet, method);
           if (method == NULL && resultDoc->type == XML_HTML_DOCUMENT_NODE)
  -            method = (const xmlChar*)"html";
  -        if (xmlStrEqual(method, (const xmlChar*)"html"))
  +            method = (const xmlChar *)"html";
  +        if (xmlStrEqual(method, (const xmlChar *)"html"))
               result = m_sourceDocument->implementation()->createHTMLDocument(view);
           else
               result = m_sourceDocument->implementation()->createDocument(view);
  @@ -140,16 +181,20 @@
           result->docLoader()->setShowAnimations(m_sourceDocument->docLoader()->showAnimations());
           result->setTransformSourceDocument(m_sourceDocument);
   
  -        if (xmlStrEqual(method, (const xmlChar*)"text")) {
  -            // Modify the output so that it is a well-formed XHTML document with a <pre> tag enclosing
  -            // the text.
  -            QString beforeString("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/strict.dtd\">\n<html xmlns=\"http://www.w3.org/1999/xhtml\">\n<body>\n<pre>\n<![CDATA[");
  -            QString afterString("]]>\n</pre>\n</body>\n</html>\n");
  -            m_resultOutput = beforeString + m_resultOutput + afterString;
  +        if (xmlStrEqual(method, (const xmlChar *)"text")) {
  +            // Modify the output so that it is a well-formed XHTML document with a <pre> tag enclosing the text.
  +            m_resultOutput = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/strict.dtd\">\n"
  +                "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
  +                "<body>\n"
  +                "<pre>\n"
  +                "<![CDATA[" + m_resultOutput + "]]>\n"
  +                "</pre>\n"
  +                "</body>\n"
  +                "</html>\n";
           }
           
           // Before parsing, we need to detach the old document completely and get the new document
  -        // in place.  We have to do this only if we're rendering the result document.
  +        // in place. We have to do this only if we're rendering the result document.
           if (view) {
               view->clear();
               view->part()->replaceDocImpl(result);
  @@ -170,4 +215,5 @@
   }
   
   }
  +
   #endif
  
  
  
  1.2.10.1  +3 -0      WebCore/khtml/xsl/xslt_processorimpl.h
  
  Index: xslt_processorimpl.h
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/xsl/xslt_processorimpl.h,v
  retrieving revision 1.2
  retrieving revision 1.2.10.1
  diff -u -r1.2 -r1.2.10.1
  --- xslt_processorimpl.h	19 Aug 2004 22:50:30 -0000	1.2
  +++ xslt_processorimpl.h	2 Aug 2005 21:35:31 -0000	1.2.10.1
  @@ -53,6 +53,9 @@
       // Helpers
       void addToResult(const char* buffer, int len);
       
  +    XSLStyleSheetImpl *stylesheet() { return m_stylesheet; }
  +    DocumentImpl *sourceDocument() { return m_sourceDocument; }
  +    
   protected:
       XSLStyleSheetImpl* m_stylesheet;
       QString m_resultOutput;
  
  
  



More information about the webkit-changes mailing list