to <xslt stylesheet="etc/pqf2pqf.xsl"/> 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
<?xml version="1.0"?>
-<!-- $Id: config-bytarget.xml,v 1.4 2006-11-29 13:00:53 marc Exp $ -->
+<!-- $Id: config-bytarget.xml,v 1.5 2006-12-01 12:37:26 marc Exp $ -->
<metaproxy xmlns="http://indexdata.com/metaproxy" version="1.0">
<start route="start"/>
<routes>
</route>
<route id="group1">
<filter type="query_rewrite">
- <xslt>pqf2pqf.xsl</xslt>
+ <xslt stylesheet="etc/pqf2pqf.xsl"/>
</filter>
<filter type="log">
<message>LoC</message>
<?xml version="1.0"?>
-<!-- $Id: config5.xml,v 1.6 2006-11-29 13:00:54 marc Exp $ -->
+<!-- $Id: config5.xml,v 1.7 2006-12-01 12:37:26 marc Exp $ -->
<!-- Uses dummy backend + query rewrite filter.. -->
<metaproxy xmlns="http://indexdata.com/metaproxy" version="1.0">
<start route="start"/>
<filename>my.log</filename>
</filter>
<filter type="query_rewrite">
- <xslt>pqf2pqf.xsl</xslt>
+ <xslt stylesheet="etc/pqf2pqf.xsl"/>
</filter>
<filter type="log">
<message>B</message>
-/* $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
#include "package.hpp"
#include "util.hpp"
+#include "xmlutil.hpp"
#include "filter_query_rewrite.hpp"
#include <yaz/zgdu.h>
{
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)
{
("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 <xslt stylesheet=\""
+ + fname
+ + "\"> 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
-/* $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
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
-/* $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 <string.h>
#include "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;
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;
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)
-/* $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
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);
# 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.
#
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" },