1 /* 2 * This file is part of the XSL implementation. 3 * 4 * Copyright (C) 2004, 2007, 2008 Apple, Inc. All rights reserved. 5 * 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. 10 * 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. 15 * 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. 20 * 21 */ 22 23 #ifndef XSLTProcessor_h 24 #define XSLTProcessor_h 25 26 #include "bindings/v8/ScriptWrappable.h" 27 #include "core/dom/Node.h" 28 #include "core/xml/XSLStyleSheet.h" 29 #include "wtf/HashMap.h" 30 #include "wtf/text/StringHash.h" 31 32 #include <libxml/parserInternals.h> 33 #include <libxslt/documents.h> 34 35 namespace WebCore { 36 37 class Frame; 38 class Document; 39 class DocumentFragment; 40 41 class XSLTProcessor : public RefCounted<XSLTProcessor>, public ScriptWrappable { 42 public: 43 static PassRefPtr<XSLTProcessor> create() { return adoptRef(new XSLTProcessor); } 44 ~XSLTProcessor(); 45 46 void setXSLStyleSheet(PassRefPtr<XSLStyleSheet> styleSheet) { m_stylesheet = styleSheet; } 47 bool transformToString(Node* source, String& resultMIMEType, String& resultString, String& resultEncoding); 48 PassRefPtr<Document> createDocumentFromSource(const String& source, const String& sourceEncoding, const String& sourceMIMEType, Node* sourceNode, Frame* frame); 49 50 // DOM methods 51 void importStylesheet(PassRefPtr<Node> style) 52 { 53 if (style) 54 m_stylesheetRootNode = style; 55 } 56 PassRefPtr<DocumentFragment> transformToFragment(Node* source, Document* ouputDoc); 57 PassRefPtr<Document> transformToDocument(Node* source); 58 59 void setParameter(const String& namespaceURI, const String& localName, const String& value); 60 String getParameter(const String& namespaceURI, const String& localName) const; 61 void removeParameter(const String& namespaceURI, const String& localName); 62 void clearParameters() { m_parameters.clear(); } 63 64 void reset(); 65 66 static void parseErrorFunc(void* userData, xmlError*); 67 static void genericErrorFunc(void* userData, const char* msg, ...); 68 69 // Only for libXSLT callbacks 70 XSLStyleSheet* xslStylesheet() const { return m_stylesheet.get(); } 71 72 typedef HashMap<String, String> ParameterMap; 73 74 private: 75 XSLTProcessor() 76 { 77 ScriptWrappable::init(this); 78 } 79 80 RefPtr<XSLStyleSheet> m_stylesheet; 81 RefPtr<Node> m_stylesheetRootNode; 82 ParameterMap m_parameters; 83 }; 84 85 } 86 87 #endif 88