• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
38 namespace WebCore {
39 
40 class XSLImportRule;
41 
42 class XSLStyleSheet : public StyleSheet {
43 public:
44 #if !USE(QXMLQUERY)
create(XSLImportRule * parentImport,const String & originalURL,const KURL & finalURL)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
create(ProcessingInstruction * parentNode,const String & originalURL,const KURL & finalURL)50     static PassRefPtr<XSLStyleSheet> create(ProcessingInstruction* parentNode, const String& originalURL, const KURL& finalURL)
51     {
52         return adoptRef(new XSLStyleSheet(parentNode, originalURL, finalURL, false));
53     }
createEmbedded(ProcessingInstruction * parentNode,const KURL & finalURL)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.
createForXSLTProcessor(Node * parentNode,const String & originalURL,const KURL & finalURL)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     virtual ~XSLStyleSheet();
67 
isXSLStyleSheet()68     virtual bool isXSLStyleSheet() const { return true; }
69 
type()70     virtual String type() const { return "text/xml"; }
71 
72     virtual bool parseString(const String &string, bool strict = true);
73 
74     virtual bool isLoading();
75     virtual void checkLoaded();
76 
77     void loadChildSheets();
78     void loadChildSheet(const String& href);
79 
80     CachedResourceLoader* cachedResourceLoader();
81 
82     Document* ownerDocument();
parentStyleSheet()83     XSLStyleSheet* parentStyleSheet() const { return m_parentStyleSheet; }
84     void setParentStyleSheet(XSLStyleSheet* parent);
85 
86 #if USE(QXMLQUERY)
sheetString()87     String sheetString() const { return m_sheetString; }
88 #else
89     xmlDocPtr document();
90     xsltStylesheetPtr compileStyleSheet();
91     xmlDocPtr locateStylesheetSubResource(xmlDocPtr parentDoc, const xmlChar* uri);
92 #endif
93 
94     void clearDocuments();
95 
96     void markAsProcessed();
processed()97     bool processed() const { return m_processed; }
98 
99 private:
100     XSLStyleSheet(Node* parentNode, const String& originalURL, const KURL& finalURL, bool embedded);
101 #if !USE(QXMLQUERY)
102     XSLStyleSheet(XSLImportRule* parentImport, const String& originalURL, const KURL& finalURL);
103 #endif
104 
105     Document* m_ownerDocument;
106     bool m_embedded;
107     bool m_processed;
108 
109 #if USE(QXMLQUERY)
110     String m_sheetString;
111 #else
112     xmlDocPtr m_stylesheetDoc;
113     bool m_stylesheetDocTaken;
114 #endif
115 
116     XSLStyleSheet* m_parentStyleSheet;
117 };
118 
119 } // namespace WebCore
120 
121 #endif // ENABLE(XSLT)
122 
123 #endif // XSLStyleSheet_h
124