Commit 06b7e555 authored by hausmann@webkit.org's avatar hausmann@webkit.org

[Qt] Implement XSLT support with QtXmlPatterns.

https://bugs.webkit.org/show_bug.cgi?id=28303

Patch by Jakub Wieczorek <faw217@gmail.com> on 2009-09-28
Reviewed by Simon Hausmann.

JavaScriptCore:

* wtf/Platform.h: Add a WTF_USE_QXMLQUERY #define.

WebCore:

* GNUmakefile.am:
* WebCore.gypi:
* WebCore.pro:
* WebCore.vcproj/WebCore.vcproj:
* WebCoreSources.bkl:
* dom/Document.cpp:
(WebCore::Document::Document):
(WebCore::Document::~Document):
(WebCore::Document::setTransformSource):
* dom/Document.h:
(WebCore::Document::transformSource):
* dom/TransformSource.h: Added.
(WebCore::TransformSource::platformSource):
* dom/TransformSourceLibxslt.cpp: Added.
(WebCore::TransformSource::TransformSource): Wraps a libxml2 document.
(WebCore::TransformSource::~TransformSource):
* dom/TransformSourceQt.cpp: Added.
(WebCore::TransformSource::TransformSource): Wraps a plain string.
(WebCore::TransformSource::~TransformSource):
* dom/XMLTokenizerLibxml2.cpp:
(WebCore::XMLTokenizer::doEnd):
* dom/XMLTokenizerQt.cpp:
(WebCore::XMLTokenizer::doEnd):
(WebCore::XMLTokenizer::parseProcessingInstruction):
* xml/XSLStyleSheet.h:
(WebCore::XSLStyleSheet::sheetString):
* xml/XSLStyleSheetLibxslt.cpp:
(WebCore::XSLStyleSheet::document):
* xml/XSLStyleSheetQt.cpp: Added.
* xml/XSLTProcessor.h:
* xml/XSLTProcessorLibxslt.cpp:
(WebCore::xmlDocPtrFromNode):
* xml/XSLTProcessorQt.cpp: Added.
(WebCore::XSLTMessageHandler::XSLTMessageHandler): A subclass of QAbstractMessageHandler.
(WebCore::XSLTMessageHandler::handleMessage): Forwards all processor messages to the Console.
(WebCore::XSLTProcessor::transformToString): Uses QXmlQuery.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@48826 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent f1a58635
2009-09-28 Jakub Wieczorek <faw217@gmail.com>
Reviewed by Simon Hausmann.
[Qt] Implement XSLT support with QtXmlPatterns.
https://bugs.webkit.org/show_bug.cgi?id=28303
* wtf/Platform.h: Add a WTF_USE_QXMLQUERY #define.
2009-09-28 Yongjun Zhang <yongjun.zhang@nokia.com>
Reviewed by Eric Seidel.
......
......@@ -777,11 +777,11 @@ on MinGW. See https://bugs.webkit.org/show_bug.cgi?id=29268 */
#define ENABLE_PAN_SCROLLING 1
#endif
/* Use the QtXmlStreamReader implementation for XMLTokenizer */
/* Use the QXmlStreamReader implementation for XMLTokenizer */
/* Use the QXmlQuery implementation for XSLTProcessor */
#if PLATFORM(QT)
#if !ENABLE(XSLT)
#define WTF_USE_QXMLSTREAM 1
#endif
#define WTF_USE_QXMLQUERY 1
#endif
#if !PLATFORM(QT)
......
2009-09-28 Jakub Wieczorek <faw217@gmail.com>
Reviewed by Simon Hausmann.
[Qt] Implement XSLT support with QtXmlPatterns.
https://bugs.webkit.org/show_bug.cgi?id=28303
* GNUmakefile.am:
* WebCore.gypi:
* WebCore.pro:
* WebCore.vcproj/WebCore.vcproj:
* WebCoreSources.bkl:
* dom/Document.cpp:
(WebCore::Document::Document):
(WebCore::Document::~Document):
(WebCore::Document::setTransformSource):
* dom/Document.h:
(WebCore::Document::transformSource):
* dom/TransformSource.h: Added.
(WebCore::TransformSource::platformSource):
* dom/TransformSourceLibxslt.cpp: Added.
(WebCore::TransformSource::TransformSource): Wraps a libxml2 document.
(WebCore::TransformSource::~TransformSource):
* dom/TransformSourceQt.cpp: Added.
(WebCore::TransformSource::TransformSource): Wraps a plain string.
(WebCore::TransformSource::~TransformSource):
* dom/XMLTokenizerLibxml2.cpp:
(WebCore::XMLTokenizer::doEnd):
* dom/XMLTokenizerQt.cpp:
(WebCore::XMLTokenizer::doEnd):
(WebCore::XMLTokenizer::parseProcessingInstruction):
* xml/XSLStyleSheet.h:
(WebCore::XSLStyleSheet::sheetString):
* xml/XSLStyleSheetLibxslt.cpp:
(WebCore::XSLStyleSheet::document):
* xml/XSLStyleSheetQt.cpp: Added.
* xml/XSLTProcessor.h:
* xml/XSLTProcessorLibxslt.cpp:
(WebCore::xmlDocPtrFromNode):
* xml/XSLTProcessorQt.cpp: Added.
(WebCore::XSLTMessageHandler::XSLTMessageHandler): A subclass of QAbstractMessageHandler.
(WebCore::XSLTMessageHandler::handleMessage): Forwards all processor messages to the Console.
(WebCore::XSLTProcessor::transformToString): Uses QXmlQuery.
2009-09-28 Yongjun Zhang <yongjun.zhang@nokia.com>
Reviewed by Eric Seidel.
......@@ -2410,6 +2410,8 @@ FEATURE_DEFINES_JAVASCRIPT += ENABLE_XSLT=1
webcore_cppflags += -DENABLE_XSLT=1
webcore_sources += \
WebCore/dom/TransformSourceLibxslt.cpp \
WebCore/dom/TransformSource.h \
WebCore/xml/XSLImportRule.cpp \
WebCore/xml/XSLImportRule.h \
WebCore/xml/XSLStyleSheetLibxslt.cpp \
......
......@@ -1110,6 +1110,8 @@
'dom/TextEvent.cpp',
'dom/TextEvent.h',
'dom/Tokenizer.h',
'dom/TransformSourceLibxslt.cpp',
'dom/TransformSource.h',
'dom/Traversal.cpp',
'dom/Traversal.h',
'dom/TreeWalker.cpp',
......
......@@ -127,7 +127,6 @@ contains(DEFINES, ENABLE_SINGLE_THREADED=1) {
!contains(DEFINES, ENABLE_DASHBOARD_SUPPORT=.): DEFINES += ENABLE_DASHBOARD_SUPPORT=0
!contains(DEFINES, ENABLE_FILTERS=.): DEFINES += ENABLE_FILTERS=0
!contains(DEFINES, ENABLE_XPATH=.): DEFINES += ENABLE_XPATH=1
!contains(DEFINES, ENABLE_XSLT=.): DEFINES += ENABLE_XSLT=0
#!contains(DEFINES, ENABLE_XBL=.): DEFINES += ENABLE_XBL=1
!contains(DEFINES, ENABLE_WCSS=.): DEFINES += ENABLE_WCSS=0
!contains(DEFINES, ENABLE_WML=.): DEFINES += ENABLE_WML=0
......@@ -172,6 +171,12 @@ contains(DEFINES, ENABLE_SINGLE_THREADED=1) {
# Web Socket support.
!contains(DEFINES, ENABLE_WEB_SOCKETS=.): DEFINES += ENABLE_WEB_SOCKETS=1
# XSLT support with QtXmlPatterns
!contains(DEFINES, ENABLE_XSLT=.) {
contains(QT_CONFIG, xmlpatterns):!lessThan(QT_MINOR_VERSION, 5):DEFINES += ENABLE_XSLT=1
else:DEFINES += ENABLE_XSLT=0
}
DEFINES += WTF_USE_JAVASCRIPTCORE_BINDINGS=1 WTF_CHANGES=1
# Used to compute defaults for the build-webkit script
......@@ -908,7 +913,6 @@ SOURCES += \
dom/WheelEvent.cpp \
dom/XMLTokenizer.cpp \
dom/XMLTokenizerQt.cpp \
dom/XMLTokenizerScope.cpp \
dom/default/PlatformMessagePortChannel.cpp \
editing/AppendNodeCommand.cpp \
editing/ApplyStyleCommand.cpp \
......@@ -1568,6 +1572,7 @@ HEADERS += \
dom/TagNodeList.h \
dom/TextEvent.h \
dom/Text.h \
dom/TransformSource.h \
dom/Traversal.h \
dom/TreeWalker.h \
dom/UIEvent.h \
......@@ -1576,7 +1581,6 @@ HEADERS += \
dom/WebKitTransitionEvent.h \
dom/WheelEvent.h \
dom/XMLTokenizer.h \
dom/XMLTokenizerScope.h \
editing/AppendNodeCommand.h \
editing/ApplyStyleCommand.h \
editing/BreakBlockquoteCommand.h \
......@@ -2714,25 +2718,16 @@ unix:!mac:CONFIG += link_pkgconfig
contains(DEFINES, ENABLE_XSLT=1) {
FEATURE_DEFINES_JAVASCRIPT += ENABLE_XSLT=1
PKGCONFIG += libxml-2.0 libxslt
macx {
INCLUDEPATH += /usr/include/libxml2
LIBS += -lxml2 -lxslt
}
win32-msvc* {
LIBS += -llibxml2 -llibxslt
}
QT += xmlpatterns
SOURCES += \
bindings/js/JSXSLTProcessorConstructor.cpp \
bindings/js/JSXSLTProcessorCustom.cpp \
xml/XSLImportRule.cpp \
xml/XSLStyleSheet.cpp \
xml/XSLTExtensions.cpp \
dom/TransformSourceQt.cpp \
xml/XSLStyleSheetQt.cpp \
xml/XSLTProcessor.cpp \
xml/XSLTUnicodeSort.cpp
xml/XSLTProcessorQt.cpp
}
contains(DEFINES, ENABLE_XBL=1) {
......
......@@ -24475,6 +24475,14 @@
RelativePath="..\dom\Tokenizer.h"
>
</File>
<File
RelativePath="..\dom\TransformSourceLibxslt.cpp"
>
</File>
<File
RelativePath="..\dom\TransformSource.h"
>
</File>
<File
RelativePath="..\dom\Traversal.cpp"
>
......
......@@ -1544,6 +1544,8 @@
854FE7370A2297BE0058D7AD /* Traversal.h in Headers */ = {isa = PBXBuildFile; fileRef = 854FE72D0A2297BE0058D7AD /* Traversal.h */; };
854FE7380A2297BE0058D7AD /* TreeWalker.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 854FE72E0A2297BE0058D7AD /* TreeWalker.cpp */; };
854FE7390A2297BE0058D7AD /* TreeWalker.h in Headers */ = {isa = PBXBuildFile; fileRef = 854FE72F0A2297BE0058D7AD /* TreeWalker.h */; };
854FE7400A2297BE0058D7AD /* TransformSourceLibxslt.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 854FE72G0A2297BE0058D7AD /* TransformSourceLibxslt.cpp */; };
854FE7410A2297BE0058D7AD /* TransformSource.h in Headers */ = {isa = PBXBuildFile; fileRef = 854FE72H0A2297BE0058D7AD /* TransformSource.h */; };
855247CF0AD850B80012093B /* DOMHTMLAppletElementInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 855247CD0AD850B80012093B /* DOMHTMLAppletElementInternal.h */; };
855247D00AD850B80012093B /* DOMHTMLEmbedElementInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 855247CE0AD850B80012093B /* DOMHTMLEmbedElementInternal.h */; };
85526C370AB0A17E000302EA /* DOMNodeIterator.h in Headers */ = {isa = PBXBuildFile; fileRef = 85526C350AB0A17E000302EA /* DOMNodeIterator.h */; };
......@@ -6773,6 +6775,8 @@
854FE72D0A2297BE0058D7AD /* Traversal.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = Traversal.h; sourceTree = "<group>"; };
854FE72E0A2297BE0058D7AD /* TreeWalker.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = TreeWalker.cpp; sourceTree = "<group>"; };
854FE72F0A2297BE0058D7AD /* TreeWalker.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = TreeWalker.h; sourceTree = "<group>"; };
854FE72G0A2297BE0058D7AD /* TransformSourceLibxslt.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = TransformSourceLibxslt.cpp; sourceTree = "<group>"; };
854FE72H0A2297BE0058D7AD /* TransformSource.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = TransformSource.h; sourceTree = "<group>"; };
855247CD0AD850B80012093B /* DOMHTMLAppletElementInternal.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = DOMHTMLAppletElementInternal.h; sourceTree = "<group>"; };
855247CE0AD850B80012093B /* DOMHTMLEmbedElementInternal.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = DOMHTMLEmbedElementInternal.h; sourceTree = "<group>"; };
85526C350AB0A17E000302EA /* DOMNodeIterator.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = DOMNodeIterator.h; sourceTree = "<group>"; };
......@@ -15476,6 +15480,8 @@
854FE72E0A2297BE0058D7AD /* TreeWalker.cpp */,
854FE72F0A2297BE0058D7AD /* TreeWalker.h */,
1A750D3C0A90DE35000FF215 /* TreeWalker.idl */,
854FE72G0A2297BE0058D7AD /* TransformSourceLibxslt.cpp */,
854FE72H0A2297BE0058D7AD /* TransformSource.h */,
85031B370A44EFC700F992E0 /* UIEvent.cpp */,
85031B380A44EFC700F992E0 /* UIEvent.h */,
141B94EE09EC425A000E9413 /* UIEvent.idl */,
......@@ -19799,6 +19805,7 @@
49E911C30EF86D47009D0CAF /* TransformationMatrix.cpp in Sources */,
B27535580B053814002CE64F /* TransformationMatrixCG.cpp in Sources */,
49E911CF0EF86D47009D0CAF /* TransformOperations.cpp in Sources */,
854FE7400A2297BE0058D7AD /* TransformSourceLibxslt.cpp in Sources */,
0F500AB10F54DB3100EEF928 /* TransformState.cpp in Sources */,
49E911D10EF86D47009D0CAF /* TranslateTransformOperation.cpp in Sources */,
854FE7360A2297BE0058D7AD /* Traversal.cpp in Sources */,
......@@ -507,6 +507,7 @@ This file contains the list of files needed to build WebCore.
dom/TagNodeList.cpp
dom/Text.cpp
dom/TextEvent.cpp
dom/TransformSourceLibxslt.cpp
dom/Traversal.cpp
dom/TreeWalker.cpp
dom/UIEvent.cpp
......
......@@ -116,6 +116,7 @@
#include "TextIterator.h"
#include "TextResourceDecoder.h"
#include "Timer.h"
#include "TransformSource.h"
#include "TreeWalker.h"
#include "UIEvent.h"
#include "WebKitAnimationEvent.h"
......@@ -321,9 +322,6 @@ Document::Document(Frame* frame, bool isXHTML)
, m_titleSetExplicitly(false)
, m_updateFocusAppearanceTimer(this, &Document::updateFocusAppearanceTimerFired)
, m_executeScriptSoonTimer(this, &Document::executeScriptSoonTimerFired)
#if ENABLE(XSLT)
, m_transformSource(0)
#endif
, m_xmlVersion("1.0")
, m_xmlStandalone(false)
#if ENABLE(XBL)
......@@ -487,10 +485,6 @@ Document::~Document()
m_renderArena = 0;
}
#if ENABLE(XSLT)
xmlFreeDoc((xmlDocPtr)m_transformSource);
#endif
#if ENABLE(XBL)
delete m_bindingManager;
#endif
......@@ -3850,13 +3844,11 @@ void Document::applyXSLTransform(ProcessingInstruction* pi)
processor->createDocumentFromSource(newSource, resultEncoding, resultMIMEType, this, frame());
}
void Document::setTransformSource(void* doc)
void Document::setTransformSource(PassOwnPtr<TransformSource> source)
{
if (doc == m_transformSource)
if (m_transformSource == source)
return;
xmlFreeDoc((xmlDocPtr)m_transformSource);
m_transformSource = doc;
m_transformSource = source;
}
#endif
......
......@@ -37,6 +37,8 @@
#include "ScriptExecutionContext.h"
#include "Timer.h"
#include <wtf/HashCountedSet.h>
#include <wtf/OwnPtr.h>
#include <wtf/PassOwnPtr.h>
namespace WebCore {
......@@ -103,6 +105,10 @@ namespace WebCore {
class SVGDocumentExtensions;
#endif
#if ENABLE(XSLT)
class TransformSource;
#endif
#if ENABLE(XBL)
class XBLBindingManager;
#endif
......@@ -746,10 +752,11 @@ public:
#if ENABLE(XSLT)
void applyXSLTransform(ProcessingInstruction* pi);
void setTransformSource(void* doc);
const void* transformSource() { return m_transformSource; }
PassRefPtr<Document> transformSourceDocument() { return m_transformSourceDocument; }
void setTransformSourceDocument(Document* doc) { m_transformSourceDocument = doc; }
void setTransformSource(PassOwnPtr<TransformSource>);
TransformSource* transformSource() const { return m_transformSource.get(); }
#endif
#if ENABLE(XBL)
......@@ -1054,7 +1061,7 @@ private:
Timer<Document> m_executeScriptSoonTimer;
#if ENABLE(XSLT)
void* m_transformSource;
OwnPtr<TransformSource> m_transformSource;
RefPtr<Document> m_transformSourceDocument;
#endif
......
/*
* Copyright (C) 2009 Jakub Wieczorek <faw217@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef TransformSource_h
#define TransformSource_h
#if ENABLE(XSLT)
#include "PlatformString.h"
#include <wtf/Noncopyable.h>
namespace WebCore {
#if USE(QXMLQUERY)
typedef String PlatformTransformSource;
#else
typedef void* PlatformTransformSource;
#endif
class TransformSource : public Noncopyable {
public:
TransformSource(const PlatformTransformSource& source);
~TransformSource();
PlatformTransformSource platformSource() const { return m_source; }
private:
PlatformTransformSource m_source;
};
} // namespace WebCore
#endif
#endif // TransformSource_h
/*
* Copyright (C) 2009 Apple 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 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 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 "TransformSource.h"
#include <libxml/tree.h>
namespace WebCore {
TransformSource::TransformSource(const PlatformTransformSource& source)
: m_source(source)
{
}
TransformSource::~TransformSource()
{
xmlFreeDoc((xmlDocPtr)m_source);
}
}
/*
* Copyright (C) 2009 Jakub Wieczorek <faw217@gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "config.h"
#include "TransformSource.h"
namespace WebCore {
TransformSource::TransformSource(const PlatformTransformSource& source)
: m_source(source)
{
}
TransformSource::~TransformSource()
{
}
}
......@@ -50,6 +50,7 @@
#include "ScriptSourceCode.h"
#include "ScriptValue.h"
#include "TextResourceDecoder.h"
#include "TransformSource.h"
#include "XMLTokenizerScope.h"
#include <libxml/parser.h>
#include <libxml/parserInternals.h>
......@@ -1280,7 +1281,8 @@ void XMLTokenizer::doEnd()
{
#if ENABLE(XSLT)
if (m_sawXSLTransform) {
m_doc->setTransformSource(xmlDocPtrForString(m_doc->docLoader(), m_originalSourceForTransform, m_doc->url().string()));
void* doc = xmlDocPtrForString(m_doc->docLoader(), m_originalSourceForTransform, m_doc->url().string());
m_doc->setTransformSource(new TransformSource(doc));
m_doc->setParsing(false); // Make the doc think it's done, so it will apply xsl sheets.
m_doc->updateStyleSelector();
......
......@@ -50,6 +50,7 @@
#include "ScriptSourceCode.h"
#include "ScriptValue.h"
#include "TextResourceDecoder.h"
#include "TransformSource.h"
#include <QDebug>
#include <wtf/Platform.h>
#include <wtf/StringExtras.h>
......@@ -248,45 +249,19 @@ void XMLTokenizer::initializeParserContext(const char* chunk)
void XMLTokenizer::doEnd()
{
#if ENABLE(XSLT)
#warning Look at XMLTokenizerLibXml.cpp
#endif
if (m_stream.error() == QXmlStreamReader::PrematureEndOfDocumentError || (m_wroteText && !m_sawFirstElement)) {
handleError(fatal, qPrintable(m_stream.errorString()), lineNumber(),
columnNumber());
if (m_sawXSLTransform) {
m_doc->setTransformSource(new TransformSource(m_originalSourceForTransform));
m_doc->setParsing(false); // Make the doc think it's done, so it will apply xsl sheets.
m_doc->updateStyleSelector();
m_doc->setParsing(true);
m_parserStopped = true;
}
}
#if ENABLE(XSLT)
void* xmlDocPtrForString(DocLoader* docLoader, const String& source, const String& url)
{
if (source.isEmpty())
return 0;
// 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 UChar BOM = 0xFEFF;
const unsigned char BOMHighByte = *reinterpret_cast<const unsigned char*>(&BOM);
xmlGenericErrorFunc oldErrorFunc = xmlGenericError;
void* oldErrorContext = xmlGenericErrorContext;
setLoaderForLibXMLCallbacks(docLoader);
xmlSetGenericErrorFunc(0, errorFunc);
xmlDocPtr sourceDoc = xmlReadMemory(reinterpret_cast<const char*>(source.characters()),
source.length() * sizeof(UChar),
url.latin1().data(),
BOMHighByte == 0xFF ? "UTF-16LE" : "UTF-16BE",
XSLT_PARSE_OPTIONS);
setLoaderForLibXMLCallbacks(0);
xmlSetGenericErrorFunc(oldErrorContext, oldErrorFunc);
#endif
return sourceDoc;
if (m_stream.error() == QXmlStreamReader::PrematureEndOfDocumentError
|| (m_wroteText && !m_sawFirstElement && !m_sawXSLTransform))
handleError(fatal, qPrintable(m_stream.errorString()), lineNumber(), columnNumber());
}
#endif
int XMLTokenizer::lineNumber() const
{
......@@ -683,7 +658,7 @@ void XMLTokenizer::parseProcessingInstruction()
#if ENABLE(XSLT)
m_sawXSLTransform = !m_sawFirstElement && pi->isXSL();
if (m_sawXSLTransform && !m_doc->transformSourceDocument()))
if (m_sawXSLTransform && !m_doc->transformSourceDocument())
stopParsing();
#endif
}
......
......@@ -26,8 +26,12 @@
#if ENABLE(XSLT)
#include "StyleSheet.h"
#if !USE(QXMLQUERY)
#include <libxml/parser.h>
#include <libxslt/transform.h>
#endif
#include <wtf/PassRefPtr.h>
namespace WebCore {
......@@ -38,10 +42,12 @@ class XSLImportRule;
class XSLStyleSheet : public StyleSheet {
public:
#if !USE(QXMLQUERY)
static PassRefPtr<XSLStyleSheet> create(XSLImportRule* parentImport, const String& href)
{
return adoptRef(new XSLStyleSheet(parentImport, href));
}
#endif
static PassRefPtr<XSLStyleSheet> create(Node* parentNode, const String& href)
{
return adoptRef(new XSLStyleSheet(parentNode, href, false));
......@@ -65,31 +71,41 @@ public:
void loadChildSheets();
void loadChildSheet(const String& href);
xsltStylesheetPtr compileStyleSheet();
DocLoader* docLoader();
Document* ownerDocument() { return m_ownerDocument; }
void setParentStyleSheet(XSLStyleSheet* parent);
#if USE(QXMLQUERY)
String sheetString() const { return m_sheetString; }
#else
xmlDocPtr document();
xsltStylesheetPtr compileStyleSheet();
xmlDocPtr locateStylesheetSubResource(xmlDocPtr parentDoc, const xmlChar* uri);
#endif
void clearDocuments();
xmlDocPtr locateStylesheetSubResource(xmlDocPtr parentDoc, const xmlChar* uri);
void markAsProcessed();
bool processed() const { return m_processed; }
private:
XSLStyleSheet(Node* parentNode, const String& href, bool embedded);
#if !USE(QXMLQUERY)
XSLStyleSheet(XSLImportRule* parentImport, const String& href);
#endif
Document* m_ownerDocument;
xmlDocPtr m_stylesheetDoc;
bool m_embedded;
bool m_processed;
#if USE(QXMLQUERY)
String m_sheetString;
#else
xmlDocPtr m_stylesheetDoc;
bool m_stylesheetDocTaken;
#endif
XSLStyleSheet* m_parentStyleSheet;
};
......
......@@ -31,6 +31,7 @@
#include "Document.h"
#include "Frame.h"
#include "Node.h"
#include "TransformSource.h"
#include "XMLTokenizer.h"
#include "XMLTokenizerScope.h"
#include "XSLImportRule.h"
......@@ -57,9 +58,9 @@ namespace WebCore {
XSLStyleSheet::XSLStyleSheet(XSLImportRule* parentRule, const String& href)
: StyleSheet(parentRule, href)
, m_ownerDocument(0)
, m_stylesheetDoc(0)
, m_embedded(false)
, m_processed(false) // Child sheets get marked as processed when the libxslt engine has finally seen them.
, m_stylesheetDoc(0)
, m_stylesheetDocTaken(false)
, m_parentStyleSheet(0)
{
......@@ -68,9 +69,9 @@ XSLStyleSheet::XSLStyleSheet(XSLImportRule* parentRule, const String& href)
XSLStyleSheet::XSLStyleSheet(Node* parentNode, const String& href, bool embedded)
: StyleSheet(parentNode, href)
, m_ownerDocument(parentNode->document())
, m_stylesheetDoc(0)
, m_embedded(embedded)
, m_processed(true) // The root sheet starts off processed.
, m_stylesheetDoc(0)
, m_stylesheetDocTaken(false)
, m_parentStyleSheet(0)
{
......@@ -108,8 +109,8 @@ void XSLStyleSheet::checkLoaded()
xmlDocPtr XSLStyleSheet::document()
{
if (m_embedded && ownerDocument())
return (xmlDocPtr)ownerDocument()->transformSource();
if (m_embedded && ownerDocument() && ownerDocument()->transformSource())
return (xmlDocPtr)ownerDocument()->transformSource()->platformSource();