1 // vim: set noexpandtab tabstop=4 shiftwidth=4:
2 //----------------------------------------------------------------------------
4 //----------------------------------------------------------------------------
5 // This file is part of PlaQui.
7 // PlaQui is free software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the Free Software
9 // Foundation; either version 2 of the License, or (at your option) any later
12 // PlaQui is distributed in the hope that it will be useful, but WITHOUT ANY
13 // WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 // FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17 // You should have received a copy of the GNU General Public License along
18 // with PlaQui; if not, write to the Free Software Foundation, Inc., 59 Temple
19 // Place, Suite 330, Boston, MA 02111-1307 USA
20 //----------------------------------------------------------------------------
21 // Creado: jue nov 27 13:33:22 ART 2003
22 // Autores: Leandro Lucarella <llucare@fi.uba.ar>
23 //----------------------------------------------------------------------------
28 #include "plaqui/server/response.h"
29 #include "plaqui/server/string.h"
41 Response::Parser::~Parser(void) {
43 cerr << __FILE__ << "(" << __LINE__ << ")"
44 << ": destructor." << endl;
48 Response::Parser::Parser(Response& resp): response(&resp), root(true) {
50 cerr << __FILE__ << "(" << __LINE__ << ")"
51 << ": constructor();" << endl;
55 void Response::Parser::on_start_element(const string& name,
56 const AttributeMap& attrs) {
58 cerr << __FILE__ << "(" << __LINE__ << ")"
59 << ": on_start_element(name = " << name << ", attrs = [";
60 for (AttributeMap::const_iterator i = attrs.begin();
61 i != attrs.end(); i++) {
62 cerr << i->first << " = " << i->second << ", ";
64 cerr << "]);" << endl;
67 // Si es el elemento raíz, debe ser la respuesta.
68 if (name == "plaqui-response") {
69 AttributeMap::const_iterator i = attrs.find("version");
70 if (i != attrs.end()) {
71 response->xml_version = i->second;
73 i = attrs.find("code");
74 if (i != attrs.end()) {
77 response->xml_code = static_cast<Response::Code>(c);
79 i = attrs.find("description");
80 if (i != attrs.end()) {
81 response->xml_description = i->second;
85 // Si no es el elemento raíz, lo agrego al body.
87 response->xml_contents += "<";
88 response->xml_contents += name + " ";
89 for (AttributeMap::const_iterator i = attrs.begin();
90 i != attrs.end(); i++) {
91 response->xml_contents += i->first + " = \"" + i->second + "\" ";
93 response->xml_contents += ">";
97 void Response::Parser::on_end_element(const string& name) {
99 cerr << __FILE__ << "(" << __LINE__ << ")"
100 << ": on_end_element(name = " << name << ");" << endl;
102 // Si es el fin de la respuesta, volvemos a la raíz.
103 if (name == "plaqui-response") {
105 // Si no, agrega al cuerpo.
107 response->xml_contents += "</";
108 response->xml_contents += name + ">";
112 void Response::Parser::on_characters(const string& chars) {
114 cerr << __FILE__ << "(" << __LINE__ << ")"
115 << ": on_characters(chars = " << chars << ");" << endl;
117 // Sólo nos importa el contenido, lo agregamos.
119 response->xml_contents += chars;
123 /*void Response::Parser::on_comment(const string& text) {
125 cerr << __FILE__ << "(" << __LINE__ << ")"
126 << ": on_comment(text = " << text << ");" << endl;
130 } // namespace Server
132 } // namespace PlaQui