/* This file is part of the Zebra server.
- Copyright (C) 1994-2011 Index Data
+ Copyright (C) 2004-2013 Index Data
Zebra 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
tinfo->schemas = 0;
#if YAZ_HAVE_EXSLT
- exsltRegisterAll();
+ exsltRegisterAll();
#endif
#if ENABLE_INPUT_CALLBACK
static int attr_content(struct _xmlAttr *attr, const char *name,
const char **dst_content)
{
- if (!XML_STRCMP(attr->name, name) && attr->children
+ if (!XML_STRCMP(attr->name, name) && attr->children
&& attr->children->type == XML_TEXT_NODE)
{
*dst_content = (const char *)(attr->children->content);
tinfo->schemas = 0;
xfree(tinfo->fname);
if (tinfo->doc)
- xmlFreeDoc(tinfo->doc);
+ xmlFreeDoc(tinfo->doc);
tinfo->doc = 0;
}
char tmp_full_name[1024];
xmlNodePtr ptr;
tinfo->fname = xstrdup(fname);
-
- if (yaz_filepath_resolve(tinfo->fname, tinfo->profile_path,
+
+ if (yaz_filepath_resolve(tinfo->fname, tinfo->profile_path,
NULL, tmp_full_name))
tinfo->full_name = xstrdup(tmp_full_name);
else
tinfo->full_name = xstrdup(tinfo->fname);
-
+
yaz_log(YLOG_LOG, "alvis filter: loading config file %s", tinfo->full_name);
-
+
tinfo->doc = xmlParseFile(tinfo->full_name);
-
+
if (!tinfo->doc)
{
- yaz_log(YLOG_WARN, "alvis filter: could not parse config file %s",
+ yaz_log(YLOG_WARN, "alvis filter: could not parse config file %s",
tinfo->full_name);
-
+
return ZEBRA_FAIL;
}
-
+
ptr = xmlDocGetRootElement(tinfo->doc);
- if (!ptr || ptr->type != XML_ELEMENT_NODE
+ if (!ptr || ptr->type != XML_ELEMENT_NODE
|| XML_STRCMP(ptr->name, "schemaInfo"))
{
- yaz_log(YLOG_WARN,
- "alvis filter: config file %s :"
- " expected root element <schemaInfo>",
- tinfo->full_name);
+ yaz_log(YLOG_WARN,
+ "alvis filter: config file %s :"
+ " expected root element <schemaInfo>",
+ tinfo->full_name);
return ZEBRA_FAIL;
}
if (ptr->type != XML_ELEMENT_NODE)
continue;
if (!XML_STRCMP(ptr->name, "schema"))
- {
+ {
struct _xmlAttr *attr;
struct filter_schema *schema = xmalloc(sizeof(*schema));
schema->name = 0;
attr_content(attr, "stylesheet", &schema->stylesheet);
attr_content(attr, "default", &schema->default_schema);
}
- /*yaz_log(YLOG_LOG, "XSLT add %s %s %s",
+ /*yaz_log(YLOG_LOG, "XSLT add %s %s %s",
schema->name, schema->identifier, schema->stylesheet); */
/* find requested schema */
if (schema->stylesheet)
{
char tmp_xslt_full_name[1024];
- if (!yaz_filepath_resolve(schema->stylesheet, tinfo->profile_path,
- NULL, tmp_xslt_full_name))
+ if (!yaz_filepath_resolve(schema->stylesheet, tinfo->profile_path,
+ NULL, tmp_xslt_full_name))
{
- yaz_log(YLOG_WARN,
+ yaz_log(YLOG_WARN,
"alvis filter: stylesheet %s not found in path %s",
schema->stylesheet, tinfo->profile_path);
return ZEBRA_FAIL;
}
- schema->stylesheet_xsp
+ schema->stylesheet_xsp
= xsltParseStylesheetFile((const xmlChar*) tmp_xslt_full_name);
if (!schema->stylesheet_xsp)
{
- yaz_log(YLOG_WARN,
- "alvis filter: could not parse xslt stylesheet %s",
+ yaz_log(YLOG_WARN,
+ "alvis filter: could not parse xslt stylesheet %s",
tmp_xslt_full_name);
return ZEBRA_FAIL;
}
{
const char *split_level_str = 0;
attr_content(attr, "level", &split_level_str);
- tinfo->split_level =
+ tinfo->split_level =
split_level_str ? atoi(split_level_str) : 0;
}
}
struct filter_schema *schema;
for (schema = tinfo->schemas; schema; schema = schema->next)
- {
+ {
/* find requested schema */
- if (est)
- {
+ if (est)
+ {
if (schema->identifier && !strcmp(schema->identifier, est))
return schema;
-
+
if (schema->name && !strcmp(schema->name, est))
return 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;
}
if (tinfo->fname && !strcmp(args, tinfo->fname))
return ZEBRA_OK;
-
+
tinfo->profile_path = res_get(res, "profilePath");
yaz_log(YLOG_LOG, "alvis filter: profilePath %s", tinfo->profile_path);
else if (!strcmp("delete", type_str))
yaz_log(YLOG_WARN, "alvis filter delete: to be implemented");
else
- yaz_log(YLOG_WARN, "alvis filter: unknown record type '%s'",
+ yaz_log(YLOG_WARN, "alvis filter: unknown record type '%s'",
type_str);
}
-
+
static int extract_doc(struct filter_info *tinfo, struct recExtractCtrl *p,
xmlDocPtr doc)
{
if (schema && schema->stylesheet_xsp)
{
xmlNodePtr root_ptr;
- xmlDocPtr resDoc =
+ xmlDocPtr resDoc =
xsltApplyStylesheet(schema->stylesheet_xsp,
doc, params);
if (p->flagShowRecords)
if (p->setStoreData)
(*p->setStoreData)(p, buf_out, len_out);
xmlFree(buf_out);
-
+
xmlFreeDoc(doc);
return RECCTRL_EXTRACT_OK;
}
xmlFreeTextReader(tinfo->reader);
tinfo->reader = xmlReaderForIO(ioread_ex, ioclose_ex,
p /* I/O handler */,
- 0 /* URL */,
+ 0 /* URL */,
0 /* encoding */,
XML_PARSE_XINCLUDE
| XML_PARSE_NOENT
{
xmlNodePtr ptr2 = xmlCopyNode(ptr, 1);
xmlDocPtr doc = xmlNewDoc((const xmlChar*) "1.0");
-
+
xmlDocSetRootElement(doc, ptr2);
-
+
return extract_doc(tinfo, p, doc);
}
else
if (!root)
return RECCTRL_EXTRACT_ERROR_GENERIC;
} */
-
+
return extract_doc(tinfo, p, doc);
}
else
{
esn = p->comp->u.simple->u.generic;
}
- else if (p->comp->which == Z_RecordComp_complex
+ 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_SYSTEM_ERROR_IN_PRESENTING_RECORDS;
}
- else if (!p->input_format
+ else if (!p->input_format
|| !oid_oidcmp(p->input_format, yaz_oid_recsyn_xml))
{
xmlChar *buf_out;
if (schema->stylesheet_xsp)
xsltSaveResultToString(&buf_out, &len_out, resDoc,
- schema->stylesheet_xsp);
+ schema->stylesheet_xsp);
else
- xmlDocDumpMemory(resDoc, &buf_out, &len_out);
+ xmlDocDumpMemory(resDoc, &buf_out, &len_out);
p->output_format = yaz_oid_recsyn_xml;
p->rec_len = len_out;
xsltSaveResultToString(&buf_out, &len_out, resDoc,
schema->stylesheet_xsp);
else
- xmlDocDumpMemory(resDoc, &buf_out, &len_out);
+ xmlDocDumpMemory(resDoc, &buf_out, &len_out);
p->output_format = yaz_oid_recsyn_sutrs;
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