From 3ad39d5e661cf84001a2013a3a2f395e878fab71 Mon Sep 17 00:00:00 2001 From: Mike Rylander Date: Fri, 8 Mar 2013 13:21:23 -0500 Subject: [PATCH] MARC21 feed support Now you can get MARC21 feeds from OpenSearch, e.g. http:///opac/extras/opensearch/1.1/-/marc21?searchTerms=piano with the Concerto dataset. [LFW] Syntax corrections, utf-8 encoding, release note Signed-off-by: Mike Rylander Signed-off-by: Lebbeous Fogle-Weekley --- .../lib/OpenILS/Application/SuperCat.pm | 8 ++++-- .../src/perlmods/lib/OpenILS/WWW/SuperCat.pm | 16 +++++++---- .../perlmods/lib/OpenILS/WWW/SuperCat/Feed.pm | 28 +++++++++++++++++++ docs/RELEASE_NOTES_NEXT/marc21-feeds.txt | 8 ++++++ 4 files changed, 52 insertions(+), 8 deletions(-) create mode 100644 docs/RELEASE_NOTES_NEXT/marc21-feeds.txt diff --git a/Open-ILS/src/perlmods/lib/OpenILS/Application/SuperCat.pm b/Open-ILS/src/perlmods/lib/OpenILS/Application/SuperCat.pm index dc62eee9d2..c8d35b6e59 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/Application/SuperCat.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/Application/SuperCat.pm @@ -2963,7 +2963,8 @@ sub list_authority_formats { { namespace_uri => 'http://www.loc.gov/MARC21/slim', docs => 'http://www.loc.gov/marcxml/', schema_location => 'http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd', - } + }, + marc21 => { docs => 'http://www.loc.gov/marc/' } } ); @@ -3000,8 +3001,9 @@ sub list_record_formats { { namespace_uri => 'http://www.loc.gov/MARC21/slim', docs => 'http://www.loc.gov/marcxml/', schema_location => 'http://www.loc.gov/standards/marcxml/schema/MARC21slim.xsd', - } - } + }, + marc21 => { docs => 'http://www.loc.gov/marc/' } + }, ); for my $type ( keys %record_xslt ) { diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/SuperCat.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/SuperCat.pm index 8fc95f1efe..1956b5a6a9 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/SuperCat.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/SuperCat.pm @@ -679,7 +679,7 @@ sub unapi { $feed->link( unapi => $base) if ($flesh_feed); print "Content-type: ". $feed->type ."; charset=utf-8\n\n"; - print $U->entityize($feed->toString) . "\n"; + print $feed->toString . "\n"; return Apache2::Const::OK; } @@ -940,7 +940,7 @@ sub supercat { $feed->link( unapi => $base) if ($flesh_feed); print "Content-type: ". $feed->type ."; charset=utf-8\n\n"; - print $U->entityize($feed->toString) . "\n"; + print $feed->toString . "\n"; return Apache2::Const::OK; } @@ -1064,7 +1064,7 @@ sub bookbag_feed { print "Content-type: ". $feed->type ."; charset=utf-8\n\n"; - print $U->entityize($feed->toString) . "\n"; + print $feed->toString . "\n"; return Apache2::Const::OK; } @@ -1151,7 +1151,7 @@ sub changes_feed { print "Content-type: ". $feed->type ."; charset=utf-8\n\n"; - print $U->entityize($feed->toString) . "\n"; + print $feed->toString . "\n"; return Apache2::Const::OK; } @@ -1198,6 +1198,8 @@ Content-type: application/opensearchdescription+xml; charset=utf-8 template="$base/1.1/$lib/mods3/$class/?searchTerms={searchTerms}&startPage={startPage?}&startIndex={startIndex?}&count={count?}&searchLang={language?}"/> + unapi($unapi) if ($flesh); $type = 'atom' if ($type eq 'html'); - $type = 'marcxml' if (($type eq 'htmlholdings') || ($type eq 'marctxt') || ($type eq 'ris')); + $type = 'marcxml' if + $type eq 'htmlholdings' or + $type eq 'marctxt' or + $type eq 'ris' or + $type eq 'marc21'; # kludgy since it isn't an XML format, but needed #$records = $supercat->request( "open-ils.supercat.record.object.retrieve", $records )->gather(1); diff --git a/Open-ILS/src/perlmods/lib/OpenILS/WWW/SuperCat/Feed.pm b/Open-ILS/src/perlmods/lib/OpenILS/WWW/SuperCat/Feed.pm index 57bb67f88c..d4cd14cddf 100644 --- a/Open-ILS/src/perlmods/lib/OpenILS/WWW/SuperCat/Feed.pm +++ b/Open-ILS/src/perlmods/lib/OpenILS/WWW/SuperCat/Feed.pm @@ -852,5 +852,33 @@ sub toString { package OpenILS::WWW::SuperCat::Feed::ris::item; use base 'OpenILS::WWW::SuperCat::Feed::marcxml::item'; +package OpenILS::WWW::SuperCat::Feed::marc21; +use base 'OpenILS::WWW::SuperCat::Feed::marcxml'; +use MARC::File::XML ( BinaryEncoding => 'utf8', RecordFormat => 'USMARC' ); + +sub new { + my $class = shift; + my $self = $class->SUPER::new; + $self->{type} = 'application/octet-stream'; + return $self; +} + + +sub toString { + my $self = shift; + + $self->{doc} = ''; + for my $item ( $self->items ) { + my $r = MARC::Record->new_from_xml( $item->{doc}->toString(1) ); + $self->{doc} .= $r->as_usmarc; + } + + utf8::encode($self->{doc}); + return $self->{doc}; +} + +package OpenILS::WWW::SuperCat::Feed::marc21::item; +use base 'OpenILS::WWW::SuperCat::Feed::marcxml::item'; + 1; diff --git a/docs/RELEASE_NOTES_NEXT/marc21-feeds.txt b/docs/RELEASE_NOTES_NEXT/marc21-feeds.txt new file mode 100644 index 0000000000..0b861a90e2 --- /dev/null +++ b/docs/RELEASE_NOTES_NEXT/marc21-feeds.txt @@ -0,0 +1,8 @@ +MARC21 Feeds from OpenSearch +============================ + +In addition to the already supported formats, you can now get raw MARC21 from +OpenSearch feeds, à la: + + http:///opac/extras/opensearch/1.1/-/marc21?searchTerms=piano + -- 2.43.2