1 package OpenILS::WWW::SuperCat;
2 use strict; use warnings;
5 use Apache2::Const -compile => qw(OK REDIRECT DECLINED NOT_FOUND :log);
6 use APR::Const -compile => qw(:error SUCCESS);
7 use Apache2::RequestRec ();
8 use Apache2::RequestIO ();
9 use Apache2::RequestUtil;
15 use OpenSRF::EX qw(:try);
16 use OpenSRF::Utils qw/:datetime/;
17 use OpenSRF::Utils::Cache;
19 use OpenSRF::AppSession;
24 use Unicode::Normalize;
25 use OpenILS::Utils::Fieldmapper;
26 use OpenILS::WWW::SuperCat::Feed;
27 use OpenSRF::Utils::Logger qw/$logger/;
32 # set the bootstrap config when this module is loaded
33 my ($bootstrap, $cstore, $supercat, $actor, $parser, $search, $xslt, $cn_browse_xslt, %browse_types);
35 $browse_types{call_number}{xml} = sub {
38 my $year = (gmtime())[5] + 1900;
41 $content .= "<hold:volumes xmlns:hold='http://open-ils.org/spec/holdings/v1'>";
44 (my $cn_class = $cn->class_name) =~ s/::/-/gso;
45 $cn_class =~ s/Fieldmapper-//gso;
47 my $cn_tag = "tag:open-ils.org,$year:$cn_class/".$cn->id;
48 my $cn_lib = $cn->owning_lib->shortname;
49 my $cn_label = $cn->label;
51 $cn_label =~ s/\n//gos;
52 $cn_label =~ s/'/'/go;
54 (my $ou_class = $cn->owning_lib->class_name) =~ s/::/-/gso;
55 $ou_class =~ s/Fieldmapper-//gso;
57 my $ou_tag = "tag:open-ils.org,$year:$ou_class/".$cn->owning_lib->id;
58 my $ou_name = $cn->owning_lib->name;
60 $ou_name =~ s/\n//gos;
61 $ou_name =~ s/'/'/go;
63 (my $rec_class = $cn->record->class_name) =~ s/::/-/gso;
64 $rec_class =~ s/Fieldmapper-//gso;
66 my $rec_tag = "tag:open-ils.org,$year:$rec_class/".$cn->record->id.'/'.$cn->owning_lib->shortname;
68 $content .= "<hold:volume id='$cn_tag' lib='$cn_lib' label='$cn_label'>";
69 $content .= "<act:owning_lib xmlns:act='http://open-ils.org/spec/actors/v1' id='$ou_tag' name='$ou_name'/>";
71 my $r_doc = $parser->parse_string($cn->record->marc);
72 $r_doc->documentElement->setAttribute( id => $rec_tag );
73 $content .= entityize($r_doc->documentElement->toString);
75 $content .= "</hold:volume>";
78 $content .= '</hold:volumes>';
79 return ("Content-type: application/xml\n\n",$content);
83 $browse_types{call_number}{html} = sub {
88 if (!$cn_browse_xslt) {
89 $cn_browse_xslt = $parser->parse_file(
90 OpenSRF::Utils::SettingsClient
92 ->config_value( dirs => 'xsl' ).
95 $cn_browse_xslt = $xslt->parse_stylesheet( $cn_browse_xslt );
98 my (undef,$xml) = $browse_types{call_number}{xml}->($tree);
101 "Content-type: text/html\n\n",
103 $cn_browse_xslt->transform(
104 $parser->parse_string( $xml ),
119 OpenSRF::System->bootstrap_client( config_file => $bootstrap );
121 my $idl = OpenSRF::Utils::SettingsClient->new->config_value("IDL");
122 Fieldmapper->import(IDL => $idl);
124 $supercat = OpenSRF::AppSession->create('open-ils.supercat');
125 $cstore = OpenSRF::AppSession->create('open-ils.cstore');
126 $actor = OpenSRF::AppSession->create('open-ils.actor');
127 $search = OpenSRF::AppSession->create('open-ils.search');
128 $parser = new XML::LibXML;
129 $xslt = new XML::LibXSLT;
131 $cn_browse_xslt = $parser->parse_file(
132 OpenSRF::Utils::SettingsClient
134 ->config_value( dirs => 'xsl' ).
138 $cn_browse_xslt = $xslt->parse_stylesheet( $cn_browse_xslt );
145 return Apache2::Const::DECLINED if (-e $apache->filename);
147 (my $isbn = $apache->path_info) =~ s{^.*?([^/]+)$}{$1}o;
150 ->request("open-ils.supercat.oisbn", $isbn)
153 print "Content-type: application/xml; charset=utf-8\n\n";
154 print "<?xml version='1.0' encoding='UTF-8' ?>\n";
156 unless (exists $$list{metarecord}) {
158 return Apache2::Const::OK;
161 print "<idlist metarecord='$$list{metarecord}'>\n";
163 for ( keys %{ $$list{record_list} } ) {
164 (my $o = $$list{record_list}{$_}) =~s/^(\S+).*?$/$1/o;
165 print " <isbn record='$_'>$o</isbn>\n"
170 return Apache2::Const::OK;
176 return Apache2::Const::DECLINED if (-e $apache->filename);
181 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
182 my $rel_name = $cgi->url(-relative=>1);
183 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
186 my $url = $cgi->url(-path_info=>$add_path);
187 my $root = (split 'unapi', $url)[0];
188 my $base = (split 'unapi', $url)[0] . 'unapi';
191 my $uri = $cgi->param('id') || '';
192 my $host = $cgi->virtual_host || $cgi->server_name;
194 my $format = $cgi->param('format');
195 my $flesh_feed = ($format =~ /-full$/o) ? 1 : 0;
196 (my $base_format = $format) =~ s/-full$//o;
197 my ($id,$type,$command,$lib) = ('','','');
200 my $body = "Content-type: application/xml; charset=utf-8\n\n";
202 if ($uri =~ m{^tag:[^:]+:([^\/]+)/([^/]+)(?:/(.+))$}o) {
206 $type = 'metarecord' if ($1 =~ /^m/o);
209 ->request("open-ils.supercat.$type.formats")
212 if ($type eq 'record' or $type eq 'isbn') {
213 $body .= <<" FORMATS";
215 <format name='opac' type='text/html'/>
216 <format name='html' type='text/html'/>
217 <format name='htmlholdings' type='text/html'/>
218 <format name='html-full' type='text/html'/>
219 <format name='htmlholdings-full' type='text/html'/>
221 } elsif ($type eq 'metarecord') {
222 $body .= <<" FORMATS";
224 <format name='opac' type='text/html'/>
229 my ($type) = keys %$h;
230 $body .= "\t<format name='$type' type='application/xml'";
232 for my $part ( qw/namespace_uri docs schema_location/ ) {
233 $body .= " $part='$$h{$type}{$part}'"
234 if ($$h{$type}{$part});
239 if (OpenILS::WWW::SuperCat::Feed->exists($type)) {
240 $body .= "\t<format name='$type-full' type='application/xml'";
242 for my $part ( qw/namespace_uri docs schema_location/ ) {
243 $body .= " $part='$$h{$type}{$part}'"
244 if ($$h{$type}{$part});
251 $body .= "</formats>\n";
255 ->request("open-ils.supercat.record.formats")
260 ->request("open-ils.supercat.metarecord.formats")
264 my %hash = map { ( (keys %$_)[0] => (values %$_)[0] ) } @$list;
265 $list = [ map { { $_ => $hash{$_} } } sort keys %hash ];
267 $body .= <<" FORMATS";
269 <format name='opac' type='text/html'/>
270 <format name='html' type='text/html'/>
271 <format name='htmlholdings' type='text/html'/>
272 <format name='html-full' type='text/html'/>
273 <format name='htmlholdings-full' type='text/html'/>
278 my ($type) = keys %$h;
279 $body .= "\t<format name='$type' type='application/xml'";
281 for my $part ( qw/namespace_uri docs schema_location/ ) {
282 $body .= " $part='$$h{$type}{$part}'"
283 if ($$h{$type}{$part});
288 if (OpenILS::WWW::SuperCat::Feed->exists($type)) {
289 $body .= "\t<format name='$type-full' type='application/xml'";
291 for my $part ( qw/namespace_uri docs schema_location/ ) {
292 $body .= " $part='$$h{$type}{$part}'"
293 if ($$h{$type}{$part});
300 $body .= "</formats>\n";
304 return Apache2::Const::OK;
307 if ($uri =~ m{^tag:[^:]+:([^\/]+)/([^/]+)(?:/(.+))?}o) {
311 $type = 'metarecord' if ($1 =~ /^metabib/o);
312 $type = 'isbn' if ($1 =~ /^isbn/o);
313 $type = 'call_number' if ($1 =~ /^call_number/o);
314 $command = 'retrieve';
315 $command = 'browse' if ($type eq 'call_number');
318 if (!$lib || $lib eq '-') {
319 $lib = $actor->request(
320 'open-ils.actor.org_unit_list.search' => parent_ou => undef
321 )->gather(1)->[0]->shortname;
324 my $lib_object = $actor->request(
325 'open-ils.actor.org_unit_list.search' => shortname => $lib
327 my $lib_id = $lib_object->id;
329 my $ou_types = $actor->request( 'open-ils.actor.org_types.retrieve' )->gather(1);
330 my $lib_depth = (grep { $_->id == $lib_object->ou_type } @$ou_types)[0]->depth;
332 if ($type eq 'call_number' and $command eq 'browse') {
333 print "Location: $root/browse/$base_format/call_number/$lib/$id\n\n";
337 if ($type eq 'isbn') {
338 my $rec = $supercat->request('open-ils.supercat.isbn.object.retrieve',$id)->gather(1);
340 print "Content-type: text/html; charset=utf-8\n\n";
341 $apache->custom_response( 404, <<" HTML");
344 <title>Type [$type] with id [$id] not found!</title>
348 <center>Sorry, we couldn't $command a $type with the id of $id in format $format.</center>
359 { (keys(%$_))[0] eq $base_format }
360 @{ $supercat->request("open-ils.supercat.$type.formats")->gather(1) }
362 { $_ eq $base_format }
363 qw/opac html htmlholdings/
365 print "Content-type: text/html; charset=utf-8\n\n";
366 $apache->custom_response( 406, <<" HTML");
369 <title>Invalid format [$format] for type [$type]!</title>
373 <center>Sorry, format $format is not valid for type $type.</center>
380 if ($format eq 'opac') {
381 print "Location: $root/../../en-US/skin/default/xml/rresult.xml?m=$id&l=$lib_id&d=$lib_depth\n\n"
382 if ($type eq 'metarecord');
383 print "Location: $root/../../en-US/skin/default/xml/rdetail.xml?r=$id&l=$lib_id&d=$lib_depth\n\n"
384 if ($type eq 'record');
386 } elsif (OpenILS::WWW::SuperCat::Feed->exists($base_format)) {
387 my $feed = create_record_feed(
396 print "Content-type: text/html; charset=utf-8\n\n";
397 $apache->custom_response( 404, <<" HTML");
400 <title>Type [$type] with id [$id] not found!</title>
404 <center>Sorry, we couldn't $command a $type with the id of $id in format $format.</center>
412 $feed->creator($host);
413 $feed->update_ts(gmtime_ISO8601());
414 $feed->link( unapi => $base) if ($flesh_feed);
416 print "Content-type: ". $feed->type ."; charset=utf-8\n\n";
417 print entityize($feed->toString) . "\n";
419 return Apache2::Const::OK;
422 my $req = $supercat->request("open-ils.supercat.$type.$format.$command",$id);
423 my $data = $req->gather(1);
425 if ($req->failed || !$data) {
426 print "Content-type: text/html; charset=utf-8\n\n";
427 $apache->custom_response( 404, <<" HTML");
430 <title>$type $id not found!</title>
434 <center>Sorry, we couldn't $command a $type with the id of $id in format $format.</center>
441 print "Content-type: application/xml; charset=utf-8\n\n$data";
443 return Apache2::Const::OK;
449 return Apache2::Const::DECLINED if (-e $apache->filename);
454 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
455 my $rel_name = $cgi->url(-relative=>1);
456 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
459 my $url = $cgi->url(-path_info=>$add_path);
460 my $root = (split 'supercat', $url)[0];
461 my $base = (split 'supercat', $url)[0] . 'supercat';
462 my $unapi = (split 'supercat', $url)[0] . 'unapi';
464 my $host = $cgi->virtual_host || $cgi->server_name;
466 my $path = $cgi->path_info;
467 my ($id,$type,$format,$command) = reverse split '/', $path;
468 my $flesh_feed = ($type =~ /-full$/o) ? 1 : 0;
469 (my $base_format = $format) =~ s/-full$//o;
471 if ( $path =~ m{^/formats(?:/([^\/]+))?$}o ) {
472 print "Content-type: application/xml; charset=utf-8\n";
475 ->request("open-ils.supercat.$1.formats")
483 <type>text/html</type>
486 if ($1 eq 'record' or $1 eq 'isbn') {
488 <name>htmlholdings</name>
489 <type>text/html</type>
493 <type>text/html</type>
496 <name>htmlholdings-full</name>
497 <type>text/html</type>
500 <name>html-full</name>
501 <type>text/html</type>
506 my ($type) = keys %$h;
507 print "<format><name>$type</name><type>application/xml</type>";
509 for my $part ( qw/namespace_uri docs schema_location/ ) {
510 print "<$part>$$h{$type}{$part}</$part>"
511 if ($$h{$type}{$part});
516 if (OpenILS::WWW::SuperCat::Feed->exists($type)) {
517 print "<format><name>$type-full</name><type>application/xml</type>";
519 for my $part ( qw/namespace_uri docs schema_location/ ) {
520 print "<$part>$$h{$type}{$part}</$part>"
521 if ($$h{$type}{$part});
529 print "</formats>\n";
531 return Apache2::Const::OK;
535 ->request("open-ils.supercat.record.formats")
540 ->request("open-ils.supercat.metarecord.formats")
544 my %hash = map { ( (keys %$_)[0] => (values %$_)[0] ) } @$list;
545 $list = [ map { { $_ => $hash{$_} } } sort keys %hash ];
550 <type>text/html</type>
553 <name>htmlholdings</name>
554 <type>text/html</type>
558 <type>text/html</type>
561 <name>htmlholdings-full</name>
562 <type>text/html</type>
565 <name>html-full</name>
566 <type>text/html</type>
570 my ($type) = keys %$h;
571 print "<format><name>$type</name><type>application/xml</type>";
573 for my $part ( qw/namespace_uri docs schema_location/ ) {
574 print "<$part>$$h{$type}{$part}</$part>"
575 if ($$h{$type}{$part});
580 if (OpenILS::WWW::SuperCat::Feed->exists($type)) {
581 print "<format><name>$type-full</name><type>application/xml</type>";
583 for my $part ( qw/namespace_uri docs schema_location/ ) {
584 print "<$part>$$h{$type}{$part}</$part>"
585 if ($$h{$type}{$part});
593 print "</formats>\n";
596 return Apache2::Const::OK;
599 if ($format eq 'opac') {
600 print "Location: $root/../../en-US/skin/default/xml/rresult.xml?m=$id\n\n"
601 if ($type eq 'metarecord');
602 print "Location: $root/../../en-US/skin/default/xml/rdetail.xml?r=$id\n\n"
603 if ($type eq 'record');
606 } elsif ($base_format eq 'marc21') {
610 my $bib = $supercat->request( "open-ils.supercat.record.object.retrieve", $id )->gather(1)->[0];
612 my $r = MARC::Record->new_from_xml( $bib->marc, 'UTF-8', 'USMARC' );
613 $r->delete_field( $_ ) for ($r->field(901));
618 a => $bib->tcn_value,
619 b => $bib->tcn_source,
624 print "Content-type: application/octet-stream\n\n";
630 print "Content-type: text/html; charset=utf-8\n\n";
631 $apache->custom_response( 404, <<" HTML");
638 <center>Couldn't fetch $id as MARC21.</center>
645 return Apache2::Const::OK;
647 } elsif (OpenILS::WWW::SuperCat::Feed->exists($base_format)) {
648 my $feed = create_record_feed(
656 $feed->creator($host);
657 $feed->update_ts(gmtime_ISO8601());
658 $feed->link( unapi => $base) if ($flesh_feed);
660 print "Content-type: ". $feed->type ."; charset=utf-8\n\n";
661 print entityize($feed->toString) . "\n";
663 return Apache2::Const::OK;
666 my $req = $supercat->request("open-ils.supercat.$type.$format.$command",$id);
670 print "Content-type: text/html; charset=utf-8\n\n";
671 $apache->custom_response( 404, <<" HTML");
674 <title>$type $id not found!</title>
678 <center>Sorry, we couldn't $command a $type with the id of $id in format $format.</center>
685 print "Content-type: application/xml; charset=utf-8\n\n";
686 print entityize( $parser->parse_string( $req->gather(1) )->documentElement->toString );
688 return Apache2::Const::OK;
694 return Apache2::Const::DECLINED if (-e $apache->filename);
698 my $year = (gmtime())[5] + 1900;
699 my $host = $cgi->virtual_host || $cgi->server_name;
702 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
703 my $rel_name = $cgi->url(-relative=>1);
704 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
707 my $url = $cgi->url(-path_info=>$add_path);
708 my $root = (split 'feed', $url)[0] . '/';
709 my $base = (split 'bookbag', $url)[0] . '/bookbag';
710 my $unapi = (split 'feed', $url)[0] . '/unapi';
712 $root =~ s{(?<!http:)//}{/}go;
713 $base =~ s{(?<!http:)//}{/}go;
714 $unapi =~ s{(?<!http:)//}{/}go;
716 my $path = $cgi->path_info;
717 #warn "URL breakdown: $url -> $root -> $base -> $path -> $unapi";
719 my ($id,$type) = reverse split '/', $path;
720 my $flesh_feed = ($type =~ /-full$/o) ? 1 : 0;
722 my $bucket = $actor->request("open-ils.actor.container.public.flesh", 'biblio', $id)->gather(1);
723 return Apache2::Const::NOT_FOUND unless($bucket);
725 my $bucket_tag = "tag:$host,$year:record_bucket/$id";
726 if ($type eq 'opac') {
727 print "Location: $root/../../en-US/skin/default/xml/rresult.xml?rt=list&" .
728 join('&', map { "rl=" . $_->target_biblio_record_entry } @{ $bucket->items }) .
733 my $feed = create_record_feed(
736 [ map { $_->target_biblio_record_entry } @{ $bucket->items } ],
743 $feed->title("Items in Book Bag [".$bucket->name."]");
744 $feed->creator($host);
745 $feed->update_ts(gmtime_ISO8601());
747 $feed->link(rss => $base . "/rss2-full/$id" => 'application/rss+xml');
748 $feed->link(alternate => $base . "/atom-full/$id" => 'application/atom+xml');
749 $feed->link(html => $base . "/html-full/$id" => 'text/html');
750 $feed->link(unapi => $unapi);
754 '/opac/en-US/skin/default/xml/rresult.xml?rt=list&' .
755 join('&', map { 'rl=' . $_->target_biblio_record_entry } @{$bucket->items} ),
760 print "Content-type: ". $feed->type ."; charset=utf-8\n\n";
761 print entityize($feed->toString) . "\n";
763 return Apache2::Const::OK;
768 return Apache2::Const::DECLINED if (-e $apache->filename);
772 my $year = (gmtime())[5] + 1900;
773 my $host = $cgi->virtual_host || $cgi->server_name;
776 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
777 my $rel_name = $cgi->url(-relative=>1);
778 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
781 my $url = $cgi->url(-path_info=>$add_path);
782 my $root = (split 'feed', $url)[0];
783 my $base = (split 'freshmeat', $url)[0] . 'freshmeat';
784 my $unapi = (split 'feed', $url)[0] . 'unapi';
786 my $path = $cgi->path_info;
787 #warn "URL breakdown: $url ($rel_name) -> $root -> $base -> $path -> $unapi";
789 $path =~ s/^\/(?:feed\/)?freshmeat\///og;
791 my ($type,$rtype,$axis,$limit,$date) = split '/', $path;
792 my $flesh_feed = ($type =~ /-full$/o) ? 1 : 0;
795 my $list = $supercat->request("open-ils.supercat.$rtype.record.$axis.recent", $date, $limit)->gather(1);
797 #if ($type eq 'opac') {
798 # print "Location: $root/../../en-US/skin/default/xml/rresult.xml?rt=list&" .
799 # join('&', map { "rl=" . $_ } @$list) .
804 my $feed = create_record_feed( 'record', $type, $list, $unapi, undef, $flesh_feed);
808 $feed->title("Up to $limit recent $rtype ${axis}s from $date forward");
810 $feed->title("$limit most recent $rtype ${axis}s");
813 $feed->creator($host);
814 $feed->update_ts(gmtime_ISO8601());
816 $feed->link(rss => $base . "/rss2-full/$rtype/$axis/$limit/$date" => 'application/rss+xml');
817 $feed->link(alternate => $base . "/atom-full/$rtype/$axis/$limit/$date" => 'application/atom+xml');
818 $feed->link(html => $base . "/html-full/$rtype/$axis/$limit/$date" => 'text/html');
819 $feed->link(unapi => $unapi);
823 '/opac/en-US/skin/default/xml/rresult.xml?rt=list&' .
824 join('&', map { 'rl=' . $_} @$list ),
829 print "Content-type: ". $feed->type ."; charset=utf-8\n\n";
830 print entityize($feed->toString) . "\n";
832 return Apache2::Const::OK;
841 if ($version eq '1.0') {
843 Content-type: application/opensearchdescription+xml; charset=utf-8
845 <?xml version="1.0" encoding="UTF-8"?>
846 <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearchdescription/1.0/">
847 <Url>$base/1.0/$lib/-/$class/?searchTerms={searchTerms}&startPage={startPage}&startIndex={startIndex}&count={count}</Url>
848 <Format>http://a9.com/-/spec/opensearchrss/1.0/</Format>
849 <ShortName>$lib</ShortName>
850 <LongName>Search $lib</LongName>
851 <Description>Search the $lib OPAC by $class.</Description>
852 <Tags>$lib book library</Tags>
853 <SampleSearch>harry+potter</SampleSearch>
854 <Developer>Mike Rylander for GPLS/PINES</Developer>
855 <Contact>feedback\@open-ils.org</Contact>
856 <SyndicationRight>open</SyndicationRight>
857 <AdultContent>false</AdultContent>
858 </OpenSearchDescription>
862 Content-type: application/opensearchdescription+xml; charset=utf-8
864 <?xml version="1.0" encoding="UTF-8"?>
865 <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
866 <ShortName>$lib</ShortName>
867 <Description>Search the $lib OPAC by $class.</Description>
868 <Tags>$lib book library</Tags>
869 <Url type="application/rss+xml"
870 template="$base/1.1/$lib/rss2-full/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
871 <Url type="application/atom+xml"
872 template="$base/1.1/$lib/atom-full/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
873 <Url type="application/x-mods3+xml"
874 template="$base/1.1/$lib/mods3/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
875 <Url type="application/x-mods+xml"
876 template="$base/1.1/$lib/mods/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
877 <Url type="application/x-marcxml+xml"
878 template="$base/1.1/$lib/marcxml/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
879 <Url type="text/html"
880 template="$base/1.1/$lib/html-full/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/>
881 <LongName>Search $lib</LongName>
882 <Query role="example" searchTerms="harry+potter" />
883 <Developer>Mike Rylander for GPLS/PINES</Developer>
884 <Contact>feedback\@open-ils.org</Contact>
885 <SyndicationRight>open</SyndicationRight>
886 <AdultContent>false</AdultContent>
887 <Language>en-US</Language>
888 <OutputEncoding>UTF-8</OutputEncoding>
889 <InputEncoding>UTF-8</InputEncoding>
890 </OpenSearchDescription>
894 return Apache2::Const::OK;
897 sub opensearch_feed {
899 return Apache2::Const::DECLINED if (-e $apache->filename);
902 my $year = (gmtime())[5] + 1900;
904 my $host = $cgi->virtual_host || $cgi->server_name;
907 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
908 my $rel_name = $cgi->url(-relative=>1);
909 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
912 my $url = $cgi->url(-path_info=>$add_path);
913 my $root = (split 'opensearch', $url)[0];
914 my $base = (split 'opensearch', $url)[0] . 'opensearch';
915 my $unapi = (split 'opensearch', $url)[0] . 'unapi';
917 my $path = $cgi->path_info;
918 #warn "URL breakdown: $url ($rel_name) -> $root -> $base -> $path -> $unapi";
920 if ($path =~ m{^/?(1\.\d{1})/(?:([^/]+)/)?([^/]+)/osd.xml}o) {
926 if (!$lib || $lib eq '-') {
927 $lib = $actor->request(
928 'open-ils.actor.org_unit_list.search' => parent_ou => undef
929 )->gather(1)->[0]->shortname;
936 return opensearch_osd($version, $lib, $class, $base);
940 my $page = $cgi->param('startPage') || 1;
941 my $offset = $cgi->param('startIndex') || 1;
942 my $limit = $cgi->param('count') || 10;
944 $page = 1 if ($page !~ /^\d+$/);
945 $offset = 1 if ($offset !~ /^\d+$/);
946 $limit = 10 if ($limit !~ /^\d+$/); $limit = 25 if ($limit > 25);
949 $offset = ($page - 1) * $limit;
954 my ($version,$org,$type,$class,$terms,$sort,$sortdir,$lang) = ('','','','','','','','');
955 (undef,$version,$org,$type,$class,$terms,$sort,$sortdir,$lang) = split '/', $path;
957 $lang = $cgi->param('searchLang') if $cgi->param('searchLang');
958 $lang = '' if ($lang eq '*');
960 $sort = $cgi->param('searchSort') if $cgi->param('searchSort');
961 $sortdir = $cgi->param('searchSortDir') if $cgi->param('searchSortDir');
962 $terms .= " " . $cgi->param('searchTerms') if $cgi->param('searchTerms');
964 $class = $cgi->param('searchClass') if $cgi->param('searchClass');
967 $type = $cgi->param('responseType') if $cgi->param('responseType');
970 $org = $cgi->param('searchOrg') if $cgi->param('searchOrg');
974 my $kwt = $cgi->param('kw');
975 my $tit = $cgi->param('ti');
976 my $aut = $cgi->param('au');
977 my $sut = $cgi->param('su');
978 my $set = $cgi->param('se');
980 $terms .= " keyword: $kwt" if ($kwt);
981 $terms .= " title: $tit" if ($tit);
982 $terms .= " author: $aut" if ($aut);
983 $terms .= " subject: $sut" if ($sut);
984 $terms .= " series: $set" if ($set);
986 if ($version eq '1.0') {
988 } elsif ($type eq '-') {
991 my $flesh_feed = ($type =~ /-full$/o) ? 1 : 0;
993 if ($terms eq 'help') {
994 print $cgi->header(-type => 'text/html');
998 <title>just type something!</title>
1001 <p>You are in a maze of dark, twisty stacks, all alike.</p>
1005 return Apache2::Const::OK;
1008 $terms = decode_utf8($terms);
1009 $lang = 'eng' if ($lang eq 'en-US');
1013 $org_unit = $actor->request(
1014 'open-ils.actor.org_unit_list.search' => parent_ou => undef
1017 $org_unit = $actor->request(
1018 'open-ils.actor.org_unit_list.search' => shortname => uc($org)
1022 my $recs = $search->request(
1023 'open-ils.search.biblio.multiclass.query' => {
1024 org_unit => $org_unit->[0]->id,
1027 ($lang ? ( 'language' => $lang ) : ()),
1031 my $feed = create_record_feed(
1034 [ map { $_->[0] } @{$recs->{ids}} ],
1041 $feed->search($terms);
1042 $feed->class($class);
1044 $feed->title("Search results for [$class => $terms] at ".$org_unit->[0]->name);
1046 $feed->creator($host);
1047 $feed->update_ts(gmtime_ISO8601());
1049 $feed->_create_node(
1050 $feed->{item_xpath},
1051 'http://a9.com/-/spec/opensearch/1.1/',
1056 $feed->_create_node(
1057 $feed->{item_xpath},
1058 'http://a9.com/-/spec/opensearch/1.1/',
1063 $feed->_create_node(
1064 $feed->{item_xpath},
1065 'http://a9.com/-/spec/opensearch/1.1/',
1072 $base . "/$version/$org/$type/$class?searchTerms=$terms&searchSort=$sort&searchSortDir=$sortdir&searchLang=$lang&startIndex=" . int($offset + $limit + 1) . "&count=" . $limit =>
1073 'application/opensearch+xml'
1074 ) if ($offset + $limit < $recs->{count});
1078 $base . "/$version/$org/$type/$class?searchTerms=$terms&searchSort=$sort&searchSortDir=$sortdir&searchLang=$lang&startIndex=" . int(($offset - $limit) + 1) . "&count=" . $limit =>
1079 'application/opensearch+xml'
1084 $base . "/$version/$org/$type/$class?searchTerms=$terms&searchSort=$sort&searchSortDir=$sortdir&searchLang=$lang" =>
1085 'application/opensearch+xml'
1090 $base . "/$version/$org/rss2-full/$class?searchTerms=$terms&searchSort=$sort&searchSortDir=$sortdir&searchLang=$lang" =>
1091 'application/rss+xml'
1096 $base . "/$version/$org/atom-full/$class?searchTerms=$terms&searchSort=$sort&searchSortDir=$sortdir&searchLang=$lang" =>
1097 'application/atom+xml'
1102 $base . "/$version/$org/html/$class?searchTerms=$terms&searchSort=$sort&searchSortDir=$sortdir&searchLang=$lang" =>
1108 $base . "/$version/$org/html-full/$class?searchTerms=$terms&searchSort=$sort&searchSortDir=$sortdir&searchLang=$lang" =>
1112 $feed->link( 'unapi-server' => $unapi);
1116 # $root . "../$lang/skin/default/xml/rresult.xml?rt=list&" .
1117 # join('&', map { 'rl=' . $_->[0] } grep { ref $_ && defined $_->[0] } @{$recs->{ids}} ),
1121 print entityize($feed->toString) . "\n";
1123 return Apache2::Const::OK;
1126 sub create_record_feed {
1129 my $records = shift;
1132 my $lib = uc(shift()) || '-';
1134 $flesh = 1 if (!defined($flesh));
1137 my $base = $cgi->url;
1138 my $host = $cgi->virtual_host || $cgi->server_name;
1140 my $year = (gmtime())[5] + 1900;
1142 my $flesh_feed = ($type =~ s/-full$//o) ? 1 : 0;
1144 my $feed = new OpenILS::WWW::SuperCat::Feed ($type);
1145 $feed->base($base) if ($flesh);
1146 $feed->unapi($unapi) if ($flesh);
1148 $type = 'atom' if ($type eq 'html');
1149 $type = 'marcxml' if ($type eq 'htmlholdings');
1151 #$records = $supercat->request( "open-ils.supercat.record.object.retrieve", $records )->gather(1);
1154 for my $record (@$records) {
1155 next unless($record);
1157 #my $rec = $record->id;
1160 my $item_tag = "tag:$host,$year:biblio-record_entry/$rec/$lib";
1161 $item_tag = "tag:$host,$year:isbn/$rec/$lib" if ($search eq 'isbn');
1163 my $xml = $supercat->request(
1164 "open-ils.supercat.$search.$type.retrieve",
1169 my $node = $feed->add_item($xml);
1173 if ($lib && $type eq 'marcxml' && $flesh) {
1174 my $r = $supercat->request( "open-ils.supercat.$search.holdings_xml.retrieve", $rec, $lib );
1175 while ( !$r->complete ) {
1176 $xml .= join('', map {$_->content} $r->recv);
1178 $xml .= join('', map {$_->content} $r->recv);
1179 $node->add_holdings($xml);
1182 $node->id($item_tag) if ($flesh);
1183 #$node->update_ts(clense_ISO8601($record->edit_date));
1184 $node->link(alternate => $feed->unapi . "?id=$item_tag&format=htmlholdings-full" => 'text/html') if ($flesh);
1185 $node->link(opac => $feed->unapi . "?id=$item_tag&format=opac") if ($flesh);
1186 $node->link(unapi => $feed->unapi . "?id=$item_tag") if ($flesh);
1187 $node->link('unapi-id' => $item_tag) if ($flesh);
1194 my $stuff = NFC(shift());
1195 $stuff =~ s/&(?!\S+;)/&/gso;
1196 $stuff =~ s/([\x{0080}-\x{fffd}])/sprintf('&#x%X;',ord($1))/sgoe;
1202 return Apache2::Const::DECLINED if (-e $apache->filename);
1205 my $year = (gmtime())[5] + 1900;
1207 my $host = $cgi->virtual_host || $cgi->server_name;
1210 if ( $cgi->server_software !~ m|^Apache/2.2| ) {
1211 my $rel_name = $cgi->url(-relative=>1);
1212 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
1215 my $url = $cgi->url(-path_info=>$add_path);
1216 my $root = (split 'browse', $url)[0];
1217 my $base = (split 'browse', $url)[0] . 'browse';
1218 my $unapi = (split 'browse', $url)[0] . 'unapi';
1220 my $path = $cgi->path_info;
1223 my ($format,$axis,$site,$string,$page,$page_size) = split '/', $path;
1224 #warn " >>> $format -> $axis -> $site -> $string -> $page -> $page_size ";
1226 $site ||= $cgi->param('searchOrg');
1227 $page ||= $cgi->param('startPage') || 0;
1228 $page_size ||= $cgi->param('count') || 9;
1230 $page = 0 if ($page !~ /^-?\d+$/);
1232 my $prev = join('/', $base,$format,$axis,$site,$string,$page - 1,$page_size);
1233 my $next = join('/', $base,$format,$axis,$site,$string,$page + 1,$page_size);
1235 unless ($string and $axis and grep { $axis eq $_ } keys %browse_types) {
1236 warn "something's wrong...";
1237 warn " >>> $format -> $axis -> $site -> $string -> $page -> $page_size ";
1241 $string = decode_utf8($string);
1242 $string =~ s/\+/ /go;
1245 my $tree = $supercat->request(
1246 "open-ils.supercat.$axis.browse",
1253 my ($header,$content) = $browse_types{$axis}{$format}->($tree,$prev,$next);
1254 print $header.$content;
1255 return Apache2::Const::OK;
1261 my $req = SRU::Request->newFromCGI( $cgi );
1262 my $resp = SRU::Response->newFromRequest( $req );
1264 if ( $resp->type eq 'searchRetrieve' ) {
1265 my $cql_query = $req->query;
1266 my $search_string = $req->cql->toEvergreen;
1268 my $offset = $req->startRecord;
1269 $offset-- if ($offset);
1272 my $limit = $req->maximumRecords;
1275 warn "SRU search string [$cql_query] converted to [$search_string]\n";
1277 my $recs = $search->request(
1278 'open-ils.search.biblio.multiclass.query' => {offset => $offset, limit => $limit} => $search_string
1281 my $bre = $supercat->request( 'open-ils.supercat.record.object.retrieve' => [ map { $_->[0] } @{$recs->{ids}} ] )->gather(1);
1284 SRU::Response::Record->new(
1285 recordSchema => 'info:srw/schema/1/marcxml-v1.1',
1286 recordData => $_->marc
1290 $resp->numberOfRecords($recs->{count});
1292 print $cgi->header( -type => 'application/xml' );
1293 print entityize($resp->asXML) . "\n";
1294 return Apache2::Const::OK;
1299 package CQL::BooleanNode;
1303 my $left = $self->left();
1304 my $right = $self->right();
1305 my $leftStr = $left->toEvergreen;
1306 my $rightStr = $right->toEvergreen();
1308 my $op = '||' if uc $self->op() eq 'OR';
1311 return "$leftStr $rightStr";
1314 package CQL::TermNode;
1316 our %qualifier_map = (
1319 'eg.site' => 'site',
1320 'eg.sort' => 'sort',
1321 'eg.direction' => 'dir',
1322 'eg.available' => 'available',
1325 'dc.title' => 'title',
1326 'bib.titleabbreviated' => 'title|abbreviated',
1327 'bib.titleuniform' => 'title|uniform',
1328 'bib.titletranslated' => 'title|translated',
1329 'bib.titlealternative' => 'title',
1330 'bib.titleseries' => 'series',
1332 # Author/Name class:
1333 'creator' => 'author',
1334 'dc.creator' => 'author',
1335 'dc.contributer' => 'author',
1336 'dc.publisher' => 'keyword',
1337 'bib.name' => 'author',
1338 'bib.namepersonal' => 'author|personal',
1339 'bib.namepersonalfamily'=> 'author|personal',
1340 'bib.namepersonalgiven' => 'author|personal',
1341 'bib.namecorporate' => 'author|corporate',
1342 'bib.nameconference' => 'author|converence',
1345 'dc.subject' => 'subject',
1346 'bib.subjectplace' => 'subject|geographic',
1347 'bib.subjecttitle' => 'keyword',
1348 'bib.subjectname' => 'subject|name',
1349 'bib.subjectoccupation' => 'keyword',
1352 'srw.serverchoice' => 'keyword',
1355 'dc.identifier' => 'keyword',
1358 'bib.dateissued' => undef,
1359 'bib.datecreated' => undef,
1360 'bib.datevalid' => undef,
1361 'bib.datemodified' => undef,
1362 'bib.datecopyright' => undef,
1368 'dc.format' => undef,
1371 'bib.genre' => 'keyword',
1374 'bib.audience' => undef,
1377 'bib.originplace' => undef,
1380 'dc.language' => 'lang',
1383 'bib.edition' => 'keyword',
1386 'bib.volume' => 'keyword',
1387 'bib.issue' => 'keyword',
1388 'bib.startpage' => 'keyword',
1389 'bib.endpage' => 'keyword',
1392 'bib.issuance' => 'keyword',
1397 my $qualifier = $self->getQualifier();
1398 my $term = $self->getTerm();
1399 my $relation = $self->getRelation();
1404 if ( exists($qualifier_map{lc($qualifier)}) ) {
1405 $qualifier = $qualifier_map{lc($qualifier)} || 'kw';
1409 my @modifiers = $relation->getModifiers();
1411 my $base = $relation->getBase();
1412 if ( grep { $base eq $_ } qw/= scr exact all/ ) {
1415 foreach my $m ( @modifiers ) {
1416 if( grep { $m->[ 1 ] eq $_ } qw/cql.fuzzy cql.stem cql.relevant cql.word/ ) {
1422 $quote_it = 0 if ( $base eq 'all' );
1423 $term = maybeQuote($term) if $quote_it;
1426 croak( "Evergreen doesn't support the $base relations" );
1429 return "$qualifier:$term";