From: Adam Dickmeiss Date: Mon, 3 Feb 2014 12:31:43 +0000 (+0100) Subject: Allow stylesheet to be given for sru_z3950 filter MP-510 X-Git-Tag: v1.4.4~5 X-Git-Url: http://lists.indexdata.dk/?a=commitdiff_plain;h=36124975217061b8fb61e5bafb18accee24dba53;p=metaproxy-moved-to-github.git Allow stylesheet to be given for sru_z3950 filter MP-510 This is based on a patch by Sven Porst and the functionality of the YAZ Generic Frontend Server. --- diff --git a/doc/sru_z3950.xml b/doc/sru_z3950.xml index df973ed..f9bc256 100644 --- a/doc/sru_z3950.xml +++ b/doc/sru_z3950.xml @@ -41,6 +41,11 @@ for more information. + Optionally the default stylesheet may be specified. If the client + do not specify a stylesheet, the CDATA of element + stylesheet is used. + + 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. @@ -123,6 +128,7 @@ A typical configuration looks like this: + /my.xsl ... diff --git a/etc/config-sru-to-z3950.xml b/etc/config-sru-to-z3950.xml index ff681b0..d0d0755 100644 --- a/etc/config-sru-to-z3950.xml +++ b/etc/config-sru-to-z3950.xml @@ -9,6 +9,7 @@ @:9000 + /my.xsl diff --git a/src/filter_sru_to_z3950.cpp b/src/filter_sru_to_z3950.cpp index 3e050ef..fa12345 100644 --- a/src/filter_sru_to_z3950.cpp +++ b/src/filter_sru_to_z3950.cpp @@ -63,6 +63,7 @@ namespace metaproxy_1 { FrontendPtr get_frontend(mp::Package &package); void release_frontend(mp::Package &package); std::map m_database_explain; + std::string default_stylesheet; typedef std::map 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, diff --git a/src/filter_zeerex_explain.cpp b/src/filter_zeerex_explain.cpp index 3436135..c628c89 100644 --- a/src/filter_zeerex_explain.cpp +++ b/src/filter_zeerex_explain.cpp @@ -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); diff --git a/src/sru_util.cpp b/src/sru_util.cpp index 92dabd2..5ce98f7 100644 --- a/src/sru_util.cpp +++ b/src/sru_util.cpp @@ -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; diff --git a/src/sru_util.hpp b/src/sru_util.hpp index 703fb65..38eabb9 100644 --- a/src/sru_util.hpp +++ b/src/sru_util.hpp @@ -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, diff --git a/xml/schema/filter_sru_z3950.rnc b/xml/schema/filter_sru_z3950.rnc index bd1d24a..60dc133 100644 --- a/xml/schema/filter_sru_z3950.rnc +++ b/xml/schema/filter_sru_z3950.rnc @@ -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