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

Eric eseidel at opensource.apple.com
Thu Oct 27 15:34:53 PDT 2005


eseidel     05/10/27 15:34:52

  Modified:    .        ChangeLog
               khtml    khtml_part.cpp
               khtml/ecma kjs_window.cpp kjs_window.h
               khtml/xml dom_docimpl.cpp dom_docimpl.h xml_tokenizer.cpp
                        xml_tokenizer.h
               khtml/xsl xslt_processorimpl.cpp xslt_processorimpl.h
  Added:       khtml/ecma XSLTProcessor.cpp XSLTProcessor.h
  Log:
  Bug #: 3275
  Submitted by: eseidel
  Reviewed by: hyatt, darin
          Add XSLTProcessor support to WebCore's JavaScript bindings.
          <rdar://problem/3642402> add XSLTProcessor to WebCore's JavaScript support
          http://bugzilla.opendarwin.org/show_bug.cgi?id=3275
  
          * WebCore.xcodeproj/project.pbxproj:
          * khtml/ecma/XSLTProcessor.cpp: Added.
          (KJS::):
          (KJS::XSLTProcessor::XSLTProcessor):
          (KJS::XSLTProcessor::~XSLTProcessor):
          (KJS::XSLTProcessorProtoFunc::callAsFunction):
          * khtml/ecma/XSLTProcessor.h: Added.
          (KJS::XSLTProcessor::classInfo):
          (KJS::XSLTProcessor::):
          (KJS::XSLTProcessor::impl):
          (KJS::XSLTProcessorConstructorImp::XSLTProcessorConstructorImp):
          (KJS::XSLTProcessorConstructorImp::implementsConstruct):
          (KJS::XSLTProcessorConstructorImp::construct):
          * khtml/ecma/kjs_window.cpp:
          (KJS::Window::getValueProperty):
          * khtml/ecma/kjs_window.h:
          (KJS::Window::):
          * khtml/khtml_part.cpp:
          (KHTMLPart::replaceDocImpl):
          * khtml/xml/dom_docimpl.cpp:
          (DocumentImpl::DocumentImpl):
          (DocumentImpl::~DocumentImpl):
          (DocumentImpl::applyXSLTransform):
          * khtml/xml/dom_docimpl.h:
          (DOM::DocumentImpl::transformSourceDocument):
          (DOM::DocumentImpl::setTransformSourceDocument):
          * khtml/xml/xml_tokenizer.cpp:
          (khtml::xmlDocPtrForString):
          (khtml::XMLTokenizer::setTransformSource):
          * khtml/xml/xml_tokenizer.h:
          * khtml/xsl/xslt_processorimpl.cpp:
          (DOM::parseErrorFunc):
          (DOM::stylesheetLoadFunc):
          (DOM::setXSLTLoadCallBack):
          (DOM::writeToQString):
          (DOM::saveResultToString):
          (DOM::transformTextStringToXHTMLDocumentString):
          (DOM::xsltParamArrayFromQDict):
          (DOM::freeXsltParamArray):
          (DOM::XSLTProcessorImpl::createDocumentFromSource):
          (DOM::createFragmentFromSource):
          (DOM::xsltStylesheetPointer):
          (DOM::xmlDocPtrFromNode):
          (DOM::resultMIMEType):
          (DOM::XSLTProcessorImpl::transformToString):
          (DOM::XSLTProcessorImpl::transformToDocument):
          (DOM::XSLTProcessorImpl::transformToFragment):
          (DOM::XSLTProcessorImpl::setParameter):
          (DOM::XSLTProcessorImpl::getParameter):
          (DOM::XSLTProcessorImpl::removeParameter):
          * khtml/xsl/xslt_processorimpl.h:
          (DOM::XSLTProcessorImpl::XSLTProcessorImpl):
          (DOM::XSLTProcessorImpl::setXSLStylesheet):
          (DOM::XSLTProcessorImpl::importStylesheet):
          (DOM::XSLTProcessorImpl::clearParameters):
          (DOM::XSLTProcessorImpl::reset):
          (DOM::XSLTProcessorImpl::xslStylesheet):
  
  Revision  Changes    Path
  1.304     +67 -0     WebCore/ChangeLog
  
  Index: ChangeLog
  ===================================================================
  RCS file: /cvs/root/WebCore/ChangeLog,v
  retrieving revision 1.303
  retrieving revision 1.304
  diff -u -r1.303 -r1.304
  --- ChangeLog	27 Oct 2005 20:13:35 -0000	1.303
  +++ ChangeLog	27 Oct 2005 22:34:37 -0000	1.304
  @@ -1,3 +1,70 @@
  +2005-10-27  Eric Seidel  <eseidel at apple.com>
  +
  +        Reviewed by hyatt.
  +
  +        Add XSLTProcessor support to WebCore's JavaScript bindings.
  +        <rdar://problem/3642402> add XSLTProcessor to WebCore's JavaScript support
  +        http://bugzilla.opendarwin.org/show_bug.cgi?id=3275
  +
  +
  +        * WebCore.xcodeproj/project.pbxproj:
  +        * khtml/ecma/XSLTProcessor.cpp: Added.
  +        (KJS::):
  +        (KJS::XSLTProcessor::XSLTProcessor):
  +        (KJS::XSLTProcessor::~XSLTProcessor):
  +        (KJS::XSLTProcessorProtoFunc::callAsFunction):
  +        * khtml/ecma/XSLTProcessor.h: Added.
  +        (KJS::XSLTProcessor::classInfo):
  +        (KJS::XSLTProcessor::):
  +        (KJS::XSLTProcessor::impl):
  +        (KJS::XSLTProcessorConstructorImp::XSLTProcessorConstructorImp):
  +        (KJS::XSLTProcessorConstructorImp::implementsConstruct):
  +        (KJS::XSLTProcessorConstructorImp::construct):
  +        * khtml/ecma/kjs_window.cpp:
  +        (KJS::Window::getValueProperty):
  +        * khtml/ecma/kjs_window.h:
  +        (KJS::Window::):
  +        * khtml/khtml_part.cpp:
  +        (KHTMLPart::replaceDocImpl):
  +        * khtml/xml/dom_docimpl.cpp:
  +        (DocumentImpl::DocumentImpl):
  +        (DocumentImpl::~DocumentImpl):
  +        (DocumentImpl::applyXSLTransform):
  +        * khtml/xml/dom_docimpl.h:
  +        (DOM::DocumentImpl::transformSourceDocument):
  +        (DOM::DocumentImpl::setTransformSourceDocument):
  +        * khtml/xml/xml_tokenizer.cpp:
  +        (khtml::xmlDocPtrForString):
  +        (khtml::XMLTokenizer::setTransformSource):
  +        * khtml/xml/xml_tokenizer.h:
  +        * khtml/xsl/xslt_processorimpl.cpp:
  +        (DOM::parseErrorFunc):
  +        (DOM::stylesheetLoadFunc):
  +        (DOM::setXSLTLoadCallBack):
  +        (DOM::writeToQString):
  +        (DOM::saveResultToString):
  +        (DOM::transformTextStringToXHTMLDocumentString):
  +        (DOM::xsltParamArrayFromQDict):
  +        (DOM::freeXsltParamArray):
  +        (DOM::XSLTProcessorImpl::createDocumentFromSource):
  +        (DOM::createFragmentFromSource):
  +        (DOM::xsltStylesheetPointer):
  +        (DOM::xmlDocPtrFromNode):
  +        (DOM::resultMIMEType):
  +        (DOM::XSLTProcessorImpl::transformToString):
  +        (DOM::XSLTProcessorImpl::transformToDocument):
  +        (DOM::XSLTProcessorImpl::transformToFragment):
  +        (DOM::XSLTProcessorImpl::setParameter):
  +        (DOM::XSLTProcessorImpl::getParameter):
  +        (DOM::XSLTProcessorImpl::removeParameter):
  +        * khtml/xsl/xslt_processorimpl.h:
  +        (DOM::XSLTProcessorImpl::XSLTProcessorImpl):
  +        (DOM::XSLTProcessorImpl::setXSLStylesheet):
  +        (DOM::XSLTProcessorImpl::importStylesheet):
  +        (DOM::XSLTProcessorImpl::clearParameters):
  +        (DOM::XSLTProcessorImpl::reset):
  +        (DOM::XSLTProcessorImpl::xslStylesheet):
  +
   2005-10-27  Adele Peterson  <adele at apple.com>
   
           Reviewed by Vicki.
  
  
  
  1.355     +3 -18     WebCore/khtml/khtml_part.cpp
  
  Index: khtml_part.cpp
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/khtml_part.cpp,v
  retrieving revision 1.354
  retrieving revision 1.355
  diff -u -r1.354 -r1.355
  --- khtml_part.cpp	27 Oct 2005 20:13:42 -0000	1.354
  +++ khtml_part.cpp	27 Oct 2005 22:34:43 -0000	1.355
  @@ -693,23 +693,6 @@
     return true;
   }
   
  -#if !KHTML_NO_CPLUSPLUS_DOM
  -
  -DOM::HTMLDocument KHTMLPart::htmlDocument() const
  -{
  -  if (d->m_doc && d->m_doc->isHTMLDocument())
  -    return static_cast<HTMLDocumentImpl*>(d->m_doc);
  -  else
  -    return static_cast<HTMLDocumentImpl*>(0);
  -}
  -
  -DOM::Document KHTMLPart::document() const
  -{
  -    return d->m_doc;
  -}
  -
  -#endif
  -
   KParts::BrowserExtension *KHTMLPart::browserExtension() const
   {
     return d->m_extension;
  @@ -1187,8 +1170,10 @@
               d->m_doc->deref();
           }
           d->m_doc = newDoc;
  -        if (newDoc)
  +        if (newDoc) {
               newDoc->ref();
  +            newDoc->attach();
  +        }
       }
   }
   
  
  
  
  1.184     +5 -1      WebCore/khtml/ecma/kjs_window.cpp
  
  Index: kjs_window.cpp
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/ecma/kjs_window.cpp,v
  retrieving revision 1.183
  retrieving revision 1.184
  diff -u -r1.183 -r1.184
  --- kjs_window.cpp	11 Oct 2005 06:55:29 -0000	1.183
  +++ kjs_window.cpp	27 Oct 2005 22:34:45 -0000	1.184
  @@ -52,6 +52,7 @@
   #include "kjs_events.h"
   #include "xmlhttprequest.h"
   #include "xmlserializer.h"
  +#include "XSLTProcessor.h"
   #include "domparser.h"
   
   #include "khtmlview.h"
  @@ -212,7 +213,7 @@
   const ClassInfo Window::info = { "Window", 0, &WindowTable, 0 };
   
   /*
  - at begin WindowTable 91
  + at begin WindowTable 103
     closed	Window::Closed		DontDelete|ReadOnly
     crypto	Window::Crypto		DontDelete|ReadOnly
     defaultStatus	Window::DefaultStatus	DontDelete
  @@ -270,6 +271,7 @@
     XMLHttpRequest	Window::XMLHttpRequest	DontDelete|ReadOnly
     XMLSerializer	Window::XMLSerializer	DontDelete|ReadOnly
     DOMParser	Window::DOMParser	DontDelete|ReadOnly
  +  XSLTProcessor	Window::XSLTProcessor	DontDelete|ReadOnly
     alert		Window::Alert		DontDelete|Function 1
     confirm	Window::Confirm		DontDelete|Function 1
     prompt	Window::Prompt		DontDelete|Function 2
  @@ -866,6 +868,8 @@
         return new XMLSerializerConstructorImp(exec);
       case DOMParser:
         return new DOMParserConstructorImp(exec, m_part->xmlDocImpl());
  +    case XSLTProcessor:
  +      return new XSLTProcessorConstructorImp(exec);
       case FrameElement:
         if (DocumentImpl *doc = m_part->xmlDocImpl())
           if (ElementImpl *fe = doc->ownerElement())
  
  
  
  1.54      +2 -1      WebCore/khtml/ecma/kjs_window.h
  
  Index: kjs_window.h
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/ecma/kjs_window.h,v
  retrieving revision 1.53
  retrieving revision 1.54
  diff -u -r1.53 -r1.54
  --- kjs_window.h	19 Sep 2005 18:52:11 -0000	1.53
  +++ kjs_window.h	27 Oct 2005 22:34:47 -0000	1.54
  @@ -146,7 +146,8 @@
              ScrollTo, ScrollX, ScrollY, MoveBy, MoveTo, ResizeBy, ResizeTo, Self, _Window, Top, _Screen,
              Image, Option, Alert, Confirm, Prompt, Open, Print, SetTimeout, ClearTimeout,
              Focus, GetSelection, Blur, Close, SetInterval, ClearInterval, CaptureEvents, 
  -           ReleaseEvents, AddEventListener, RemoveEventListener, XMLHttpRequest, XMLSerializer, DOMParser,
  +           ReleaseEvents, AddEventListener, RemoveEventListener,
  +           XMLHttpRequest, XMLSerializer, DOMParser, XSLTProcessor,
   	   Onabort, Onblur, Onchange, Onclick, Ondblclick, Ondragdrop, Onerror, 
   	   Onfocus, Onkeydown, Onkeypress, Onkeyup, Onload, Onmousedown, Onmousemove,
              Onmouseout, Onmouseover, Onmouseup, OnWindowMouseWheel, Onmove, Onreset, Onresize, Onscroll, Onsearch,
  
  
  
  1.1                  WebCore/khtml/ecma/XSLTProcessor.cpp
  
  Index: XSLTProcessor.cpp
  ===================================================================
  /*
   * Copyright (C) 2005 Apple Computer, Inc.  All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in the
   *    documentation and/or other materials provided with the distribution.
   *
   * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
   * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
   * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
   * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
   * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
   * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
   * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
   */
  
  #include "config.h"
  
  #include "XSLTProcessor.h"
  #include "xslt_processorimpl.h"
  #include "XSLTProcessor.lut.h"
  #include "kjs_dom.h"
  #include "dom_docimpl.h"
  
  #include <JavaScriptCore/lookup.h>
  
  using namespace DOM;
  
  namespace KJS {
  
  const ClassInfo XSLTProcessor::info = { "XSLTProcessor", 0, 0, 0 };
  
  /*
  @begin XSLTProcessorProtoTable 7
    importStylesheet      XSLTProcessor::ImportStylesheet     DontDelete|Function 1
    transformToFragment   XSLTProcessor::TransformToFragment  DontDelete|Function 2
    transformToDocument   XSLTProcessor::TransformToDocument  DontDelete|Function 2
    setParameter          XSLTProcessor::SetParameter         DontDelete|Function 3
    getParameter          XSLTProcessor::GetParameter         DontDelete|Function 2
    removeParameter       XSLTProcessor::RemoveParameter      DontDelete|Function 2
    clearParameters       XSLTProcessor::ClearParameters      DontDelete|Function 0
    reset                 XSLTProcessor::Reset                DontDelete|Function 0
  @end
  */
  
  DEFINE_PROTOTYPE("XSLTProcessor", XSLTProcessorProto)
  IMPLEMENT_PROTOFUNC(XSLTProcessorProtoFunc)
  IMPLEMENT_PROTOTYPE(XSLTProcessorProto, XSLTProcessorProtoFunc)
  
  XSLTProcessor::XSLTProcessor(ExecState *exec) : m_impl(new XSLTProcessorImpl())
  {
      setPrototype(XSLTProcessorProto::self(exec));
  }
  
  XSLTProcessor::~XSLTProcessor()
  {
      ScriptInterpreter::forgetDOMObject(m_impl.get());
  }
  
  ValueImp *XSLTProcessorProtoFunc::callAsFunction(ExecState *exec, ObjectImp *thisObj, const List &args)
  {
      if (!thisObj->inherits(&KJS::XSLTProcessor::info))
          return throwError(exec, TypeError);
      XSLTProcessorImpl &processor = *static_cast<XSLTProcessor *>(thisObj)->impl();
      switch (id) {
          case XSLTProcessor::ImportStylesheet:
          {
              ValueImp *nodeVal = args[0];
              if (nodeVal->isObject(&DOMNode::info)) {
                  DOMNode *node = static_cast<DOMNode *>(nodeVal);
                  processor.importStylesheet(node->impl());
                  return jsUndefined();
              }
              // Throw exception?
              break;
          }
          case XSLTProcessor::TransformToFragment:
          {
              ValueImp *nodeVal = args[0];
              ValueImp *docVal = args[1];
              if (nodeVal->isObject(&DOMNode::info) && docVal->isObject(&DOMDocument::info)) {
                  DOMNode *node = static_cast<DOMNode *>(nodeVal);
                  DOMDocument *doc = static_cast<DOMDocument *>(docVal);
                  DocumentImpl *docImpl = static_cast<DocumentImpl *>(doc->impl());
                  return getDOMNode(exec, processor.transformToFragment(node->impl(), docImpl).get());
              }
              // Throw exception?
              break;
          }
          case XSLTProcessor::TransformToDocument:
          {
              ValueImp *nodeVal = args[0];
              if (nodeVal->isObject(&DOMNode::info)) {
                  DOMNode *node = static_cast<DOMNode *>(nodeVal);
                  SharedPtr<DocumentImpl> resultDocument = processor.transformToDocument(node->impl());
                  if (resultDocument)
                      return getDOMDocumentNode(exec, resultDocument.get());
                  return jsUndefined();
              }
              // Throw exception?
              break;
          }
          case XSLTProcessor::SetParameter:
          {
              if (args[1]->isUndefinedOrNull() || args[2]->isUndefinedOrNull())
                  return jsUndefined(); // Throw exception?
              DOMString namespaceURI = args[0]->toString(exec).domString();
              DOMString localName = args[1]->toString(exec).domString();
              DOMString value = args[2]->toString(exec).domString();
              processor.setParameter(namespaceURI.impl(), localName.impl(), value.impl());
              return jsUndefined();
          }
          case XSLTProcessor::GetParameter:
          {
              if (args[1]->isUndefinedOrNull())
                  return jsUndefined();
              DOMString namespaceURI = args[0]->toString(exec).domString();
              DOMString localName = args[1]->toString(exec).domString();
              DOMStringImpl *value = processor.getParameter(namespaceURI.impl(), localName.impl()).get();
              if (value)
                  return jsString(UString(value));
              return jsUndefined();
          }
          case XSLTProcessor::RemoveParameter:
          {
              if (args[1]->isUndefinedOrNull())
                  return jsUndefined();
              DOMString namespaceURI = args[0]->toString(exec).domString();
              DOMString localName = args[1]->toString(exec).domString();
              processor.removeParameter(namespaceURI.impl(), localName.impl());
              return jsUndefined();
          }
          case XSLTProcessor::ClearParameters:
              processor.clearParameters();
              return jsUndefined();
          case XSLTProcessor::Reset:
              processor.reset();
              return jsUndefined();
      }
      return jsUndefined();
  }
  
  };
  
  
  
  
  1.1                  WebCore/khtml/ecma/XSLTProcessor.h
  
  Index: XSLTProcessor.h
  ===================================================================
  /*
   * Copyright (C) 2005 Apple Computer, Inc.  All rights reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in the
   *    documentation and/or other materials provided with the distribution.
   *
   * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
   * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
   * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
   * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
   * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
   * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
   * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
   */
  
  #ifndef XSLTProcessor_H
  #define XSLTProcessor_H
  
  #include <kxmlcore/SharedPtr.h>
  #include "kjs_binding.h"
  
  namespace DOM {
      class XSLTProcessorImpl;
  };
  
  // Eventually we should implement XSLTException:
  // http://lxr.mozilla.org/seamonkey/source/content/xsl/public/nsIXSLTException.idl
  // http://bugzilla.opendarwin.org/show_bug.cgi?id=5446
  
  namespace KJS {
  
  class XSLTProcessor : public DOMObject {
  public:
      XSLTProcessor(ExecState *exec);
      ~XSLTProcessor();
      
      virtual const ClassInfo *classInfo() const { return &info; }
      static const ClassInfo info;
      
      enum { ImportStylesheet, TransformToFragment, TransformToDocument, SetParameter,
              GetParameter, RemoveParameter, ClearParameters, Reset };
      
      DOM::XSLTProcessorImpl *impl() const { return m_impl.get(); }
  private:
      SharedPtr<DOM::XSLTProcessorImpl> m_impl;
  };
  
  class XSLTProcessorConstructorImp : public ObjectImp {
  public:
      XSLTProcessorConstructorImp(ExecState *) { }
      virtual bool implementsConstruct() const { return true; }
      virtual ObjectImp *construct(ExecState *exec, const List &args) { return new XSLTProcessor(exec); }
  };
  
  };
  
  #endif
  
  
  
  1.263     +9 -17     WebCore/khtml/xml/dom_docimpl.cpp
  
  Index: dom_docimpl.cpp
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/xml/dom_docimpl.cpp,v
  retrieving revision 1.262
  retrieving revision 1.263
  diff -u -r1.262 -r1.263
  --- dom_docimpl.cpp	26 Oct 2005 06:10:09 -0000	1.262
  +++ dom_docimpl.cpp	27 Oct 2005 22:34:49 -0000	1.263
  @@ -372,8 +372,7 @@
         , m_bindingManager(new XBLBindingManager(this))
   #endif
   #ifdef KHTML_XSLT
  -    , m_transformSource(NULL)
  -    , m_transformSourceDocument(0)
  +    , m_transformSource(0)
   #endif
   #if APPLE_CHANGES
       , m_finishedParsing(this, SIGNAL(finishedParsing()))
  @@ -518,8 +517,6 @@
   
   #ifdef KHTML_XSLT
       xmlFreeDoc((xmlDocPtr)m_transformSource);
  -    if (m_transformSourceDocument)
  -        m_transformSourceDocument->deref();
   #endif
   
   #ifndef KHTML_NO_XBL
  @@ -3101,20 +3098,15 @@
   
   void DocumentImpl::applyXSLTransform(ProcessingInstructionImpl* pi)
   {
  -    // FIXME: Be sure to change this next line to use a SharedPtr instead of a stack-allocated
  -    // object once XSLTProcessorImpl gets a ref count.
  -    XSLTProcessorImpl processor(static_cast<XSLStyleSheetImpl*>(pi->sheet()), this);
  -    processor.transformDocument(this);
  +    SharedPtr<XSLTProcessorImpl> processor = new XSLTProcessorImpl;
  +    processor->setXSLStylesheet(static_cast<XSLStyleSheetImpl*>(pi->sheet()));
  +    
  +    QString resultMIMEType;
  +    QString newSource;
  +    if (!processor->transformToString(this, resultMIMEType, newSource))
  +        return;
       // FIXME: If the transform failed we should probably report an error (like Mozilla does).
  -}
  -
  -void DocumentImpl::setTransformSourceDocument(DocumentImpl* doc)
  -{ 
  -    if (doc)
  -        doc->ref();
  -    if (m_transformSourceDocument)
  -        m_transformSourceDocument->deref(); 
  -    m_transformSourceDocument = doc;
  +    processor->createDocumentFromSource(newSource, resultMIMEType, this, view());
   }
   
   #endif
  
  
  
  1.133     +4 -4      WebCore/khtml/xml/dom_docimpl.h
  
  Index: dom_docimpl.h
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/xml/dom_docimpl.h,v
  retrieving revision 1.132
  retrieving revision 1.133
  diff -u -r1.132 -r1.133
  --- dom_docimpl.h	26 Oct 2005 06:10:09 -0000	1.132
  +++ dom_docimpl.h	27 Oct 2005 22:34:50 -0000	1.133
  @@ -572,8 +572,8 @@
       void applyXSLTransform(ProcessingInstructionImpl* pi);
       void setTransformSource(void* doc) { m_transformSource = doc; }
       const void* transformSource() { return m_transformSource; }
  -    DocumentImpl* transformSourceDocument() { return m_transformSourceDocument; }
  -    void setTransformSourceDocument(DocumentImpl* doc);
  +    SharedPtr<DocumentImpl> transformSourceDocument() { return m_transformSourceDocument; }
  +    void setTransformSourceDocument(DocumentImpl *doc) { m_transformSourceDocument = doc; }
   #endif
   
   #ifndef KHTML_NO_XBL
  @@ -696,8 +696,8 @@
       bool m_overMinimumLayoutThreshold;
       
   #ifdef KHTML_XSLT
  -    void* m_transformSource;
  -    DocumentImpl* m_transformSourceDocument;
  +    void *m_transformSource;
  +    SharedPtr<DocumentImpl> m_transformSourceDocument;
   #endif
   
   #ifndef KHTML_NO_XBL
  
  
  
  1.49      +11 -6     WebCore/khtml/xml/xml_tokenizer.cpp
  
  Index: xml_tokenizer.cpp
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/xml/xml_tokenizer.cpp,v
  retrieving revision 1.48
  retrieving revision 1.49
  diff -u -r1.48 -r1.49
  --- xml_tokenizer.cpp	26 Oct 2005 06:10:10 -0000	1.48
  +++ xml_tokenizer.cpp	27 Oct 2005 22:34:50 -0000	1.49
  @@ -791,20 +791,25 @@
   }
   
   #ifdef KHTML_XSLT
  -void XMLTokenizer::setTransformSource(DocumentImpl* doc)
  +void *xmlDocPtrForString(const QString &source, const QString &url)
   {
  -    // Time to spin up a new parse and save the xmlDocPtr.
       // Parse in a single chunk into an xmlDocPtr
       // FIXME: Hook up error handlers so that a failure to parse the main document results in
       // good error messages.
       const QChar BOM(0xFEFF);
       const unsigned char BOMHighByte = *reinterpret_cast<const unsigned char *>(&BOM);
  -    xmlDocPtr sourceDoc = xmlReadMemory(reinterpret_cast<const char *>(m_xmlCode.unicode()),
  -                                        m_xmlCode.length() * sizeof(QChar),
  -                                        doc->URL().ascii(),
  +    xmlDocPtr sourceDoc = xmlReadMemory(reinterpret_cast<const char *>(source.unicode()),
  +                                        source.length() * sizeof(QChar),
  +                                        url.ascii(),
                                           BOMHighByte == 0xFF ? "UTF-16LE" : "UTF-16BE", 
                                           XML_PARSE_NOCDATA|XML_PARSE_DTDATTR|XML_PARSE_NOENT);
  -    doc->setTransformSource(sourceDoc);
  +    return sourceDoc;
  +}
  +
  +void XMLTokenizer::setTransformSource(DocumentImpl *doc)
  +{
  +    // Time to spin up a new parse and save the xmlDocPtr.
  +    doc->setTransformSource(xmlDocPtrForString(m_xmlCode, doc->URL()));
   }
   #endif
   
  
  
  
  1.21      +3 -0      WebCore/khtml/xml/xml_tokenizer.h
  
  Index: xml_tokenizer.h
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/xml/xml_tokenizer.h,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- xml_tokenizer.h	25 Oct 2005 22:32:55 -0000	1.20
  +++ xml_tokenizer.h	27 Oct 2005 22:34:50 -0000	1.21
  @@ -84,6 +84,9 @@
   };
   
   Tokenizer *newXMLTokenizer(DOM::DocumentPtr *, KHTMLView * = 0);
  +#ifdef KHTML_XSLT
  +void *xmlDocPtrForString(const QString &source, const QString &url = QString());
  +#endif
   QMap<QString, QString> parseAttributes(const DOM::DOMString &, bool &attrsOK);
   bool parseXMLDocumentFragment(const DOM::DOMString &, DOM::DocumentFragmentImpl *, DOM::ElementImpl *parent = 0);
   }
  
  
  
  1.14      +245 -104  WebCore/khtml/xsl/xslt_processorimpl.cpp
  
  Index: xslt_processorimpl.cpp
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/xsl/xslt_processorimpl.cpp,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- xslt_processorimpl.cpp	10 Oct 2005 23:48:55 -0000	1.13
  +++ xslt_processorimpl.cpp	27 Oct 2005 22:34:52 -0000	1.14
  @@ -24,8 +24,11 @@
   #include "config.h"
   #include "xslt_processorimpl.h"
   #include "xsl_stylesheetimpl.h"
  +#include "xml_tokenizer.h"
  +#include "htmltokenizer.h"
   #include "html_documentimpl.h"
   #include "loader.h"
  +#include "markup.h"
   #include "khtmlview.h"
   #include "khtml_part.h"
   #include "KWQLoader.h"
  @@ -36,27 +39,32 @@
   #include <libxslt/documents.h>
   #include <libxslt/imports.h>
   
  +#include <kxmlcore/Assertions.h>
  +
   using namespace khtml;
   using namespace DOM;
   
   namespace DOM {
  -    
  -XSLTProcessorImpl::XSLTProcessorImpl(XSLStyleSheetImpl* sheet, DocumentImpl* source)
  -    : m_stylesheet(sheet), m_sourceDocument(source)
  -{
  -}
  -
  -XSLTProcessorImpl::~XSLTProcessorImpl()
  -{
  -}
   
   static void parseErrorFunc(void *ctxt, const char *msg, ...)
   {
       // FIXME: It would be nice to display error messages somewhere.
  +#if !ERROR_DISABLED
  +    char *errorMessage = 0;
  +    va_list args;
  +    va_start(args, msg);
  +    vasprintf(&errorMessage, msg, args);
  +    ERROR("%s", errorMessage);
  +    if (errorMessage)
  +        free(errorMessage);
  +    va_end(args);
  +#endif
   }
   
  +// FIXME: There seems to be no way to control the ctxt pointer for loading here, thus we have globals.
   static XSLTProcessorImpl *globalProcessor = 0;
  -static xmlDocPtr stylesheetLoadFunc(const xmlChar* uri,
  +static khtml::DocLoader *globalDocLoader = 0;
  +static xmlDocPtr stylesheetLoadFunc(const xmlChar *uri,
                                       xmlDictPtr dict,
                                       int options,
                                       void* ctxt,
  @@ -77,7 +85,7 @@
               void *oldErrorContext = xmlGenericErrorContext;
               
               data = KWQServeSynchronousRequest(khtml::Cache::loader(), 
  -                                              globalProcessor->sourceDocument()->docLoader(), job, finalURL, headers);
  +                                              globalDocLoader, job, finalURL, headers);
           
               xmlSetGenericErrorFunc(0, parseErrorFunc);
               // We don't specify an encoding here. Neither Gecko nor WinIE respects
  @@ -87,7 +95,7 @@
               return doc;
           }
           case XSLT_LOAD_STYLESHEET:
  -            return globalProcessor->stylesheet()->locateStylesheetSubResource(((xsltStylesheetPtr)ctxt)->doc, uri);
  +            return globalProcessor->xslStylesheet()->locateStylesheetSubResource(((xsltStylesheetPtr)ctxt)->doc, uri);
           default:
               break;
       }
  @@ -95,120 +103,253 @@
       return 0;
   }
   
  -SharedPtr<DocumentImpl> XSLTProcessorImpl::transformDocument(DocumentImpl* doc)
  +static inline void setXSLTLoadCallBack(xsltDocLoaderFunc func, XSLTProcessorImpl *processor, khtml::DocLoader *loader)
   {
  -    // FIXME: Right now we assume |doc| is unparsed, but if it has been parsed we will need to serialize it
  -    // and then feed that resulting source to libxslt.
  -    m_resultOutput = "";
  +    xsltSetLoaderFunc(func);
  +    globalProcessor = processor;
  +    globalDocLoader = loader;
  +}
   
  -    if (!m_stylesheet || !m_stylesheet->document()) return 0;
  -        
  -    globalProcessor = this;
  -    xsltSetLoaderFunc(stylesheetLoadFunc);
  +static int writeToQString(void *context, const char *buffer, int len)
  +{
  +    QString &resultOutput = *static_cast<QString *>(context);
  +    resultOutput += QString::fromUtf8(buffer, len);
  +    return len;
  +}
   
  -    xsltStylesheetPtr sheet = m_stylesheet->compileStyleSheet();
  +static bool saveResultToString(xmlDocPtr resultDoc, xsltStylesheetPtr sheet, QString &resultString)
  +{
  +    xmlOutputBufferPtr outputBuf = xmlAllocOutputBuffer(0);
  +    if (!outputBuf)
  +        return false;
  +    outputBuf->context = &resultString;
  +    outputBuf->writecallback = writeToQString;
  +    
  +    int retval = xsltSaveResultTo(outputBuf, resultDoc, sheet);
  +    xmlOutputBufferClose(outputBuf);
  +    
  +    return (retval >= 0);
  +}
   
  -    if (!sheet) {
  -        globalProcessor = 0;
  -        xsltSetLoaderFunc(0);
  +static inline void transformTextStringToXHTMLDocumentString(QString &text)
  +{
  +    // Modify the output so that it is a well-formed XHTML document with a <pre> tag enclosing the text.
  +    text.replace('&', "&amp;");
  +    text.replace('<', "&lt;");
  +    text = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  +        "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
  +        "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
  +        "<head><title/></head>\n"
  +        "<body>\n"
  +        "<pre>" + text + "</pre>\n"
  +        "</body>\n"
  +        "</html>\n";
  +}
  +
  +static const char **xsltParamArrayFromQDict(QDict<DOMString> parameters)
  +{
  +    if (parameters.count())
           return 0;
  +    const char **parameterArray = (const char **)malloc(((parameters.count() * 2) + 1) * sizeof(char *));
  +
  +    QDictIterator<DOMString> it(parameters);
  +    unsigned index = 0;
  +    for (it.toFirst(); it.current(); ++it) {
  +        parameterArray[++index] = strdup(it.currentKey().utf8().data());
  +        parameterArray[++index] = strdup(it.current()->qstring().utf8().data());
       }
  +    parameterArray[index] = 0;
  +
  +    return parameterArray;
  +}
  +
  +static void freeXsltParamArray(const char **params)
  +{
  +    const char **temp = params;
  +    if (!params)
  +        return;
       
  -    m_stylesheet->clearDocuments();
  -  
  -    // Get the parsed source document.
  -    xmlDocPtr sourceDoc = (xmlDocPtr)doc->transformSource();
  -    xmlDocPtr resultDoc = xsltApplyStylesheet(sheet, sourceDoc, 0);
  -    
  -    globalProcessor = 0;
  -    xsltSetLoaderFunc(0);
  +    while (*temp) {
  +        free((void *)*(temp++));
  +        free((void *)*(temp++));
  +    }
  +    free(params);
  +}
   
  -    SharedPtr<DocumentImpl> result = documentFromXMLDocPtr(resultDoc, sheet);
  -    xsltFreeStylesheet(sheet);
  -    xmlFreeDoc(resultDoc);
   
  +SharedPtr<DocumentImpl> XSLTProcessorImpl::createDocumentFromSource(const QString &sourceString, const QString &sourceMIMEType, NodeImpl *sourceNode, KHTMLView *view)
  +{
  +    SharedPtr<DocumentImpl> ownerDocument = sourceNode->getDocument();
  +    bool sourceIsDocument = (sourceNode == ownerDocument.get());
  +    QString documentSource = sourceString;
  +
  +    SharedPtr<DocumentImpl> result;
  +    if (sourceMIMEType == "text/html")
  +        result = ownerDocument->impl()->createHTMLDocument(view);
  +    else {
  +        result = ownerDocument->impl()->createDocument(view);
  +        if (sourceMIMEType == "text/plain")
  +            transformTextStringToXHTMLDocumentString(documentSource);
  +    }
  +    
  +    result->docLoader()->setShowAnimations(ownerDocument->docLoader()->showAnimations());
  +    
  +    // Before parsing, we need to save & detach the old document and get the new document
  +    // in place. We have to do this only if we're rendering the result document.
  +    if (view) {
  +        view->clear();
  +        result->setTransformSourceDocument(view->part()->xmlDocImpl());
  +        view->part()->replaceDocImpl(result.get());
  +    }
  +    
  +    result->open();
  +    if (sourceIsDocument) {
  +        result->setURL(ownerDocument->URL());
  +        result->setBaseURL(ownerDocument->baseURL());
  +    }
  +    result->determineParseMode(documentSource); // Make sure we parse in the correct mode.
  +    result->write(documentSource);
  +    result->finishParsing();
  +    result->setParsing(false);
  +    if (view)
  +        view->part()->checkCompleted();
  +    else
  +        result->close(); // FIXME: Even viewless docs can load subresources. onload will fire too early.
  +                         // This is probably a bug in XMLHttpRequestObjects as well.
       return result;
   }
   
  -static int bufferWrite(void* context, const char* buffer, int len)
  +static inline SharedPtr<DocumentFragmentImpl> createFragmentFromSource(QString sourceString, QString sourceMIMEType, NodeImpl *sourceNode, DocumentImpl *ouputDoc)
   {
  -    static_cast<XSLTProcessorImpl*>(context)->addToResult(buffer, len);
  -    return len;
  +    SharedPtr<DocumentFragmentImpl> fragment = new DocumentFragmentImpl(ouputDoc->docPtr());
  +    
  +    if (sourceMIMEType == "text/html")
  +        parseHTMLDocumentFragment(sourceString, fragment.get());
  +    else {
  +        if (sourceMIMEType == "text/plain")
  +            transformTextStringToXHTMLDocumentString(sourceString);
  +        bool successfulParse = parseXMLDocumentFragment(sourceString, fragment.get(), ouputDoc->documentElement());
  +        if (!successfulParse)
  +            return 0;
  +    }
  +    
  +    // FIXME: Do we need to mess with URLs here?
  +        
  +    return fragment;
   }
   
  -void XSLTProcessorImpl::addToResult(const char* buffer, int len)
  +static xsltStylesheetPtr xsltStylesheetPointer(SharedPtr<XSLStyleSheetImpl> &cachedStylesheet, NodeImpl *stylesheetRootNode)
   {
  -    m_resultOutput += QString::fromUtf8(buffer, len);
  +    if (!cachedStylesheet && stylesheetRootNode) {
  +        cachedStylesheet = new XSLStyleSheetImpl(stylesheetRootNode->parent() ? stylesheetRootNode->parent() : stylesheetRootNode);
  +        cachedStylesheet->parseString(createMarkup(stylesheetRootNode));
  +    }
  +    
  +    if (!cachedStylesheet || !cachedStylesheet->document())
  +        return 0;
  +    
  +    return cachedStylesheet->compileStyleSheet();
   }
   
  -SharedPtr<DocumentImpl> XSLTProcessorImpl::documentFromXMLDocPtr(xmlDocPtr resultDoc, xsltStylesheetPtr sheet)
  +static inline xmlDocPtr xmlDocPtrFromNode(NodeImpl *sourceNode)
   {
  -    if (!resultDoc || !sheet)
  -        return 0;
  +    SharedPtr<DocumentImpl> ownerDocument = sourceNode->getDocument();
  +    bool sourceIsDocument = (sourceNode == ownerDocument.get());
  +    
  +    xmlDocPtr sourceDoc = 0;
  +    if (sourceIsDocument)
  +        sourceDoc = (xmlDocPtr)ownerDocument->transformSource();
  +    if (!sourceDoc)
  +        sourceDoc = (xmlDocPtr)xmlDocPtrForString(createMarkup(sourceNode), sourceIsDocument ? ownerDocument->URL() : QString());
  +    return sourceDoc;
  +}
   
  -    SharedPtr<DocumentImpl> result;
  -    xmlOutputBufferPtr outputBuf = xmlAllocOutputBuffer(0);
  -    if (outputBuf) {
  -        outputBuf->context = this;
  -        outputBuf->writecallback = bufferWrite;
  -        
  -        int retval = xsltSaveResultTo(outputBuf, resultDoc, sheet);
  -        xmlOutputBufferClose(outputBuf);
  -        
  -        if (retval < 0)
  -            return 0;
  -        
  -        // 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 create an XML document).
  -        KHTMLView *view = m_sourceDocument->view();
  -        const xmlChar *method;
  -        XSLT_GET_IMPORT_PTR(method, sheet, method);
  -        if (method == 0 && resultDoc->type == XML_HTML_DOCUMENT_NODE)
  -            method = (const xmlChar *)"html";
  -        if (xmlStrEqual(method, (const xmlChar *)"html"))
  -            result = m_sourceDocument->impl()->createHTMLDocument(view);
  -        else
  -            result = m_sourceDocument->impl()->createDocument(view);
  -        result->attach();
  -        result->docLoader()->setShowAnimations(m_sourceDocument->docLoader()->showAnimations());
  -        result->setTransformSourceDocument(m_sourceDocument.get());
  -
  -        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.replace('&', "&amp;");
  -            m_resultOutput.replace('<', "&lt;");
  -            m_resultOutput = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
  -                "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n"
  -                "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"
  -                "<head><title/></head>\n"
  -                "<body>\n"
  -                "<pre>" + m_resultOutput + "</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.
  -        if (view) {
  -            view->clear();
  -            view->part()->replaceDocImpl(result.get());
  -        }
  +static inline QString resultMIMEType(xmlDocPtr resultDoc, xsltStylesheetPtr sheet)
  +{
  +    // 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 create an XML document).
  +
  +    const xmlChar *resultType = 0;
  +    XSLT_GET_IMPORT_PTR(resultType, sheet, method);
  +    if (resultType == 0 && resultDoc->type == XML_HTML_DOCUMENT_NODE)
  +        resultType = (const xmlChar *)"html";
  +    
  +    if (xmlStrEqual(resultType, (const xmlChar *)"html"))
  +        return QString("text/html");
  +    else if (xmlStrEqual(resultType, (const xmlChar *)"text"))
  +        return QString("text/plain");
           
  -        result->open();
  -        result->setURL(m_sourceDocument->URL());
  -        result->setBaseURL(m_sourceDocument->baseURL());
  -        result->determineParseMode(m_resultOutput); // Make sure we parse in the correct mode.
  -        result->write(m_resultOutput);
  -        result->finishParsing();
  -        result->setParsing(false);
  -        if (view)
  -            view->part()->checkCompleted();
  -        else
  -            result->close(); // FIXME: Even viewless docs can load subresources. onload will fire too early.
  -                             // This is probably a bug in XMLHttpRequestObjects as well.
  +    return QString("application/xml");
  +}
  +
  +bool XSLTProcessorImpl::transformToString(NodeImpl *sourceNode, QString &mimeType, QString &resultString)
  +{
  +    SharedPtr<DocumentImpl> ownerDocument = sourceNode->getDocument();
  +    SharedPtr<XSLStyleSheetImpl> cachedStylesheet = m_stylesheet;
  +    
  +    setXSLTLoadCallBack(stylesheetLoadFunc, this, ownerDocument->docLoader());
  +    xsltStylesheetPtr sheet = xsltStylesheetPointer(cachedStylesheet, m_stylesheetRootNode.get());
  +    if (!sheet) {
  +        setXSLTLoadCallBack(0, 0, 0);
  +        return false;
       }
  -    return result;
  +    cachedStylesheet->clearDocuments();
  +    
  +    xmlDocPtr sourceDoc = xmlDocPtrFromNode(sourceNode);
  +    const char **params = xsltParamArrayFromQDict(m_parameters);
  +    xmlDocPtr resultDoc = xsltApplyStylesheet(sheet, sourceDoc, params);
  +    freeXsltParamArray(params);
  +    
  +    setXSLTLoadCallBack(0, 0, 0);
  +    
  +    if (!saveResultToString(resultDoc, sheet, resultString))
  +        return false;
  +    
  +    mimeType = resultMIMEType(resultDoc, sheet);
  +    
  +    xsltFreeStylesheet(sheet);
  +    xmlFreeDoc(resultDoc);
  +    
  +    return true;
  +}
  +
  +SharedPtr<DocumentImpl> XSLTProcessorImpl::transformToDocument(NodeImpl *sourceNode)
  +{
  +    QString resultMIMEType;
  +    QString resultString;
  +    if (!transformToString(sourceNode, resultMIMEType, resultString))
  +        return 0;
  +    return createDocumentFromSource(resultString, resultMIMEType, sourceNode);
  +}
  +
  +SharedPtr<DocumentFragmentImpl> XSLTProcessorImpl::transformToFragment(NodeImpl *sourceNode, DocumentImpl *outputDoc)
  +{
  +    QString resultMIMEType;
  +    QString resultString;
  +    if (!transformToString(sourceNode, resultMIMEType, resultString))
  +        return 0;
  +    return createFragmentFromSource(resultString, resultMIMEType, sourceNode, outputDoc);
  +}
  +
  +void XSLTProcessorImpl::setParameter(DOMStringImpl *namespaceURI, DOMStringImpl *localName, DOMStringImpl *value)
  +{
  +    // FIXME: namespace support?
  +    m_parameters.replace(DOMString(localName).qstring(), new DOMString(value));
  +}
  +
  +SharedPtr<DOMStringImpl> XSLTProcessorImpl::getParameter(DOMStringImpl *namespaceURI, DOMStringImpl *localName) const
  +{
  +    // FIXME: namespace support?
  +    if (DOMString *value = m_parameters.find(DOMString(localName).qstring()))
  +        return value->impl();
  +    return 0;
  +}
  +
  +void XSLTProcessorImpl::removeParameter(DOMStringImpl *namespaceURI, DOMStringImpl *localName)
  +{
  +    // FIXME: namespace support?
  +    m_parameters.remove(DOMString(localName).qstring());
   }
   
   }
  
  
  
  1.5       +30 -17    WebCore/khtml/xsl/xslt_processorimpl.h
  
  Index: xslt_processorimpl.h
  ===================================================================
  RCS file: /cvs/root/WebCore/khtml/xsl/xslt_processorimpl.h,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- xslt_processorimpl.h	10 Oct 2005 23:48:55 -0000	1.4
  +++ xslt_processorimpl.h	27 Oct 2005 22:34:52 -0000	1.5
  @@ -29,38 +29,51 @@
   #include <libxml/parserInternals.h>
   
   #include <libxslt/transform.h>
  +#include <libxslt/documents.h>
   
   #include <misc/shared.h>
  +#include "dom_stringimpl.h"
  +#include "xsl_stylesheetimpl.h"
   #include <qstring.h>
   
   namespace DOM {
   
  -class XSLStyleSheetImpl;
  +class NodeImpl;
   class DocumentImpl;
  -    
  -class XSLTProcessorImpl
  +class DocumentFragmentImpl;
  +
  +class XSLTProcessorImpl : public khtml::Shared<XSLTProcessorImpl>
   {
   public:
  -    // Constructors
  -    XSLTProcessorImpl(XSLStyleSheetImpl* stylesheet, DocumentImpl* source);
  -    ~XSLTProcessorImpl();
  -    
  -    // Method for transforming a source document into a result document.
  -    SharedPtr<DocumentImpl> transformDocument(DocumentImpl* sourceDoc);
  +    XSLTProcessorImpl() { m_parameters.setAutoDelete(true); };
   
  -    // Convert a libxml doc ptr to a KHTML DOM Document
  -    SharedPtr<DocumentImpl> documentFromXMLDocPtr(xmlDocPtr resultDoc, xsltStylesheetPtr sheet);
  +    void setXSLStylesheet(XSLStyleSheetImpl *styleSheet) { m_stylesheet = styleSheet; }
  +    bool transformToString(NodeImpl *source, QString &resultMIMEType, QString &resultString);
  +    SharedPtr<DocumentImpl> createDocumentFromSource(const QString &source, const QString &sourceMIMEType, NodeImpl *sourceNode, KHTMLView *view = 0);
       
  -    // Helpers
  -    void addToResult(const char* buffer, int len);
  +    // DOM methods
  +    void importStylesheet(NodeImpl *style) { m_stylesheetRootNode = style; }
  +    SharedPtr<DocumentFragmentImpl> transformToFragment(NodeImpl *source, DocumentImpl *ouputDoc);
  +    SharedPtr<DocumentImpl> transformToDocument(NodeImpl *source);
       
  -    XSLStyleSheetImpl *stylesheet() { return m_stylesheet.get(); }
  -    DocumentImpl *sourceDocument() { return m_sourceDocument.get(); }
  +    void setParameter(DOMStringImpl *namespaceURI, DOMStringImpl *localName, DOMStringImpl *value);
  +    SharedPtr<DOMStringImpl> getParameter(DOMStringImpl *namespaceURI, DOMStringImpl *localName) const;
  +    void removeParameter(DOMStringImpl *namespaceURI, DOMStringImpl *localName);
  +    void clearParameters() { m_parameters.clear(); }
  +
  +    void reset() { m_stylesheet = NULL; m_stylesheetRootNode = NULL;  m_parameters.clear(); }
  +    
  +public:
  +    // Only for libXSLT callbacks
  +    XSLStyleSheetImpl *xslStylesheet() const { return m_stylesheet.get(); }
       
   private:
  +    // Convert a libxml doc ptr to a KHTML DOM Document
  +    SharedPtr<DocumentImpl> documentFromXMLDocPtr(xmlDocPtr resultDoc, xsltStylesheetPtr sheet, DocumentImpl *ownerDocument, bool sourceIsDocument);
  +
       SharedPtr<XSLStyleSheetImpl> m_stylesheet;
  -    QString m_resultOutput;
  -    SharedPtr<DocumentImpl> m_sourceDocument;
  +    SharedPtr<NodeImpl> m_stylesheetRootNode;
  +    QDict<DOMString> m_parameters;
   };
   
   }
  
  
  



More information about the webkit-changes mailing list