~ubuntu-branches/ubuntu/maverick/webkit/maverick

« back to all changes in this revision

Viewing changes to WebCore/dom/XMLTokenizer.h

  • Committer: Bazaar Package Importer
  • Author(s): Mike Hommey
  • Date: 2007-08-19 15:54:12 UTC
  • Revision ID: james.westby@ubuntu.com-20070819155412-uxxg1h9plpghmtbi
Tags: upstream-0~svn25144
ImportĀ upstreamĀ versionĀ 0~svn25144

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of the DOM implementation for KDE.
 
3
 *
 
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
 
8
 *
 
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.
 
13
 *
 
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.
 
18
 *
 
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.
 
23
 *
 
24
 */
 
25
 
 
26
#ifndef XMLTokenizer_h
 
27
#define XMLTokenizer_h
 
28
 
 
29
#include "config.h"
 
30
 
 
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>
 
37
 
 
38
#if PLATFORM(QT)
 
39
#if !ENABLE(XSLT)
 
40
#define USE_QXMLSTREAM
 
41
#endif
 
42
#endif
 
43
 
 
44
#ifndef USE_QXMLSTREAM
 
45
#include <libxml/tree.h>
 
46
#include <libxml/xmlstring.h>
 
47
#else
 
48
#include <QtXml/qxmlstream.h>
 
49
#endif
 
50
 
 
51
namespace WebCore {
 
52
 
 
53
    class Node;
 
54
    class CachedScript;
 
55
    class DocLoader;
 
56
    class DocumentFragment;
 
57
    class Document;
 
58
    class Element;
 
59
    class FrameView;
 
60
    class PendingCallbacks;
 
61
 
 
62
    class XMLTokenizer : public Tokenizer, public CachedResourceClient {
 
63
    public:
 
64
        XMLTokenizer(Document*, FrameView* = 0);
 
65
        XMLTokenizer(DocumentFragment*, Element*);
 
66
        ~XMLTokenizer();
 
67
 
 
68
        enum ErrorType { warning, nonFatal, fatal };
 
69
 
 
70
        // from Tokenizer
 
71
        virtual bool write(const SegmentedString&, bool appendData);
 
72
        virtual void finish();
 
73
        virtual bool isWaitingForScripts() const;
 
74
        virtual void stopParsing();
 
75
 
 
76
        void end();
 
77
 
 
78
        void pauseParsing();
 
79
        void resumeParsing();
 
80
 
 
81
        void setIsXHTMLDocument(bool isXHTML) { m_isXHTMLDocument = isXHTML; }
 
82
        bool isXHTMLDocument() const { return m_isXHTMLDocument; }
 
83
 
 
84
        // from CachedResourceClient
 
85
        virtual void notifyFinished(CachedResource* finishedObj);
 
86
 
 
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);
 
92
        void endElementNs();
 
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);
 
99
#else
 
100
        void parse();
 
101
        void startDocument();
 
102
        void parseStartElement();
 
103
        void parseEndElement();
 
104
        void parseCharacters();
 
105
        void parseProcessingInstruction();
 
106
        void parseCdata();
 
107
        void parseComment();
 
108
        void endDocument();
 
109
        void parseDtd();
 
110
        bool hasError() const;
 
111
#endif
 
112
 
 
113
        void handleError(ErrorType type, const char* m, int lineNumber, int columnNumber);
 
114
 
 
115
        virtual bool wellFormed() const { return !m_sawError; }
 
116
 
 
117
        int lineNumber() const;
 
118
        int columnNumber() const;
 
119
 
 
120
    private:
 
121
        void initializeParserContext();
 
122
        void setCurrentNode(Node*);
 
123
 
 
124
        void insertErrorMessageBlock();
 
125
 
 
126
        bool enterText();
 
127
        void exitText();
 
128
 
 
129
        Document* m_doc;
 
130
        FrameView* m_view;
 
131
 
 
132
        String m_originalSourceForTransform;
 
133
 
 
134
#ifdef USE_QXMLSTREAM
 
135
        QXmlStreamReader m_stream;
 
136
#else
 
137
        xmlParserCtxtPtr m_context;
 
138
#endif
 
139
        Node* m_currentNode;
 
140
        bool m_currentNodeIsReferenced;
 
141
 
 
142
        bool m_sawError;
 
143
        bool m_sawXSLTransform;
 
144
        bool m_sawFirstElement;
 
145
        bool m_isXHTMLDocument;
 
146
 
 
147
        bool m_parserPaused;
 
148
        bool m_requestingScript;
 
149
        bool m_finishCalled;
 
150
 
 
151
        int m_errorCount;
 
152
        int m_lastErrorLine;
 
153
        int m_lastErrorColumn;
 
154
        String m_errorMessages;
 
155
 
 
156
        CachedScript* m_pendingScript;
 
157
        RefPtr<Element> m_scriptElement;
 
158
        int m_scriptStartLine;
 
159
 
 
160
        bool m_parsingFragment;
 
161
        String m_defaultNamespaceURI;
 
162
 
 
163
        typedef HashMap<String, String> PrefixForNamespaceMap;
 
164
        PrefixForNamespaceMap m_prefixToNamespaceMap;
 
165
#ifndef USE_QXMLSTREAM
 
166
        OwnPtr<PendingCallbacks> m_pendingCallbacks;
 
167
#endif
 
168
        SegmentedString m_pendingSrc;
 
169
    };
 
170
 
 
171
#if ENABLE(XSLT)
 
172
void* xmlDocPtrForString(DocLoader*, const String& source, const DeprecatedString& URL);
 
173
void setLoaderForLibXMLCallbacks(DocLoader*);
 
174
#endif
 
175
 
 
176
HashMap<String, String> parseAttributes(const String&, bool& attrsOK);
 
177
bool parseXMLDocumentFragment(const String&, DocumentFragment*, Element* parent = 0);
 
178
 
 
179
} // namespace WebCore
 
180
 
 
181
#endif // XMLTokenizer_h