libepp_nicbr
Action.H
Go to the documentation of this file.
1 /* ${copyright}$ */
2 /* $Id: Action.H 1086 2010-12-10 13:07:28Z eduardo $ */
7 #ifndef __ACTION_H__
8 #define __ACTION_H__
9 
10 #include <string>
11 
12 #include "libepp_nicbr.H"
13 
14 #include "Response.H"
15 #include "Command.H"
16 #include "DomParser.H"
17 #include "CommonData.H"
18 
19 using std::string;
20 
21 LIBEPP_NICBR_NS_BEGIN
22 
24 class Action
25 {
26 public:
28  virtual ~Action() {}
29 
30 
32 
35  virtual void set_xml_template(const string &xml_template) = 0;
36 
38 
41  string get_xml() { return _xml; }
42 
44 
47  ActionType who_am_i() { return _type; }
48 
50 
54  virtual void set_response(const string &xml_payload, DomParser *parser) = 0;
55 
57 
61  {
62  return _response.get();
63  }
64 
66 
70  {
71  return _command.get();
72  }
73 
74 protected:
76  auto_ptr<Command> _command;
77 
79  auto_ptr<Response> _response;
80 
83 
85  string _xml;
86 
88 
91  Action(const ActionType &type) : _type(type) {}
92 
94 
97  void set_xml_template_common(const string &xml_template)
98  {
99  StrUtil su;
100  string clTRID = _command->get_clTRID();
101  map < string, string, less<string> > to_parse;
102  if (clTRID != "") {
103  to_parse["clTRID"] = "<clTRID>" + su.esc_xml_markup(clTRID) +
104  "</clTRID>";
105  } else {
106  to_parse["clTRID"] = "";
107  }
108 
109  // Response specific attributes
110  to_parse["svTRID"] = su.esc_xml_markup(_response->get_svTRID());
111 
112  string lang = "";
113  if (_response->get_result_lang() != "en") {
114  lang = " lang=\"" + su.esc_xml_markup(_response->get_result_lang()) +
115  "\"";
116  }
117 
118  map <Response::ResultCode, Response::ResultInfo> results;
119  map <Response::ResultCode, Response::ResultInfo>::const_iterator it;
120  list<Response::ResultExtValue>::const_iterator ev_it;
121  results = _response->get_result_list();
122  to_parse["result"] = "";
123  for (it = results.begin(); it != results.end(); it++) {
124  to_parse["result"] += "<result code=\"" +
125  StrUtil::to_string("%d", (int)it->first) + "\">" +
126  "<msg" + lang + ">" + su.esc_xml_markup(it->second.msg) + "</msg>";
127  for (ev_it = it->second.ext_values.begin();
128  ev_it != it->second.ext_values.end(); ev_it++) {
129  // Contents of the value element must be escaped by the
130  // application as it can be an XML string
131  if (ev_it->reason == "") {
132  to_parse["result"] += "<value " + ev_it->xmlns + ">" +
133  ev_it->value + "</value>";
134  } else {
135  to_parse["result"] += "<extValue><value " + ev_it->xmlns + ">" +
136  ev_it->value + "</value><reason" + lang + ">" +
137  su.esc_xml_markup(ev_it->reason) + "</reason></extValue>";
138  }
139  }
140  to_parse["result"] += "</result>";
141  }
142 
143  _xml = StrUtil::parse(xml_template, to_parse, "$(", ")$");
144  }
145 
146 private:
147  Action();
148 
149 };
150 
151 LIBEPP_NICBR_NS_END
152 #endif //__ACTION_H__
Action(const ActionType &type)
Constructor that forces childs to set their types.
Definition: Action.H:91
StrUtil Class: String Manipulation Utilities.
Definition: StrUtil.H:26
static string to_string(const char *format, const kind &number)
Convert number to string where the format string looks like printf format.
Definition: StrUtil.H:57
string get_xml()
Returns XML.
Definition: Action.H:41
EPP Response Class.
Definition: Response.H:24
virtual void set_xml_template(const string &xml_template)=0
Sets the xml template and parses the tags (pure virtual)
Project defines.
EPP CommonData Class.
EPP DomParser Class.
EPP Response Class.
EPP DomParser Class.
Definition: DomParser.H:62
EPP Action Class.
Definition: Action.H:24
static string parse(const string &text, const map< string, string, less< string > > &to_parse, string tag_begin, string tag_end)
Used for parsing XML Templates.
auto_ptr< Response > _response
Generic response.
Definition: Action.H:79
Response * get_response()
Returns raw pointer to the response.
Definition: Action.H:60
ActionType who_am_i()
Returns Action type.
Definition: Action.H:47
static string esc_xml_markup(const string &input_txt)
Escape &'><" characters.
Command * get_command()
Returns raw pointer to the command.
Definition: Action.H:69
auto_ptr< Command > _command
Generic command.
Definition: Action.H:76
ActionType
Action Types.
Definition: CommonData.H:23
ActionType _type
Action type.
Definition: Action.H:82
EPP Command Class.
Definition: Command.H:18
virtual void set_response(const string &xml_payload, DomParser *parser)=0
Pure virtual method to set response from a XML document.
EPP Command Class.
virtual ~Action()
virtual destructor
Definition: Action.H:28
string _xml
XML command.
Definition: Action.H:85
void set_xml_template_common(const string &xml_template)
Sets the xml template and parses the tags (protected)
Definition: Action.H:97