1 /* This file is part of the YAZ toolkit.
2 * Copyright (C) 1995-2008 Index Data
3 * See the file LICENSE for details.
7 * \brief Implements OPAC record display
15 #include <yaz/proto.h>
16 #include <yaz/marcdisp.h>
18 static void opac_element_str(WRBUF wrbuf, yaz_iconv_t cd,
19 int l, const char *elem,
25 wrbuf_puts(wrbuf, " ");
26 wrbuf_puts(wrbuf, "<");
27 wrbuf_puts(wrbuf, elem);
28 wrbuf_puts(wrbuf, ">");
29 wrbuf_iconv_puts_cdata(wrbuf, cd, data);
30 wrbuf_puts(wrbuf, "</");
31 wrbuf_puts(wrbuf, elem);
32 wrbuf_puts(wrbuf, ">\n");
36 static void opac_element_bool(WRBUF wrbuf, int l, const char *elem, int *data)
41 wrbuf_puts(wrbuf, " ");
42 wrbuf_puts(wrbuf, "<");
43 wrbuf_puts(wrbuf, elem);
45 wrbuf_puts(wrbuf, " value=\"1\"");
47 wrbuf_puts(wrbuf, " value=\"0\"");
48 wrbuf_puts(wrbuf, "/>\n");
52 void yaz_opac_decode_wrbuf(yaz_marc_t mt, Z_OPACRecord *r, WRBUF wrbuf)
55 yaz_iconv_t cd = yaz_marc_get_iconv(mt);
57 wrbuf_puts(wrbuf, "<opacRecord>\n");
58 if (r->bibliographicRecord)
60 Z_External *ext = r->bibliographicRecord;
62 wrbuf_puts(wrbuf, " <bibliographicRecord>\n");
63 if (ext->which == Z_External_octet)
64 yaz_marc_decode_wrbuf(mt, (const char *) ext->u.octet_aligned->buf,
65 ext->u.octet_aligned->len, wrbuf);
66 wrbuf_puts(wrbuf, " </bibliographicRecord>\n");
68 wrbuf_puts(wrbuf, "<holdings>\n");
70 for (i = 0; i < r->num_holdingsData; i++)
72 Z_HoldingsRecord *h = r->holdingsData[i];
73 wrbuf_puts(wrbuf, " <holding>\n");
75 if (h->which == Z_HoldingsRecord_marcHoldingsRecord)
77 Z_External *ext = h->u.marcHoldingsRecord;
79 wrbuf_puts(wrbuf, " <marcHoldingsRecord>\n");
80 if (ext->which == Z_External_octet)
81 yaz_marc_decode_wrbuf(mt, (const char *)
82 ext->u.octet_aligned->buf,
83 ext->u.octet_aligned->len, wrbuf);
84 wrbuf_puts(wrbuf, " </marcHoldingsRecord>\n");
86 else if (h->which == Z_HoldingsRecord_holdingsAndCirc)
90 Z_HoldingsAndCircData *d = h->u.holdingsAndCirc;
92 opac_element_str(wrbuf, cd, 2, "typeOfRecord", d->typeOfRecord);
93 opac_element_str(wrbuf, cd, 2, "encodingLevel", d->encodingLevel);
94 opac_element_str(wrbuf, cd, 2, "format", d->format);
95 opac_element_str(wrbuf, cd, 2, "receiptAcqStatus", d->receiptAcqStatus);
96 opac_element_str(wrbuf, cd, 2, "generalRetention", d->generalRetention);
97 opac_element_str(wrbuf, cd, 2, "completeness", d->completeness);
98 opac_element_str(wrbuf, cd, 2, "dateOfReport", d->dateOfReport);
99 opac_element_str(wrbuf, cd, 2, "nucCode", d->nucCode);
100 opac_element_str(wrbuf, cd, 2, "localLocation", d->localLocation);
101 opac_element_str(wrbuf, cd, 2, "shelvingLocation", d->shelvingLocation);
102 opac_element_str(wrbuf, cd, 2, "callNumber", d->callNumber);
103 opac_element_str(wrbuf, cd, 2, "shelvingData", d->shelvingData);
105 opac_element_str(wrbuf, cd, 2, "copyNumber", d->copyNumber);
106 opac_element_str(wrbuf, cd, 2, "publicNote", d->publicNote);
107 opac_element_str(wrbuf, cd, 2, "reproductionNote", d->reproductionNote);
108 opac_element_str(wrbuf, cd, 2, "termsUseRepro", d->termsUseRepro);
109 opac_element_str(wrbuf, cd, 2, "enumAndChron", d->enumAndChron);
112 wrbuf_puts (wrbuf, " <volumes>\n");
113 for (j = 0; j<d->num_volumes; j++)
115 wrbuf_puts (wrbuf, " <volume>\n");
116 opac_element_str(wrbuf, cd, 4, "enumeration",
117 d->volumes[j]->enumeration);
118 opac_element_str(wrbuf, cd, 4, "chronology",
119 d->volumes[j]->chronology);
120 opac_element_str(wrbuf, cd, 4, "enumAndChron",
121 d->volumes[j]->enumAndChron);
122 wrbuf_puts(wrbuf, " </volume>\n");
124 wrbuf_puts(wrbuf, " </volumes>\n");
126 if (d->num_circulationData)
128 wrbuf_puts (wrbuf, " <circulations>\n");
129 for (j = 0; j<d->num_circulationData; j++)
131 wrbuf_puts(wrbuf," <circulation>\n");
132 opac_element_bool(wrbuf, 4, "availableNow",
133 d->circulationData[j]->availableNow);
134 opac_element_str(wrbuf, cd, 4, "availabiltyDate",
135 d->circulationData[j]->availablityDate);
136 opac_element_str(wrbuf, cd, 4, "availableThru",
137 d->circulationData[j]->availableThru);
138 opac_element_str(wrbuf, cd, 4, "restrictions",
139 d->circulationData[j]->restrictions);
140 opac_element_str(wrbuf, cd, 4, "itemId",
141 d->circulationData[j]->itemId);
142 opac_element_bool(wrbuf, 4, "renewable",
143 d->circulationData[j]->renewable);
144 opac_element_bool(wrbuf, 4, "onHold",
145 d->circulationData[j]->onHold);
146 opac_element_str(wrbuf, cd, 4, "enumAndChron",
147 d->circulationData[j]->enumAndChron);
148 opac_element_str(wrbuf, cd, 4, "midspine",
149 d->circulationData[j]->midspine);
150 opac_element_str(wrbuf, cd, 4, "temporaryLocation",
151 d->circulationData[j]->temporaryLocation);
152 wrbuf_puts(wrbuf, " </circulation>\n");
154 wrbuf_puts(wrbuf, " </circulations>\n");
157 wrbuf_puts(wrbuf, " </holding>\n");
159 wrbuf_puts(wrbuf, "</holdings>\n");
160 wrbuf_puts(wrbuf, "</opacRecord>\n");
163 void yaz_display_OPAC(WRBUF wrbuf, Z_OPACRecord *opac_rec, int flags)
165 yaz_marc_t mt = yaz_marc_create();
167 yaz_marc_xml(mt, YAZ_MARC_MARCXML);
168 yaz_opac_decode_wrbuf(mt, opac_rec, wrbuf);
169 yaz_marc_destroy(mt);
175 * indent-tabs-mode: nil
177 * vim: shiftwidth=4 tabstop=8 expandtab