X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=recctrl%2Falvis.c;h=ec22ed700d7e5a04986755123d7be04ab06fd356;hb=66eb724d4e68e942529f4d356daa8b888a51d8c0;hp=d2a7abaa149d1fb2401675b10d78ab59bd3c954f;hpb=11b80ecf43b2c8bd1d376859e52ed6e61781b70c;p=idzebra-moved-to-github.git diff --git a/recctrl/alvis.c b/recctrl/alvis.c index d2a7aba..ec22ed7 100644 --- a/recctrl/alvis.c +++ b/recctrl/alvis.c @@ -1,4 +1,4 @@ -/* $Id: alvis.c,v 1.5 2005-08-19 21:40:17 adam Exp $ +/* $Id: alvis.c,v 1.15 2006-05-24 18:31:33 adam Exp $ Copyright (C) 1995-2005 Index Data ApS @@ -41,6 +41,7 @@ struct filter_schema { const char *stylesheet; struct filter_schema *next; const char *default_schema; + /* char default_schema; */ const char *include_snippet; xsltStylesheetPtr stylesheet_xsp; }; @@ -57,6 +58,9 @@ struct filter_info { #define ZEBRA_SCHEMA_XSLT_NS "http://indexdata.dk/zebra/xslt/1" +#define XML_STRCMP(a,b) strcmp((char*)a, b) +#define XML_STRLEN(a) strlen((char*)a) + static const char *zebra_xslt_ns = ZEBRA_SCHEMA_XSLT_NS; static void set_param_xml(const char **params, const char *name, @@ -93,9 +97,12 @@ static void set_param_int(const char **params, const char *name, params[2] = 0; } +#define ENABLE_INPUT_CALLBACK 0 + +#if ENABLE_INPUT_CALLBACK static int zebra_xmlInputMatchCallback (char const *filename) { - /* yaz_log(YLOG_LOG, "match %s", filename); */ + yaz_log(YLOG_LOG, "match %s", filename); return 0; } @@ -113,8 +120,9 @@ static int zebra_xmlInputCloseCallback (void * context) { return 0; } +#endif -static void *filter_init_xslt(Res res, RecType recType) +static void *filter_init(Res res, RecType recType) { struct filter_info *tinfo = (struct filter_info *) xmalloc(sizeof(*tinfo)); tinfo->reader = 0; @@ -125,7 +133,7 @@ static void *filter_init_xslt(Res res, RecType recType) tinfo->doc = 0; tinfo->schemas = 0; -#if 0 +#if ENABLE_INPUT_CALLBACK xmlRegisterDefaultInputCallbacks(); xmlRegisterInputCallbacks(zebra_xmlInputMatchCallback, zebra_xmlInputOpenCallback, @@ -138,10 +146,10 @@ static void *filter_init_xslt(Res res, RecType recType) static int attr_content(struct _xmlAttr *attr, const char *name, const char **dst_content) { - if (!strcmp(attr->name, name) && attr->children && + if (!XML_STRCMP(attr->name, name) && attr->children && attr->children->type == XML_TEXT_NODE) { - *dst_content = attr->children->content; + *dst_content = (const char *)(attr->children->content); return 1; } return 0; @@ -174,13 +182,13 @@ static ZEBRA_RES create_schemas(struct filter_info *tinfo, const char *fname) return ZEBRA_FAIL; ptr = xmlDocGetRootElement(tinfo->doc); if (!ptr || ptr->type != XML_ELEMENT_NODE || - strcmp(ptr->name, "schemaInfo")) + XML_STRCMP(ptr->name, "schemaInfo")) return ZEBRA_FAIL; for (ptr = ptr->children; ptr; ptr = ptr->next) { if (ptr->type != XML_ELEMENT_NODE) continue; - if (!strcmp(ptr->name, "schema")) + if (!XML_STRCMP(ptr->name, "schema")) { struct _xmlAttr *attr; struct filter_schema *schema = xmalloc(sizeof(*schema)); @@ -200,12 +208,19 @@ static ZEBRA_RES create_schemas(struct filter_info *tinfo, const char *fname) attr_content(attr, "default", &schema->default_schema); attr_content(attr, "snippet", &schema->include_snippet); } + /*yaz_log(YLOG_LOG, "XSLT add %s %s %s", + schema->name, schema->identifier, schema->stylesheet); */ + + /* find requested schema */ + if (schema->stylesheet) schema->stylesheet_xsp = xsltParseStylesheetFile( (const xmlChar*) schema->stylesheet); + + } - else if (!strcmp(ptr->name, "split")) + else if (!XML_STRCMP(ptr->name, "split")) { struct _xmlAttr *attr; for (attr = ptr->properties; attr; attr = attr->next) @@ -227,30 +242,40 @@ static struct filter_schema *lookup_schema(struct filter_info *tinfo, const char *est) { struct filter_schema *schema; + for (schema = tinfo->schemas; schema; schema = schema->next) - { - if (est) - { + { + /* find requested schema */ + if (est) + { if (schema->identifier && !strcmp(schema->identifier, est)) - return schema; + return schema; + if (schema->name && !strcmp(schema->name, est)) return schema; - } - if (schema->default_schema) + } + /* or return default schema if defined */ + else if (schema->default_schema) return schema; } + + /* return first schema if no default schema defined */ + if (tinfo->schemas) + return tinfo->schemas; + return 0; } -static void filter_config(void *clientData, Res res, const char *args) +static ZEBRA_RES filter_config(void *clientData, Res res, const char *args) { struct filter_info *tinfo = clientData; if (!args || !*args) - args = "xsltfilter.xml"; + return ZEBRA_FAIL; if (tinfo->fname && !strcmp(args, tinfo->fname)) - return; + return ZEBRA_OK; destroy_schemas(tinfo); create_schemas(tinfo, args); + return ZEBRA_OK; } static void filter_destroy(void *clientData) @@ -282,8 +307,8 @@ static void index_cdata(struct filter_info *tinfo, struct recExtractCtrl *ctrl, index_cdata(tinfo, ctrl, ptr->children, recWord); if (ptr->type != XML_TEXT_NODE) continue; - recWord->term_buf = ptr->content; - recWord->term_len = strlen(ptr->content); + recWord->term_buf = (const char *)ptr->content; + recWord->term_len = XML_STRLEN(ptr->content); (*ctrl->tokenAdd)(recWord); } } @@ -295,9 +320,9 @@ static void index_node(struct filter_info *tinfo, struct recExtractCtrl *ctrl, { index_node(tinfo, ctrl, ptr->children, recWord); if (ptr->type != XML_ELEMENT_NODE || !ptr->ns || - strcmp(ptr->ns->href, zebra_xslt_ns)) + XML_STRCMP(ptr->ns->href, zebra_xslt_ns)) continue; - if (!strcmp(ptr->name, "index")) + if (!XML_STRCMP(ptr->name, "index")) { const char *name_str = 0; const char *type_str = 0; @@ -328,8 +353,8 @@ static void index_record(struct filter_info *tinfo,struct recExtractCtrl *ctrl, xmlNodePtr ptr, RecWord *recWord) { if (ptr && ptr->type == XML_ELEMENT_NODE && ptr->ns && - !strcmp(ptr->ns->href, zebra_xslt_ns) - && !strcmp(ptr->name, "record")) + !XML_STRCMP(ptr->ns->href, zebra_xslt_ns) + && !XML_STRCMP(ptr->name, "record")) { const char *type_str = "update"; const char *id_str = 0; @@ -433,11 +458,11 @@ static int extract_split(struct filter_info *tinfo, struct recExtractCtrl *p) { xmlNodePtr ptr = xmlTextReaderExpand(tinfo->reader); xmlNodePtr ptr2 = xmlCopyNode(ptr, 1); - xmlDocPtr doc = xmlNewDoc("1.0"); + xmlDocPtr doc = xmlNewDoc((const xmlChar*) "1.0"); xmlDocSetRootElement(doc, ptr2); - return extract_doc(tinfo, p, doc); + return extract_doc(tinfo, p, doc); } ret = xmlTextReaderRead(tinfo->reader); } @@ -539,8 +564,9 @@ static const char *snippet_doc(struct recRetrieveCtrl *p, int text_mode, static int filter_retrieve (void *clientData, struct recRetrieveCtrl *p) { - const char *esn = zebra_xslt_ns; - const char *params[10]; + /* const char *esn = zebra_xslt_ns; */ + const char *esn = 0; + const char *params[32]; struct filter_info *tinfo = clientData; xmlDocPtr resDoc; xmlDocPtr doc; @@ -549,13 +575,18 @@ static int filter_retrieve (void *clientData, struct recRetrieveCtrl *p) if (p->comp) { - if (p->comp->which != Z_RecordComp_simple - || p->comp->u.simple->which != Z_ElementSetNames_generic) + if (p->comp->which == Z_RecordComp_simple + && p->comp->u.simple->which == Z_ElementSetNames_generic) + { + esn = p->comp->u.simple->u.generic; + } + else if (p->comp->which == Z_RecordComp_complex + && p->comp->u.complex->generic->elementSpec + && p->comp->u.complex->generic->elementSpec->which == + Z_ElementSpec_elementSetName) { - p->diagnostic = YAZ_BIB1_PRESENT_COMP_SPEC_PARAMETER_UNSUPP; - return 0; + esn = p->comp->u.complex->generic->elementSpec->u.elementSetName; } - esn = p->comp->u.simple->u.generic; } schema = lookup_schema(tinfo, esn); if (!schema) @@ -569,13 +600,25 @@ static int filter_retrieve (void *clientData, struct recRetrieveCtrl *p) window_size = atoi(schema->include_snippet); params[0] = 0; - set_param_str(params, "schema", esn, p->odr); + set_param_int(params, "id", p->localno, p->odr); if (p->fname) set_param_str(params, "filename", p->fname, p->odr); + if (p->staticrank >= 0) + set_param_int(params, "rank", p->staticrank, p->odr); + + if (esn) + set_param_str(params, "schema", esn, p->odr); + else + if (schema->name) + set_param_str(params, "schema", schema->name, p->odr); + else if (schema->identifier) + set_param_str(params, "schema", schema->identifier, p->odr); + else + set_param_str(params, "schema", "", p->odr); + if (p->score >= 0) set_param_int(params, "score", p->score, p->odr); set_param_int(params, "size", p->recordSize, p->odr); - set_param_int(params, "id", p->localno, p->odr); if (window_size >= 0) set_param_xml(params, "snippet", snippet_doc(p, 1, window_size), @@ -613,20 +656,23 @@ static int filter_retrieve (void *clientData, struct recRetrieveCtrl *p) { xmlChar *buf_out; int len_out; - xmlDocDumpMemory(resDoc, &buf_out, &len_out); + + xsltSaveResultToString(&buf_out, &len_out, resDoc, + schema->stylesheet_xsp); p->output_format = VAL_TEXT_XML; p->rec_len = len_out; p->rec_buf = odr_malloc(p->odr, p->rec_len); memcpy(p->rec_buf, buf_out, p->rec_len); - xmlFree(buf_out); } else if (p->output_format == VAL_SUTRS) { xmlChar *buf_out; int len_out; - xmlDocDumpMemory(resDoc, &buf_out, &len_out); + + xsltSaveResultToString(&buf_out, &len_out, resDoc, + schema->stylesheet_xsp); p->output_format = VAL_SUTRS; p->rec_len = len_out; @@ -643,10 +689,10 @@ static int filter_retrieve (void *clientData, struct recRetrieveCtrl *p) return 0; } -static struct recType filter_type_alvis = { +static struct recType filter_type = { 0, "alvis", - filter_init_xslt, + filter_init, filter_config, filter_destroy, filter_extract, @@ -661,6 +707,14 @@ idzebra_filter #endif [] = { - &filter_type_alvis, + &filter_type, 0, }; +/* + * Local variables: + * c-basic-offset: 4 + * indent-tabs-mode: nil + * End: + * vim: shiftwidth=4 tabstop=8 expandtab + */ +