# khtml Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Source Files

# xml_tokenizer.h

    00001 /*
    00002  * This file is part of the DOM implementation for KDE.
    00003  *
    00004  * Copyright (C) 2000 Peter Kelly (pmk@post.com)
    00005  *
    00006  * This library is free software; you can redistribute it and/or
    00007  * modify it under the terms of the GNU Library General Public
    00008  * License as published by the Free Software Foundation; either
    00009  * version 2 of the License, or (at your option) any later version.
    00010  *
    00011  * This library is distributed in the hope that it will be useful,
    00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00014  * Library General Public License for more details.
    00015  *
    00016  * You should have received a copy of the GNU Library General Public License
    00017  * along with this library; see the file COPYING.LIB.  If not, write to
    00018  * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00019  * Boston, MA 02111-1307, USA.
    00020  *
    00021  * $Id: xml_tokenizer.h,v 1.17.2.1 2003/05/18 12:34:41 mueller Exp $
    00022  */
    00023
    00024 #ifndef _XML_Tokenizer_h_
    00025 #define _XML_Tokenizer_h_
    00026
    00027 #include <qxml.h>
    00028 #include <qptrlist.h>
    00029 #include <qobject.h>
    00030 #include "misc/loader_client.h"
    00031
    00032 class KHTMLView;
    00033
    00034 namespace khtml {
    00035     class CachedObject;
    00036     class CachedScript;
    00037 }
    00038
    00039 namespace DOM {
    00040     class DocumentImpl;
    00041     class NodeImpl;
    00042     class HTMLScriptElementImpl;
    00043     class DocumentPtr;
    00044     class HTMLScriptElementImpl;
    00045 }
    00046
    00047 class XMLHandler : public QXmlDefaultHandler
    00048 {
    00049 public:
    00050     XMLHandler(DOM::DocumentPtr *_doc, KHTMLView *_view);
    00051     virtual ~XMLHandler();
    00052
    00053     // return the error protocol if parsing failed
    00054     QString errorProtocol();
    00055
    00056     // overloaded handler functions
    00057     bool startDocument();
    00058     bool startElement(const QString& namespaceURI, const QString& localName, const QString& qName, const QXmlAttributes& atts);
    00059     bool endElement(const QString& namespaceURI, const QString& localName, const QString& qName);
    00060     bool startCDATA();
    00061     bool endCDATA();
    00062     bool characters(const QString& ch);
    00063     bool comment(const QString & ch);
    00064     bool processingInstruction(const QString &target, const QString &data);
    00065
    00066
    00067     // from QXmlDeclHandler
    00068     bool attributeDecl(const QString &eName, const QString &aName, const QString &type, const QString &valueDefault, const QString &value);
    00069     bool externalEntityDecl(const QString &name, const QString &publicId, const QString &systemId);
    00070     bool internalEntityDecl(const QString &name, const QString &value);
    00071
    00072     // from QXmlDTDHandler
    00073     bool notationDecl(const QString &name, const QString &publicId, const QString &systemId);
    00074     bool unparsedEntityDecl(const QString &name, const QString &publicId, const QString &systemId, const QString &notationName);
    00075
    00076     bool enterText();
    00077     void exitText();
    00078
    00079     QString errorString();
    00080
    00081     bool fatalError( const QXmlParseException& exception );
    00082
    00083     unsigned long errorLine;
    00084     unsigned long errorCol;
    00085
    00086 private:
    00087     QString errorProt;
    00088     DOM::DocumentPtr *m_doc;
    00089     KHTMLView *m_view;
    00090     DOM::NodeImpl *m_currentNode;
    00091     DOM::NodeImpl *m_rootNode;
    00092
    00093     enum State {
    00094         StateInit,
    00095         StateDocument,
    00096         StateQuote,
    00097         StateLine,
    00098         StateHeading,
    00099         StateP
    00100     };
    00101     State state;
    00102 };
    00103
    00104 class Tokenizer : public QObject
    00105 {
    00106     Q_OBJECT
    00107 public:
    00108     virtual void begin() = 0;
    00109     // script output must be prepended, while new data
    00110     // received during executing a script must be appended, hence the
    00111     // extra bool to be able to distinguish between both cases. document.write()
    00112     // always uses false, while khtmlpart uses true
    00113     virtual void write( const QString &str, bool appendData) = 0;
    00114     virtual void end() = 0;
    00115     virtual void finish() = 0;
    00116     virtual void setOnHold(bool /*_onHold*/) {}
    00117
    00118 signals:
    00119     void finishedParsing();
    00120
    00121 };
    00122
    00123 class XMLTokenizer : public Tokenizer, public khtml::CachedObjectClient
    00124 {
    00125 public:
    00126     XMLTokenizer(DOM::DocumentPtr *, KHTMLView * = 0);
    00127     virtual ~XMLTokenizer();
    00128     virtual void begin();
    00129     virtual void write( const QString &str, bool );
    00130     virtual void end();
    00131     virtual void finish();
    00132
    00133     // from CachedObjectClient
    00134     void notifyFinished(khtml::CachedObject *finishedObj);
    00135
    00136 protected:
    00137     DOM::DocumentPtr *m_doc;
    00138     KHTMLView *m_view;
    00139
    00140     void executeScripts();
    00141     void addScripts(DOM::NodeImpl *n);
    00142
    00143     QString m_xmlCode;
    00144     QPtrList<DOM::HTMLScriptElementImpl> m_scripts;
    00145     QPtrListIterator<DOM::HTMLScriptElementImpl> *m_scriptsIt;
    00146     khtml::CachedScript *m_cachedScript;
    00147 };
    00148
    00149 #endif

This file is part of the documentation for kdelibs Version 3.1.5.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Jan 28 13:34:45 2004 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001