1 package OpenILS::WWW::SuperCat;
2 use strict; use warnings;
6 use Apache2::Const -compile => qw(OK REDIRECT DECLINED :log);
7 use APR::Const -compile => qw(:error SUCCESS);
8 use Apache2::RequestRec ();
9 use Apache2::RequestIO ();
10 use Apache2::RequestUtil;
14 use OpenSRF::EX qw(:try);
16 use OpenSRF::AppSession;
19 use OpenILS::Utils::Fieldmapper;
22 # set the bootstrap config when this module is loaded
23 my ($bootstrap, $supercat);
32 OpenSRF::System->bootstrap_client( config_file => $bootstrap );
33 $supercat = OpenSRF::AppSession->create('open-ils.supercat');
39 return Apache2::Const::DECLINED if (-e $apache->filename);
41 (my $isbn = $apache->path_info) =~ s{^.*?([^/]+)$}{$1}o;
44 ->request("open-ils.supercat.oisbn", $isbn)
47 print "Content-type: application/xml; charset=utf-8\n\n";
48 print "<?xml version='1.0' encoding='UTF-8' ?>\n";
50 unless (exists $$list{metarecord}) {
52 return Apache2::Const::OK;
55 print "<idlist metarecord='$$list{metarecord}'>\n";
57 for ( keys %{ $$list{record_list} } ) {
58 (my $o = $$list{record_list}{$_}) =~s/^(\S+).*?$/$1/o;
59 print " <isbn record='$_'>$o</isbn>\n"
64 return Apache2::Const::OK;
70 return Apache2::Const::DECLINED if (-e $apache->filename);
72 print "Content-type: application/xml; charset=utf-8\n";
76 my $uri = $cgi->param('uri') || '';
78 my $host = $cgi->virtual_host || $cgi->server_name;
80 my $format = $cgi->param('format');
81 my ($id,$type,$command) = ('','','');
84 if ($uri =~ m{^tag:[^:]+:([^\/]+)/(\d+)}o) {
87 $type = 'metarecord' if ($1 =~ /^m/o);
90 ->request("open-ils.supercat.$type.formats")
100 <type>text/html</type>
104 my ($type) = keys %$h;
105 $body .= "<format><name>$type</name><type>application/$type+xml</type>";
107 for my $part ( qw/namespace_uri docs schema_location/ ) {
108 $body .= "<$part>$$h{$type}{$part}</$part>"
109 if ($$h{$type}{$part});
112 $body .= '</format>';
115 $body .= "</formats>\n";
117 $apache->custom_response( 300, $body);
121 ->request("open-ils.supercat.record.formats")
126 ->request("open-ils.supercat.metarecord.formats")
130 my %hash = map { ( (keys %$_)[0] => (values %$_)[0] ) } @$list;
131 $list = [ map { { $_ => $hash{$_} } } sort keys %hash ];
136 <type>text/html</type>
140 my ($type) = keys %$h;
141 print "<format><name>$type</name><type>application/$type+xml</type>";
143 for my $part ( qw/namespace_uri docs schema_location/ ) {
144 print "<$part>$$h{$type}{$part}</$part>"
145 if ($$h{$type}{$part});
151 print "</formats>\n";
154 return Apache2::Const::OK;
159 if ($uri =~ m{^tag:[^:]+:([^\/]+)/(\d+)}o) {
162 $type = 'metarecord' if ($1 =~ /^m/o);
163 $command = 'retrieve';
166 if ($format eq 'opac') {
167 print "Location: $base/../../en-US/skin/default/xml/rresult.xml?m=$id\n\n"
168 if ($type eq 'metarecord');
169 print "Location: $base/../../en-US/skin/default/xml/rdetail.xml?r=$id\n\n"
170 if ($type eq 'record');
174 print "\n" . $supercat->request("open-ils.supercat.$type.$format.$command",$id)->gather(1);
176 return Apache2::Const::OK;
182 return Apache2::Const::DECLINED if (-e $apache->filename);
184 my $path = $apache->path_info;
187 my $base = $cgi->url;
189 my ($id,$type,$format,$command) = reverse split '/', $path;
191 print "Content-type: application/xml; charset=utf-8\n";
193 if ( $path =~ m{^/formats(?:/([^\/]+))?$}o ) {
196 ->request("open-ils.supercat.$1.formats")
204 <type>text/html</type>
208 my ($type) = keys %$h;
209 print "<format><name>$type</name><type>application/$type+xml</type>";
211 for my $part ( qw/namespace_uri docs schema_location/ ) {
212 print "<$part>$$h{$type}{$part}</$part>"
213 if ($$h{$type}{$part});
219 print "</formats>\n";
221 return Apache2::Const::OK;
225 ->request("open-ils.supercat.record.formats")
230 ->request("open-ils.supercat.metarecord.formats")
234 my %hash = map { ( (keys %$_)[0] => (values %$_)[0] ) } @$list;
235 $list = [ map { { $_ => $hash{$_} } } sort keys %hash ];
240 <type>text/html</type>
244 my ($type) = keys %$h;
245 print "<format><name>$type</name><type>application/$type+xml</type>";
247 for my $part ( qw/namespace_uri docs schema_location/ ) {
248 print "<$part>$$h{$type}{$part}</$part>"
249 if ($$h{$type}{$part});
255 print "</formats>\n";
258 return Apache2::Const::OK;
261 if ($format eq 'opac') {
262 print "Location: $base/../../en-US/skin/default/xml/rresult.xml?m=$id\n\n"
263 if ($type eq 'metarecord');
264 print "Location: $base/../../en-US/skin/default/xml/rdetail.xml?r=$id\n\n"
265 if ($type eq 'record');
269 print "\n" . $supercat->request("open-ils.supercat.$type.$format.$command",$id)->gather(1);
271 return Apache2::Const::OK;