Lines 42-50
use C4::Context;
Link Here
|
42 |
use C4::Biblio; |
42 |
use C4::Biblio; |
43 |
use XML::LibXML; |
43 |
use XML::LibXML; |
44 |
use XML::LibXSLT; |
44 |
use XML::LibXSLT; |
|
|
45 |
use utf8; |
45 |
|
46 |
|
46 |
my $cgi = CGI->new(); |
47 |
my $cgi = CGI->new(); |
47 |
binmode(STDOUT, ":encoding(UTF-8)"); #output as utf8 |
|
|
48 |
|
48 |
|
49 |
=head1 VARIABLES |
49 |
=head1 VARIABLES |
50 |
|
50 |
|
Lines 95-100
my $format_to_stylesheet_map = {
Link Here
|
95 |
}, |
95 |
}, |
96 |
}; |
96 |
}; |
97 |
|
97 |
|
|
|
98 |
my %redirect_error = ( |
99 |
'error400' => '/cgi-bin/koha/errors/400.pl', |
100 |
'error404' => '/cgi-bin/koha/errors/404.pl', |
101 |
'error500' => '/cgi-bin/koha/errors/500.pl' |
102 |
); |
103 |
|
98 |
=head2 $format_info |
104 |
=head2 $format_info |
99 |
|
105 |
|
100 |
This hashref maps from unAPI output formats to the <format> elements |
106 |
This hashref maps from unAPI output formats to the <format> elements |
Lines 132-144
if (not defined $format) {
Link Here
|
132 |
my $marcxml = GetXmlBiblio($biblionumber); |
138 |
my $marcxml = GetXmlBiblio($biblionumber); |
133 |
unless (defined $marcxml) { |
139 |
unless (defined $marcxml) { |
134 |
# no bib, so 404 |
140 |
# no bib, so 404 |
135 |
print $cgi->header( -status => '404 record not found'); |
141 |
print $cgi->redirect( -uri => $redirect_error{error404} ); |
136 |
exit 0; |
142 |
exit 0; |
137 |
} |
143 |
} |
138 |
|
144 |
|
139 |
my $transformer = get_transformer($format, $format_to_stylesheet_map, $format_info); |
145 |
my $transformer = get_transformer($format, $format_to_stylesheet_map, $format_info); |
140 |
unless (defined $transformer) { |
146 |
unless (defined $transformer) { |
141 |
print $cgi->header( -status => '406 invalid format requested' ); |
147 |
# invalid format requested |
|
|
148 |
print $cgi->redirect( -uri => $redirect_error{error400} ); |
142 |
exit 0; |
149 |
exit 0; |
143 |
} |
150 |
} |
144 |
my $parser = XML::LibXML->new(); |
151 |
my $parser = XML::LibXML->new(); |
Lines 146-166
if (not defined $format) {
Link Here
|
146 |
$record_dom = $transformer->transform( $record_dom ); |
153 |
$record_dom = $transformer->transform( $record_dom ); |
147 |
$content = $record_dom->toString(); |
154 |
$content = $record_dom->toString(); |
148 |
}; |
155 |
}; |
149 |
if ($@) { |
156 |
if ($@) { #$@->code(), $@->message() can't be passed to 500.pl |
150 |
print $cgi->header( -status => '500 internal error ' . $@->code() . ": " . $@->message() ); |
157 |
print $cgi->redirect( -uri => $redirect_error{error500} ); |
151 |
exit 0; |
158 |
exit 0; |
152 |
} |
159 |
} |
153 |
|
160 |
|
154 |
print $cgi->header( -type =>'application/xml' ); |
161 |
print $cgi->header( -type =>'application/xml' ); |
|
|
162 |
utf8::decode($content); #output as utf8 |
155 |
print $content; |
163 |
print $content; |
156 |
} else { |
164 |
} else { |
157 |
# ID is obviously wrong, so 404 |
165 |
# ID is obviously wrong, so 404 |
158 |
print $cgi->header( -status => '404 record not found'); |
166 |
print $cgi->redirect( -uri => $redirect_error{error404} ); |
159 |
exit 0; |
167 |
exit 0; |
160 |
} |
168 |
} |
161 |
} else { |
169 |
} else { |
162 |
# supplied a format but no id - caller is doing it wrong |
170 |
# supplied a format but no id - caller is doing it wrong |
163 |
print $cgi->header( -status => '400 bad request - if you specify format, must specify id'); |
171 |
print $cgi->redirect( -uri => $redirect_error{error404} ); |
164 |
exit 0; |
172 |
exit 0; |
165 |
} |
173 |
} |
166 |
|
174 |
|
167 |
- |
|
|