00001
00002
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) + "</clTRID>";
00104 } else {
00105 to_parse["clTRID"] = "";
00106 }
00107
00108
00109 to_parse["svTRID"] = su.esc_xml_markup(_response->get_svTRID());
00110
00111 string lang = "";
00112 if (_response->get_result_lang() != "en") {
00113 lang = " lang=\"" + su.esc_xml_markup(_response->get_result_lang()) +
00114 "\"";
00115 }
00116
00117 map <Response::ResultCode, Response::ResultInfo> results;
00118 map <Response::ResultCode, Response::ResultInfo>::const_iterator it;
00119 list<Response::ResultExtValue>::const_iterator ev_it;
00120 results = _response->get_result_list();
00121 to_parse["result"] = "";
00122 for (it = results.begin(); it != results.end(); it++) {
00123 to_parse["result"] += "<result code=\"" +
00124 StrUtil::to_string("%d", (int)it->first) + "\">" +
00125 "<msg" + lang + ">" + su.esc_xml_markup(it->second.msg) + "</msg>";
00126 for (ev_it = it->second.ext_values.begin();
00127 ev_it != it->second.ext_values.end(); ev_it++) {
00128
00129
00130 if (ev_it->reason == "") {
00131 to_parse["result"] += "<value " + ev_it->xmlns + ">" +
00132 ev_it->value + "</value>";
00133 } else {
00134 to_parse["result"] += "<extValue><value " + ev_it->xmlns + ">" +
00135 ev_it->value + "</value><reason" + lang + ">" +
00136 su.esc_xml_markup(ev_it->reason) + "</reason></extValue>";
00137 }
00138 }
00139 to_parse["result"] += "</result>";
00140 }
00141
00142 _xml = StrUtil::parse(xml_template, to_parse, "$(", ")$");
00143 }
00144
00145 private:
00146 Action();
00147
00148 };
00149
00150 LIBEPP_NICBR_NS_END
00151 #endif //__ACTION_H__