Allow stylesheet to be given for sru_z3950 filter MP-510
authorAdam Dickmeiss <adam@indexdata.dk>
Mon, 3 Feb 2014 12:31:43 +0000 (13:31 +0100)
committerAdam Dickmeiss <adam@indexdata.dk>
Mon, 3 Feb 2014 12:31:43 +0000 (13:31 +0100)
This is based on a patch by Sven Porst and the functionality
of the YAZ Generic Frontend Server.

doc/sru_z3950.xml
etc/config-sru-to-z3950.xml
src/filter_sru_to_z3950.cpp
src/filter_zeerex_explain.cpp
src/sru_util.cpp
src/sru_util.hpp
xml/schema/filter_sru_z3950.rnc

index df973ed..f9bc256 100644 (file)
    for more information.
   </para>
   <para>
+   Optionally the default stylesheet may be specified. If the client
+   do not specify a stylesheet, the CDATA of element
+   <literal>stylesheet</literal> is used.
+  </para>
+  <para>
    All Z39.50 packages and all HTTP packages that do not resolve to
    one configured database name are passed unaltered to the next
    filters on the route.
    A typical configuration looks like this:
    <screen><![CDATA[
     <filter type="sru_z3950">
+      <stylesheet>/my.xsl</stylesheet>
       <database name="Default">
         <explain xmlns="http://explain.z3950.org/dtd/2.0/">
           ...
index ff681b0..d0d0755 100644 (file)
@@ -9,6 +9,7 @@
       <port>@:9000</port>
     </filter>
     <filter id="sru" type="sru_z3950">
+      <stylesheet>/my.xsl</stylesheet>
       <database name="Default">
        <xi:include xmlns:xi="http://www.w3.org/2001/XInclude"
                     href="../etc/explain.xml"/>
index 3e050ef..fa12345 100644 (file)
@@ -63,6 +63,7 @@ namespace metaproxy_1 {
             FrontendPtr get_frontend(mp::Package &package);
             void release_frontend(mp::Package &package);
             std::map<std::string, const xmlNode *> m_database_explain;
+            std::string default_stylesheet;
 
             typedef std::map<std::string, int> ActiveUrlMap;
 
@@ -151,27 +152,40 @@ void yf::SRUtoZ3950::Impl::configure(const xmlNode *confignode)
         if (dbnode->type != XML_ELEMENT_NODE)
             continue;
 
-        std::string database;
-        mp::xml::check_element_mp(dbnode, "database");
-
-        for (struct _xmlAttr *attr = dbnode->properties;
-             attr; attr = attr->next)
+        if (!strcmp((const char *) dbnode->name, "database"))
         {
+            std::string database;
 
-            mp::xml::check_attribute(attr, "", "name");
-            database = mp::xml::get_text(attr);
-
-            const xmlNode *explainnode;
-            for (explainnode = dbnode->children;
-                 explainnode; explainnode = explainnode->next)
+            for (struct _xmlAttr *attr = dbnode->properties;
+                 attr; attr = attr->next)
             {
-                if (explainnode->type != XML_ELEMENT_NODE)
-                    continue;
-                if (explainnode)
-                    break;
+                mp::xml::check_attribute(attr, "", "name");
+                database = mp::xml::get_text(attr);
+
+                const xmlNode *explainnode;
+                for (explainnode = dbnode->children;
+                     explainnode; explainnode = explainnode->next)
+                {
+                    if (explainnode->type == XML_ELEMENT_NODE)
+                    {
+                        m_database_explain.insert(
+                            std::make_pair(database, explainnode));
+                        break;
+                    }
+                }
             }
-            // assigning explain node to database name - no check yet
-            m_database_explain.insert(std::make_pair(database, explainnode));
+        }
+        else if (!strcmp((const char *) dbnode->name, "stylesheet"))
+        {
+            default_stylesheet = mp::xml::get_text(dbnode);
+        }
+        else
+        {
+            throw mp::filter::FilterException
+                ("Bad element "
+                 + std::string((const char *) dbnode->name)
+                 + " in sru_z3950"
+                    );
         }
     }
 }
@@ -201,12 +215,12 @@ void yf::SRUtoZ3950::Impl::sru(mp::Package &package, Z_GDU *zgdu_req)
     // decode SRU request
     Z_SOAP *soap = 0;
     char *charset = 0;
-    char *stylesheet = 0;
+    const char *stylesheet = 0;
 
     // filter acts as sink for non-valid SRU requests
     if (! (sru_pdu_req = mp_util::decode_sru_request(package, odr_de, odr_en,
                                                      sru_pdu_res, &soap,
-                                                     charset, stylesheet)))
+                                                     charset)))
     {
         if (soap)
         {
@@ -267,6 +281,8 @@ void yf::SRUtoZ3950::Impl::sru(mp::Package &package, Z_GDU *zgdu_req)
     if (sru_pdu_req->which == Z_SRW_explain_request)
     {
         Z_SRW_explainRequest *er_req = sru_pdu_req->u.explain_request;
+        stylesheet = er_req->stylesheet;
+
         mp_util::build_sru_explain(package, odr_en, sru_pdu_res,
                                    sruinfo, explainnode, er_req);
     }
@@ -274,6 +290,7 @@ void yf::SRUtoZ3950::Impl::sru(mp::Package &package, Z_GDU *zgdu_req)
              && sru_pdu_req->u.request)
     {   // searchRetrieve
         Z_SRW_searchRetrieveRequest *sr_req = sru_pdu_req->u.request;
+        stylesheet = sr_req->stylesheet;
 
         sru_pdu_res = yaz_srw_get_pdu(odr_en, Z_SRW_searchRetrieve_response,
                                       sru_pdu_req->srw_version);
@@ -305,6 +322,7 @@ void yf::SRUtoZ3950::Impl::sru(mp::Package &package, Z_GDU *zgdu_req)
     {
         sru_pdu_res = yaz_srw_get_pdu(odr_en, Z_SRW_scan_response,
                                       sru_pdu_req->srw_version);
+        stylesheet = sru_pdu_req->u.scan_request->stylesheet;
 
         // we do not do scan at the moment, therefore issuing a diagnostic
         yaz_add_srw_diagnostic(odr_en,
@@ -339,6 +357,8 @@ void yf::SRUtoZ3950::Impl::sru(mp::Package &package, Z_GDU *zgdu_req)
                 odr_strdup(odr_en, wrbuf_cstr(w));
         }
     }
+    if (!stylesheet && default_stylesheet.length())
+        stylesheet = default_stylesheet.c_str();
 
     // build and send SRU response
     mp_util::build_sru_response(package, odr_en, soap,
index 3436135..c628c89 100644 (file)
@@ -153,7 +153,7 @@ void yf::ZeeRexExplain::Impl::process(mp::Package &package)
     char *stylesheet = 0;
     if (! (sru_pdu_req = mp_util::decode_sru_request(package, odr_de, odr_en,
                                             sru_pdu_res, &soap,
-                                            charset, stylesheet)))
+                                            charset)))
     {
         mp_util::build_sru_explain(package, odr_en, sru_pdu_res,
                                    sruinfo, explainnode);
index 92dabd2..5ce98f7 100644 (file)
@@ -229,8 +229,7 @@ Z_SRW_PDU * mp_util::decode_sru_request(mp::Package &package,
                                         mp::odr &odr_en,
                                         Z_SRW_PDU *sru_pdu_res,
                                         Z_SOAP **soap,
-                                        char *charset,
-                                        char *stylesheet)
+                                        char *charset)
 {
     Z_GDU *zgdu_req = package.request().get();
     Z_SRW_PDU *sru_pdu_req = 0;
index 703fb65..38eabb9 100644 (file)
@@ -76,8 +76,7 @@ namespace metaproxy_1 {
                                        metaproxy_1::odr &odr_en,
                                        Z_SRW_PDU *sru_pdu_res,
                                        Z_SOAP **soap,
-                                       char *charset,
-                                       char *stylesheet);
+                                       char *charset);
 
         bool check_sru_query_exists(metaproxy_1::Package &package,
                                     metaproxy_1::odr &odr_en,
index bd1d24a..60dc133 100644 (file)
@@ -6,6 +6,7 @@ filter_sru_z3950 =
   attribute type { "sru_z3950" },
   attribute id { xsd:NCName }?,
   attribute name { xsd:NCName }?,
+  element mp:stylesheet { xsd:string }?,
   element mp:database {  
      attribute name { xsd:NCName },
      any