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 THIRD_PARTY_BLINK_RENDERER_CORE_XML_XSLT_PROCESSOR_H_
24 #define THIRD_PARTY_BLINK_RENDERER_CORE_XML_XSLT_PROCESSOR_H_
26 #include "third_party/blink/renderer/core/dom/node.h"
27 #include "third_party/blink/renderer/core/xml/xsl_style_sheet.h"
28 #include "third_party/blink/renderer/platform/bindings/script_wrappable.h"
29 #include "third_party/blink/renderer/platform/wtf/hash_map.h"
30 #include "third_party/blink/renderer/platform/wtf/text/string_hash.h"
32 #include <libxml/parserInternals.h>
33 #include <libxslt/documents.h>
39 class DocumentFragment;
41 class XSLTProcessor final : public ScriptWrappable {
42 DEFINE_WRAPPERTYPEINFO();
45 static XSLTProcessor* Create(Document& document) {
46 return MakeGarbageCollected<XSLTProcessor>(document);
49 XSLTProcessor(Document& document) : document_(&document) {}
50 ~XSLTProcessor() override;
52 void SetXSLStyleSheet(XSLStyleSheet* style_sheet) {
53 stylesheet_ = style_sheet;
55 bool TransformToString(Node* source,
56 String& result_mime_type,
57 String& result_string,
58 String& result_encoding);
59 Document* CreateDocumentFromSource(const String& source,
60 const String& source_encoding,
61 const String& source_mime_type,
66 void importStylesheet(Node* style) { stylesheet_root_node_ = style; }
67 DocumentFragment* transformToFragment(Node* source, Document* ouput_doc);
68 Document* transformToDocument(Node* source);
70 void setParameter(const String& namespace_uri,
71 const String& local_name,
73 String getParameter(const String& namespace_uri,
74 const String& local_name) const;
75 void removeParameter(const String& namespace_uri, const String& local_name);
76 void clearParameters() { parameters_.clear(); }
80 #if LIBXML_VERSION >= 21205
81 static void ParseErrorFunc(void* user_data, const xmlError*);
83 static void ParseErrorFunc(void* user_data, xmlError*);
85 static void GenericErrorFunc(void* user_data, const char* msg, ...);
87 // Only for libXSLT callbacks
88 XSLStyleSheet* XslStylesheet() const { return stylesheet_.Get(); }
90 typedef HashMap<String, String> ParameterMap;
92 void Trace(Visitor*) const override;
95 Member<XSLStyleSheet> stylesheet_;
96 Member<Node> stylesheet_root_node_;
97 Member<Document> document_;
98 ParameterMap parameters_;
103 #endif // THIRD_PARTY_BLINK_RENDERER_CORE_XML_XSLT_PROCESSOR_H_