java script mime type added to the list of allowed mime types to be served by YAZ...
[yaz-moved-to-github.git] / src / opacdisp.c
1 /*
2  * Copyright (C) 1995-2005, Index Data ApS
3  * See the file LICENSE for details.
4  *
5  * $Id: opacdisp.c,v 1.8 2005-08-22 20:34:21 adam Exp $
6  */
7 /**
8  * \file opacdisp.c
9  * \brief Implements OPAC record display
10  */
11
12 #include <stdio.h>
13 #include <string.h>
14 #include <stdlib.h>
15 #include <ctype.h>
16
17 #include <yaz/proto.h>
18 #include <yaz/marcdisp.h>
19
20 static void opac_element_str(WRBUF wrbuf, int l, const char *elem,
21                              const char *data)
22 {
23     if (data)
24     {
25         while (--l >= 0)
26             wrbuf_puts(wrbuf, " ");
27         wrbuf_puts(wrbuf, "<");
28         wrbuf_puts(wrbuf, elem);
29         wrbuf_puts(wrbuf, ">");
30         wrbuf_xmlputs(wrbuf, data);
31         wrbuf_puts(wrbuf, "</");
32         wrbuf_puts(wrbuf, elem);
33         wrbuf_puts(wrbuf, ">\n");
34     }
35 }
36
37 static void opac_element_bool(WRBUF wrbuf, int l, const char *elem, int *data)
38 {
39     if (data)
40     {
41         while (--l >= 0)
42             wrbuf_puts(wrbuf, " ");
43         wrbuf_puts(wrbuf, "<");
44         wrbuf_puts(wrbuf, elem);
45         if (*data)
46             wrbuf_puts(wrbuf, " value=\"1\"");
47         else
48             wrbuf_puts(wrbuf, " value=\"0\"");
49         wrbuf_puts(wrbuf, "/>\n");
50     }
51 }
52
53 void yaz_opac_decode_wrbuf(yaz_marc_t mt, Z_OPACRecord *r, WRBUF wrbuf)
54 {
55     int i;
56
57     wrbuf_puts(wrbuf, "<opacRecord>\n");
58     if (r->bibliographicRecord)
59     {
60         Z_External *ext = r->bibliographicRecord;
61         
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");
67     }
68     wrbuf_puts(wrbuf, "<holdings>\n");
69
70     for (i = 0; i < r->num_holdingsData; i++)
71     {
72         Z_HoldingsRecord *h = r->holdingsData[i];
73         wrbuf_puts(wrbuf, " <holding>\n");
74
75         if (h->which == Z_HoldingsRecord_marcHoldingsRecord)
76         {
77             Z_External *ext = h->u.marcHoldingsRecord;
78
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");
85         }
86         else if (h->which == Z_HoldingsRecord_holdingsAndCirc)
87         {
88             int j;
89             
90             Z_HoldingsAndCircData *d = h->u.holdingsAndCirc;
91         
92             opac_element_str(wrbuf, 2, "typeOfRecord", d->typeOfRecord);
93             opac_element_str(wrbuf, 2, "encodingLevel", d->encodingLevel);
94             opac_element_str(wrbuf, 2, "format", d->format);
95             opac_element_str(wrbuf, 2, "receiptAcqStatus", d->receiptAcqStatus);
96             opac_element_str (wrbuf, 2, "generalRetention", d->generalRetention);
97             opac_element_str (wrbuf, 2, "completeness", d->completeness);
98             opac_element_str (wrbuf, 2, "dateOfReport", d->dateOfReport);
99             opac_element_str (wrbuf, 2, "nucCode", d->nucCode);
100             opac_element_str (wrbuf, 2, "localLocation", d->localLocation);
101             opac_element_str (wrbuf, 2, "shelvingLocation", d->shelvingLocation);
102             opac_element_str (wrbuf, 2, "callNumber", d->callNumber);
103             opac_element_str (wrbuf, 2, "shelvingData", d->shelvingData);
104             
105             opac_element_str (wrbuf, 2, "copyNumber", d->copyNumber);
106             opac_element_str (wrbuf, 2, "publicNote", d->publicNote);
107             opac_element_str (wrbuf, 2, "reproductionNote", d->reproductionNote);
108             opac_element_str (wrbuf, 2, "termsUseRepro", d->termsUseRepro);
109             opac_element_str (wrbuf, 2, "enumAndChron", d->enumAndChron);
110             if (d->num_volumes)
111             {
112                 wrbuf_puts (wrbuf, "  <volumes>\n");
113                 for (j = 0; j<d->num_volumes; j++)
114                 {
115                     wrbuf_puts (wrbuf, "   <volume>\n");
116                     opac_element_str (wrbuf, 4, "enumeration",
117                                       d->volumes[j]->enumeration);
118                     opac_element_str (wrbuf, 4, "chronology",
119                                       d->volumes[j]->chronology);
120                     opac_element_str (wrbuf, 4, "enumAndChron",
121                                       d->volumes[j]->enumAndChron);
122                     wrbuf_puts (wrbuf, "   </volume>\n");
123                 }
124                 wrbuf_puts (wrbuf, "  </volumes>\n");
125             }
126             if (d->num_circulationData)
127             {
128                 wrbuf_puts (wrbuf, "  <circulations>\n");
129                 for (j = 0; j<d->num_circulationData; j++)
130                 {
131                     wrbuf_puts (wrbuf,"   <circulation>\n");
132                     opac_element_bool (wrbuf, 4, "availableNow",
133                                        d->circulationData[j]->availableNow);
134                     opac_element_str (wrbuf, 4, "availabiltyDate",
135                                       d->circulationData[j]->availablityDate);
136                     opac_element_str (wrbuf, 4, "availableThru",
137                                       d->circulationData[j]->availableThru);
138                     opac_element_str (wrbuf, 4, "restrictions",
139                                       d->circulationData[j]->restrictions);
140                     opac_element_str (wrbuf, 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, 4, "enumAndChron",
147                                       d->circulationData[j]->enumAndChron);
148                     opac_element_str (wrbuf, 4, "midspine",
149                                       d->circulationData[j]->midspine);
150                     opac_element_str (wrbuf, 4, "temporaryLocation",
151                                       d->circulationData[j]->temporaryLocation);
152                     wrbuf_puts (wrbuf, "   </circulation>\n");
153                 }
154                 wrbuf_puts (wrbuf, "  </circulations>\n");
155             }
156         }
157         wrbuf_puts(wrbuf, " </holding>\n");
158     }
159     wrbuf_puts(wrbuf, "</holdings>\n");
160     wrbuf_puts(wrbuf, "</opacRecord>\n");
161 }
162
163 void yaz_display_OPAC(WRBUF wrbuf, Z_OPACRecord *opac_rec, int flags)
164 {
165     yaz_marc_t mt = yaz_marc_create();
166
167     yaz_marc_xml(mt, YAZ_MARC_MARCXML);
168     yaz_opac_decode_wrbuf(mt, opac_rec, wrbuf);
169     yaz_marc_destroy(mt);
170 }
171
172 /*
173  * Local variables:
174  * c-basic-offset: 4
175  * indent-tabs-mode: nil
176  * End:
177  * vim: shiftwidth=4 tabstop=8 expandtab
178  */
179