summaryrefslogtreecommitdiffstats
path: root/src/translators/xmlimporter.cpp
blob: 99cf00237f1cf0d56224429127df8e6b4100a2c7 (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
/***************************************************************************
    copyright            : (C) 2003-2006 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 "xmlimporter.h"
#include "../filehandler.h"
#include "../collection.h"

#include <klocale.h>

using Tellico::Import::XMLImporter;

XMLImporter::XMLImporter(const KURL& url_) : Import::Importer(url_) {
  if(!url_.isEmpty() && url_.isValid()) {
    m_dom = FileHandler::readXMLFile(url_, true);
  }
}

XMLImporter::XMLImporter(const TQString& text_) : Import::Importer(text_) {
  if(text_.isEmpty()) {
    return;
  }
  setText(text_);
}

XMLImporter::XMLImporter(const TQByteArray& data_) : Import::Importer(KURL()) {
  if(data_.isEmpty()) {
    return;
  }

  TQString errorMsg;
  int errorLine, errorColumn;
  if(!m_dom.setContent(data_, true, &errorMsg, &errorLine, &errorColumn)) {
    TQString str = i18n("There is an XML parsing error in line %1, column %2.").tqarg(errorLine).tqarg(errorColumn);
    str += TQString::tqfromLatin1("\n");
    str += i18n("The error message from TQt is:");
    str += TQString::tqfromLatin1("\n\t") + errorMsg;
    setStatusMessage(str);
    return;
  }
}

XMLImporter::XMLImporter(const TQDomDocument& dom_) : Import::Importer(KURL()), m_dom(dom_) {
}

void XMLImporter::setText(const TQString& text_) {
  Importer::setText(text_);
  TQString errorMsg;
  int errorLine, errorColumn;
  if(!m_dom.setContent(text_, true, &errorMsg, &errorLine, &errorColumn)) {
    TQString str = i18n("There is an XML parsing error in line %1, column %2.").tqarg(errorLine).tqarg(errorColumn);
    str += TQString::tqfromLatin1("\n");
    str += i18n("The error message from TQt is:");
    str += TQString::tqfromLatin1("\n\t") + errorMsg;
    setStatusMessage(str);
  }
}

Tellico::Data::CollPtr XMLImporter::collection() {
  return 0;
}

#include "xmlimporter.moc"