2
* This file is part of the DOM implementation for KDE.
4
* Copyright (C) 2000 Peter Kelly (pmk@post.com)
5
* Copyright (C) 2005, 2006 Apple Computer, Inc.
6
* Copyright (C) 2007 Samuel Weinig (sam@webkit.org)
7
* Copyright (C) 2007 Trolltech ASA
9
* This library is free software; you can redistribute it and/or
10
* modify it under the terms of the GNU Library General Public
11
* License as published by the Free Software Foundation; either
12
* version 2 of the License, or (at your option) any later version.
14
* This library is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
* Library General Public License for more details.
19
* You should have received a copy of the GNU Library General Public License
20
* along with this library; see the file COPYING.LIB. If not, write to
21
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
22
* Boston, MA 02111-1307, USA.
26
#ifndef XMLTokenizer_h
27
#define XMLTokenizer_h
31
#include "CachedResourceClient.h"
32
#include "SegmentedString.h"
33
#include "StringHash.h"
34
#include "Tokenizer.h"
35
#include <wtf/HashMap.h>
36
#include <wtf/OwnPtr.h>
40
#define USE_QXMLSTREAM
44
#ifndef USE_QXMLSTREAM
45
#include <libxml/tree.h>
46
#include <libxml/xmlstring.h>
48
#include <QtXml/qxmlstream.h>
56
class DocumentFragment;
60
class PendingCallbacks;
62
class XMLTokenizer : public Tokenizer, public CachedResourceClient {
64
XMLTokenizer(Document*, FrameView* = 0);
65
XMLTokenizer(DocumentFragment*, Element*);
68
enum ErrorType { warning, nonFatal, fatal };
71
virtual bool write(const SegmentedString&, bool appendData);
72
virtual void finish();
73
virtual bool isWaitingForScripts() const;
74
virtual void stopParsing();
81
void setIsXHTMLDocument(bool isXHTML) { m_isXHTMLDocument = isXHTML; }
82
bool isXHTMLDocument() const { return m_isXHTMLDocument; }
84
// from CachedResourceClient
85
virtual void notifyFinished(CachedResource* finishedObj);
87
#ifndef USE_QXMLSTREAM
88
// callbacks from parser SAX
89
void error(ErrorType, const char* message, va_list args);
90
void startElementNs(const xmlChar* xmlLocalName, const xmlChar* xmlPrefix, const xmlChar* xmlURI, int nb_namespaces,
91
const xmlChar** namespaces, int nb_attributes, int nb_defaulted, const xmlChar** libxmlAttributes);
93
void characters(const xmlChar* s, int len);
94
void processingInstruction(const xmlChar* target, const xmlChar* data);
95
void cdataBlock(const xmlChar* s, int len);
96
void comment(const xmlChar* s);
97
void startDocument(const xmlChar* version, const xmlChar* encoding, int standalone);
98
void internalSubset(const xmlChar* name, const xmlChar* externalID, const xmlChar* systemID);
101
void startDocument();
102
void parseStartElement();
103
void parseEndElement();
104
void parseCharacters();
105
void parseProcessingInstruction();
110
bool hasError() const;
113
void handleError(ErrorType type, const char* m, int lineNumber, int columnNumber);
115
virtual bool wellFormed() const { return !m_sawError; }
117
int lineNumber() const;
118
int columnNumber() const;
121
void initializeParserContext();
122
void setCurrentNode(Node*);
124
void insertErrorMessageBlock();
132
String m_originalSourceForTransform;
134
#ifdef USE_QXMLSTREAM
135
QXmlStreamReader m_stream;
137
xmlParserCtxtPtr m_context;
140
bool m_currentNodeIsReferenced;
143
bool m_sawXSLTransform;
144
bool m_sawFirstElement;
145
bool m_isXHTMLDocument;
148
bool m_requestingScript;
153
int m_lastErrorColumn;
154
String m_errorMessages;
156
CachedScript* m_pendingScript;
157
RefPtr<Element> m_scriptElement;
158
int m_scriptStartLine;
160
bool m_parsingFragment;
161
String m_defaultNamespaceURI;
163
typedef HashMap<String, String> PrefixForNamespaceMap;
164
PrefixForNamespaceMap m_prefixToNamespaceMap;
165
#ifndef USE_QXMLSTREAM
166
OwnPtr<PendingCallbacks> m_pendingCallbacks;
168
SegmentedString m_pendingSrc;
172
void* xmlDocPtrForString(DocLoader*, const String& source, const DeprecatedString& URL);
173
void setLoaderForLibXMLCallbacks(DocLoader*);
176
HashMap<String, String> parseAttributes(const String&, bool& attrsOK);
177
bool parseXMLDocumentFragment(const String&, DocumentFragment*, Element* parent = 0);
179
} // namespace WebCore
181
#endif // XMLTokenizer_h