1 package OpenILS::WWW::SuperCat::Feed;
2 use strict; use warnings;
4 use OpenSRF::EX qw(:try);
7 use OpenSRF::Utils::SettingsClient;
17 throw OpenSRF::EX::ERROR ("I need a feed type!") ;
24 $parser = new XML::LibXML if (!$parser);
26 my $self = { doc => $parser->parse_string($xml), items => [] };
28 return bless $self => $class;
34 $self->{type} = $type if ($type);
41 $self->{search} = $search if ($search);
42 return $self->{search};
48 $self->{lib} = $lib if ($lib);
55 $self->{base} = $base if ($base);
62 $self->{root} = $root if ($root);
69 $self->{unapi} = $unapi if ($unapi);
70 return $self->{unapi};
75 push @{ $self->{items} }, @_;
80 return @{ $self->{items} } if (wantarray);
81 return $self->{items};
90 for my $node ($self->{doc}->findnodes($xpath)) {
91 $node->appendChild($new);
105 for my $node ($self->{doc}->findnodes($xpath)) {
106 my $new = $self->{doc}->createElement($name) if (!$ns);
107 $new = $self->{doc}->createElementNS($ns,$name) if ($ns);
109 $new->appendChild( $self->{doc}->createTextNode( $text ) )
113 for my $key (keys %$attrs) {
114 $new->setAttribute( $key => $$attrs{$key} );
118 $node->appendChild( $new );
126 my $class = ref($self) || $self;
129 my $item_xml = shift;
130 my $entry = $class->new($item_xml);
132 $entry->base($self->base);
133 $entry->unapi($self->unapi);
135 $self->push_item($entry);
141 my $holdings_xml = shift;
143 $parser = new XML::LibXML if (!$parser);
144 my $new_doc = $parser->parse_string($holdings_xml);
146 for my $root ( $self->{doc}->findnodes($self->{holdings_xpath}) ) {
147 $root->appendChild($new_doc->documentElement);
155 for my $root ( $self->{doc}->findnodes($self->{item_xpath}) ) {
156 for my $item ( $self->items ) {
157 $root->appendChild( $item->{doc}->documentElement );
166 return $self->{doc}->toString(1);
175 #----------------------------------------------------------
177 package OpenILS::WWW::SuperCat::Feed::atom;
178 use base 'OpenILS::WWW::SuperCat::Feed';
182 my $self = $class->SUPER::build('<atom:feed xmlns:atom="http://www.w3.org/2005/Atom"/>');
183 $self->{type} = 'application/xml';
184 $self->{item_xpath} = '/atom:feed';
191 $self->_create_node('/atom:feed','http://www.w3.org/2005/Atom','atom:title', $text);
197 $self->_create_node('/atom:feed','http://www.w3.org/2005/Atom','atom:updated', $text);
203 $self->_create_node('/atom:feed','http://www.w3.org/2005/Atom','atom:author');
204 $self->_create_node('/atom:feed/atom:author', 'http://www.w3.org/2005/Atom','atom:name', $text);
211 my $mime = shift || "application/x-$type+xml";
214 $type = 'self' if ($type eq 'atom');
218 'http://www.w3.org/2005/Atom',
233 $self->_create_node( '/atom:feed', 'http://www.w3.org/2005/Atom', 'atom:id', $id );
236 package OpenILS::WWW::SuperCat::Feed::atom::item;
237 use base 'OpenILS::WWW::SuperCat::Feed::atom';
242 my $self = $class->SUPER::build($xml);
243 $self->{doc}->documentElement->setNamespace('http://www.w3.org/2005/Atom', 'atom');
244 $self->{item_xpath} = '/atom:entry';
245 $self->{holdings_xpath} = '/atom:entry';
246 $self->{type} = 'application/xml';
251 #----------------------------------------------------------
253 package OpenILS::WWW::SuperCat::Feed::rss2;
254 use base 'OpenILS::WWW::SuperCat::Feed';
258 my $self = $class->SUPER::build('<rss version="2.0"><channel/></rss>');
259 $self->{type} = 'application/xml';
260 $self->{item_xpath} = '/rss/channel';
267 $self->_create_node('/rss/channel',undef,'title', $text);
273 $self->_create_node('/rss/channel',undef,'lastBuildDate', $text);
279 $self->_create_node('/rss/channel', undef,'generator', $text);
286 my $mime = shift || "application/x-$type+xml";
288 $type = 'self' if ($type eq 'rss2');
301 package OpenILS::WWW::SuperCat::Feed::rss2::item;
302 use base 'OpenILS::WWW::SuperCat::Feed::rss2';
307 my $self = $class->SUPER::build($xml);
308 $self->{type} = 'application/xml';
309 $self->{item_xpath} = '/item';
310 $self->{holdings_xpath} = '/item';
315 #----------------------------------------------------------
317 package OpenILS::WWW::SuperCat::Feed::mods;
318 use base 'OpenILS::WWW::SuperCat::Feed';
322 my $self = $class->SUPER::build('<mods:modsCollection version="3.0" xmlns:mods="http://www.loc.gov/mods/"/>');
323 $self->{type} = 'application/xml';
324 $self->{item_xpath} = '/mods:modsCollection';
328 package OpenILS::WWW::SuperCat::Feed::mods::item;
329 use base 'OpenILS::WWW::SuperCat::Feed::mods';
334 my $self = $class->SUPER::build($xml);
335 $self->{doc}->documentElement->setNamespace('http://www.loc.gov/mods/', 'mods');
336 $self->{type} = 'application/xml';
337 $self->{holdings_xpath} = '/mods:mods';
348 if ($type eq 'unapi' || $type eq 'opac') {
351 'http://www.loc.gov/mods/',
354 { type => 'otherFormat', id => 'link-'.$linkid }
357 "mods:mods/mods:relatedItem[\@id='link-$linkid']",
358 'http://www.loc.gov/mods/',
359 'mods:recordIdentifier',
367 #----------------------------------------------------------
369 package OpenILS::WWW::SuperCat::Feed::mods3;
370 use base 'OpenILS::WWW::SuperCat::Feed';
374 my $self = $class->SUPER::build('<mods:modsCollection version="3.0" xmlns:mods="http://www.loc.gov/mods/v3"/>');
375 $self->{type} = 'application/xml';
376 $self->{item_xpath} = '/mods:modsCollection';
380 package OpenILS::WWW::SuperCat::Feed::mods3::item;
381 use base 'OpenILS::WWW::SuperCat::Feed::mods3';
386 my $self = $class->SUPER::build($xml);
387 $self->{doc}->documentElement->setNamespace('http://www.loc.gov/mods/v3', 'mods');
388 $self->{type} = 'application/xml';
389 $self->{holdings_xpath} = '/mods:mods';
394 #----------------------------------------------------------
396 package OpenILS::WWW::SuperCat::Feed::marcxml;
397 use base 'OpenILS::WWW::SuperCat::Feed';
401 my $self = $class->SUPER::build('<marc:collection xmlns:marc="http://www.loc.gov/MARC21/slim"/>');
402 $self->{type} = 'application/xml';
403 $self->{item_xpath} = '/marc:collection';
407 package OpenILS::WWW::SuperCat::Feed::marcxml::item;
408 use base 'OpenILS::WWW::SuperCat::Feed::marcxml';
413 my $self = $class->SUPER::build($xml);
414 $self->{doc}->documentElement->setNamespace('http://www.loc.gov/MARC21/slim', 'marc');
415 $self->{type} = 'application/xml';
416 $self->{holdings_xpath} = '/marc:record';
420 #----------------------------------------------------------
422 package OpenILS::WWW::SuperCat::Feed::html;
423 use base 'OpenILS::WWW::SuperCat::Feed::atom';
427 my $self = $class->SUPER::new;
428 $self->type('text/html');
432 our ($_parser, $_xslt, $xslt_file);
436 my $base = $self->base || '';
437 my $root = $self->root || '';
438 my $search = $self->search || '';
439 my $lib = $self->lib || '-';
443 $_parser ||= new XML::LibXML;
444 $_xslt ||= new XML::LibXSLT;
447 OpenSRF::Utils::SettingsClient
449 ->config_value( dirs => 'xsl' ).
452 # parse the MODS xslt ...
453 my $atom2html_xslt = $_xslt->parse_stylesheet( $_parser->parse_file($xslt_file) );
455 my $new_doc = $atom2html_xslt->transform(
457 base_dir => "'$root'",
459 searchTerms => "'$search'",
462 return $new_doc->toString(1);
466 package OpenILS::WWW::SuperCat::Feed::html::item;
467 use base 'OpenILS::WWW::SuperCat::Feed::atom::item';
469 #----------------------------------------------------------
471 package OpenILS::WWW::SuperCat::Feed::htmlcard;
472 use base 'OpenILS::WWW::SuperCat::Feed::marcxml';
476 my $self = $class->SUPER::new;
477 $self->type('text/html');
478 $self->{xsl} = "/MARC21slim2HTMLCard.xsl";
482 our ($_parser, $_xslt, $xslt_file);
486 my $base = $self->base || '';
487 my $root = $self->root || '';
488 my $search = $self->search || '';
489 my $lib = $self->lib || '-';
493 $_parser ||= new XML::LibXML;
494 $_xslt ||= new XML::LibXSLT;
497 OpenSRF::Utils::SettingsClient
499 ->config_value( dirs => 'xsl' ).$self->{xsl};
501 # parse the MODS xslt ...
502 my $atom2html_xslt = $_xslt->parse_stylesheet( $_parser->parse_file($xslt_file) );
504 my $new_doc = $atom2html_xslt->transform(
506 base_dir => "'$root'",
508 searchTerms => "'$search'",
511 return $new_doc->toString(1);
514 package OpenILS::WWW::SuperCat::Feed::htmlholdings;
515 use base 'OpenILS::WWW::SuperCat::Feed::htmlcard';
519 my $self = $class->SUPER::new;
520 $self->{xsl} = "/MARC21slim2HTMLCard-holdings.xsl";
524 package OpenILS::WWW::SuperCat::Feed::htmlcard::item;
525 use base 'OpenILS::WWW::SuperCat::Feed::marcxml::item';
527 package OpenILS::WWW::SuperCat::Feed::htmlholdings::item;
528 use base 'OpenILS::WWW::SuperCat::Feed::htmlcard::item';