+ if (m_subst.empty() && (m_regex.empty() || m_match.empty()))
+ throw saml2md::MetadataException("Unable to resolve metadata dynamically from an artifact.");
+ name = "{sha1}" + criteria.artifact->getSource();
+ }
+
+ // Possibly transform the input into a different URL to use.
+ if (!m_subst.empty()) {
+ string name2 = boost::replace_first_copy(m_subst, "$entityID",
+ m_encoded ? XMLToolingConfig::getConfig().getURLEncoder()->encode(name.c_str()) : name);
+ log.info("transformed location from (%s) to (%s)", name.c_str(), name2.c_str());
+ name = name2;
+ }
+ else if (!m_match.empty() && !m_regex.empty()) {
+ try {
+ RegularExpression exp(m_match.c_str());
+ XMLCh* temp = exp.replace(name.c_str(), m_regex.c_str());
+ if (temp) {
+ auto_ptr_char narrow(temp);
+ XMLString::release(&temp);
+
+ // For some reason it returns the match string if it doesn't match the expression.
+ if (name != narrow.get()) {
+ log.info("transformed location from (%s) to (%s)", name.c_str(), narrow.get());
+ name = narrow.get();
+ }
+ }
+ }
+ catch (XMLException& ex) {
+ auto_ptr_char msg(ex.getMessage());
+ log.error("caught error applying regular expression: %s", msg.get());
+ }