Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add xercesc parsing of environment variables in the xml path #1326

Merged
merged 5 commits into from
Oct 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 15 additions & 14 deletions DDCore/src/XML/DocumentHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ namespace {
return fn;
}
int s_minPrintLevel = dd4hep::INFO;

std::string _clean_fname(const std::string& filepath) {
// This function seems to resolve environment variables inside the filepath string and return resolved string
std::string const& temp = getEnviron(filepath);
std::string temp2 = undressed_file_name( temp.empty() ? filepath : temp );
if ( strncmp(temp2.c_str(),"file:",5)==0 ) return temp2.substr(5);
return temp2;
}

}

#ifndef __TIXML__
Expand Down Expand Up @@ -328,13 +337,14 @@ Document DocumentHandler::load(Handle_t base, const XMLCh* fname, UriReader* rea

/// Load XML file and parse it using URI resolver to read data.
Document DocumentHandler::load(const std::string& fname, UriReader* reader) const {
auto fname_clean = _clean_fname(fname);
std::string path;
printout(DEBUG,"DocumentHandler","+++ Loading document URI: %s",fname.c_str());
printout(DEBUG,"DocumentHandler","+++ Loading document URI: %s",fname_clean.c_str());
try {
size_t idx = fname.find(':');
size_t idq = fname.find('/');
size_t idx = fname_clean.find(':');
size_t idq = fname_clean.find('/');
if ( idq == std::string::npos ) idq = 0;
XMLURL xerurl = (const XMLCh*) Strng_t(idx==std::string::npos || idx>idq ? "file:"+fname : fname);
XMLURL xerurl = (const XMLCh*) Strng_t(idx==std::string::npos || idx>idq ? "file:"+fname_clean : fname_clean);
std::string proto = _toString(xerurl.getProtocolName());
path = _toString(xerurl.getPath());
printout(DEBUG,"DocumentHandler","+++ protocol:%s path:%s",proto.c_str(), path.c_str());
Expand All @@ -348,7 +358,7 @@ Document DocumentHandler::load(const std::string& fname, UriReader* reader) cons
if ( reader ) reader->parserLoaded(path);
}
else {
if ( reader && reader->load(fname, path) ) {
if ( reader && reader->load(fname_clean, path) ) {
MemBufInputSource src((const XMLByte*)path.c_str(), path.length(), fname.c_str(), false);
parser->parse(src);
return (XmlDocument*)parser->adoptDocument();
Expand Down Expand Up @@ -431,15 +441,6 @@ namespace dd4hep {
};
}}

namespace {
static std::string _clean_fname(const std::string& s) {
std::string const& temp = getEnviron(s);
std::string temp2 = undressed_file_name(temp.empty() ? s : temp);
if ( strncmp(temp2.c_str(),"file:",5)==0 ) return temp2.substr(5);
return temp2;
}
}

/// System ID of a given XML entity
std::string DocumentHandler::system_path(Handle_t base, const std::string& fname) {
std::string fn, clean = _clean_fname(fname);
Expand Down
Loading