X-Git-Url: http://lists.indexdata.com/cgi-bin?a=blobdiff_plain;f=src%2Ffilter_query_rewrite.cpp;h=eafd89523644807c2b80d3caeb3f8ae7748fe994;hb=0264192f26c10308aad161983ea29568c96521a6;hp=e63cc62b1424f464f809640b3f016952a4b70541;hpb=0a9ca76b43522ed5bf45f220e93b8679084098cd;p=metaproxy-moved-to-github.git diff --git a/src/filter_query_rewrite.cpp b/src/filter_query_rewrite.cpp index e63cc62..eafd895 100644 --- a/src/filter_query_rewrite.cpp +++ b/src/filter_query_rewrite.cpp @@ -1,15 +1,30 @@ -/* $Id: filter_query_rewrite.cpp,v 1.5 2006-03-16 09:38:33 adam Exp $ - Copyright (c) 2005, Index Data. +/* $Id: filter_query_rewrite.cpp,v 1.11 2007-05-09 21:23:09 adam Exp $ + Copyright (c) 2005-2007, Index Data. -%LICENSE% - */ +This file is part of Metaproxy. + +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 Metaproxy; see the file LICENSE. If not, write to the +Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA +02111-1307, USA. + */ #include "config.hpp" #include "filter.hpp" #include "package.hpp" #include "util.hpp" +#include "xmlutil.hpp" #include "filter_query_rewrite.hpp" #include @@ -19,15 +34,16 @@ #include #include -namespace yf = yp2::filter; +namespace mp = metaproxy_1; +namespace yf = mp::filter; -namespace yp2 { +namespace metaproxy_1 { namespace filter { class QueryRewrite::Rep { public: Rep(); ~Rep(); - void process(yp2::Package &package) const; + void process(mp::Package &package) const; void configure(const xmlNode * ptr); private: xsltStylesheetPtr m_stylesheet; @@ -54,17 +70,17 @@ yf::QueryRewrite::~QueryRewrite() { // must have a destructor because of boost::scoped_ptr } -void yf::QueryRewrite::process(yp2::Package &package) const +void yf::QueryRewrite::process(mp::Package &package) const { m_p->process(package); } -void yp2::filter::QueryRewrite::configure(const xmlNode *ptr) +void mp::filter::QueryRewrite::configure(const xmlNode *ptr) { m_p->configure(ptr); } -void yf::QueryRewrite::Rep::process(yp2::Package &package) const +void yf::QueryRewrite::Rep::process(mp::Package &package) const { Z_GDU *gdu = package.request().get(); @@ -75,7 +91,7 @@ void yf::QueryRewrite::Rep::process(yp2::Package &package) const { int error_code = 0; const char *addinfo = 0; - yp2::odr odr; + mp::odr odr; Z_SearchRequest *req = apdu_req->u.searchRequest; xmlDocPtr doc_input = 0; @@ -120,33 +136,49 @@ void yf::QueryRewrite::Rep::process(yp2::Package &package) const package.move(); } -void yp2::filter::QueryRewrite::Rep::configure(const xmlNode *ptr) +void mp::filter::QueryRewrite::Rep::configure(const xmlNode *ptr) { for (ptr = ptr->children; ptr; ptr = ptr->next) { 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) { - throw yp2::filter::FilterException + throw mp::filter::FilterException ("Only one xslt element allowed in query_rewrite filter"); } - std::string fname = yp2::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 yp2::filter::FilterException - ("Failed to read stylesheet " + throw mp::filter::FilterException + ("Failed to read XSLT stylesheet '" + fname - + " in query_rewrite filter"); + + "' in query_rewrite filter"); } } else { - throw yp2::filter::FilterException + throw mp::filter::FilterException ("Bad element " + std::string((const char *) ptr->name) + " in query_rewrite filter"); @@ -154,15 +186,15 @@ void yp2::filter::QueryRewrite::Rep::configure(const xmlNode *ptr) } } -static yp2::filter::Base* filter_creator() +static mp::filter::Base* filter_creator() { - return new yp2::filter::QueryRewrite; + return new mp::filter::QueryRewrite; } extern "C" { - struct yp2_filter_struct yp2_filter_query_rewrite = { + struct metaproxy_1_filter_struct metaproxy_1_filter_query_rewrite = { 0, - "query-rewrite", + "query_rewrite", filter_creator }; }