Beginnings of url recipe handling
authorAdam Dickmeiss <adam@indexdata.dk>
Thu, 30 Jun 2011 15:40:29 +0000 (17:40 +0200)
committerAdam Dickmeiss <adam@indexdata.dk>
Thu, 30 Jun 2011 15:40:29 +0000 (17:40 +0200)
include/metaproxy/xmlutil.hpp
src/Makefile.am
src/filter_zoom.cpp
src/url_recipe.cpp [new file with mode: 0644]

index ab3556d..ff265ef 100644 (file)
@@ -51,6 +51,7 @@ namespace metaproxy_1 {
 
         void check_empty(const xmlNode *node);
 
+        void url_recipe_handle(xmlDoc *doc, std::string recipe);
     }
     class XMLError : public std::runtime_error {
     public:
index 0f756ea..903c637 100644 (file)
@@ -53,6 +53,7 @@ libmetaproxy_la_SOURCES = \
        sru_util.cpp sru_util.hpp \
        thread_pool_observer.cpp thread_pool_observer.hpp \
        torus.cpp torus.hpp \
+       url_recipe.cpp \
        util.cpp \
        xmlutil.cpp 
 
index 35512ca..39b5624 100644 (file)
@@ -23,6 +23,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #include <yaz/srw.h>
 #include <metaproxy/package.hpp>
 #include <metaproxy/util.hpp>
+#include <metaproxy/xmlutil.hpp>
 #include "torus.hpp"
 
 #include <libxslt/xsltutils.h>
@@ -60,6 +61,7 @@ namespace metaproxy_1 {
             std::string element_set;
             std::string record_encoding;
             std::string transform_xsl_fname;
+            std::string urlRecipe;
             bool use_turbomarc;
             bool piggyback;
             CCL_bibset ccl_bibset;
@@ -400,6 +402,11 @@ yf::Zoom::SearchablePtr yf::Zoom::Impl::parse_torus_record(const xmlNode *ptr)
             s->transform_xsl_fname = mp::xml::get_text(ptr);
         }
         else if (!strcmp((const char *) ptr->name,
+                         "urlRecipe"))
+        {
+            s->urlRecipe = mp::xml::get_text(ptr);
+        }
+        else if (!strcmp((const char *) ptr->name,
                          "useTurboMarc"))
         {
             ; // useTurboMarc is ignored
@@ -866,6 +873,12 @@ Z_Records *yf::Zoom::Frontend::get_records(Odr_int start,
 
                 if (rec_buf)
                 {
+                    xmlDoc *doc = xmlParseMemory(rec_buf, rec_len);
+                    mp::xml::url_recipe_handle(doc, b->sptr->urlRecipe);
+                    xmlFreeDoc(doc);
+                }
+                if (rec_buf)
+                {
                     npr = (Z_NamePlusRecord *) odr_malloc(odr, sizeof(*npr));
                     npr->databaseName = odr_database;
                     npr->which = Z_NamePlusRecord_databaseRecord;
diff --git a/src/url_recipe.cpp b/src/url_recipe.cpp
new file mode 100644 (file)
index 0000000..bba6a41
--- /dev/null
@@ -0,0 +1,101 @@
+/* This file is part of Metaproxy.
+   Copyright (C) 2005-2011 Index Data
+
+Metaproxy is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 2, or (at your option) any later
+version.
+
+Metaproxy 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 General Public License
+for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#include <metaproxy/xmlutil.hpp>
+
+#include <string.h>
+
+namespace mp = metaproxy_1;
+// Doxygen doesn't like mp::xml, so we use this instead
+namespace mp_xml = metaproxy_1::xml;
+
+void mp_xml::url_recipe_handle(xmlDoc *doc, std::string recipe)
+{
+    if (recipe.length() == 0)
+        return;
+    std::string result;
+
+    size_t p0 = 0, p1 = 0;
+    for (;;)
+    {
+        p1 = recipe.find_first_of("${", p0);
+        if (p1 == std::string::npos)
+        {
+            result += recipe.substr(p0);
+            break;
+        }
+        result += recipe.substr(p0, p1 - p0);
+
+        int step = 0;  // 0=variable, 1=pattern, 2=replacement, 3=mode
+        std::string variable;
+        std::string pattern;
+        std::string replacement;
+        std::string mode;
+        p0 = p1+2;
+        while (p0 < recipe.length() && step < 5)
+        {
+            char c = recipe[p0];
+            if (c == '}')
+                step = 5;
+            else if (step == 0)
+            {
+                if (c == '[')
+                    step = 1;
+                else
+                    variable += c;
+            }
+            else if (step == 1)
+            {
+                if (c == '/')
+                    step = 2;
+                else
+                    pattern += c;
+            }
+            else if (step == 2)
+            {
+                if (c == '/')
+                    step = 3;
+                else
+                    replacement += c;
+            }
+            else if (step == 3)
+            {
+                if (c == ']')
+                    step = 4;
+                else
+                    mode += c;
+            }
+            p0++;
+        }
+        if (variable.length())
+        {
+            ;
+        }
+    }
+}
+
+
+/*
+ * Local variables:
+ * c-basic-offset: 4
+ * c-file-style: "Stroustrup"
+ * indent-tabs-mode: nil
+ * End:
+ * vim: shiftwidth=4 tabstop=8 expandtab
+ */
+