summaryrefslogtreecommitdiff
path: root/src/xmlparser.cc
blob: 97a8bdba65c6817a118ebb8bd3d30fe7669103ec (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
97
98
99
100
101
102
103
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set et sw=2 ts=2: */
/***************************************************************************
 *            xmlparser.cc
 *
 *  Wed Mar 21 09:15:51 CET 2012
 *  Copyright 2012 Jonas Suhr Christensen 
 *  jsc@umbraculum.org
 ****************************************************************************/

/*
 *  This file is part of Munia.
 *
 *  Munia is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  Munia is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with Munia; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
 */
#include "xmlparser.h"

#include "stdio.h"

#include "xml_encode_decode.h"

XmlParser::XmlParser(std::string filename) {
  // open file handler
  fp = fopen(filename.c_str(), "r");
  if(!fp) {
    fprintf(stderr, "Could not open file\n");
  }

  task = NULL;
  tasklist.clear();

  open_tagtype = none;
}

XmlParser::~XmlParser() {
  // close file handler
  fclose(fp);
  if(task) delete task;
}

void XmlParser::characterData(std::string& data) {
  characterbuf += data;
   
  /*
  switch(open_tagtype) {
  case title:
    //    task->title += xml_decode(data);
    break;
  case desc:
    //    task->desc += xml_decode(data);
    break;
  default:
    break;
  }
  */
}

void XmlParser::startTag(std::string name, attributes_t &attr) {
  //  printf("start: %s\n", name.c_str());
  characterbuf.clear();
  if(name == "task") {
    if(task) delete task;

    task = new task_t();
    task->id = atoi(xml_decode(attr["id"]).c_str());
    //  task->parent_id = atoi(xml_decode(attr["parent_id"]).c_str());
  }

}

void XmlParser::endTag(std::string name) {
  //  printf("end: %s\n", name.c_str());
  if (name == "task") {
    //    if(task) tasklist.push_back(*task);
  }
  else if (name == "title") {
    if(task) task->title = characterbuf;
    //    open_tagtype = title;
  }
  else if (name == "desc") {
    if(task) task->desc = characterbuf;
    //    open_tagtype = desc;
  }
  //  open_tagtype = none;
}

int XmlParser::readData(char* data, size_t size) {
  if(!fp) return 0; // Could not read file
 
  return fread(data, 1, size, fp);
}