KWQXmlSimpleReader.h 4.82 KB
Newer Older
gramps's avatar
gramps committed
1
/*
darin's avatar
darin committed
2
 * Copyright (C) 2001, 2002, 2003 Apple Computer, Inc.  All rights reserved.
gramps's avatar
gramps committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
gramps's avatar
gramps committed
24
 */
gramps's avatar
gramps committed
25

darin's avatar
darin committed
26 27
#ifndef KWQXMLSIMPLEREADER_H
#define KWQXMLSIMPLEREADER_H
gramps's avatar
gramps committed
28

darin's avatar
darin committed
29 30 31
#include "KWQString.h"

class QXmlAttributes;
32

darin's avatar
darin committed
33 34
class QXmlInputSource {
public:
darin's avatar
darin committed
35 36 37 38
    void setData(const QString &data) { _data = data; }
    QString data() const { return _data; }
private:
    QString _data;
darin's avatar
darin committed
39 40 41 42 43 44 45 46 47 48
};

class QXmlParseException {
public:
    QString message() const;
    int columnNumber() const;
    int lineNumber() const;
};

class QXmlContentHandler {
49
public:
darin's avatar
darin committed
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
    virtual bool startDocument() = 0;
    virtual bool endDocument() = 0;
    virtual bool startPrefixMapping(const QString &prefix, const QString &URI) = 0;
    virtual bool endPrefixMapping(const QString &prefix) = 0;
    virtual bool startElement(const QString &namespaceURI, const QString &localName, const QString &qName, const QXmlAttributes &attributes) = 0;
    virtual bool endElement(const QString &namespaceURI, const QString &localName, const QString &qName) = 0;
    virtual bool characters(const QString &characters) = 0;
    virtual bool ignorableWhitespace(const QString &characters) = 0;
    virtual bool processingInstruction(const QString &target, const QString &data) = 0;
    virtual bool skippedEntity(const QString &name) = 0;
    virtual QString errorString() = 0;
};

class QXmlLexicalHandler {
public:
    virtual bool startDTD(const QString &name, const QString &publicId, const QString &systemId) = 0;
    virtual bool endDTD() = 0;
    virtual bool startEntity(const QString &name) = 0;
    virtual bool endEntity(const QString &name) = 0;
    virtual bool startCDATA() = 0;
    virtual bool endCDATA() = 0;
    virtual bool comment(const QString &characters) = 0;
    virtual QString errorString() = 0;
};

class QXmlErrorHandler {
public:
    virtual bool warning(const QXmlParseException &exception) = 0;
    virtual bool error(const QXmlParseException &exception) = 0;
    virtual bool fatalError(const QXmlParseException &exception) = 0;
    virtual QString errorString() = 0;
81
};
82

darin's avatar
darin committed
83 84 85 86 87 88 89 90 91 92 93 94 95
class QXmlDeclHandler {
public:
    virtual bool attributeDecl(const QString &entityName, const QString &attributeName, const QString &type, const QString &valueDefault, const QString &value) = 0;
    virtual bool externalEntityDecl(const QString &name, const QString &publicId, const QString &systemId) = 0;
    virtual bool internalEntityDecl(const QString &name, const QString &value) = 0;
};

class QXmlDTDHandler {
public:
    virtual bool notationDecl(const QString& name, const QString& publicId, const QString& systemId) = 0;
    virtual bool unparsedEntityDecl(const QString& name, const QString& publicId, const QString& systemId, const QString& notationName) = 0;
    virtual QString errorString() = 0;
};
96

97 98
class QXmlSimpleReader {
public:
darin's avatar
darin committed
99 100 101 102 103 104 105 106 107 108
    QXmlSimpleReader();
    
    void setContentHandler(QXmlContentHandler *handler) { _contentHandler = handler; }
    void setDeclHandler(QXmlDeclHandler *handler) { _declarationHandler= handler; }
    void setDTDHandler(QXmlDTDHandler *handler) { _DTDHandler = handler; }
    void setErrorHandler(QXmlErrorHandler *handler) { _errorHandler = handler; }
    void setLexicalHandler(QXmlLexicalHandler *handler) { _lexicalHandler = handler; }
    
    QXmlContentHandler *contentHandler() const { return _contentHandler; }
    QXmlLexicalHandler *lexicalHandler() const { return _lexicalHandler; }
109

darin's avatar
darin committed
110
    bool parse(const QXmlInputSource &input);
darin's avatar
darin committed
111 112 113 114 115 116 117

private:
    QXmlContentHandler *_contentHandler;
    QXmlDeclHandler *_declarationHandler;
    QXmlDTDHandler *_DTDHandler;
    QXmlErrorHandler *_errorHandler;
    QXmlLexicalHandler *_lexicalHandler;
118
};
119

gramps's avatar
gramps committed
120
#endif