--- /dev/null
+// vim: set noexpandtab tabstop=4 shiftwidth=4:
+//----------------------------------------------------------------------------
+// PlaQui
+//----------------------------------------------------------------------------
+// This file is part of PlaQui.
+//
+// PlaQui 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.
+//
+// PlaQui 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 PlaQui; if not, write to the Free Software Foundation, Inc., 59 Temple
+// Place, Suite 330, Boston, MA 02111-1307 USA
+//----------------------------------------------------------------------------
+// Creado: jue nov 27 13:33:22 ART 2003
+// Autores: Leandro Lucarella <llucare@fi.uba.ar>
+//----------------------------------------------------------------------------
+//
+// $Id$
+//
+
+#include "plaqui/server/response.h"
+#include "plaqui/server/string.h"
+#include <sstream>
+#ifdef DEBUG
+# include <iostream>
+#endif // DEBUG
+
+using namespace std;
+
+namespace PlaQui {
+
+namespace Server {
+
+Response::Parser::~Parser(void) {
+#ifdef DEBUG
+ cerr << __FILE__ << "(" << __LINE__ << ")"
+ << ": destructor." << endl;
+#endif // DEBUG
+}
+
+Response::Parser::Parser(Response& resp): response(&resp), root(true) {
+#ifdef DEBUG
+ cerr << __FILE__ << "(" << __LINE__ << ")"
+ << ": constructor();" << endl;
+#endif // DEBUG
+}
+
+void Response::Parser::on_start_element(const string& name,
+ const AttributeMap& attrs) {
+#ifdef DEBUG
+ cerr << __FILE__ << "(" << __LINE__ << ")"
+ << ": on_start_element(name = " << name << ", attrs = [";
+ for (AttributeMap::const_iterator i = attrs.begin();
+ i != attrs.end(); i++) {
+ cerr << i->first << " = " << i->second << ", ";
+ }
+ cerr << "]);" << endl;
+#endif // DEBUG
+ if (root) {
+ // Si es el elemento raíz, debe ser la respuesta.
+ if (name == "plaqui-response") {
+ AttributeMap::const_iterator i = attrs.find("version");
+ if (i != attrs.end()) {
+ response->xml_version = i->second;
+ }
+ i = attrs.find("code");
+ if (i != attrs.end()) {
+ int c;
+ to(i->second, c);
+ response->xml_code = static_cast<Response::Code>(c);
+ }
+ i = attrs.find("description");
+ if (i != attrs.end()) {
+ response->xml_description = i->second;
+ }
+ root = false;
+ }
+ // Si no es el elemento raíz, lo agrego al body.
+ } else {
+ response->xml_body += "<";
+ response->xml_body += name + " ";
+ for (AttributeMap::const_iterator i = attrs.begin();
+ i != attrs.end(); i++) {
+ response->xml_body += i->first + " = \"" + i->second + "\" ";
+ }
+ response->xml_body += ">";
+ }
+}
+
+void Response::Parser::on_end_element(const string& name) {
+#ifdef DEBUG
+ cerr << __FILE__ << "(" << __LINE__ << ")"
+ << ": on_end_element(name = " << name << ");" << endl;
+#endif // DEBUG
+ // Si es el fin de la respuesta, volvemos a la raíz.
+ if (name == "plaqui-response") {
+ root = true;
+ // Si no, agrega al cuerpo.
+ } else {
+ response->xml_body += "</";
+ response->xml_body += name + ">";
+ }
+}
+
+void Response::Parser::on_characters(const string& chars) {
+#ifdef DEBUG
+ cerr << __FILE__ << "(" << __LINE__ << ")"
+ << ": on_characters(chars = " << chars << ");" << endl;
+#endif // DEBUG
+ // Sólo nos importa el contenido, lo agregamos.
+ if (!root) {
+ response->xml_body += chars;
+ }
+}
+
+/*void Response::Parser::on_comment(const string& text) {
+#ifdef DEBUG
+ cerr << __FILE__ << "(" << __LINE__ << ")"
+ << ": on_comment(text = " << text << ");" << endl;
+#endif // DEBUG
+}*/
+
+} // namespace Server
+
+} // namespace PlaQui
+