Add path resolution and env expansion to catalog path.
authorScott Cantor <cantor.2@osu.edu>
Sun, 20 May 2012 18:49:08 +0000 (18:49 +0000)
committerScott Cantor <cantor.2@osu.edu>
Sun, 20 May 2012 18:49:08 +0000 (18:49 +0000)
xmltooling/util/ParserPool.cpp
xmltooling/util/PathResolver.cpp

index 712b121..3650297 100644 (file)
@@ -29,6 +29,7 @@
 #include "logging.h"
 #include "util/CurlURLInputStream.h"
 #include "util/NDC.h"
+#include "util/PathResolver.h"
 #include "util/ParserPool.h"
 #include "util/Threads.h"
 #include "util/XMLHelper.h"
@@ -39,7 +40,6 @@
 #include <functional>
 #include <boost/algorithm/string.hpp>
 #include <boost/bind.hpp>
-#include <boost/tokenizer.hpp>
 #include <xercesc/util/PlatformUtils.hpp>
 #include <xercesc/util/XMLUniDefs.hpp>
 #include <xercesc/sax/SAXException.hpp>
@@ -240,13 +240,13 @@ bool ParserPool::loadSchema(const XMLCh* nsURI, const XMLCh* pathname)
 bool ParserPool::loadCatalogs(const char* pathnames)
 {
     string temp(pathnames);
-    boost::tokenizer< char_separator<char> > catpaths(temp, char_separator<char>(PATH_SEPARATOR_STR));
-    for_each(
-        catpaths.begin(), catpaths.end(),
-        // Call loadCatalog with an inner call to s->c_str() on each entry.
-        boost::bind(static_cast<bool (ParserPool::*)(const char*)>(&ParserPool::loadCatalog), this, boost::bind(&string::c_str, _1))
-        );
-    return catpaths.begin() != catpaths.end();
+    vector<string> catpaths;
+    split(catpaths, temp, is_any_of(PATH_SEPARATOR_STR), algorithm::token_compress_on);
+    for (vector<string>::iterator i = catpaths.begin(); i != catpaths.end(); ++i) {
+        XMLToolingConfig::getConfig().getPathResolver()->resolve(*i, PathResolver::XMLTOOLING_XML_FILE);
+        loadCatalog(i->c_str());
+    }
+    return !catpaths.empty();
 }
 
 bool ParserPool::loadCatalog(const char* pathname)
index 0277e0b..4ca48ec 100644 (file)
@@ -101,6 +101,16 @@ bool PathResolver::isAbsolute(const char* s) const
 
 const string& PathResolver::resolve(string& s, file_type_t filetype, const char* pkgname, const char* prefix) const
 {
+#ifdef WIN32
+    // Check for possible environment variable(s).
+    if (s.find('%') != string::npos) {
+        char expbuf[MAX_PATH + 2];
+        DWORD cnt = ExpandEnvironmentStrings(s.c_str(), expbuf, sizeof(expbuf));
+        if (cnt != 0 && cnt <= sizeof(expbuf))
+            s = expbuf;
+    }
+#endif
+
     if (!isAbsolute(s.c_str())) {
         switch (filetype) {
             case XMLTOOLING_LIB_FILE: