1 // vim: set expandtab tabstop=4 shiftwidth=4:
11 using std::stringstream;
20 void Parser::on_start_document(void) {
22 cerr << "In Parser::on_start_document();" << endl;
26 void Parser::on_end_document(void) {
28 cerr << "In Parser::on_end_document();" << endl;
32 void Parser::on_start_element(const string& name, const AttributeMap& attrs) {
34 cerr << "In Parser::on_start_element(name = '" << name << "', attrs = [";
36 Hash::const_iterator last = attrs.end();
38 for (Hash::const_iterator i = attrs.begin(); i != last; i++) { //last; i++) {
39 cerr << i->first << ": '" << i->second << "', ";
41 cerr << last->first << ": '" << last->second << "'";
43 cerr << "]);" << endl;
45 stack.push(fb_create(name, attrs));
48 void Parser::on_end_element(const string& name) {
50 cerr << "In Parser::on_end_element('" << name << "');" << endl;
52 Widget* cur = stack.top();
54 // If is the last widget, it's the root widget.
57 // If is not the last widget, we add it as content of his parent.
59 Container* par = dynamic_cast<Container*>(stack.top());
60 // If the parent is a Container, we add curent widget as content.
63 // If not, we raise an exception TODO
65 throw "Trying to add content to a non-container widget.";
70 void Parser::on_characters(const string& chars) {
72 cerr << "In Parser::on_characters('" << chars << "');" << endl;
75 Container* cur = dynamic_cast<Container*>(stack.top());
76 // If we are in a Container, we add curent string widget as content.
78 cur->append(new String(chars));
79 // If not, we raise an exception TODO
81 throw "Trying to add content to a non-container widget.";
84 // FIXME - investigar si tiene sentido.
85 throw "Characters with no tags!!!?!?!?!";
89 void Parser::on_comment(const string& text) {
91 cerr << "In Parser::on_comment('" << text << "');" << endl;
95 void Parser::on_warning(const string& warn) {
97 cerr << "In Parser::on_warning('" << warn << "');" << endl;
101 void Parser::on_error(const string& error) {
103 cerr << "In Parser::on_error('" << error << "');" << endl;
107 void Parser::on_fatal_error(const string& error) {
109 cerr << "In Parser::on_fatal_error('" << error << "');" << endl;
113 void Parser::on_validity_error(const string& error) {
115 cerr << "In Parser::on_validity_error('" << error << "');" << endl;
119 void Parser::on_validity_warning(const string& warn) {
121 cerr << "In Parser::on_validity_warning('" << warn << "');" << endl;
125 Parser::Parser(void): fb_create(NULL), fb_destroy(NULL), root(NULL) {
127 cerr << "In Parser::Parser();" << endl;
129 void* fb = dlopen("./translate.so", RTLD_NOW | RTLD_GLOBAL); // TODO - mas rapido: RTLD_LAZY);
131 throw string("No se puede cargar el plug-in: ") + dlerror();
133 fb_create = (create_t*)dlsym(fb, "create");
134 fb_destroy = (destroy_t*)dlsym(fb, "destroy");
135 if (!fb_create || !fb_destroy) {
136 throw string("No se puede cargar el creador del plug-in: ") + dlerror();
140 //Parser::Parser(const Hash& attrs): attrs(attrs) {
142 // cerr << "In Parser::Parser(attrs = {" /* TODO << attrs */ << "});" << endl;
146 Parser::~Parser(void) {
148 cerr << "In Parser destructor." << endl;
152 Parser::operator string(void) const {