XSLTProcessor.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. #ifndef XSLTProcessor_h
  23. #define XSLTProcessor_h
  24. #if ENABLE(XSLT)
  25. #include "Node.h"
  26. #include "XSLStyleSheet.h"
  27. #include <wtf/HashMap.h>
  28. #include <wtf/text/StringHash.h>
  29. #if !USE(QXMLQUERY)
  30. #include <libxml/parserInternals.h>
  31. #include <libxslt/documents.h>
  32. #endif
  33. namespace WebCore {
  34. class Frame;
  35. class Document;
  36. class DocumentFragment;
  37. class XSLTProcessor : public RefCounted<XSLTProcessor> {
  38. public:
  39. static PassRefPtr<XSLTProcessor> create() { return adoptRef(new XSLTProcessor); }
  40. ~XSLTProcessor();
  41. void setXSLStyleSheet(PassRefPtr<XSLStyleSheet> styleSheet) { m_stylesheet = styleSheet; }
  42. bool transformToString(Node* source, String& resultMIMEType, String& resultString, String& resultEncoding);
  43. PassRefPtr<Document> createDocumentFromSource(const String& source, const String& sourceEncoding, const String& sourceMIMEType, Node* sourceNode, Frame* frame);
  44. // DOM methods
  45. void importStylesheet(PassRefPtr<Node> style)
  46. {
  47. if (style)
  48. m_stylesheetRootNode = style;
  49. }
  50. PassRefPtr<DocumentFragment> transformToFragment(Node* source, Document* ouputDoc);
  51. PassRefPtr<Document> transformToDocument(Node* source);
  52. void setParameter(const String& namespaceURI, const String& localName, const String& value);
  53. String getParameter(const String& namespaceURI, const String& localName) const;
  54. void removeParameter(const String& namespaceURI, const String& localName);
  55. void clearParameters() { m_parameters.clear(); }
  56. void reset();
  57. #if !USE(QXMLQUERY)
  58. static void parseErrorFunc(void* userData, xmlError*);
  59. static void genericErrorFunc(void* userData, const char* msg, ...);
  60. // Only for libXSLT callbacks
  61. XSLStyleSheet* xslStylesheet() const { return m_stylesheet.get(); }
  62. #endif
  63. typedef HashMap<String, String> ParameterMap;
  64. private:
  65. XSLTProcessor() { }
  66. RefPtr<XSLStyleSheet> m_stylesheet;
  67. RefPtr<Node> m_stylesheetRootNode;
  68. ParameterMap m_parameters;
  69. };
  70. }
  71. #endif
  72. #endif