22 #include <boost/regex.hpp>
23 #include <metaproxy/xmlutil.hpp>
27 namespace mp_xml = metaproxy_1::xml;
29 std::string mp_xml::url_recipe_handle(xmlDoc *doc, std::string recipe)
32 if (recipe.length() == 0)
35 const xmlNode *ptr1 = xmlDocGetRootElement(doc);
36 while (ptr1 && ptr1->type != XML_ELEMENT_NODE)
39 ptr1 = ptr1->children;
42 while (p0 < recipe.length())
44 bool uri_encode =
false;
45 if (p0 < recipe.length() -1 && recipe[p0] ==
'%'
46 && recipe[p0 + 1] ==
'{')
52 else if (p0 < recipe.length() -1 && recipe[p0] ==
'$'
53 && recipe[p0 + 1] ==
'{')
67 std::string replacement;
70 while (p0 < recipe.length() && step < 5)
86 else if (c_check ==
']')
109 if (variable.length())
113 size_t md_pos = variable.find_first_of(
"md-");
116 const xmlNode *ptr = ptr1;
117 for (; ptr; ptr = ptr->next)
118 if (ptr->type == XML_ELEMENT_NODE
119 && !strcmp((
const char *) ptr->name,
"metadata"))
121 const _xmlAttr *attr = ptr->properties;
122 for (; attr; attr = attr->next)
123 if (!strcmp((
const char *) attr->name,
"type")
125 && !strcmp((
const char *) attr->children->content,
126 variable.c_str() + offset))
128 text = mp_xml::get_text(ptr);
132 if (pattern.length() > 0)
134 boost::regex::flag_type b_mode = boost::regex::perl;
135 if (mode.find_first_of(
'i') != std::string::npos)
136 b_mode |= boost::regex::icase;
137 boost::regex e(pattern, b_mode);
138 boost::match_flag_type match_mode = boost::format_first_only;
139 if (mode.find_first_of(
'g') != std::string::npos)
140 match_mode = boost::format_all;
141 text = regex_replace(text, e, replacement, match_mode);
150 for (i = 0; i < text.length(); i++)
154 yaz_encode_uri_component(dst, src);