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