summaryrefslogtreecommitdiffstats
path: root/ksayit/src/parasaxparser.cpp
blob: 575df06b6443ed5232c493b077b736ccb5a9573c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//
// C++ Implementation: parasaxparser
//
// Description: SAX2-Parser for 'para' elements of a DocBook file.
//
//
// Author: Robert Vogl <voglrobe@web.de>, (C) 2005
//
// Copyright: See COPYING file that comes with this distribution
//
//
// #include <iostream> // cout
// using namespace std;

// Qt includes

// KDE includes
#include <kdebug.h>

// App specific includes
#include "parasaxparser.h"

ParaSaxParser::ParaSaxParser()
{
    m_reader = new QXmlSimpleReader();

    m_handler = new SaxHandler();
    m_reader->setContentHandler(m_handler);
    m_reader->setErrorHandler(m_handler);
    m_reader->setEntityResolver(m_handler);
    m_reader->setDeclHandler(m_handler);

    m_XmlInputHeader = QString::null;
    m_XmlInputBody   = QString::null;    
}

ParaSaxParser::~ParaSaxParser()
{
    delete m_handler;
    delete m_reader;
}

ParaSaxParser* ParaSaxParser::_instance = 0;

ParaSaxParser* ParaSaxParser::Instance()
{
    if ( _instance == 0 ){
        _instance = new ParaSaxParser();
    }
    return _instance;
}


void ParaSaxParser::setProcessingInstruction(const QString &data)
{
    m_XmlInputHeader = data;
}


void ParaSaxParser::setData(const QString &data)
{
    m_XmlInputBody = data;
}


void ParaSaxParser::getText(QString &data)
{
    QString XmlPart = m_XmlInputHeader + m_XmlInputBody;
    
    QXmlInputSource input;
    input.setData(XmlPart);

    m_handler->reset();
    m_handler->setRTF(false);
    m_reader->parse( input );
    m_handler->getData(data);

}


void ParaSaxParser::getRTFText(QString &data)
{    
    QString XmlPart = m_XmlInputHeader + m_XmlInputBody;    
    kdDebug(100200) << "ParaSaxParser::getRTFText(): " << XmlPart << endl;
    
    QXmlInputSource input;
    input.setData(XmlPart);

    m_handler->reset();
    m_handler->setRTF(true);
    m_reader->parse( input );
    m_handler->getData(data);
}