include/Action.H

Go to the documentation of this file.
00001 /* ${copyright}$ */
00002 /* $Id: Action.H 895 2007-03-08 20:27:11Z eduardo $ */
00007 #ifndef __ACTION_H__
00008 #define __ACTION_H__
00009 
00010 #include <string>
00011 
00012 #include "libepp_nicbr.H"
00013 
00014 #include "Response.H"
00015 #include "Command.H"
00016 #include "DomParser.H"
00017 #include "CommonData.H"
00018 
00019 using std::string;
00020 
00021 LIBEPP_NICBR_NS_BEGIN
00022 
00024 class Action
00025 {
00026 public:
00028   virtual ~Action() {}  
00029   
00030 
00032 
00035   virtual void set_xml_template(const string &xml_template) = 0;
00036 
00038 
00041   string get_xml() { return _xml; }
00042 
00044 
00047   ActionType who_am_i() { return _type; }
00048 
00050 
00054   virtual void set_response(const string &xml_payload, DomParser *parser) = 0;
00055 
00057 
00060   Response* get_response()
00061   {
00062     return _response.get(); 
00063   }
00064   
00066 
00069   Command* get_command()
00070   {
00071     return _command.get(); 
00072   }
00073 
00074 protected:
00076   auto_ptr<Command> _command;
00077   
00079   auto_ptr<Response> _response;
00080   
00082   ActionType _type;
00083 
00085   string _xml;
00086 
00088 
00091   Action(const ActionType &type) : _type(type) {}
00092 
00094 
00097   void set_xml_template_common(const string &xml_template)
00098   {
00099     StrUtil su;
00100     string clTRID = _command->get_clTRID();
00101     map < string, string, less<string> > to_parse;
00102     if (clTRID != "") {
00103       to_parse["clTRID"] = "<clTRID>" + su.esc_xml_markup(clTRID) +
00104         "</clTRID>";
00105     } else {
00106       to_parse["clTRID"] = "";
00107     }
00108     
00109     // Response specific attributes
00110     to_parse["svTRID"] = su.esc_xml_markup(_response->get_svTRID());
00111 
00112     string lang = "";
00113     if (_response->get_result_lang() != "en") {
00114       lang = " lang=\"" + su.esc_xml_markup(_response->get_result_lang()) +
00115         "\"";
00116     }
00117 
00118     map <Response::ResultCode, Response::ResultInfo> results;
00119     map <Response::ResultCode, Response::ResultInfo>::const_iterator it;
00120     list<Response::ResultExtValue>::const_iterator ev_it;
00121     results = _response->get_result_list();
00122     to_parse["result"] = "";
00123     for (it = results.begin(); it != results.end(); it++) {
00124       to_parse["result"] += "<result code=\"" + 
00125         StrUtil::to_string("%d", (int)it->first) + "\">" +
00126         "<msg" + lang + ">" + su.esc_xml_markup(it->second.msg) + "</msg>";
00127       for (ev_it = it->second.ext_values.begin();
00128            ev_it != it->second.ext_values.end(); ev_it++) {
00129         // Contents of the value element must be escaped by the
00130         // application as it can be an XML string
00131         if (ev_it->reason == "") {
00132           to_parse["result"] += "<value " + ev_it->xmlns + ">" +
00133             ev_it->value + "</value>";
00134         } else {
00135           to_parse["result"] += "<extValue><value " + ev_it->xmlns + ">" +
00136             ev_it->value + "</value><reason" + lang + ">" + 
00137             su.esc_xml_markup(ev_it->reason) + "</reason></extValue>";
00138         }
00139       }
00140       to_parse["result"] += "</result>";
00141     }
00142     
00143     _xml = StrUtil::parse(xml_template, to_parse, "$(", ")$");
00144   }
00145 
00146 private:
00147   Action();
00148 
00149 };
00150 
00151 LIBEPP_NICBR_NS_END
00152 #endif //__ACTION_H__

Generated on Tue Mar 17 16:03:07 2009 for libepp_nicbr by  doxygen 1.4.7