From 617c3cf27758b63f35ab21a5d5e67be5aa9f065f Mon Sep 17 00:00:00 2001 From: Luca Padovani Date: Wed, 12 Mar 2003 15:51:55 +0000 Subject: [PATCH] * temporary fix for handling relative/absolute filenames in the inclusion mechanisms of dictionaries --- helm/DEVEL/mathml_editor/src/TDictionary.cc | 40 +++++++++++++++++---- helm/DEVEL/mathml_editor/src/TDictionary.hh | 5 +-- helm/DEVEL/mathml_editor/test/editor.cc | 2 +- 3 files changed, 38 insertions(+), 9 deletions(-) diff --git a/helm/DEVEL/mathml_editor/src/TDictionary.cc b/helm/DEVEL/mathml_editor/src/TDictionary.cc index 3cf233487..590a7db30 100644 --- a/helm/DEVEL/mathml_editor/src/TDictionary.cc +++ b/helm/DEVEL/mathml_editor/src/TDictionary.cc @@ -8,19 +8,41 @@ static TDictionary::Entry undefinedEntry; +static std::string +getURIBase(const std::string& uri) +{ + std::string::size_type slash = uri.rfind('/'); + if (slash != std::string::npos) return uri.substr(0, slash + 1); + else return ""; +} + +static std::string +getURIName(const std::string& uri) +{ + std::string::size_type slash = uri.rfind('/'); + if (slash != std::string::npos) return uri.substr(slash + 1, uri.size()); + else return uri; +} + void TDictionary::load(const std::string& uri) { - logger.debug("Dictionary: loading `" + uri + "'"); + load(getURIName(uri), getURIBase(uri)); +} + +void +TDictionary::load(const std::string& name, const std::string& base) +{ + logger.debug("Dictionary: loading `" + base + name + "'"); DOM::DOMImplementation di; - DOM::Document doc = di.createDocumentFromURI(uri.c_str()); + DOM::Document doc = di.createDocumentFromURI((base + name).c_str()); assert(doc); - load(doc); + load(doc, base); } void -TDictionary::load(const DOM::Document& doc) +TDictionary::load(const DOM::Document& doc, const std::string& base) { assert(doc); @@ -36,8 +58,14 @@ TDictionary::load(const DOM::Document& doc) DOM::Element el = p; assert(el); if (el.hasAttribute("href")) - // WARNING: this may result into an infinite loop! - load(std::string(el.getAttribute("href"))); + { + // WARNING: this may result into an infinite loop! + std::string href = el.getAttribute("href"); + std::string newBase = getURIBase(href); + std::string newName = getURIName(href); + if (newBase != "") load(newName, newBase); + else load(newName, base); + } else logger.warning("Dictionary: include statement with no href attribute (ignored)"); } diff --git a/helm/DEVEL/mathml_editor/src/TDictionary.hh b/helm/DEVEL/mathml_editor/src/TDictionary.hh index 5349cf004..358481ee0 100644 --- a/helm/DEVEL/mathml_editor/src/TDictionary.hh +++ b/helm/DEVEL/mathml_editor/src/TDictionary.hh @@ -59,8 +59,9 @@ public: unsigned table : 1; }; - void load(const std::string& uri); - void load(const DOM::Document& doc); + void load(const std::string&); + void load(const std::string&, const std::string&); + void load(const DOM::Document&, const std::string& = ""); const Entry& find(const std::string&) const; private: diff --git a/helm/DEVEL/mathml_editor/test/editor.cc b/helm/DEVEL/mathml_editor/test/editor.cc index b22bd3bed..b251d4ede 100644 --- a/helm/DEVEL/mathml_editor/test/editor.cc +++ b/helm/DEVEL/mathml_editor/test/editor.cc @@ -114,7 +114,7 @@ main(int argc, char* argv[]) TDictionary dictionary(logger); logger.info("loading the dictionary..."); - dictionary.load("dictionary-test.xml"); + dictionary.load("/home/luca/projects/helm/DEVEL/mathml_editor/dictionary-test.xml"); logger.info("loading the stylesheet..."); DOM::DOMImplementation di; -- 2.39.2