00001 /* ${copyright}$ */ 00002 /* $Id: Action.H 630 2006-03-23 21:44:45Z cesar $ */ 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 string clTRID = _command->get_clTRID(); 00100 map < string, string, less<string> > to_parse; 00101 if (clTRID != "") { 00102 to_parse["clTRID"] = "<clTRID>" + clTRID + "</clTRID>"; 00103 } else { 00104 to_parse["clTRID"] = ""; 00105 } 00106 00107 // Response specific attributes 00108 to_parse["svTRID"] = _response->get_svTRID(); 00109 to_parse["msg"] = _response->get_result_msg(); 00110 00111 to_parse["result_lang"] = ""; 00112 if (_response->get_result_lang() != "en") { 00113 to_parse["result_lang"] = " lang='" + _response->get_result_lang() + 00114 "'"; 00115 } 00116 00117 to_parse["code"] = 00118 StrUtil::to_string("%d", (int) _response->get_result_code()); 00119 00120 _xml = StrUtil::parse(xml_template, to_parse, "$(", ")$"); 00121 } 00122 00123 private: 00124 Action(); 00125 00126 }; 00127 00128 LIBEPP_NICBR_NS_END 00129 #endif //__ACTION_H__