XSLStyleSheet.h revision 81bc750723a18f21cd17d1b173cd2a4dda9cea6e
1/* 2 * This file is part of the XSL implementation. 3 * 4 * Copyright (C) 2004, 2006, 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 XSLStyleSheet_h 24#define XSLStyleSheet_h 25 26#if ENABLE(XSLT) 27 28#include "ProcessingInstruction.h" 29#include "StyleSheet.h" 30 31#if !USE(QXMLQUERY) 32#include <libxml/parser.h> 33#include <libxslt/transform.h> 34#endif 35 36#include <wtf/PassRefPtr.h> 37 38namespace WebCore { 39 40class XSLImportRule; 41 42class XSLStyleSheet : public StyleSheet { 43public: 44#if !USE(QXMLQUERY) 45 static PassRefPtr<XSLStyleSheet> create(XSLImportRule* parentImport, const String& originalURL, const KURL& finalURL) 46 { 47 return adoptRef(new XSLStyleSheet(parentImport, originalURL, finalURL)); 48 } 49#endif 50 static PassRefPtr<XSLStyleSheet> create(ProcessingInstruction* parentNode, const String& originalURL, const KURL& finalURL) 51 { 52 return adoptRef(new XSLStyleSheet(parentNode, originalURL, finalURL, false)); 53 } 54 static PassRefPtr<XSLStyleSheet> createEmbedded(ProcessingInstruction* parentNode, const KURL& finalURL) 55 { 56 return adoptRef(new XSLStyleSheet(parentNode, finalURL.string(), finalURL, true)); 57 } 58 59 // Taking an arbitrary node is unsafe, because owner node pointer can become stale. 60 // XSLTProcessor ensures that the stylesheet doesn't outlive its parent, in part by not exposing it to JavaScript. 61 static PassRefPtr<XSLStyleSheet> createForXSLTProcessor(Node* parentNode, const String& originalURL, const KURL& finalURL) 62 { 63 return adoptRef(new XSLStyleSheet(parentNode, originalURL, finalURL, false)); 64 } 65 66 static PassRefPtr<XSLStyleSheet> createForXMLTreeViewer(Node* node, const String& sheetString) 67 { 68 RefPtr<XSLStyleSheet> sheet = adoptRef(new XSLStyleSheet(node, String(), KURL(), false)); 69 sheet->parseString(sheetString); 70 71 return sheet.release(); 72 } 73 74 virtual ~XSLStyleSheet(); 75 76 virtual bool isXSLStyleSheet() const { return true; } 77 78 virtual String type() const { return "text/xml"; } 79 80 virtual bool parseString(const String &string, bool strict = true); 81 82 virtual bool isLoading(); 83 virtual void checkLoaded(); 84 85 void loadChildSheets(); 86 void loadChildSheet(const String& href); 87 88 CachedResourceLoader* cachedResourceLoader(); 89 90 Document* ownerDocument(); 91 XSLStyleSheet* parentStyleSheet() const { return m_parentStyleSheet; } 92 void setParentStyleSheet(XSLStyleSheet* parent); 93 94#if USE(QXMLQUERY) 95 String sheetString() const { return m_sheetString; } 96#else 97 xmlDocPtr document(); 98 xsltStylesheetPtr compileStyleSheet(); 99 xmlDocPtr locateStylesheetSubResource(xmlDocPtr parentDoc, const xmlChar* uri); 100#endif 101 102 void clearDocuments(); 103 104 void markAsProcessed(); 105 bool processed() const { return m_processed; } 106 107private: 108 XSLStyleSheet(Node* parentNode, const String& originalURL, const KURL& finalURL, bool embedded); 109#if !USE(QXMLQUERY) 110 XSLStyleSheet(XSLImportRule* parentImport, const String& originalURL, const KURL& finalURL); 111#endif 112 113 Document* m_ownerDocument; 114 bool m_embedded; 115 bool m_processed; 116 117#if USE(QXMLQUERY) 118 String m_sheetString; 119#else 120 xmlDocPtr m_stylesheetDoc; 121 bool m_stylesheetDocTaken; 122#endif 123 124 XSLStyleSheet* m_parentStyleSheet; 125}; 126 127} // namespace WebCore 128 129#endif // ENABLE(XSLT) 130 131#endif // XSLStyleSheet_h 132