5 #include <xercesc/parsers/XercesDOMParser.hpp> 9 #include <boost/algorithm/string.hpp> 10 #include <boost/algorithm/string/replace.hpp> 25 std::stringstream
str;
28 for (
size_t i = 1;
i < matches.size(); ++
i) {
33 if (!matchedString.empty())
34 boost::algorithm::replace_all(result, str.str(), matchedString);
43 int FileLocator::s_numberOfInstances = 0;
52 }
catch (XMLException
const&
e) {
61 init(catUrl, fallback);
91 DOMElement* ruleElement =
static_cast<DOMElement*
>(ruleNode);
96 if (destinationMatchRegexp.empty()) {
97 destinationMatchRegexp =
".*";
106 rule.destinationMatch.assign(destinationMatchRegexp);
109 rules[protocol].push_back(rule);
118 throw cms::Exception(
"TrivialFileCatalog",
"edm::SiteLocalConfigService is not available");
120 m_url = (fallback ? localconfservice->fallbackDataCatalog() : localconfservice->dataCatalog());
125 if (m_url.find(
"file:") == std::string::npos) {
127 "TrivialFileCatalog::connect: Malformed url for file catalog configuration");
130 m_url = m_url.erase(0, m_url.find(
":") + 1);
132 std::vector<std::string> tokens;
136 if (tokens.size() == 2) {
138 std::vector<std::string> optionTokens;
144 for (
size_t oi = 0, oe = optionTokens.size(); oi != oe; ++oi) {
146 std::vector<std::string> argTokens;
149 if (argTokens.size() != 2) {
151 "TrivialFileCatalog::connect: Malformed url for file catalog configuration");
154 if (argTokens[0] ==
"protocol") {
156 }
else if (argTokens[0] ==
"destination") {
164 "TrivialFileCatalog::connect: protocol was not supplied in the contact string");
167 std::ifstream configFile;
173 if (!configFile.good() || !configFile.is_open()) {
175 "TrivialFileCatalog::connect: Unable to open trivial file catalog " +
m_filename);
180 auto parser = std::make_unique<XercesDOMParser>();
182 parser->setValidationScheme(XercesDOMParser::Val_Auto);
183 parser->setDoNamespaces(
false);
185 DOMDocument*
doc =
parser->getDocument();
202 DOMNodeList*
rules = doc->getElementsByTagName(
uStr(
"lfn-to-pfn").ptr());
203 XMLSize_t
const ruleTagsNum = rules->getLength();
207 for (XMLSize_t
i = 0;
i < ruleTagsNum; ++
i) {
208 DOMNode* ruleNode = rules->item(
i);
214 DOMNodeList*
rules = doc->getElementsByTagName(
uStr(
"pfn-to-lfn").ptr());
215 XMLSize_t ruleTagsNum = rules->getLength();
217 for (XMLSize_t
i = 0;
i < ruleTagsNum; ++
i) {
218 DOMNode* ruleNode = rules->item(
i);
222 }
catch (xercesc::DOMException
const&
e) {
224 <<
"Xerces XML parser threw this exception: " <<
cStr(e.getMessage()).ptr() << std::endl;
235 ProtocolRules::const_iterator
const rulesIterator = protocolRules.find(protocol);
236 if (rulesIterator == protocolRules.end()) {
240 Rules const&
rules = (*(rulesIterator)).second;
242 std::smatch destinationMatches;
243 std::smatch nameMatches;
246 for (Rules::const_iterator
i = rules.begin();
i != rules.end(); ++
i) {
247 if (!std::regex_match(destination, destinationMatches,
i->destinationMatch)) {
251 if (!std::regex_match(name,
i->pathMatch)) {
258 if ((direct ==
true) && (!chain.empty())) {
259 name =
applyRules(protocolRules, chain, destination, direct, name);
265 std::regex_match(name, nameMatches,
i->pathMatch);
266 name = replaceWithRegexp(nameMatches,
i->result);
268 if ((direct ==
false) && (!chain.empty())) {
269 name =
applyRules(protocolRules, chain, destination, direct, name);
std::map< std::string, Rules > ProtocolRules
static int s_numberOfInstances
std::string lfn(std::string const &ipfn) const
std::string m_destination
static std::string const input
U second(std::pair< T, U > const &p)
ProtocolRules m_inverseRules
ZStr< char > cStr(XMLCh const *str)
std::string convert(std::string const &input, ProtocolRules const &rules, bool direct) const
ZStr< XMLCh > uStr(char const *str)
std::string pfn(std::string const &ilfn) const
std::string toString(const std::pair< T, T > &aT)
ProtocolRules m_directRules
std::vector< Rule > Rules
void parseRule(xercesc::DOMNode *ruleNode, ProtocolRules &rules)
std::vector< std::string > m_protocols
std::string applyRules(ProtocolRules const &protocolRules, std::string const &protocol, std::string const &destination, bool direct, std::string name) const
void init(std::string const &catUrl, bool fallback)