From: Marc Cromme Date: Fri, 1 Dec 2006 12:37:26 +0000 (+0000) Subject: changed filter query rewrite config syntax from pqf2pqf.xsl X-Git-Tag: METAPROXY.1.0.8~65 X-Git-Url: http://git.indexdata.com/?a=commitdiff_plain;h=240aff30845f7c20874ec9ee4115f3d7ea2a597e;p=metaproxy-moved-to-github.git changed filter query rewrite config syntax from pqf2pqf.xsl to to make it equal to YAZ retrievalinfo syntax. changed config files path from 'pqf2pqf.xsl' to 'etc/pqf2pqf.xsl' to make metaproxy run when started from metaproxy cvs root dir --- diff --git a/etc/config-bytarget.xml b/etc/config-bytarget.xml index a40446d..8a5d6c4 100644 --- a/etc/config-bytarget.xml +++ b/etc/config-bytarget.xml @@ -1,5 +1,5 @@ - + @@ -34,7 +34,7 @@ - pqf2pqf.xsl + LoC diff --git a/etc/config5.xml b/etc/config5.xml index 185fa36..c1e4722 100644 --- a/etc/config5.xml +++ b/etc/config5.xml @@ -1,5 +1,5 @@ - + @@ -16,7 +16,7 @@ my.log - pqf2pqf.xsl + B diff --git a/src/filter_query_rewrite.cpp b/src/filter_query_rewrite.cpp index fa50707..7b3940d 100644 --- a/src/filter_query_rewrite.cpp +++ b/src/filter_query_rewrite.cpp @@ -1,4 +1,4 @@ -/* $Id: filter_query_rewrite.cpp,v 1.8 2006-06-10 14:29:12 adam Exp $ +/* $Id: filter_query_rewrite.cpp,v 1.9 2006-12-01 12:37:26 marc Exp $ Copyright (c) 2005-2006, Index Data. See the LICENSE file for details @@ -10,6 +10,7 @@ #include "package.hpp" #include "util.hpp" +#include "xmlutil.hpp" #include "filter_query_rewrite.hpp" #include @@ -127,7 +128,8 @@ void mp::filter::QueryRewrite::Rep::configure(const xmlNode *ptr) { if (ptr->type != XML_ELEMENT_NODE) continue; - if (!strcmp((const char *) ptr->name, "xslt")) + + if (mp::xml::check_element_mp(ptr, "xslt")) { if (m_stylesheet) { @@ -135,14 +137,29 @@ void mp::filter::QueryRewrite::Rep::configure(const xmlNode *ptr) ("Only one xslt element allowed in query_rewrite filter"); } - std::string fname = mp::xml::get_text(ptr); + std::string fname;// = mp::xml::get_text(ptr); + + for (struct _xmlAttr *attr = ptr->properties; + attr; attr = attr->next) + { + mp::xml::check_attribute(attr, "", "stylesheet"); + fname = mp::xml::get_text(attr); + } + + if (0 == fname.size()) + throw mp::filter::FilterException + ("Attribute needs XSLT stylesheet path content" + + " in query_rewrite filter"); + m_stylesheet = xsltParseStylesheetFile(BAD_CAST fname.c_str()); if (!m_stylesheet) { throw mp::filter::FilterException - ("Failed to read stylesheet " + ("Failed to read XSLT stylesheet '" + fname - + " in query_rewrite filter"); + + "' in query_rewrite filter"); } } else diff --git a/src/metaproxy_prog.cpp b/src/metaproxy_prog.cpp index 721a02e..d2638b2 100644 --- a/src/metaproxy_prog.cpp +++ b/src/metaproxy_prog.cpp @@ -1,4 +1,4 @@ -/* $Id: metaproxy_prog.cpp,v 1.7 2006-11-29 22:37:08 marc Exp $ +/* $Id: metaproxy_prog.cpp,v 1.8 2006-12-01 12:37:26 marc Exp $ Copyright (c) 2005-2006, Index Data. See the LICENSE file for details @@ -73,9 +73,8 @@ int main(int argc, char **argv) std::exit(1); } // and perform Xinclude then - if (xmlXIncludeProcess(doc) <= 0) { - std::cerr << "XInclude processing failed\n"; - std::exit(1); + if (xmlXIncludeProcess(doc) > 0) { + std::cerr << "processing XInclude directive\n"; } } else diff --git a/src/xmlutil.cpp b/src/xmlutil.cpp index 6356f60..6fc8f13 100644 --- a/src/xmlutil.cpp +++ b/src/xmlutil.cpp @@ -1,18 +1,27 @@ -/* $Id: xmlutil.cpp,v 1.10 2006-11-29 13:00:54 marc Exp $ +/* $Id: xmlutil.cpp,v 1.11 2006-12-01 12:37:26 marc Exp $ Copyright (c) 2005-2006, Index Data. See the LICENSE file for details */ -#include #include "xmlutil.hpp" +#include + + namespace mp = metaproxy_1; // Doxygen doesn't like mp::xml, so we use this instead namespace mp_xml = metaproxy_1::xml; static const std::string metaproxy_ns = "http://indexdata.com/metaproxy"; +std::string mp_xml::get_text(const struct _xmlAttr *ptr) +{ + if (ptr->children->type == XML_TEXT_NODE) + return std::string((const char *) (ptr->children->content)); + return std::string(); +} + std::string mp_xml::get_text(const xmlNode *ptr) { std::string c; @@ -43,6 +52,45 @@ int mp_xml::get_int(const xmlNode *ptr, int default_value) return default_value; } +bool mp_xml::check_attribute(const _xmlAttr *ptr, + const std::string &ns, + const std::string &name) +{ + + if (!mp::xml::is_attribute(ptr, ns, name)) + { + std::string got_attr = "'"; + if (ptr && ptr->name) + got_attr += std::string((const char *)ptr->name); + if (ns.size() && ptr && ptr->ns && ptr->ns->href){ + got_attr += " "; + got_attr += std::string((const char *)ptr->ns->href); + } + got_attr += "'"; + + throw mp::XMLError("Expected XML attribute '" + name + + " " + ns + "'" + + ", not " + got_attr); + } + return true; +} + +bool mp_xml::is_attribute(const _xmlAttr *ptr, + const std::string &ns, + const std::string &name) +{ + if (0 != xmlStrcmp(BAD_CAST name.c_str(), ptr->name)) + return false; + + if (ns.size() + && (!ptr->ns || !ptr->ns->href + || 0 != xmlStrcmp(BAD_CAST ns.c_str(), ptr->ns->href))) + return false; + + return true; +} + + bool mp_xml::is_element(const xmlNode *ptr, const std::string &ns, const std::string &name) diff --git a/src/xmlutil.hpp b/src/xmlutil.hpp index bfab08c..0fe0878 100644 --- a/src/xmlutil.hpp +++ b/src/xmlutil.hpp @@ -1,4 +1,4 @@ -/* $Id: xmlutil.hpp,v 1.9 2006-11-29 13:00:54 marc Exp $ +/* $Id: xmlutil.hpp,v 1.10 2006-12-01 12:37:26 marc Exp $ Copyright (c) 2005-2006, Index Data. See the LICENSE file for details @@ -13,9 +13,16 @@ namespace metaproxy_1 { namespace xml { + std::string get_text(const struct _xmlAttr *ptr); std::string get_text(const xmlNode *ptr); bool get_bool(const xmlNode *ptr, bool default_value); int get_int(const xmlNode *ptr, int default_value); + bool check_attribute(const _xmlAttr *ptr, + const std::string &ns, + const std::string &name); + bool is_attribute(const _xmlAttr *ptr, + const std::string &ns, + const std::string &name); bool is_element(const xmlNode *ptr, const std::string &ns, const std::string &name); diff --git a/xml/schema/metaproxy.rnc b/xml/schema/metaproxy.rnc index 4757eef..56f403d 100644 --- a/xml/schema/metaproxy.rnc +++ b/xml/schema/metaproxy.rnc @@ -1,5 +1,5 @@ # Metaproxy XML config file schemas -# $Id: metaproxy.rnc,v 1.10 2006-11-30 23:10:26 marc Exp $ +# $Id: metaproxy.rnc,v 1.11 2006-12-01 12:37:26 marc Exp $ # # Copyright (c) 2005-2006, Index Data. # @@ -127,7 +127,9 @@ filter_query_rewrite = attribute type { "query_rewrite" }, attribute id { xsd:NCName }?, attribute name { xsd:NCName }?, - element mp:xslt { xsd:string } + element mp:xslt { + attribute stylesheet { xsd:string } + } filter_record_transform = attribute type { "record_transform" },