MARC21 feed support
authorMike Rylander <mrylander@gmail.com>
Fri, 8 Mar 2013 18:21:23 +0000 (13:21 -0500)
committerLebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Wed, 13 Mar 2013 20:11:41 +0000 (16:11 -0400)
Now you can get MARC21 feeds from OpenSearch, e.g.
http://<host>/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 <mrylander@gmail.com>
Signed-off-by: Lebbeous Fogle-Weekley <lebbeous@esilibrary.com>
Open-ILS/src/perlmods/lib/OpenILS/Application/SuperCat.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/SuperCat.pm
Open-ILS/src/perlmods/lib/OpenILS/WWW/SuperCat/Feed.pm
docs/RELEASE_NOTES_NEXT/marc21-feeds.txt [new file with mode: 0644]

index dc62eee..c8d35b6 100644 (file)
@@ -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 ) {
index 8fc95f1..1956b5a 100644 (file)
@@ -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}&amp;startPage={startPage?}&amp;startIndex={startIndex?}&amp;count={count?}&amp;searchLang={language?}"/>
   <Url type="application/x-mods+xml"
        template="$base/1.1/$lib/mods/$class/?searchTerms={searchTerms}&amp;startPage={startPage?}&amp;startIndex={startIndex?}&amp;count={count?}&amp;searchLang={language?}"/>
+  <Url type="application/octet-stream"
+       template="$base/1.1/$lib/marc21/$class/?searchTerms={searchTerms}&amp;startPage={startPage?}&amp;startIndex={startIndex?}&amp;count={count?}&amp;searchLang={language?}"/>
   <Url type="application/x-marcxml+xml"
        template="$base/1.1/$lib/marcxml/$class/?searchTerms={searchTerms}&amp;startPage={startPage?}&amp;startIndex={startIndex?}&amp;count={count?}&amp;searchLang={language?}"/>
   <Url type="text/html"
@@ -1487,7 +1489,11 @@ sub create_record_feed {
     $feed->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);
 
index 57bb67f..d4cd14c 100644 (file)
@@ -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 (file)
index 0000000..0b861a9
--- /dev/null
@@ -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://<host>/opac/extras/opensearch/1.1/-/marc21?searchTerms=piano
+