From c13ea4b751e1dbf4ad22b43a7a84399f496f3bee Mon Sep 17 00:00:00 2001 From: miker Date: Thu, 9 Mar 2006 05:09:34 +0000 Subject: [PATCH] initial support for html output of opensearch feeds git-svn-id: svn://svn.open-ils.org/ILS/trunk@3285 dcc99617-32d9-48b4-a31d-7c20da2025e4 --- Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm | 75 ++++++++++++------- .../src/perlmods/OpenILS/WWW/SuperCat/Feed.pm | 42 ++++++++--- 2 files changed, 76 insertions(+), 41 deletions(-) diff --git a/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm b/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm index 9b080f2822..556fd96c2f 100644 --- a/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm +++ b/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat.pm @@ -283,13 +283,17 @@ sub bookbag_feed { return Apache2::Const::DECLINED if (-e $apache->filename); my $cgi = new CGI; - (my $unapi = $cgi->url) =~ s{[^/]+/?$}{unapi}; - - my $year = (gmtime())[5]; + my $year = (gmtime())[5] + 1900; my $host = $cgi->virtual_host || $cgi->server_name; - my $path = $apache->path_info; - my $base = $cgi->url; + + my $url = $cgi->url(-path_info=>1); + my $root = (split 'feed', $url)[0]; + my $base = (split 'bookbag', $url)[0] . 'bookbag'; + my $path = (split 'bookbag', $url)[1]; + my $unapi = (split 'feed', $url)[0] . 'unapi'; + + my ($id,$type) = reverse split '/', $path; @@ -319,7 +323,7 @@ sub bookbag_feed { $feed->link( OPAC => - $base . '/../../../opac/en-US/skin/default/xml/rresult.xml?rt=list&' . + $root . '../en-US/skin/default/xml/rresult.xml?rt=list&' . join('&', map { 'rl=' . $_->target_biblio_record_entry } @{$bucket->items} ), 'text/xhtml' ); @@ -333,6 +337,7 @@ sub bookbag_feed { sub opensearch_osd { my $version = shift; + my $lib = shift; my $class = shift; my $base = shift; @@ -342,12 +347,12 @@ Content-type: application/opensearchdescription+xml; charset=utf-8 - $base/1.0/-/$class/-/{searchTerms}?startPage={startPage}&startIndex={startIndex}&count={count} + $base/1.0/$lib/$class/-/{searchTerms}?startPage={startPage}&startIndex={startIndex}&count={count} http://a9.com/-/spec/opensearchrss/1.0/ $class Search by $class - Search the OPAC by $class. - book library + Search the $lib OPAC by $class. + $lib book library harry+potter Mike Rylander for GPLS/PINES feedback\@open-ils.org @@ -362,11 +367,11 @@ Content-type: application/opensearchdescription+xml; charset=utf-8 $class - Search the OPAC by $class. - book library + Search the $lib OPAC by $class. + $lib book library + template="$base/1.1/$lib/$class/atom/{searchTerms}"> @@ -374,7 +379,7 @@ Content-type: application/opensearchdescription+xml; charset=utf-8 + template="$base/1.1/$lib/$class/rss2/{searchTerms}"> @@ -382,7 +387,7 @@ Content-type: application/opensearchdescription+xml; charset=utf-8 + template="$base/1.1/$lib/$class/mods/{searchTerms}"> @@ -390,7 +395,7 @@ Content-type: application/opensearchdescription+xml; charset=utf-8 + template="$base/1.1/$lib/$class/marcxml/{searchTerms}"> @@ -416,24 +421,32 @@ sub opensearch_feed { return Apache2::Const::DECLINED if (-e $apache->filename); my $cgi = new CGI; - (my $unapi = $cgi->url) =~ s{[^/]+/?$}{unapi}; - - my $year = (gmtime())[5]; + my $year = (gmtime())[5] + 1900; my $host = $cgi->virtual_host || $cgi->server_name; - my $base = $cgi->url; - my $path = $apache->path_info; - if ($path =~ m{^/?(1\.\d{1})/([^/]+)/osd.xml}o) { + my $url = $cgi->url(-path_info=>1); + my $root = (split 'opensearch', $url)[0]; + my $base = (split 'opensearch', $url)[0] . 'opensearch'; + my $unapi = (split 'opensearch', $url)[0] . 'unapi'; + + my $path = (split 'opensearch', $url)[1]; + + if ($path =~ m{^/?(1\.\d{1})/(?:([^/]+)/)?([^/]+)/osd.xml}o) { my $version = $1; - my $class = $2; + my $lib = $2; + my $class = $3; + + if (!$lib) { + $lib = 'PINES'; + } if ($class eq '-') { $class = 'keyword'; } - return opensearch_osd($version, $class, $base); + return opensearch_osd($version, $lib, $class, $base); } @@ -487,7 +500,7 @@ sub opensearch_feed { $unapi, ); - $feed->title("Search results for [$terms] at ".$org_unit->[0]->name); + $feed->title("$class search results for [$terms] at ".$org_unit->[0]->name); $feed->creator($host); $feed->update_ts(gmtime_ISO8601()); @@ -535,7 +548,7 @@ sub opensearch_feed { ) if ($offset + $limit < $recs->{count}); $feed->link( - prev => + previous => $base . $path . "?startIndex=" . int(($offset - $limit) + 1) . "&count=" . $limit => 'application/opensearch+xml' ) if ($offset); @@ -548,14 +561,14 @@ sub opensearch_feed { $feed->link( opac => - $base . "/../../opac/$lang/skin/default/xml/rresult.xml?rt=list&" . + $root . "../opac/$lang/skin/default/xml/rresult.xml?rt=list&" . join('&', map { 'rl=' . $_->[0] } @{$recs->{ids}} ), 'text/xhtml' ); - print "Content-type: application/xml; charset=utf-8\n\n"; - + print "Content-type: ". $feed->type ."; charset=utf-8\n\n"; print entityize($feed->toString) . "\n"; + return Apache2::Const::OK; } @@ -568,15 +581,18 @@ sub create_record_feed { my $base = $cgi->url; my $host = $cgi->virtual_host || $cgi->server_name; - my $year = (gmtime())[5]; + my $year = (gmtime())[5] + 1900; my $feed = new OpenILS::WWW::SuperCat::Feed ($type); $feed->base($base); $feed->unapi($unapi); + $type = 'atom' if ($type eq 'html'); + for my $rec (@$records) { my $item_tag = "tag:$host,$year:biblio-record_entry/" . $rec; + my $xml = $supercat->request( "open-ils.supercat.record.$type.retrieve", $rec @@ -585,6 +601,7 @@ sub create_record_feed { my $node = $feed->add_item($xml); $node->id($item_tag); + $node->link(alternate => $feed->unapi . "?uri=$item_tag&format=opac" => 'application/xml'); $node->link(opac => $feed->unapi . "?uri=$item_tag&format=opac"); $node->link(unapi => $feed->unapi . "?uri=$item_tag"); } diff --git a/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat/Feed.pm b/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat/Feed.pm index 3d75b3d92b..e15b841b79 100644 --- a/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat/Feed.pm +++ b/Open-ILS/src/perlmods/OpenILS/WWW/SuperCat/Feed.pm @@ -26,6 +26,13 @@ sub build { return bless $self => $class; } +sub type { + my $self = shift; + my $type = shift; + $self->{type} = $type if ($type); + return $self->{type}; +} + sub base { my $self = shift; my $base = shift; @@ -132,7 +139,7 @@ use base 'OpenILS::WWW::SuperCat::Feed'; sub new { my $class = shift; my $self = $class->SUPER::build(''); - $self->{type} = 'atom'; + $self->{type} = 'application/xml'; $self->{item_xpath} = '/atom:feed'; return $self; } @@ -192,7 +199,7 @@ sub new { my $self = $class->SUPER::build($xml); $self->{doc}->documentElement->setNamespace('http://www.w3.org/2005/Atom', 'atom'); $self->{item_xpath} = '/atom:entry'; - $self->{type} = 'atom::item'; + $self->{type} = 'application/xml'; return $self; } @@ -205,7 +212,7 @@ use base 'OpenILS::WWW::SuperCat::Feed'; sub new { my $class = shift; my $self = $class->SUPER::build(''); - $self->{type} = 'rss2'; + $self->{type} = 'application/xml'; $self->{item_xpath} = '/rss/channel'; return $self; } @@ -254,7 +261,7 @@ sub new { my $class = shift; my $xml = shift; my $self = $class->SUPER::build($xml); - $self->{type} = 'atom::item'; + $self->{type} = 'application/xml'; $self->{item_xpath} = '/item'; return $self; } @@ -268,7 +275,7 @@ use base 'OpenILS::WWW::SuperCat::Feed'; sub new { my $class = shift; my $self = $class->SUPER::build(''); - $self->{type} = 'mods'; + $self->{type} = 'application/xml'; $self->{item_xpath} = '/mods:modsCollection'; return $self; } @@ -281,7 +288,7 @@ sub new { my $xml = shift; my $self = $class->SUPER::build($xml); $self->{doc}->documentElement->setNamespace('http://www.loc.gov/mods/', 'mods'); - $self->{type} = 'mods::item'; + $self->{type} = 'application/xml'; return $self; } @@ -319,7 +326,7 @@ use base 'OpenILS::WWW::SuperCat::Feed'; sub new { my $class = shift; my $self = $class->SUPER::build(''); - $self->{type} = 'marcxml'; + $self->{type} = 'application/xml'; $self->{item_xpath} = '/marc:collection'; return $self; } @@ -332,22 +339,33 @@ sub new { my $xml = shift; my $self = $class->SUPER::build($xml); $self->{doc}->documentElement->setNamespace('http://www.loc.gov/MARC21/slim', 'marc'); - $self->{type} = 'marc::item'; + $self->{type} = 'application/xml'; return $self; } #---------------------------------------------------------- package OpenILS::WWW::SuperCat::Feed::html; -use base 'OpenILS::WWW::SuperCat::Feed'; +use base 'OpenILS::WWW::SuperCat::Feed::atom'; sub new { my $class = shift; - my $self = $class->SUPER::build(''); - $self->{type} = 'html'; - $self->{item_xpath} = '/html/body'; + my $self = $class->SUPER::new; + $self->{type} = 'application/xml'; return $self; } +sub toString { + my $self = shift; + my $stuff = $self->SUPER::toString; + my $base = $self->base; + $stuff =~ s{\n}{\n\n}so; + return $stuff; +} + + +package OpenILS::WWW::SuperCat::Feed::html::item; +use base 'OpenILS::WWW::SuperCat::Feed::atom::item'; + 1; -- 2.43.2