From dad9f0679e2a714ce7beddbff03acd801e52c831 Mon Sep 17 00:00:00 2001 From: Scott Cantor Date: Wed, 13 Sep 2006 21:11:20 +0000 Subject: [PATCH] Support for a catalog path. --- xmltooling/XMLToolingConfig.cpp | 16 ++++++++++++++++ xmltooling/XMLToolingConfig.h | 7 +++++++ xmltooling/internal.h | 25 +++++++++++++++++++++++++ xmltoolingtest/xmltoolingtest.h | 12 +++++++----- 4 files changed, 55 insertions(+), 5 deletions(-) diff --git a/xmltooling/XMLToolingConfig.cpp b/xmltooling/XMLToolingConfig.cpp index e248f6a..a7cbc42 100644 --- a/xmltooling/XMLToolingConfig.cpp +++ b/xmltooling/XMLToolingConfig.cpp @@ -161,6 +161,22 @@ bool XMLToolingInternalConfig::init() m_parserPool=new ParserPool(); m_validatingPool=new ParserPool(true,true); m_lock=xercesc::XMLPlatformUtils::makeMutex(); + + // Load catalogs from path. + if (!catalog_path.empty()) { + char* catpath=strdup(catalog_path.c_str()); + char* sep=NULL; + char* start=catpath; + while (start && *start) { + sep=strchr(start,PATH_SEPARATOR_CHAR); + if (sep) + *sep=0; + auto_ptr_XMLCh temp(start); + m_validatingPool->loadCatalog(temp.get()); + start = sep ? sep + 1 : NULL; + } + free(catpath); + } // default registrations XMLObjectBuilder::registerDefaultBuilder(new UnknownElementBuilder()); diff --git a/xmltooling/XMLToolingConfig.h b/xmltooling/XMLToolingConfig.h index 4b5ff2c..f60a06a 100644 --- a/xmltooling/XMLToolingConfig.h +++ b/xmltooling/XMLToolingConfig.h @@ -125,6 +125,13 @@ namespace xmltooling { * @return reference to a validating parser pool. */ virtual ParserPool& getValidatingParser() const=0; + + /** + * Set to catalog files to load into validating parser pool at initialization time. + * Like other path settings, the separator depends on the platform + * (semicolon on Windows, colon otherwise). + */ + std::string catalog_path; #ifndef XMLTOOLING_NO_XMLSEC /** diff --git a/xmltooling/internal.h b/xmltooling/internal.h index f4c51bf..b222ef4 100644 --- a/xmltooling/internal.h +++ b/xmltooling/internal.h @@ -47,6 +47,31 @@ #define XMLTOOLING_LOGCAT "XMLTooling" +// Macros for path and directory separators. +#if defined __CYGWIN32__ && !defined __CYGWIN__ + /* For backwards compatibility with Cygwin b19 and + earlier, we define __CYGWIN__ here, so that + we can rely on checking just for that macro. */ +# define __CYGWIN__ __CYGWIN32__ +#endif + +#if defined _WIN32 && !defined __CYGWIN__ + /* Use Windows separators on all _WIN32 defining + environments, except Cygwin. */ +# define DIR_SEPARATOR_CHAR '\\' +# define DIR_SEPARATOR_STR "\\" +# define PATH_SEPARATOR_CHAR ';' +# define PATH_SEPARATOR_STR ";" +#endif +#ifndef DIR_SEPARATOR_CHAR + /* Assume that not having this is an indicator that all + are missing. */ +# define DIR_SEPARATOR_CHAR '/' +# define DIR_SEPARATOR_STR "/" +# define PATH_SEPARATOR_CHAR ':' +# define PATH_SEPARATOR_STR ":" +#endif /* !DIR_SEPARATOR_CHAR */ + namespace xmltooling { /// @cond OFF diff --git a/xmltoolingtest/xmltoolingtest.h b/xmltoolingtest/xmltoolingtest.h index fe1e867..6507143 100644 --- a/xmltoolingtest/xmltoolingtest.h +++ b/xmltoolingtest/xmltoolingtest.h @@ -30,13 +30,15 @@ class ToolingFixture : public CxxTest::GlobalFixture public: bool setUpWorld() { XMLToolingConfig::getConfig().log_config(); - if (!XMLToolingConfig::getConfig().init()) - return false; + if (getenv("XMLTOOLINGTEST_DATA")) data_path=std::string(getenv("XMLTOOLINGTEST_DATA")) + "/"; - std::string catpath=data_path + "catalog.xml"; - auto_ptr_XMLCh temp(catpath.c_str()); - return XMLToolingConfig::getConfig().getValidatingParser().loadCatalog(temp.get()); + XMLToolingConfig::getConfig().catalog_path = data_path + "catalog.xml"; + + if (!XMLToolingConfig::getConfig().init()) + return false; + + return true; } bool tearDownWorld() { XMLToolingConfig::getConfig().term(); -- 2.1.4