1 /*
2 * Copyright (C) 2006-2021 Registro.br. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 * 1. Redistribution of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY REGISTRO.BR ``AS IS AND ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 * WARRANTIE OF FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
16 * EVENT SHALL REGISTRO.BR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
18 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
19 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
20 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
21 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
22 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
23 * DAMAGE.
24 */
25 /* $Id$ */
26
27 #include "config.h"
28
29 #include "DefRegCreate.H"
30 #include "StrUtil.H"
31
32 LIBEPP_NICBR_NS_BEGIN
33
set_xml_template(const string & xml_template)34 void DefRegCreate::set_xml_template(const string &xml_template)
35 {
36 StrUtil su;
37 Action::set_xml_template_common(xml_template);
38 map < string, string, less<string> > to_parse;
39
40 //name
41 DefRegName name = get_command()->get_name();
42 to_parse["name_level"] = su.esc_xml_markup(DefRegLevel::toStr(name.get_level()));
43 to_parse["name"] = su.esc_xml_markup(name.get_name());
44
45 // registrant
46 to_parse["registrant"] = su.esc_xml_markup(get_command()->get_registrant());
47
48 // trademark
49 to_parse["tm"] = "";
50 to_parse["tm_country"] = "";
51 to_parse["tm_date"] = "";
52
53 if (!get_command()->get_trademark_id().empty()) {
54 to_parse["tm"] = "<defReg:tm>" +
55 su.esc_xml_markup(get_command()->get_trademark_id()) + "</defReg:tm>";
56 }
57 if (!get_command()->get_trademark_country().empty()) {
58 to_parse["tm_country"] = "<defReg:tmCountry>" +
59 su.esc_xml_markup(get_command()->get_trademark_country()) + "</defReg:tmCountry>";
60 }
61 if (!get_command()->get_trademark_date().empty()) {
62 to_parse["tm_date"] = "<defReg:tmDate>" +
63 su.esc_xml_markup(get_command()->get_trademark_date()) + "</defReg:tmDate>";
64 }
65
66 // period
67 to_parse["period"] = "";
68 RegistrationPeriod period = get_command()->get_period();
69 if (period.time != 0 && period.unit != "") {
70 to_parse["period"] = "<defReg:period unit=\"" +
71 su.esc_xml_markup(period.unit) + "\">" +
72 StrUtil::to_string("%d", period.time) + "</defReg:period>";
73 }
74
75 // admin contact
76 to_parse["admin_contact"] = su.esc_xml_markup(get_command()->get_admin_contact());
77
78 //auth info
79 AuthInfo authInfo;
80 authInfo = get_command()->get_authInfo();
81
82 string auth_info_str = "";
83 if (authInfo.get_pw() != "") {
84 auth_info_str = "<defReg:authInfo>";
85 if (authInfo.get_roid() == "") {
86 auth_info_str += "<defReg:pw>" + su.esc_xml_markup(authInfo.get_pw())
87 + "</defReg:pw>";
88 } else {
89 auth_info_str += "<defReg:pw roid=\"" +
90 su.esc_xml_markup(authInfo.get_roid()) + "\">" +
91 su.esc_xml_markup(authInfo.get_pw()) + "</defReg:pw>";
92 }
93 auth_info_str += "</defReg:authInfo>";
94 }
95 to_parse["auth_info"] = auth_info_str;
96
97 _xml = StrUtil::parse(_xml, to_parse, "$(", ")$");
98 }
99
100 LIBEPP_NICBR_NS_END
101