YAZ  5.23.1
opac_to_xml.c
Go to the documentation of this file.
1 /* This file is part of the YAZ toolkit.
2  * Copyright (C) Index Data
3  * See the file LICENSE for details.
4  */
9 #if HAVE_CONFIG_H
10 #include <config.h>
11 #endif
12 
13 #include <stdio.h>
14 #include <string.h>
15 #include <stdlib.h>
16 
17 #include <yaz/proto.h>
18 #include <yaz/marcdisp.h>
19 
21  int l, const char *elem,
22  const char *data)
23 {
24  if (data)
25  {
26  size_t pos;
27  while (--l >= 0)
28  wrbuf_puts(wrbuf, " ");
29  wrbuf_puts(wrbuf, "<");
30  wrbuf_puts(wrbuf, elem);
31  wrbuf_puts(wrbuf, ">");
32 
33  pos = wrbuf->pos; /* save position */
34  if (wrbuf_iconv_write2(wrbuf, cd1, data, strlen(data), wrbuf_xmlputs_n)
35  && cd2)
36  {
37  wrbuf->pos = pos; /* rewind to pos */
38  wrbuf_iconv_write2(wrbuf, cd2, data, strlen(data), wrbuf_xmlputs_n);
39  }
40  wrbuf_puts(wrbuf, "</");
41  wrbuf_puts(wrbuf, elem);
42  wrbuf_puts(wrbuf, ">\n");
43  }
44 }
45 
46 static void opac_element_bool(WRBUF wrbuf, int l, const char *elem, int *data)
47 {
48  if (data)
49  {
50  while (--l >= 0)
51  wrbuf_puts(wrbuf, " ");
52  wrbuf_puts(wrbuf, "<");
53  wrbuf_puts(wrbuf, elem);
54  if (*data)
55  wrbuf_puts(wrbuf, " value=\"1\"");
56  else
57  wrbuf_puts(wrbuf, " value=\"0\"");
58  wrbuf_puts(wrbuf, "/>\n");
59  }
60 }
61 
63  yaz_iconv_t cd2)
64 {
65  int i;
67 
68  wrbuf_puts(wrbuf, "<opacRecord>\n");
69  if (r->bibliographicRecord)
70  {
72 
73  wrbuf_puts(wrbuf, " <bibliographicRecord>\n");
74  if (ext->which == Z_External_octet)
75  yaz_marc_decode_wrbuf(mt, (const char *) ext->u.octet_aligned->buf,
76  ext->u.octet_aligned->len, wrbuf);
77  wrbuf_puts(wrbuf, " </bibliographicRecord>\n");
78  }
79  wrbuf_puts(wrbuf, "<holdings>\n");
80 
81  for (i = 0; i < r->num_holdingsData; i++)
82  {
83  Z_HoldingsRecord *h = r->holdingsData[i];
84  wrbuf_puts(wrbuf, " <holding>\n");
85 
87  {
89 
90  wrbuf_puts(wrbuf, " <marcHoldingsRecord>\n");
91  if (ext->which == Z_External_octet)
92  yaz_marc_decode_wrbuf(mt, (const char *)
93  ext->u.octet_aligned->buf,
94  ext->u.octet_aligned->len, wrbuf);
95  wrbuf_puts(wrbuf, " </marcHoldingsRecord>\n");
96  }
98  {
99  int j;
100 
102 
103  opac_element_str(wrbuf, cd1, cd2, 2, "typeOfRecord",
104  d->typeOfRecord);
105  opac_element_str(wrbuf, cd1, cd2, 2, "encodingLevel",
106  d->encodingLevel);
107  opac_element_str(wrbuf, cd1, cd2, 2, "format",
108  d->format);
109  opac_element_str(wrbuf, cd1, cd2, 2, "receiptAcqStatus",
110  d->receiptAcqStatus);
111  opac_element_str(wrbuf, cd1, cd2, 2, "generalRetention",
112  d->generalRetention);
113  opac_element_str(wrbuf, cd1, cd2, 2, "completeness",
114  d->completeness);
115  opac_element_str(wrbuf, cd1, cd2, 2, "dateOfReport",
116  d->dateOfReport);
117  opac_element_str(wrbuf, cd1, cd2, 2, "nucCode", d->nucCode);
118  opac_element_str(wrbuf, cd1, cd2, 2, "localLocation",
119  d->localLocation);
120  opac_element_str(wrbuf, cd1, cd2, 2, "shelvingLocation",
121  d->shelvingLocation);
122  opac_element_str(wrbuf, cd1, cd2, 2, "callNumber",
123  d->callNumber);
124  opac_element_str(wrbuf, cd1, cd2, 2, "shelvingData",
125  d->shelvingData);
126  opac_element_str(wrbuf, cd1, cd2, 2, "copyNumber",
127  d->copyNumber);
128  opac_element_str(wrbuf, cd1, cd2, 2, "publicNote",
129  d->publicNote);
130  opac_element_str(wrbuf, cd1, cd2, 2, "reproductionNote",
131  d->reproductionNote);
132  opac_element_str(wrbuf, cd1, cd2, 2, "termsUseRepro",
133  d->termsUseRepro);
134  opac_element_str(wrbuf, cd1, cd2, 2, "enumAndChron",
135  d->enumAndChron);
136  if (d->num_volumes)
137  {
138  wrbuf_puts (wrbuf, " <volumes>\n");
139  for (j = 0; j<d->num_volumes; j++)
140  {
141  wrbuf_puts (wrbuf, " <volume>\n");
142  opac_element_str(wrbuf, cd1, cd2, 4, "enumeration",
143  d->volumes[j]->enumeration);
144  opac_element_str(wrbuf, cd1, cd2, 4, "chronology",
145  d->volumes[j]->chronology);
146  opac_element_str(wrbuf, cd1, cd2, 4, "enumAndChron",
147  d->volumes[j]->enumAndChron);
148  wrbuf_puts(wrbuf, " </volume>\n");
149  }
150  wrbuf_puts(wrbuf, " </volumes>\n");
151  }
152  if (d->num_circulationData)
153  {
154  wrbuf_puts (wrbuf, " <circulations>\n");
155  for (j = 0; j<d->num_circulationData; j++)
156  {
157  wrbuf_puts(wrbuf," <circulation>\n");
158  opac_element_bool(wrbuf, 4, "availableNow",
160  opac_element_str(wrbuf, cd1, cd2, 4, "availabilityDate",
162  opac_element_str(wrbuf, cd1, cd2, 4, "availableThru",
164  opac_element_str(wrbuf, cd1, cd2, 4, "restrictions",
166  opac_element_str(wrbuf, cd1, cd2, 4, "itemId",
167  d->circulationData[j]->itemId);
168  opac_element_bool(wrbuf, 4, "renewable",
169  d->circulationData[j]->renewable);
170  opac_element_bool(wrbuf, 4, "onHold",
171  d->circulationData[j]->onHold);
172  opac_element_str(wrbuf, cd1, cd2, 4, "enumAndChron",
174  opac_element_str(wrbuf, cd1, cd2, 4, "midspine",
175  d->circulationData[j]->midspine);
176  opac_element_str(wrbuf, cd1, cd2, 4, "temporaryLocation",
178  wrbuf_puts(wrbuf, " </circulation>\n");
179  }
180  wrbuf_puts(wrbuf, " </circulations>\n");
181  }
182  }
183  wrbuf_puts(wrbuf, " </holding>\n");
184  }
185  wrbuf_puts(wrbuf, "</holdings>\n");
186  wrbuf_puts(wrbuf, "</opacRecord>\n");
187 }
188 
190 {
191  yaz_opac_decode_wrbuf2(mt, r, wrbuf, 0);
192 }
193 
194 int yaz_opac_check_marc21_coding(const char *charset, Z_OPACRecord *r)
195 {
196  if (r->bibliographicRecord)
197  {
199  if (ext->which == Z_External_octet)
200  {
202  charset,
203  (const char *) ext->u.octet_aligned->buf,
204  ext->u.octet_aligned->len);
205  }
206  }
207  return 0;
208 }
209 
210 /*
211  * Local variables:
212  * c-basic-offset: 4
213  * c-file-style: "Stroustrup"
214  * indent-tabs-mode: nil
215  * End:
216  * vim: shiftwidth=4 tabstop=8 expandtab
217  */
218 
Z_InternationalString * typeOfRecord
Definition: z-opac.h:53
MARC conversion.
char * buf
Definition: odr.h:101
Z_InternationalString * availablityDate
Definition: z-opac.h:84
Z_InternationalString * enumAndChron
Definition: z-opac.h:69
yaz_iconv_t yaz_marc_get_iconv(yaz_marc_t mt)
supply iconv handle for character set conversion
Definition: marcdisp.c:1389
Z_InternationalString * shelvingData
Definition: z-opac.h:64
#define Z_HoldingsRecord_marcHoldingsRecord
Definition: z-opac.h:47
Z_InternationalString * copyNumber
Definition: z-opac.h:65
Odr_bool * availableNow
Definition: z-opac.h:83
Odr_bool * renewable
Definition: z-opac.h:88
void wrbuf_puts(WRBUF b, const char *buf)
appends C-string to WRBUF
Definition: wrbuf.c:89
Z_InternationalString * localLocation
Definition: z-opac.h:61
Z_InternationalString * nucCode
Definition: z-opac.h:60
Z_InternationalString * shelvingLocation
Definition: z-opac.h:62
the internals of a yaz_marc_t handle
Definition: marcdisp.c:86
#define Z_HoldingsRecord_holdingsAndCirc
Definition: z-opac.h:48
Z_InternationalString * generalRetention
Definition: z-opac.h:57
void yaz_opac_decode_wrbuf(yaz_marc_t mt, Z_OPACRecord *r, WRBUF wrbuf)
Performs "pretty" display of OPAC record to WRBUF using marc_t.
Definition: opac_to_xml.c:189
int yaz_marc_check_marc21_coding(const char *charset, const char *marc_buf, int sz)
check if MARC21 is UTF-8 encoded
Definition: marcdisp.c:1487
Z_InternationalString * enumeration
Definition: z-opac.h:77
string buffer
Definition: wrbuf.h:42
Odr_bool * onHold
Definition: z-opac.h:89
Z_InternationalString * format
Definition: z-opac.h:55
Z_InternationalString * reproductionNote
Definition: z-opac.h:67
union Z_HoldingsRecord::@106 u
union Z_External::@30 u
Z_InternationalString * restrictions
Definition: z-opac.h:86
int which
Definition: prt-ext.h:63
Z_InternationalString * itemId
Definition: z-opac.h:87
Z_External * bibliographicRecord
Definition: z-opac.h:37
void wrbuf_xmlputs_n(WRBUF b, const char *cp, size_t size)
writes buffer of certain size to WRBUF and XML encode (as CDATA)
Definition: wrbuf.c:143
Z_InternationalString * publicNote
Definition: z-opac.h:66
size_t pos
Definition: wrbuf.h:45
Z_InternationalString * dateOfReport
Definition: z-opac.h:59
Z_HoldingsAndCircData * holdingsAndCirc
Definition: z-opac.h:46
Z_InternationalString * enumAndChron
Definition: z-opac.h:79
Z_InternationalString * chronology
Definition: z-opac.h:78
Z_InternationalString * termsUseRepro
Definition: z-opac.h:68
Header for Z39.50 Protocol.
int wrbuf_iconv_write2(WRBUF b, yaz_iconv_t cd, const char *buf, size_t size, void(*wfunc)(WRBUF, const char *, size_t))
General writer of string using iconv and cdata.
Definition: wrbuf.c:190
Z_InternationalString * availableThru
Definition: z-opac.h:85
Z_InternationalString * temporaryLocation
Definition: z-opac.h:92
Z_External * marcHoldingsRecord
Definition: z-opac.h:45
int yaz_marc_decode_wrbuf(yaz_marc_t mt, const char *buf, int bsize, WRBUF wr)
decodes ISO2709/MARC buffer and stores result in WRBUF
Definition: marcdisp.c:1348
void yaz_opac_decode_wrbuf2(yaz_marc_t mt, Z_OPACRecord *r, WRBUF wrbuf, yaz_iconv_t cd2)
Performs "pretty" display of OPAC record to WRBUF using marc_t.
Definition: opac_to_xml.c:62
Z_InternationalString * callNumber
Definition: z-opac.h:63
Z_InternationalString * encodingLevel
Definition: z-opac.h:54
static void opac_element_bool(WRBUF wrbuf, int l, const char *elem, int *data)
Definition: opac_to_xml.c:46
#define Z_External_octet
Definition: prt-ext.h:66
structure for all known EXTERNALs
Definition: prt-ext.h:58
Z_HoldingsRecord ** holdingsData
Definition: z-opac.h:39
Z_InternationalString * receiptAcqStatus
Definition: z-opac.h:56
int num_holdingsData
Definition: z-opac.h:38
Z_Volume ** volumes
Definition: z-opac.h:71
Z_InternationalString * completeness
Definition: z-opac.h:58
Z_InternationalString * enumAndChron
Definition: z-opac.h:90
Z_CircRecord ** circulationData
Definition: z-opac.h:73
Odr_oct * octet_aligned
Definition: prt-ext.h:105
Z_InternationalString * midspine
Definition: z-opac.h:91
static void opac_element_str(WRBUF wrbuf, yaz_iconv_t cd1, yaz_iconv_t cd2, int l, const char *elem, const char *data)
Definition: opac_to_xml.c:20
int yaz_opac_check_marc21_coding(const char *charset, Z_OPACRecord *r)
Definition: opac_to_xml.c:194
int len
Definition: odr.h:102