]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm
supporting default searchLang param of "*"
[Evergreen.git] / Open-ILS / src / perlmods / OpenILS / WWW / SuperCat.pm
1 package OpenILS::WWW::SuperCat;
2 use strict; use warnings;
3
4 use Apache2::Log;
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;
10 use CGI;
11 use Data::Dumper;
12
13 use OpenSRF::EX qw(:try);
14 use OpenSRF::Utils qw/:datetime/;
15 use OpenSRF::Utils::Cache;
16 use OpenSRF::System;
17 use OpenSRF::AppSession;
18 use XML::LibXML;
19 use XML::LibXSLT;
20
21 use Encode;
22 use Unicode::Normalize;
23 use OpenILS::Utils::Fieldmapper;
24 use OpenILS::WWW::SuperCat::Feed;
25 use OpenSRF::Utils::Logger qw/$logger/;
26
27
28 # set the bootstrap config when this module is loaded
29 my ($bootstrap, $cstore, $supercat, $actor, $parser, $search, $xslt, $cn_browse_xslt, %browse_types);
30
31 $browse_types{call_number}{xml} = sub {
32         my $tree = shift;
33
34         my $year = (gmtime())[5] + 1900;
35         my $content = '';
36
37         $content .= "<hold:volumes  xmlns:hold='http://open-ils.org/spec/holdings/v1'>";
38
39         for my $cn (@$tree) {
40                 (my $cn_class = $cn->class_name) =~ s/::/-/gso;
41                 $cn_class =~ s/Fieldmapper-//gso;
42
43                 my $cn_tag = "tag:open-ils.org,$year:$cn_class/".$cn->id;
44                 my $cn_lib = $cn->owning_lib->shortname;
45                 my $cn_label = $cn->label;
46
47                 $cn_label =~ s/\n//gos;
48                 $cn_label =~ s/'/&apos;/go;
49
50                 (my $ou_class = $cn->owning_lib->class_name) =~ s/::/-/gso;
51                 $ou_class =~ s/Fieldmapper-//gso;
52
53                 my $ou_tag = "tag:open-ils.org,$year:$ou_class/".$cn->owning_lib->id;
54                 my $ou_name = $cn->owning_lib->name;
55
56                 $ou_name =~ s/\n//gos;
57                 $ou_name =~ s/'/&apos;/go;
58
59                 (my $rec_class = $cn->record->class_name) =~ s/::/-/gso;
60                 $rec_class =~ s/Fieldmapper-//gso;
61
62                 my $rec_tag = "tag:open-ils.org,$year:$rec_class/".$cn->record->id.'/'.$cn->owning_lib->shortname;
63
64                 $content .= "<hold:volume id='$cn_tag' lib='$cn_lib' label='$cn_label'>";
65                 $content .= "<act:owning_lib xmlns:act='http://open-ils.org/spec/actors/v1' id='$ou_tag' name='$ou_name'/>";
66
67                 my $r_doc = $parser->parse_string($cn->record->marc);
68                 $r_doc->documentElement->setAttribute( id => $rec_tag );
69                 $content .= entityize($r_doc->documentElement->toString);
70
71                 $content .= "</hold:volume>";
72         }
73
74         $content .= '</hold:volumes>';
75         return ("Content-type: application/xml\n\n",$content);
76 };
77
78
79 $browse_types{call_number}{html} = sub {
80         my $tree = shift;
81         my $p = shift;
82         my $n = shift;
83
84         if (!$cn_browse_xslt) {
85                 $cn_browse_xslt = $parser->parse_file(
86                         OpenSRF::Utils::SettingsClient
87                                 ->new
88                                 ->config_value( dirs => 'xsl' ).
89                         "/CNBrowse2HTML.xsl"
90                 );
91                 $cn_browse_xslt = $xslt->parse_stylesheet( $cn_browse_xslt );
92         }
93
94         my (undef,$xml) = $browse_types{call_number}{xml}->($tree);
95
96         return (
97                 "Content-type: text/html\n\n",
98                 entityize(
99                         $cn_browse_xslt->transform(
100                                 $parser->parse_string( $xml ),
101                                 'prev' => "'$p'",
102                                 'next' => "'$n'"
103                         )->toString(1)
104                 )
105         );
106 };
107
108 sub import {
109         my $self = shift;
110         $bootstrap = shift;
111 }
112
113
114 sub child_init {
115         OpenSRF::System->bootstrap_client( config_file => $bootstrap );
116         
117         my $idl = OpenSRF::Utils::SettingsClient->new->config_value("IDL");
118         Fieldmapper->import(IDL => $idl);
119
120         $supercat = OpenSRF::AppSession->create('open-ils.supercat');
121         $cstore = OpenSRF::AppSession->create('open-ils.cstore');
122         $actor = OpenSRF::AppSession->create('open-ils.actor');
123         $search = OpenSRF::AppSession->create('open-ils.search');
124         $parser = new XML::LibXML;
125         $xslt = new XML::LibXSLT;
126
127         $cn_browse_xslt = $parser->parse_file(
128                 OpenSRF::Utils::SettingsClient
129                         ->new
130                         ->config_value( dirs => 'xsl' ).
131                 "/CNBrowse2HTML.xsl"
132         );
133
134         $cn_browse_xslt = $xslt->parse_stylesheet( $cn_browse_xslt );
135
136 }
137
138 sub oisbn {
139
140         my $apache = shift;
141         return Apache2::Const::DECLINED if (-e $apache->filename);
142
143         (my $isbn = $apache->path_info) =~ s{^.*?([^/]+)$}{$1}o;
144
145         my $list = $supercat
146                 ->request("open-ils.supercat.oisbn", $isbn)
147                 ->gather(1);
148
149         print "Content-type: application/xml; charset=utf-8\n\n";
150         print "<?xml version='1.0' encoding='UTF-8' ?>\n";
151
152         unless (exists $$list{metarecord}) {
153                 print '<idlist/>';
154                 return Apache2::Const::OK;
155         }
156
157         print "<idlist metarecord='$$list{metarecord}'>\n";
158
159         for ( keys %{ $$list{record_list} } ) {
160                 (my $o = $$list{record_list}{$_}) =~s/^(\S+).*?$/$1/o;
161                 print "  <isbn record='$_'>$o</isbn>\n"
162         }
163
164         print "</idlist>\n";
165
166         return Apache2::Const::OK;
167 }
168
169 sub unapi {
170
171         my $apache = shift;
172         return Apache2::Const::DECLINED if (-e $apache->filename);
173
174         my $cgi = new CGI;
175
176         my $add_path = 0;
177         if ( $cgi->server_software !~ m|^Apache/2.2| ) {
178                 my $rel_name = $cgi->url(-relative=>1);
179                 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
180         }
181
182         my $url = $cgi->url(-path_info=>$add_path);
183         my $root = (split 'unapi', $url)[0];
184         my $base = (split 'unapi', $url)[0] . 'unapi';
185
186
187         my $uri = $cgi->param('id') || '';
188         my $host = $cgi->virtual_host || $cgi->server_name;
189
190         my $format = $cgi->param('format');
191         my $flesh_feed = ($format =~ /-full$/o) ? 1 : 0;
192         (my $base_format = $format) =~ s/-full$//o;
193         my ($id,$type,$command,$lib) = ('','','');
194
195         if (!$format) {
196                 my $body = "Content-type: application/xml; charset=utf-8\n\n";
197         
198                 if ($uri =~ m{^tag:[^:]+:([^\/]+)/([^/]+)(?:/(.+))$}o) {
199                         $id = $2;
200                         $lib = uc($3);
201                         $type = 'record';
202                         $type = 'metarecord' if ($1 =~ /^m/o);
203
204                         my $list = $supercat
205                                 ->request("open-ils.supercat.$type.formats")
206                                 ->gather(1);
207
208                         if ($type eq 'record' or $type eq 'isbn') {
209                                 $body .= <<"                            FORMATS";
210 <formats id='$uri'>
211         <format name='opac' type='text/html'/>
212         <format name='html' type='text/html'/>
213         <format name='htmlholdings' type='text/html'/>
214         <format name='html-full' type='text/html'/>
215         <format name='htmlholdings-full' type='text/html'/>
216                                 FORMATS
217                         } elsif ($type eq 'metarecord') {
218                                 $body .= <<"                            FORMATS";
219                                 <formats id='$uri'>
220                                         <format name='opac' type='text/html'/>
221                                 FORMATS
222                         }
223
224                         for my $h (@$list) {
225                                 my ($type) = keys %$h;
226                                 $body .= "\t<format name='$type' type='application/xml'";
227
228                                 for my $part ( qw/namespace_uri docs schema_location/ ) {
229                                         $body .= " $part='$$h{$type}{$part}'"
230                                                 if ($$h{$type}{$part});
231                                 }
232                                 
233                                 $body .= "/>\n";
234
235                                 if (OpenILS::WWW::SuperCat::Feed->exists($type)) {
236                                         $body .= "\t<format name='$type-full' type='application/xml'";
237
238                                         for my $part ( qw/namespace_uri docs schema_location/ ) {
239                                                 $body .= " $part='$$h{$type}{$part}'"
240                                                         if ($$h{$type}{$part});
241                                         }
242                                 
243                                         $body .= "/>\n";
244                                 }
245                         }
246
247                         $body .= "</formats>\n";
248
249                 } else {
250                         my $list = $supercat
251                                 ->request("open-ils.supercat.record.formats")
252                                 ->gather(1);
253                                 
254                         push @$list,
255                                 @{ $supercat
256                                         ->request("open-ils.supercat.metarecord.formats")
257                                         ->gather(1);
258                                 };
259
260                         my %hash = map { ( (keys %$_)[0] => (values %$_)[0] ) } @$list;
261                         $list = [ map { { $_ => $hash{$_} } } sort keys %hash ];
262
263                         $body .= <<"                    FORMATS";
264 <formats>
265         <format name='opac' type='text/html'/>
266         <format name='html' type='text/html'/>
267         <format name='htmlholdings' type='text/html'/>
268         <format name='html-full' type='text/html'/>
269         <format name='htmlholdings-full' type='text/html'/>
270                         FORMATS
271
272
273                         for my $h (@$list) {
274                                 my ($type) = keys %$h;
275                                 $body .= "\t<format name='$type' type='application/xml'";
276
277                                 for my $part ( qw/namespace_uri docs schema_location/ ) {
278                                         $body .= " $part='$$h{$type}{$part}'"
279                                                 if ($$h{$type}{$part});
280                                 }
281                                 
282                                 $body .= "/>\n";
283
284                                 if (OpenILS::WWW::SuperCat::Feed->exists($type)) {
285                                         $body .= "\t<format name='$type-full' type='application/xml'";
286
287                                         for my $part ( qw/namespace_uri docs schema_location/ ) {
288                                                 $body .= " $part='$$h{$type}{$part}'"
289                                                         if ($$h{$type}{$part});
290                                         }
291                                 
292                                         $body .= "/>\n";
293                                 }
294                         }
295
296                         $body .= "</formats>\n";
297
298                 }
299                 print $body;
300                 return Apache2::Const::OK;
301         }
302
303         if ($uri =~ m{^tag:[^:]+:([^\/]+)/([^/]+)(?:/(.+))?}o) {
304                 $id = $2;
305                 $lib = uc($3);
306                 $type = 'record';
307                 $type = 'metarecord' if ($1 =~ /^metabib/o);
308                 $type = 'isbn' if ($1 =~ /^isbn/o);
309                 $type = 'call_number' if ($1 =~ /^call_number/o);
310                 $command = 'retrieve';
311                 $command = 'browse' if ($type eq 'call_number');
312         }
313
314         if (!$lib || $lib eq '-') {
315                 $lib = $actor->request(
316                         'open-ils.actor.org_unit_list.search' => parent_ou => undef
317                 )->gather(1)->[0]->shortname;
318         }
319
320         my $lib_object = $actor->request(
321                 'open-ils.actor.org_unit_list.search' => shortname => $lib
322         )->gather(1)->[0];
323         my $lib_id = $lib_object->id;
324
325         my $ou_types = $actor->request( 'open-ils.actor.org_types.retrieve' )->gather(1);
326         my $lib_depth = (grep { $_->id == $lib_object->ou_type } @$ou_types)[0]->depth;
327
328         if ($type eq 'call_number' and $command eq 'browse') {
329                 print "Location: $root/browse/$base_format/call_number/$lib/$id\n\n";
330                 return 302;
331         }
332
333         if ($type eq 'isbn') {
334                 my $rec = $supercat->request('open-ils.supercat.isbn.object.retrieve',$id)->gather(1);
335                 if (!@$rec) {
336                         print "Content-type: text/html; charset=utf-8\n\n";
337                         $apache->custom_response( 404, <<"                      HTML");
338                         <html>
339                                 <head>
340                                         <title>Type [$type] with id [$id] not found!</title>
341                                 </head>
342                                 <body>
343                                         <br/>
344                                         <center>Sorry, we couldn't $command a $type with the id of $id in format $format.</center>
345                                 </body>
346                         </html>
347                         HTML
348                         return 404;
349                 }
350                 $id = $rec->[0]->id;
351                 $type = 'record';
352         }
353
354         if ( !grep
355                { (keys(%$_))[0] eq $base_format }
356                @{ $supercat->request("open-ils.supercat.$type.formats")->gather(1) }
357              and !grep
358                { $_ eq $base_format }
359                qw/opac html htmlholdings/
360         ) {
361                 print "Content-type: text/html; charset=utf-8\n\n";
362                 $apache->custom_response( 406, <<"              HTML");
363                 <html>
364                         <head>
365                                 <title>Invalid format [$format] for type [$type]!</title>
366                         </head>
367                         <body>
368                                 <br/>
369                                 <center>Sorry, format $format is not valid for type $type.</center>
370                         </body>
371                 </html>
372                 HTML
373                 return 406;
374         }
375
376         if ($format eq 'opac') {
377                 print "Location: $root/../../en-US/skin/default/xml/rresult.xml?m=$id&l=$lib_id&d=$lib_depth\n\n"
378                         if ($type eq 'metarecord');
379                 print "Location: $root/../../en-US/skin/default/xml/rdetail.xml?r=$id&l=$lib_id&d=$lib_depth\n\n"
380                         if ($type eq 'record');
381                 return 302;
382         } elsif (OpenILS::WWW::SuperCat::Feed->exists($base_format)) {
383                 my $feed = create_record_feed(
384                         $type,
385                         $format => [ $id ],
386                         $base,
387                         $lib,
388                         $flesh_feed
389                 );
390
391                 if (!$feed->count) {
392                         print "Content-type: text/html; charset=utf-8\n\n";
393                         $apache->custom_response( 404, <<"                      HTML");
394                         <html>
395                                 <head>
396                                         <title>Type [$type] with id [$id] not found!</title>
397                                 </head>
398                                 <body>
399                                         <br/>
400                                         <center>Sorry, we couldn't $command a $type with the id of $id in format $format.</center>
401                                 </body>
402                         </html>
403                         HTML
404                         return 404;
405                 }
406
407                 $feed->root($root);
408                 $feed->creator($host);
409                 $feed->update_ts(gmtime_ISO8601());
410                 $feed->link( unapi => $base) if ($flesh_feed);
411
412                 print "Content-type: ". $feed->type ."; charset=utf-8\n\n";
413                 print entityize($feed->toString) . "\n";
414
415                 return Apache2::Const::OK;
416         }
417
418         my $req = $supercat->request("open-ils.supercat.$type.$format.$command",$id);
419         my $data = $req->gather(1);
420
421         if ($req->failed || !$data) {
422                 print "Content-type: text/html; charset=utf-8\n\n";
423                 $apache->custom_response( 404, <<"              HTML");
424                 <html>
425                         <head>
426                                 <title>$type $id not found!</title>
427                         </head>
428                         <body>
429                                 <br/>
430                                 <center>Sorry, we couldn't $command a $type with the id of $id in format $format.</center>
431                         </body>
432                 </html>
433                 HTML
434                 return 404;
435         }
436
437         print "Content-type: application/xml; charset=utf-8\n\n$data";
438
439         return Apache2::Const::OK;
440 }
441
442 sub supercat {
443
444         my $apache = shift;
445         return Apache2::Const::DECLINED if (-e $apache->filename);
446
447         my $cgi = new CGI;
448
449         my $add_path = 0;
450         if ( $cgi->server_software !~ m|^Apache/2.2| ) {
451                 my $rel_name = $cgi->url(-relative=>1);
452                 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
453         }
454
455         my $url = $cgi->url(-path_info=>$add_path);
456         my $root = (split 'supercat', $url)[0];
457         my $base = (split 'supercat', $url)[0] . 'supercat';
458         my $unapi = (split 'supercat', $url)[0] . 'unapi';
459
460         my $host = $cgi->virtual_host || $cgi->server_name;
461
462         my $path = $cgi->path_info;
463         my ($id,$type,$format,$command) = reverse split '/', $path;
464         my $flesh_feed = ($type =~ /-full$/o) ? 1 : 0;
465         (my $base_format = $format) =~ s/-full$//o;
466         
467         if ( $path =~ m{^/formats(?:/([^\/]+))?$}o ) {
468                 print "Content-type: application/xml; charset=utf-8\n";
469                 if ($1) {
470                         my $list = $supercat
471                                 ->request("open-ils.supercat.$1.formats")
472                                 ->gather(1);
473
474                         print "\n";
475
476                         print "<formats>
477                                    <format>
478                                      <name>opac</name>
479                                      <type>text/html</type>
480                                    </format>";
481
482                         if ($1 eq 'record' or $1 eq 'isbn') {
483                                 print "<format>
484                                      <name>htmlholdings</name>
485                                      <type>text/html</type>
486                                    </format>
487                                    <format>
488                                      <name>html</name>
489                                      <type>text/html</type>
490                                    </format>
491                                    <format>
492                                      <name>htmlholdings-full</name>
493                                      <type>text/html</type>
494                                    </format>
495                                    <format>
496                                      <name>html-full</name>
497                                      <type>text/html</type>
498                                    </format>";
499                         }
500
501                         for my $h (@$list) {
502                                 my ($type) = keys %$h;
503                                 print "<format><name>$type</name><type>application/xml</type>";
504
505                                 for my $part ( qw/namespace_uri docs schema_location/ ) {
506                                         print "<$part>$$h{$type}{$part}</$part>"
507                                                 if ($$h{$type}{$part});
508                                 }
509                                 
510                                 print '</format>';
511
512                                 if (OpenILS::WWW::SuperCat::Feed->exists($type)) {
513                                         print "<format><name>$type-full</name><type>application/xml</type>";
514
515                                         for my $part ( qw/namespace_uri docs schema_location/ ) {
516                                                 print "<$part>$$h{$type}{$part}</$part>"
517                                                         if ($$h{$type}{$part});
518                                         }
519                                 
520                                         print '</format>';
521                                 }
522
523                         }
524
525                         print "</formats>\n";
526
527                         return Apache2::Const::OK;
528                 }
529
530                 my $list = $supercat
531                         ->request("open-ils.supercat.record.formats")
532                         ->gather(1);
533                                 
534                 push @$list,
535                         @{ $supercat
536                                 ->request("open-ils.supercat.metarecord.formats")
537                                 ->gather(1);
538                         };
539
540                 my %hash = map { ( (keys %$_)[0] => (values %$_)[0] ) } @$list;
541                 $list = [ map { { $_ => $hash{$_} } } sort keys %hash ];
542
543                 print "\n<formats>
544                            <format>
545                              <name>opac</name>
546                              <type>text/html</type>
547                            </format>
548                            <format>
549                              <name>htmlholdings</name>
550                              <type>text/html</type>
551                            </format>
552                            <format>
553                              <name>html</name>
554                              <type>text/html</type>
555                            </format>
556                            <format>
557                              <name>htmlholdings-full</name>
558                              <type>text/html</type>
559                            </format>
560                            <format>
561                              <name>html-full</name>
562                              <type>text/html</type>
563                            </format>";
564
565                 for my $h (@$list) {
566                         my ($type) = keys %$h;
567                         print "<format><name>$type</name><type>application/xml</type>";
568
569                         for my $part ( qw/namespace_uri docs schema_location/ ) {
570                                 print "<$part>$$h{$type}{$part}</$part>"
571                                         if ($$h{$type}{$part});
572                         }
573                         
574                         print '</format>';
575
576                         if (OpenILS::WWW::SuperCat::Feed->exists($type)) {
577                                 print "<format><name>$type-full</name><type>application/xml</type>";
578
579                                 for my $part ( qw/namespace_uri docs schema_location/ ) {
580                                         print "<$part>$$h{$type}{$part}</$part>"
581                                                 if ($$h{$type}{$part});
582                                 }
583                                 
584                                 print '</format>';
585                         }
586
587                 }
588
589                 print "</formats>\n";
590
591
592                 return Apache2::Const::OK;
593         }
594
595         if ($format eq 'opac') {
596                 print "Location: $root/../../en-US/skin/default/xml/rresult.xml?m=$id\n\n"
597                         if ($type eq 'metarecord');
598                 print "Location: $root/../../en-US/skin/default/xml/rdetail.xml?r=$id\n\n"
599                         if ($type eq 'record');
600                 return 302;
601         } elsif (OpenILS::WWW::SuperCat::Feed->exists($base_format)) {
602                 my $feed = create_record_feed(
603                         $type,
604                         $format => [ $id ],
605                         undef, undef,
606                         $flesh_feed
607                 );
608
609                 $feed->root($root);
610                 $feed->creator($host);
611                 $feed->update_ts(gmtime_ISO8601());
612                 $feed->link( unapi => $base) if ($flesh_feed);
613
614                 print "Content-type: ". $feed->type ."; charset=utf-8\n\n";
615                 print entityize($feed->toString) . "\n";
616
617                 return Apache2::Const::OK;
618         }
619
620         my $req = $supercat->request("open-ils.supercat.$type.$format.$command",$id);
621         $req->wait_complete;
622
623         if ($req->failed) {
624                 print "Content-type: text/html; charset=utf-8\n\n";
625                 $apache->custom_response( 404, <<"              HTML");
626                 <html>
627                         <head>
628                                 <title>$type $id not found!</title>
629                         </head>
630                         <body>
631                                 <br/>
632                                 <center>Sorry, we couldn't $command a $type with the id of $id in format $format.</center>
633                         </body>
634                 </html>
635                 HTML
636                 return 404;
637         }
638
639         print "Content-type: application/xml; charset=utf-8\n\n";
640         print entityize( $parser->parse_string( $req->gather(1) )->documentElement->toString );
641
642         return Apache2::Const::OK;
643 }
644
645
646 sub bookbag_feed {
647         my $apache = shift;
648         return Apache2::Const::DECLINED if (-e $apache->filename);
649
650         my $cgi = new CGI;
651
652         my $year = (gmtime())[5] + 1900;
653         my $host = $cgi->virtual_host || $cgi->server_name;
654
655         my $add_path = 0;
656         if ( $cgi->server_software !~ m|^Apache/2.2| ) {
657                 my $rel_name = $cgi->url(-relative=>1);
658                 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
659         }
660
661         my $url = $cgi->url(-path_info=>$add_path);
662         my $root = (split 'feed', $url)[0] . '/';
663         my $base = (split 'bookbag', $url)[0] . '/bookbag';
664         my $unapi = (split 'feed', $url)[0] . '/unapi';
665
666         $root =~ s{(?<!http:)//}{/}go;
667         $base =~ s{(?<!http:)//}{/}go;
668         $unapi =~ s{(?<!http:)//}{/}go;
669
670         my $path = $cgi->path_info;
671         #warn "URL breakdown: $url -> $root -> $base -> $path -> $unapi";
672
673         my ($id,$type) = reverse split '/', $path;
674         my $flesh_feed = ($type =~ /-full$/o) ? 1 : 0;
675
676         my $bucket = $actor->request("open-ils.actor.container.public.flesh", 'biblio', $id)->gather(1);
677         return Apache2::Const::NOT_FOUND unless($bucket);
678
679         my $bucket_tag = "tag:$host,$year:record_bucket/$id";
680         if ($type eq 'opac') {
681                 print "Location: $root/../../en-US/skin/default/xml/rresult.xml?rt=list&" .
682                         join('&', map { "rl=" . $_->target_biblio_record_entry } @{ $bucket->items }) .
683                         "\n\n";
684                 return 302;
685         }
686
687         my $feed = create_record_feed(
688                 'record',
689                 $type,
690                 [ map { $_->target_biblio_record_entry } @{ $bucket->items } ],
691                 $unapi,
692                 undef,
693                 $flesh_feed
694         );
695         $feed->root($root);
696
697         $feed->title("Items in Book Bag [".$bucket->name."]");
698         $feed->creator($host);
699         $feed->update_ts(gmtime_ISO8601());
700
701         $feed->link(rss => $base . "/rss2-full/$id" => 'application/rss+xml');
702         $feed->link(alternate => $base . "/atom-full/$id" => 'application/atom+xml');
703         $feed->link(html => $base . "/html-full/$id" => 'text/html');
704         $feed->link(unapi => $unapi);
705
706         $feed->link(
707                 OPAC =>
708                 '/opac/en-US/skin/default/xml/rresult.xml?rt=list&' .
709                         join('&', map { 'rl=' . $_->target_biblio_record_entry } @{$bucket->items} ),
710                 'text/html'
711         );
712
713
714         print "Content-type: ". $feed->type ."; charset=utf-8\n\n";
715         print entityize($feed->toString) . "\n";
716
717         return Apache2::Const::OK;
718 }
719
720 sub changes_feed {
721         my $apache = shift;
722         return Apache2::Const::DECLINED if (-e $apache->filename);
723
724         my $cgi = new CGI;
725
726         my $year = (gmtime())[5] + 1900;
727         my $host = $cgi->virtual_host || $cgi->server_name;
728
729         my $add_path = 0;
730         if ( $cgi->server_software !~ m|^Apache/2.2| ) {
731                 my $rel_name = $cgi->url(-relative=>1);
732                 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
733         }
734
735         my $url = $cgi->url(-path_info=>$add_path);
736         my $root = (split 'feed', $url)[0];
737         my $base = (split 'freshmeat', $url)[0] . 'freshmeat';
738         my $unapi = (split 'feed', $url)[0] . 'unapi';
739
740         my $path = $cgi->path_info;
741         #warn "URL breakdown: $url ($rel_name) -> $root -> $base -> $path -> $unapi";
742
743         $path =~ s/^\/(?:feed\/)?freshmeat\///og;
744         
745         my ($type,$rtype,$axis,$limit,$date) = split '/', $path;
746         my $flesh_feed = ($type =~ /-full$/o) ? 1 : 0;
747         $limit ||= 10;
748
749         my $list = $supercat->request("open-ils.supercat.$rtype.record.$axis.recent", $date, $limit)->gather(1);
750
751         #if ($type eq 'opac') {
752         #       print "Location: $root/../../en-US/skin/default/xml/rresult.xml?rt=list&" .
753         #               join('&', map { "rl=" . $_ } @$list) .
754         #               "\n\n";
755         #       return 302;
756         #}
757
758         my $feed = create_record_feed( 'record', $type, $list, $unapi, undef, $flesh_feed);
759         $feed->root($root);
760
761         if ($date) {
762                 $feed->title("Up to $limit recent $rtype ${axis}s from $date forward");
763         } else {
764                 $feed->title("$limit most recent $rtype ${axis}s");
765         }
766
767         $feed->creator($host);
768         $feed->update_ts(gmtime_ISO8601());
769
770         $feed->link(rss => $base . "/rss2-full/$rtype/$axis/$limit/$date" => 'application/rss+xml');
771         $feed->link(alternate => $base . "/atom-full/$rtype/$axis/$limit/$date" => 'application/atom+xml');
772         $feed->link(html => $base . "/html-full/$rtype/$axis/$limit/$date" => 'text/html');
773         $feed->link(unapi => $unapi);
774
775         $feed->link(
776                 OPAC =>
777                 '/opac/en-US/skin/default/xml/rresult.xml?rt=list&' .
778                         join('&', map { 'rl=' . $_} @$list ),
779                 'text/html'
780         );
781
782
783         print "Content-type: ". $feed->type ."; charset=utf-8\n\n";
784         print entityize($feed->toString) . "\n";
785
786         return Apache2::Const::OK;
787 }
788
789 sub opensearch_osd {
790         my $version = shift;
791         my $lib = shift;
792         my $class = shift;
793         my $base = shift;
794
795         if ($version eq '1.0') {
796                 print <<OSD;
797 Content-type: application/opensearchdescription+xml; charset=utf-8
798
799 <?xml version="1.0" encoding="UTF-8"?>
800 <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearchdescription/1.0/">
801   <Url>$base/1.0/$lib/-/$class/?searchTerms={searchTerms}&amp;startPage={startPage}&amp;startIndex={startIndex}&amp;count={count}</Url>
802   <Format>http://a9.com/-/spec/opensearchrss/1.0/</Format>
803   <ShortName>$lib</ShortName>
804   <LongName>Search $lib</LongName>
805   <Description>Search the $lib OPAC by $class.</Description>
806   <Tags>$lib book library</Tags>
807   <SampleSearch>harry+potter</SampleSearch>
808   <Developer>Mike Rylander for GPLS/PINES</Developer>
809   <Contact>feedback\@open-ils.org</Contact>
810   <SyndicationRight>open</SyndicationRight>
811   <AdultContent>false</AdultContent>
812 </OpenSearchDescription>
813 OSD
814         } else {
815                 print <<OSD;
816 Content-type: application/opensearchdescription+xml; charset=utf-8
817
818 <?xml version="1.0" encoding="UTF-8"?>
819 <OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
820   <ShortName>$lib</ShortName>
821   <Description>Search the $lib OPAC by $class.</Description>
822   <Tags>$lib book library</Tags>
823   <Url type="application/rss+xml"
824        template="$base/1.1/$lib/rss2-full/$class/?searchTerms={searchTerms}&amp;startPage={startPage?}&amp;startIndex={startIndex?}&amp;count={count?}&amp;searchLang={language?}"/>
825   <Url type="application/atom+xml"
826        template="$base/1.1/$lib/atom-full/$class/?searchTerms={searchTerms}&amp;startPage={startPage?}&amp;startIndex={startIndex?}&amp;count={count?}&amp;searchLang={language?}"/>
827   <Url type="application/x-mods3+xml"
828        template="$base/1.1/$lib/mods3/$class/?searchTerms={searchTerms}&amp;startPage={startPage?}&amp;startIndex={startIndex?}&amp;count={count?}&amp;searchLang={language?}"/>
829   <Url type="application/x-mods+xml"
830        template="$base/1.1/$lib/mods/$class/?searchTerms={searchTerms}&amp;startPage={startPage?}&amp;startIndex={startIndex?}&amp;count={count?}&amp;searchLang={language?}"/>
831   <Url type="application/x-marcxml+xml"
832        template="$base/1.1/$lib/marcxml/$class/?searchTerms={searchTerms}&amp;startPage={startPage?}&amp;startIndex={startIndex?}&amp;count={count?}&amp;searchLang={language?}"/>
833   <Url type="text/html"
834        template="$base/1.1/$lib/html-full/$class/?searchTerms={searchTerms}&amp;startPage={startPage?}&amp;startIndex={startIndex?}&amp;count={count?}&amp;searchLang={language?}"/>
835   <LongName>Search $lib</LongName>
836   <Query role="example" searchTerms="harry+potter" />
837   <Developer>Mike Rylander for GPLS/PINES</Developer>
838   <Contact>feedback\@open-ils.org</Contact>
839   <SyndicationRight>open</SyndicationRight>
840   <AdultContent>false</AdultContent>
841   <Language>en-US</Language>
842   <OutputEncoding>UTF-8</OutputEncoding>
843   <InputEncoding>UTF-8</InputEncoding>
844 </OpenSearchDescription>
845 OSD
846         }
847
848         return Apache2::Const::OK;
849 }
850
851 sub opensearch_feed {
852         my $apache = shift;
853         return Apache2::Const::DECLINED if (-e $apache->filename);
854
855         my $cgi = new CGI;
856         my $year = (gmtime())[5] + 1900;
857
858         my $host = $cgi->virtual_host || $cgi->server_name;
859
860         my $add_path = 0;
861         if ( $cgi->server_software !~ m|^Apache/2.2| ) {
862                 my $rel_name = $cgi->url(-relative=>1);
863                 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
864         }
865
866         my $url = $cgi->url(-path_info=>$add_path);
867         my $root = (split 'opensearch', $url)[0];
868         my $base = (split 'opensearch', $url)[0] . 'opensearch';
869         my $unapi = (split 'opensearch', $url)[0] . 'unapi';
870
871         my $path = $cgi->path_info;
872         #warn "URL breakdown: $url ($rel_name) -> $root -> $base -> $path -> $unapi";
873
874         if ($path =~ m{^/?(1\.\d{1})/(?:([^/]+)/)?([^/]+)/osd.xml}o) {
875                 
876                 my $version = $1;
877                 my $lib = uc($2);
878                 my $class = $3;
879
880                 if (!$lib || $lib eq '-') {
881                         $lib = $actor->request(
882                                 'open-ils.actor.org_unit_list.search' => parent_ou => undef
883                         )->gather(1)->[0]->shortname;
884                 }
885
886                 if ($class eq '-') {
887                         $class = 'keyword';
888                 }
889
890                 return opensearch_osd($version, $lib, $class, $base);
891         }
892
893
894         my $page = $cgi->param('startPage') || 1;
895         my $offset = $cgi->param('startIndex') || 1;
896         my $limit = $cgi->param('count') || 10;
897
898         $page = 1 if ($page !~ /^\d+$/);
899         $offset = 1 if ($offset !~ /^\d+$/);
900         $limit = 10 if ($limit !~ /^\d+$/); $limit = 25 if ($limit > 25);
901
902         if ($page > 1) {
903                 $offset = ($page - 1) * $limit;
904         } else {
905                 $offset -= 1;
906         }
907
908         my ($version,$org,$type,$class,$terms,$sort,$sortdir,$lang) = ('','','','','','','','');
909         (undef,$version,$org,$type,$class,$terms,$sort,$sortdir,$lang) = split '/', $path;
910
911         $lang = $cgi->param('searchLang') if $cgi->param('searchLang');
912         $lang = '' if ($lang eq '*');
913
914         $sort = $cgi->param('searchSort') if $cgi->param('searchSort');
915         $sortdir = $cgi->param('searchSortDir') if $cgi->param('searchSortDir');
916         $terms .= " " . $cgi->param('searchTerms') if $cgi->param('searchTerms');
917
918         $class = $cgi->param('searchClass') if $cgi->param('searchClass');
919         $class ||= '-';
920
921         $type = $cgi->param('responseType') if $cgi->param('responseType');
922         $type ||= '-';
923
924         $org = $cgi->param('searchOrg') if $cgi->param('searchOrg');
925         $org ||= '-';
926
927
928         my $kwt = $cgi->param('kw');
929         my $tit = $cgi->param('ti');
930         my $aut = $cgi->param('au');
931         my $sut = $cgi->param('su');
932         my $set = $cgi->param('se');
933
934         $terms .= " keyword: $kwt" if ($kwt);
935         $terms .= " title: $tit" if ($tit);
936         $terms .= " author: $aut" if ($aut);
937         $terms .= " subject: $sut" if ($sut);
938         $terms .= " series: $set" if ($set);
939
940         if ($version eq '1.0') {
941                 $type = 'rss2';
942         } elsif ($type eq '-') {
943                 $type = 'atom';
944         }
945         my $flesh_feed = ($type =~ /-full$/o) ? 1 : 0;
946
947         $terms = decode_utf8($terms);
948         $terms =~ s/\+/ /go;
949         $terms =~ s/'//go;
950         $terms =~ s/^\s+//go;
951         my $term_copy = $terms;
952
953         my $complex_terms = 0;
954         if ($terms eq 'help') {
955                 print $cgi->header(-type => 'text/html');
956                 print <<"               HTML";
957                         <html>
958                          <head>
959                           <title>just type something!</title>
960                          </head>
961                          <body>
962                           <p>You are in a maze of dark, twisty stacks, all alike.</p>
963                          </body>
964                         </html>
965                 HTML
966                 return Apache2::Const::OK;
967         }
968
969         my $cache_key = '';
970         my $searches = {};
971         while ($term_copy =~ s/((?:keyword(?:\|\w+)?|title(?:\|\w+)?|author(?:\|\w+)?|subject(?:\|\w+)?|series(?:\|\w+)?|site|dir|sort|lang):[^:]+)$//so) {
972                 my ($c,$t) = split ':' => $1;
973                 if ($c eq 'site') {
974                         $org = $t;
975                         $org =~ s/^\s*//o;
976                         $org =~ s/\s*$//o;
977                 } elsif ($c eq 'sort') {
978                         ($sort = lc($t)) =~ s/^\s*(\w+)\s*$/$1/go;
979                 } elsif ($c eq 'dir') {
980                         ($sortdir = lc($t)) =~ s/^\s*(\w+)\s*$/$1/go;
981                 } elsif ($c eq 'lang') {
982                         ($lang = lc($t)) =~ s/^\s*(\w+)\s*$/$1/go;
983                 } else {
984                         $$searches{$c}{term} .= ' '.$t;
985                         $cache_key .= $c . $t;
986                         $complex_terms = 1;
987                 }
988         }
989
990         $lang = 'eng' if ($lang eq 'en-US');
991
992         if ($term_copy) {
993                 no warnings;
994                 $class = 'keyword' if ($class eq '-');
995                 $$searches{$class}{term} .= " $term_copy";
996                 $cache_key .= $class . $term_copy;
997         }
998
999         my $org_unit;
1000         if ($org eq '-') {
1001                 $org_unit = $actor->request(
1002                         'open-ils.actor.org_unit_list.search' => parent_ou => undef
1003                 )->gather(1);
1004         } else {
1005                 $org_unit = $actor->request(
1006                         'open-ils.actor.org_unit_list.search' => shortname => uc($org)
1007                 )->gather(1);
1008         }
1009
1010         { no warnings; $cache_key .= $org.$sort.$sortdir.$lang; }
1011
1012         my $rs_name = $cgi->cookie('os_session');
1013         my $cached_res = OpenSRF::Utils::Cache->new->get_cache( "os_session:$rs_name" ) if ($rs_name);
1014
1015         my $recs;
1016         if (!($recs = $$cached_res{os_results}{$cache_key})) {
1017                 $rs_name = $cgi->remote_host . '::' . rand(time);
1018                 $recs = $search->request(
1019                         'open-ils.search.biblio.multiclass' => {
1020                                 searches        => $searches,
1021                                 org_unit        => $org_unit->[0]->id,
1022                                 offset          => 0,
1023                                 limit           => 5000,
1024                                 ($sort ?    ( 'sort'     => $sort    ) : ()),
1025                                 ($sortdir ? ( 'sort_dir' => $sortdir ) : ($sort ? (sort_dir => 'asc') : (sort_dir => 'desc') )),
1026                                 ($lang ?    ( 'language' => $lang    ) : ()),
1027                         }
1028                 )->gather(1);
1029                 try {
1030                         $$cached_res{os_results}{$cache_key} = $recs;
1031                         OpenSRF::Utils::Cache->new->put_cache( "os_session:$rs_name", $cached_res, 1800 );
1032                 } catch Error with {
1033                         warn "supercat unable to store IDs in memcache server\n";
1034                         $logger->error("supercat unable to store IDs in memcache server");
1035                 };
1036         }
1037
1038         my $feed = create_record_feed(
1039                 'record',
1040                 $type,
1041                 [ map { $_->[0] } @{$recs->{ids}}[$offset .. $offset + $limit - 1] ],
1042                 $unapi,
1043                 $org,
1044                 $flesh_feed
1045         );
1046         $feed->root($root);
1047         $feed->lib($org);
1048         $feed->search($terms);
1049         $feed->class($class);
1050
1051         if ($complex_terms) {
1052                 $feed->title("Search results for [$terms] at ".$org_unit->[0]->name);
1053         } else {
1054                 $feed->title("Search results for [$class => $terms] at ".$org_unit->[0]->name);
1055         }
1056
1057         $feed->creator($host);
1058         $feed->update_ts(gmtime_ISO8601());
1059
1060         $feed->_create_node(
1061                 $feed->{item_xpath},
1062                 'http://a9.com/-/spec/opensearch/1.1/',
1063                 'totalResults',
1064                 $recs->{count},
1065         );
1066
1067         $feed->_create_node(
1068                 $feed->{item_xpath},
1069                 'http://a9.com/-/spec/opensearch/1.1/',
1070                 'startIndex',
1071                 $offset + 1,
1072         );
1073
1074         $feed->_create_node(
1075                 $feed->{item_xpath},
1076                 'http://a9.com/-/spec/opensearch/1.1/',
1077                 'itemsPerPage',
1078                 $limit,
1079         );
1080
1081         $feed->link(
1082                 next =>
1083                 $base . "/$version/$org/$type/$class?searchTerms=$terms&searchSort=$sort&searchSortDir=$sortdir&searchLang=$lang&startIndex=" . int($offset + $limit + 1) . "&count=" . $limit =>
1084                 'application/opensearch+xml'
1085         ) if ($offset + $limit < $recs->{count});
1086
1087         $feed->link(
1088                 previous =>
1089                 $base . "/$version/$org/$type/$class?searchTerms=$terms&searchSort=$sort&searchSortDir=$sortdir&searchLang=$lang&startIndex=" . int(($offset - $limit) + 1) . "&count=" . $limit =>
1090                 'application/opensearch+xml'
1091         ) if ($offset);
1092
1093         $feed->link(
1094                 self =>
1095                 $base .  "/$version/$org/$type/$class?searchTerms=$terms&searchSort=$sort&searchSortDir=$sortdir&searchLang=$lang" =>
1096                 'application/opensearch+xml'
1097         );
1098
1099         $feed->link(
1100                 rss =>
1101                 $base .  "/$version/$org/rss2-full/$class?searchTerms=$terms&searchSort=$sort&searchSortDir=$sortdir&searchLang=$lang" =>
1102                 'application/rss+xml'
1103         );
1104
1105         $feed->link(
1106                 alternate =>
1107                 $base .  "/$version/$org/atom-full/$class?searchTerms=$terms&searchSort=$sort&searchSortDir=$sortdir&searchLang=$lang" =>
1108                 'application/atom+xml'
1109         );
1110
1111         $feed->link(
1112                 'html' =>
1113                 $base .  "/$version/$org/html/$class?searchTerms=$terms&searchSort=$sort&searchSortDir=$sortdir&searchLang=$lang" =>
1114                 'text/html'
1115         );
1116
1117         $feed->link(
1118                 'html-full' =>
1119                 $base .  "/$version/$org/html-full/$class?searchTerms=$terms&searchSort=$sort&searchSortDir=$sortdir&searchLang=$lang" =>
1120                 'text/html'
1121         );
1122
1123         $feed->link( 'unapi-server' => $unapi);
1124
1125 #       $feed->link(
1126 #               opac =>
1127 #               $root . "../$lang/skin/default/xml/rresult.xml?rt=list&" .
1128 #                       join('&', map { 'rl=' . $_->[0] } grep { ref $_ && defined $_->[0] } @{$recs->{ids}} ),
1129 #               'text/html'
1130 #       );
1131
1132         print $cgi->header(
1133                 -type           => $feed->type,
1134                 -charset        => 'UTF-8',
1135                 -cookie         => $cgi->cookie( -name => 'os_session', -value => $rs_name, -expires => '+30m' ),
1136         );
1137
1138         print entityize($feed->toString) . "\n";
1139
1140         return Apache2::Const::OK;
1141 }
1142
1143 sub create_record_feed {
1144         my $search = shift;
1145         my $type = shift;
1146         my $records = shift;
1147         my $unapi = shift;
1148
1149         my $lib = uc(shift()) || '-';
1150         my $flesh = shift;
1151         $flesh = 1 if (!defined($flesh));
1152
1153         my $cgi = new CGI;
1154         my $base = $cgi->url;
1155         my $host = $cgi->virtual_host || $cgi->server_name;
1156
1157         my $year = (gmtime())[5] + 1900;
1158
1159         my $flesh_feed = ($type =~ s/-full$//o) ? 1 : 0;
1160
1161         my $feed = new OpenILS::WWW::SuperCat::Feed ($type);
1162         $feed->base($base) if ($flesh);
1163         $feed->unapi($unapi) if ($flesh);
1164
1165         $type = 'atom' if ($type eq 'html');
1166         $type = 'marcxml' if ($type eq 'htmlholdings');
1167
1168         #$records = $supercat->request( "open-ils.supercat.record.object.retrieve", $records )->gather(1);
1169
1170         my $count = 0;
1171         for my $record (@$records) {
1172                 next unless($record);
1173
1174                 #my $rec = $record->id;
1175                 my $rec = $record;
1176
1177                 my $item_tag = "tag:$host,$year:biblio-record_entry/$rec/$lib";
1178                 $item_tag = "tag:$host,$year:isbn/$rec/$lib" if ($search eq 'isbn');
1179
1180                 my $xml = $supercat->request(
1181                         "open-ils.supercat.$search.$type.retrieve",
1182                         $rec
1183                 )->gather(1);
1184                 next unless $xml;
1185
1186                 my $node = $feed->add_item($xml);
1187                 next unless $node;
1188
1189                 $xml = '';
1190                 if ($lib && $type eq 'marcxml' &&  $flesh) {
1191                         my $r = $supercat->request( "open-ils.supercat.$search.holdings_xml.retrieve", $rec, $lib );
1192                         while ( !$r->complete ) {
1193                                 $xml .= join('', map {$_->content} $r->recv);
1194                         }
1195                         $xml .= join('', map {$_->content} $r->recv);
1196                         $node->add_holdings($xml);
1197                 }
1198
1199                 $node->id($item_tag) if ($flesh);
1200                 #$node->update_ts(clense_ISO8601($record->edit_date));
1201                 $node->link(alternate => $feed->unapi . "?id=$item_tag&format=htmlholdings-full" => 'text/html') if ($flesh);
1202                 $node->link(opac => $feed->unapi . "?id=$item_tag&format=opac") if ($flesh);
1203                 $node->link(unapi => $feed->unapi . "?id=$item_tag") if ($flesh);
1204                 $node->link('unapi-id' => $item_tag) if ($flesh);
1205         }
1206
1207         return $feed;
1208 }
1209
1210 sub entityize {
1211         my $stuff = NFC(shift());
1212         $stuff =~ s/&(?!\S+;)/&amp;/gso;
1213         $stuff =~ s/([\x{0080}-\x{fffd}])/sprintf('&#x%X;',ord($1))/sgoe;
1214         return $stuff;
1215 }
1216
1217 sub string_browse {
1218         my $apache = shift;
1219         return Apache2::Const::DECLINED if (-e $apache->filename);
1220
1221         my $cgi = new CGI;
1222         my $year = (gmtime())[5] + 1900;
1223
1224         my $host = $cgi->virtual_host || $cgi->server_name;
1225
1226         my $add_path = 0;
1227         if ( $cgi->server_software !~ m|^Apache/2.2| ) {
1228                 my $rel_name = $cgi->url(-relative=>1);
1229                 $add_path = 1 if ($cgi->url(-path_info=>1) !~ /$rel_name$/);
1230         }
1231
1232         my $url = $cgi->url(-path_info=>$add_path);
1233         my $root = (split 'browse', $url)[0];
1234         my $base = (split 'browse', $url)[0] . 'browse';
1235         my $unapi = (split 'browse', $url)[0] . 'unapi';
1236
1237         my $path = $cgi->path_info;
1238         $path =~ s/^\///og;
1239
1240         my ($format,$axis,$site,$string,$page,$page_size) = split '/', $path;
1241         #warn " >>> $format -> $axis -> $site -> $string -> $page -> $page_size ";
1242
1243         $site ||= $cgi->param('searchOrg');
1244         $page ||= $cgi->param('startPage') || 0;
1245         $page_size ||= $cgi->param('count') || 9;
1246
1247         $page = 0 if ($page !~ /^-?\d+$/);
1248
1249         my $prev = join('/', $base,$format,$axis,$site,$string,$page - 1,$page_size);
1250         my $next = join('/', $base,$format,$axis,$site,$string,$page + 1,$page_size);
1251
1252         unless ($string and $axis and grep { $axis eq $_ } keys %browse_types) {
1253                 warn "something's wrong...";
1254                 warn " >>> $format -> $axis -> $site -> $string -> $page -> $page_size ";
1255                 return undef;
1256         }
1257
1258         $string = decode_utf8($string);
1259         $string =~ s/\+/ /go;
1260         $string =~ s/'//go;
1261
1262         my $tree = $supercat->request(
1263                 "open-ils.supercat.$axis.browse",
1264                 $string,
1265                 $site,
1266                 $page_size,
1267                 $page
1268         )->gather(1);
1269
1270         my ($header,$content) = $browse_types{$axis}{$format}->($tree,$prev,$next);
1271         print $header.$content;
1272         return Apache2::Const::OK;
1273 }
1274
1275 1;