2 * This file is part of the XSL implementation.
4 * Copyright (C) 2004, 2007, 2008 Apple, Inc. All rights reserved.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
23 #ifndef XSLTProcessor_h
24 #define XSLTProcessor_h
26 #include "bindings/core/v8/ScriptWrappable.h"
27 #include "core/dom/Node.h"
28 #include "core/xml/XSLStyleSheet.h"
29 #include "platform/RuntimeEnabledFeatures.h"
30 #include "wtf/HashMap.h"
31 #include "wtf/text/StringHash.h"
33 #include <libxml/parserInternals.h>
34 #include <libxslt/documents.h>
40 class DocumentFragment;
42 class XSLTProcessor : public RefCountedWillBeGarbageCollectedFinalized<XSLTProcessor>, public ScriptWrappable {
43 DEFINE_WRAPPERTYPEINFO();
45 static PassRefPtrWillBeRawPtr<XSLTProcessor> create(Document& document)
47 ASSERT(RuntimeEnabledFeatures::xsltEnabled());
48 return adoptRefWillBeNoop(new XSLTProcessor(document));
52 void setXSLStyleSheet(PassRefPtrWillBeRawPtr<XSLStyleSheet> styleSheet) { m_stylesheet = styleSheet; }
53 bool transformToString(Node* source, String& resultMIMEType, String& resultString, String& resultEncoding);
54 PassRefPtrWillBeRawPtr<Document> createDocumentFromSource(const String& source, const String& sourceEncoding, const String& sourceMIMEType, Node* sourceNode, LocalFrame*);
57 void importStylesheet(PassRefPtrWillBeRawPtr<Node> style)
60 m_stylesheetRootNode = style;
62 PassRefPtrWillBeRawPtr<DocumentFragment> transformToFragment(Node* source, Document* ouputDoc);
63 PassRefPtrWillBeRawPtr<Document> transformToDocument(Node* source);
65 void setParameter(const String& namespaceURI, const String& localName, const String& value);
66 String getParameter(const String& namespaceURI, const String& localName) const;
67 void removeParameter(const String& namespaceURI, const String& localName);
68 void clearParameters() { m_parameters.clear(); }
72 static void parseErrorFunc(void* userData, xmlError*);
73 static void genericErrorFunc(void* userData, const char* msg, ...);
75 // Only for libXSLT callbacks
76 XSLStyleSheet* xslStylesheet() const { return m_stylesheet.get(); }
78 typedef HashMap<String, String> ParameterMap;
83 XSLTProcessor(Document& document)
84 : m_document(&document)
87 RefPtrWillBeMember<XSLStyleSheet> m_stylesheet;
88 RefPtrWillBeMember<Node> m_stylesheetRootNode;
89 RefPtrWillBeMember<Document> m_document;
90 ParameterMap m_parameters;
95 #endif // XSLTProcessor_h