]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/DEVEL/mathml_editor/src/TDictionary.cc
debian release 0.0.4-2:
[helm.git] / helm / DEVEL / mathml_editor / src / TDictionary.cc
index 3cf2334876ded1f66367a302c558675c6c017f51..b0366338838b4ea20dae7910465f0f3a4159df06 100644 (file)
@@ -1,3 +1,27 @@
+/* This file is part of EdiTeX, an editor of mathematical
+ * expressions based on TeX syntax.
+ * 
+ * Copyright (C) 2002-2003 Luca Padovani <lpadovan@cs.unibo.it>,
+ *                    2003 Paolo Marinelli <pmarinel@cs.unibo.it>.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ * For more information, please visit the project's home page
+ * http://helm.cs.unibo.it/editex/
+ * or send an email to <lpadovan@cs.unibo.it>
+ */
 
 #include <sstream>
 
 
 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 +82,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)");
       }