]>
Commit | Line | Data |
---|---|---|
a90939db JF |
1 | /* |
2 | * Copyright (C) 2000 Peter Kelly (pmk@post.com) | |
3 | * Copyright (C) 2005, 2006, 2007 Apple Inc. All rights reserved. | |
4 | * Copyright (C) 2007 Samuel Weinig (sam@webkit.org) | |
5 | * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) | |
6 | * | |
7 | * This library is free software; you can redistribute it and/or | |
8 | * modify it under the terms of the GNU Library General Public | |
9 | * License as published by the Free Software Foundation; either | |
10 | * version 2 of the License, or (at your option) any later version. | |
11 | * | |
12 | * This library is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * Library General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU Library General Public License | |
18 | * along with this library; see the file COPYING.LIB. If not, write to | |
19 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | |
20 | * Boston, MA 02110-1301, USA. | |
21 | * | |
22 | */ | |
23 | ||
24 | #ifndef XMLTokenizer_h | |
25 | #define XMLTokenizer_h | |
26 | ||
27 | #include "CachedResourceClient.h" | |
28 | #include "CachedResourceHandle.h" | |
29 | #include "SegmentedString.h" | |
30 | #include "StringHash.h" | |
31 | #include "Tokenizer.h" | |
32 | #include <wtf/HashMap.h> | |
33 | #include <wtf/OwnPtr.h> | |
34 | ||
35 | #if USE(QXMLSTREAM) | |
36 | #include <QtXml/qxmlstream.h> | |
37 | #else | |
38 | #include <libxml/tree.h> | |
39 | #include <libxml/xmlstring.h> | |
40 | #endif | |
41 | ||
42 | namespace WebCore { | |
43 | ||
44 | class Node; | |
45 | class CachedScript; | |
46 | class DocLoader; | |
47 | class DocumentFragment; | |
48 | class Document; | |
49 | class Element; | |
50 | class FrameView; | |
51 | class PendingCallbacks; | |
52 | class ScriptElement; | |
53 | ||
54 | class XMLTokenizer : public Tokenizer, public CachedResourceClient { | |
55 | public: | |
56 | XMLTokenizer(Document*, FrameView* = 0); | |
57 | XMLTokenizer(DocumentFragment*, Element*); | |
58 | ~XMLTokenizer(); | |
59 | ||
60 | enum ErrorType { warning, nonFatal, fatal }; | |
61 | ||
62 | // from Tokenizer | |
63 | virtual bool write(const SegmentedString&, bool appendData); | |
64 | virtual void finish(); | |
65 | virtual bool isWaitingForScripts() const; | |
66 | virtual void stopParsing(); | |
67 | ||
68 | void end(); | |
69 | ||
70 | void pauseParsing(); | |
71 | void resumeParsing(); | |
72 | ||
73 | void setIsXHTMLDocument(bool isXHTML) { m_isXHTMLDocument = isXHTML; } | |
74 | bool isXHTMLDocument() const { return m_isXHTMLDocument; } | |
75 | #if ENABLE(WML) | |
76 | bool isWMLDocument() const; | |
77 | #endif | |
78 | ||
79 | // from CachedResourceClient | |
80 | virtual void notifyFinished(CachedResource* finishedObj); | |
81 | ||
82 | ||
83 | void handleError(ErrorType type, const char* m, int lineNumber, int columnNumber); | |
84 | ||
85 | virtual bool wellFormed() const { return !m_sawError; } | |
86 | ||
87 | int lineNumber() const; | |
88 | int columnNumber() const; | |
89 | ||
90 | #if USE(QXMLSTREAM) | |
91 | private: | |
92 | void parse(); | |
93 | void startDocument(); | |
94 | void parseStartElement(); | |
95 | void parseEndElement(); | |
96 | void parseCharacters(); | |
97 | void parseProcessingInstruction(); | |
98 | void parseCdata(); | |
99 | void parseComment(); | |
100 | void endDocument(); | |
101 | void parseDtd(); | |
102 | bool hasError() const; | |
103 | #else | |
104 | public: | |
105 | // callbacks from parser SAX | |
106 | void error(ErrorType, const char* message, va_list args) WTF_ATTRIBUTE_PRINTF(3, 0); | |
107 | void startElementNs(const xmlChar* xmlLocalName, const xmlChar* xmlPrefix, const xmlChar* xmlURI, int nb_namespaces, | |
108 | const xmlChar** namespaces, int nb_attributes, int nb_defaulted, const xmlChar** libxmlAttributes); | |
109 | void endElementNs(); | |
110 | void characters(const xmlChar* s, int len); | |
111 | void processingInstruction(const xmlChar* target, const xmlChar* data); | |
112 | void cdataBlock(const xmlChar* s, int len); | |
113 | void comment(const xmlChar* s); | |
114 | void startDocument(const xmlChar* version, const xmlChar* encoding, int standalone); | |
115 | void internalSubset(const xmlChar* name, const xmlChar* externalID, const xmlChar* systemID); | |
116 | void endDocument(); | |
117 | #endif | |
118 | private: | |
119 | friend bool parseXMLDocumentFragment(const String& chunk, DocumentFragment* fragment, Element* parent); | |
120 | ||
121 | void initializeParserContext(const char* chunk = 0); | |
122 | void setCurrentNode(Node*); | |
123 | ||
124 | void insertErrorMessageBlock(); | |
125 | ||
126 | bool enterText(); | |
127 | void exitText(); | |
128 | ||
129 | void doWrite(const String&); | |
130 | void doEnd(); | |
131 | ||
132 | Document* m_doc; | |
133 | FrameView* m_view; | |
134 | ||
135 | String m_originalSourceForTransform; | |
136 | ||
137 | #if USE(QXMLSTREAM) | |
138 | QXmlStreamReader m_stream; | |
139 | bool m_wroteText; | |
140 | #else | |
141 | xmlParserCtxtPtr m_context; | |
142 | OwnPtr<PendingCallbacks> m_pendingCallbacks; | |
143 | Vector<xmlChar> m_bufferedText; | |
144 | #endif | |
145 | Node* m_currentNode; | |
146 | bool m_currentNodeIsReferenced; | |
147 | ||
148 | bool m_sawError; | |
149 | bool m_sawXSLTransform; | |
150 | bool m_sawFirstElement; | |
151 | bool m_isXHTMLDocument; | |
152 | ||
153 | bool m_parserPaused; | |
154 | bool m_requestingScript; | |
155 | bool m_finishCalled; | |
156 | ||
157 | int m_errorCount; | |
158 | int m_lastErrorLine; | |
159 | int m_lastErrorColumn; | |
160 | String m_errorMessages; | |
161 | ||
162 | CachedResourceHandle<CachedScript> m_pendingScript; | |
163 | RefPtr<Element> m_scriptElement; | |
164 | int m_scriptStartLine; | |
165 | ||
166 | bool m_parsingFragment; | |
167 | String m_defaultNamespaceURI; | |
168 | ||
169 | typedef HashMap<String, String> PrefixForNamespaceMap; | |
170 | PrefixForNamespaceMap m_prefixToNamespaceMap; | |
171 | SegmentedString m_pendingSrc; | |
172 | }; | |
173 | ||
174 | #if ENABLE(XSLT) | |
175 | void* xmlDocPtrForString(DocLoader*, const String& source, const String& url); | |
176 | #endif | |
177 | ||
178 | HashMap<String, String> parseAttributes(const String&, bool& attrsOK); | |
179 | bool parseXMLDocumentFragment(const String&, DocumentFragment*, Element* parent = 0); | |
180 | ||
181 | } // namespace WebCore | |
182 | ||
183 | #endif // XMLTokenizer_h |