summaryrefslogtreecommitdiffstats
path: root/src/translators/tellicoxmlhandler.cpp
blob: 5b3f063f8925f5fe1c0a45110625579014e972a4 (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
/***************************************************************************
    copyright            : (C) 2008 by Robby Stephenson
    email                : [email protected]
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of version 2 of the GNU General Public License as  *
 *   published by the Free Software Foundation;                            *
 *                                                                         *
 ***************************************************************************/

#include "tellicoxmlhandler.h"
#include "../collection.h"
#include "../tellico_debug.h"

using Tellico::Import::TellicoXMLHandler;

TellicoXMLHandler::TellicoXMLHandler() : TQXmlDefaultHandler(), m_data(new SAX::StateData) {
  m_handlers.setAutoDelete(true);
  m_handlers.push(new SAX::RootHandler(m_data));
}

TellicoXMLHandler::~TellicoXMLHandler() {
  delete m_data;
  m_data = 0;
}

bool TellicoXMLHandler::startElement(const TQString& nsURI_, const TQString& localName_,
                                     const TQString& qName_, const TQXmlAttributes& atts_) {
  SAX::StateHandler* handler = m_handlers.top()->nextHandler(nsURI_, localName_, qName_);
  Q_ASSERT(handler);
  m_handlers.push(handler);
  return handler->start(nsURI_, localName_, qName_, atts_);
}

bool TellicoXMLHandler::endElement(const TQString& nsURI_, const TQString& localName_,
                                   const TQString& qName_) {
  m_data->text = m_data->text.stripWhiteSpace();
/*
  if(!m_data->text.isEmpty()) {
    myDebug() << " text: " << m_text << endl;
  }
*/

  SAX::StateHandler* handler = m_handlers.pop();
  bool res = handler->end(nsURI_, localName_, qName_);
  // need to reset character data, too
  m_data->text = TQString();
  delete handler;
  return res;
}

bool TellicoXMLHandler::characters(const TQString& ch_) {
  m_data->text += ch_;
  return true;
}

TQString TellicoXMLHandler::errorString() {
  return m_data->error;
}

Tellico::Data::CollPtr TellicoXMLHandler::collection() const {
  return m_data->coll;
}

bool TellicoXMLHandler::hasImages() const {
  return m_data->hasImages;
}

void TellicoXMLHandler::setLoadImages(bool loadImages_) {
  m_data->loadImages = loadImages_;
}