From b64bbdad88b7c3a990dc7b224e2716fd96e92f78 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 31 Jan 2013 11:32:36 +0100 Subject: [PATCH] record_transform: allow OPACXML to OPAC conversion --- src/filter_record_transform.cpp | 51 +++++++++++++++++++++++++++++++++------ 1 file changed, 43 insertions(+), 8 deletions(-) diff --git a/src/filter_record_transform.cpp b/src/filter_record_transform.cpp index 9b14282..4218030 100644 --- a/src/filter_record_transform.cpp +++ b/src/filter_record_transform.cpp @@ -25,6 +25,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include #include #include +#include #include @@ -461,14 +462,16 @@ void yf::RecordTransform::Impl::process(mp::Package &package) const Z_NamePlusRecord *npr = records->records[i]; if (npr->which == Z_NamePlusRecord_databaseRecord) { + const char *details = 0; mp::wrbuf output_record; Z_External *r = npr->u.databaseRecord; - int ret_trans = 0; + int ret_trans = -1; if (r->which == Z_External_OPAC) { ret_trans = yaz_record_conv_opac_record(rc, r->u.opac, output_record); + details = yaz_record_conv_get_error(rc); } else if (r->which == Z_External_octet) { @@ -477,21 +480,53 @@ void yf::RecordTransform::Impl::process(mp::Package &package) const r->u.octet_aligned->buf, r->u.octet_aligned->len, output_record); + details = yaz_record_conv_get_error(rc); } - if (ret_trans == 0) + else { - npr->u.databaseRecord = - z_ext_record_oid(odr_en, match_syntax, - output_record.buf(), - output_record.len()); + details = "unsupported record type for record_conv"; } - else + if (ret_trans) { records->records[i] = zget_surrogateDiagRec( odr_en, npr->databaseName, YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS, - yaz_record_conv_get_error(rc)); + details); + } + else + { + if (!oid_oidcmp(match_syntax, yaz_oid_recsyn_opac)) + { + yaz_marc_t mt = yaz_marc_create(); + Z_OPACRecord *opac = 0; + if (yaz_xml_to_opac(mt, output_record.buf(), + output_record.len(), + &opac, 0 /* iconv */, + ((ODR )odr_en)->mem, 0) + && opac) + { + npr->u.databaseRecord = + z_ext_record_oid(odr_en, match_syntax, + (const char *) opac, -1); + } + else + { + records->records[i] = + zget_surrogateDiagRec( + odr_en, npr->databaseName, + YAZ_BIB1_SYSTEM_ERROR_IN_PRESENTING_RECORDS, + "XML to OPAC conversion failed"); + } + yaz_marc_destroy(mt); + } + else + { + npr->u.databaseRecord = + z_ext_record_oid(odr_en, match_syntax, + output_record.buf(), + output_record.len()); + } } } } -- 1.7.10.4