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->{class} = $search if ($search);
49 return $self->{class};
55 $self->{lib} = $lib if ($lib);
62 $self->{base} = $base if ($base);
69 $self->{root} = $root if ($root);
76 $self->{unapi} = $unapi if ($unapi);
77 return $self->{unapi};
82 push @{ $self->{items} }, @_;
87 return @{ $self->{items} } if (wantarray);
88 return $self->{items};
97 for my $node ($self->{doc}->findnodes($xpath)) {
98 $node->appendChild($new);
112 for my $node ($self->{doc}->findnodes($xpath)) {
113 my $new = $self->{doc}->createElement($name) if (!$ns);
114 $new = $self->{doc}->createElementNS($ns,$name) if ($ns);
116 $new->appendChild( $self->{doc}->createTextNode( $text ) )
120 for my $key (keys %$attrs) {
121 $new->setAttribute( $key => $$attrs{$key} );
125 $node->appendChild( $new );
133 my $class = ref($self) || $self;
136 my $item_xml = shift;
137 my $entry = $class->new($item_xml);
139 $entry->base($self->base);
140 $entry->unapi($self->unapi);
142 $self->push_item($entry);
148 my $holdings_xml = shift;
150 $parser = new XML::LibXML if (!$parser);
151 my $new_doc = $parser->parse_string($holdings_xml);
153 for my $root ( $self->{doc}->findnodes($self->{holdings_xpath}) ) {
154 $root->appendChild($new_doc->documentElement);
162 for my $root ( $self->{doc}->findnodes($self->{item_xpath}) ) {
163 for my $item ( $self->items ) {
164 $root->appendChild( $item->{doc}->documentElement );
173 return $self->{doc}->toString(1);
182 #----------------------------------------------------------
184 package OpenILS::WWW::SuperCat::Feed::atom;
185 use base 'OpenILS::WWW::SuperCat::Feed';
189 my $self = $class->SUPER::build('<atom:feed xmlns:atom="http://www.w3.org/2005/Atom"/>');
190 $self->{type} = 'application/xml';
191 $self->{item_xpath} = '/atom:feed';
198 $self->_create_node('/atom:feed','http://www.w3.org/2005/Atom','atom:title', $text);
204 $self->_create_node('/atom:feed','http://www.w3.org/2005/Atom','atom:updated', $text);
210 $self->_create_node('/atom:feed','http://www.w3.org/2005/Atom','atom:author');
211 $self->_create_node('/atom:feed/atom:author', 'http://www.w3.org/2005/Atom','atom:name', $text);
218 my $mime = shift || "application/x-$type+xml";
221 $type = 'self' if ($type eq 'atom');
225 'http://www.w3.org/2005/Atom',
240 $self->_create_node( '/atom:feed', 'http://www.w3.org/2005/Atom', 'atom:id', $id );
243 package OpenILS::WWW::SuperCat::Feed::atom::item;
244 use base 'OpenILS::WWW::SuperCat::Feed::atom';
249 my $self = $class->SUPER::build($xml);
250 $self->{doc}->documentElement->setNamespace('http://www.w3.org/2005/Atom', 'atom');
251 $self->{item_xpath} = '/atom:entry';
252 $self->{holdings_xpath} = '/atom:entry';
253 $self->{type} = 'application/xml';
258 #----------------------------------------------------------
260 package OpenILS::WWW::SuperCat::Feed::rss2;
261 use base 'OpenILS::WWW::SuperCat::Feed';
265 my $self = $class->SUPER::build('<rss version="2.0"><channel/></rss>');
266 $self->{type} = 'application/xml';
267 $self->{item_xpath} = '/rss/channel';
274 $self->_create_node('/rss/channel',undef,'title', $text);
280 $self->_create_node('/rss/channel',undef,'lastBuildDate', $text);
286 $self->_create_node('/rss/channel', undef,'generator', $text);
293 my $mime = shift || "application/x-$type+xml";
295 $type = 'self' if ($type eq 'rss2');
308 package OpenILS::WWW::SuperCat::Feed::rss2::item;
309 use base 'OpenILS::WWW::SuperCat::Feed::rss2';
314 my $self = $class->SUPER::build($xml);
315 $self->{type} = 'application/xml';
316 $self->{item_xpath} = '/item';
317 $self->{holdings_xpath} = '/item';
322 #----------------------------------------------------------
324 package OpenILS::WWW::SuperCat::Feed::mods;
325 use base 'OpenILS::WWW::SuperCat::Feed';
329 my $self = $class->SUPER::build('<mods:modsCollection version="3.0" xmlns:mods="http://www.loc.gov/mods/"/>');
330 $self->{type} = 'application/xml';
331 $self->{item_xpath} = '/mods:modsCollection';
335 package OpenILS::WWW::SuperCat::Feed::mods::item;
336 use base 'OpenILS::WWW::SuperCat::Feed::mods';
341 my $self = $class->SUPER::build($xml);
342 $self->{doc}->documentElement->setNamespace('http://www.loc.gov/mods/', 'mods');
343 $self->{type} = 'application/xml';
344 $self->{holdings_xpath} = '/mods:mods';
355 if ($type eq 'unapi' || $type eq 'opac') {
358 'http://www.loc.gov/mods/',
361 { type => 'otherFormat', id => 'link-'.$linkid }
364 "mods:mods/mods:relatedItem[\@id='link-$linkid']",
365 'http://www.loc.gov/mods/',
366 'mods:recordIdentifier',
374 #----------------------------------------------------------
376 package OpenILS::WWW::SuperCat::Feed::mods3;
377 use base 'OpenILS::WWW::SuperCat::Feed::mods';
381 my $self = $class->SUPER::build('<mods:modsCollection version="3.0" xmlns:mods="http://www.loc.gov/mods/v3"/>');
382 $self->{type} = 'application/xml';
383 $self->{item_xpath} = '/mods:modsCollection';
387 package OpenILS::WWW::SuperCat::Feed::mods3::item;
388 use base 'OpenILS::WWW::SuperCat::Feed::mods::item';
393 my $self = $class->SUPER::build($xml);
394 $self->{doc}->documentElement->setNamespace('http://www.loc.gov/mods/v3', 'mods');
395 $self->{type} = 'application/xml';
396 $self->{holdings_xpath} = '/mods:mods';
405 if ($type eq 'unapi' || $type eq 'opac') {
408 'http://www.loc.gov/mods/v3',
411 { type => 'otherFormat', id => 'link-'.$linkid }
414 "mods:mods/mods:relatedItem[\@id='link-$linkid']",
415 'http://www.loc.gov/mods/v3',
416 'mods:recordIdentifier',
424 #----------------------------------------------------------
426 package OpenILS::WWW::SuperCat::Feed::marcxml;
427 use base 'OpenILS::WWW::SuperCat::Feed';
431 my $self = $class->SUPER::build('<marc:collection xmlns:marc="http://www.loc.gov/MARC21/slim"/>');
432 $self->{type} = 'application/xml';
433 $self->{item_xpath} = '/marc:collection';
437 package OpenILS::WWW::SuperCat::Feed::marcxml::item;
438 use base 'OpenILS::WWW::SuperCat::Feed::marcxml';
443 my $self = $class->SUPER::build($xml);
444 $self->{doc}->documentElement->setNamespace('http://www.loc.gov/MARC21/slim', 'marc');
445 $self->{type} = 'application/xml';
446 $self->{holdings_xpath} = '/marc:record';
455 if ($type eq 'unapi' || $type eq 'opac') {
458 'http://www.w3.org/1999/xhtml',
461 { rel => 'otherFormat', href => $id, title => "Dynamic Details" }
468 #----------------------------------------------------------
470 package OpenILS::WWW::SuperCat::Feed::html;
471 use base 'OpenILS::WWW::SuperCat::Feed::atom';
475 my $self = $class->SUPER::new;
476 $self->type('text/html');
480 our ($_parser, $_xslt, $xslt_file);
484 my $base = $self->base || '';
485 my $root = $self->root || '';
486 my $search = $self->search || '';
487 my $class = $self->class || '';
488 my $lib = $self->lib || '-';
492 $_parser ||= new XML::LibXML;
493 $_xslt ||= new XML::LibXSLT;
496 OpenSRF::Utils::SettingsClient
498 ->config_value( dirs => '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'",
509 searchClass => "'$class'",
512 return $new_doc->toString(1);
516 package OpenILS::WWW::SuperCat::Feed::html::item;
517 use base 'OpenILS::WWW::SuperCat::Feed::atom::item';
519 #----------------------------------------------------------
521 package OpenILS::WWW::SuperCat::Feed::htmlcard;
522 use base 'OpenILS::WWW::SuperCat::Feed::marcxml';
526 my $self = $class->SUPER::new;
527 $self->type('text/html');
528 $self->{xsl} = "/MARC21slim2HTMLCard.xsl";
532 our ($_parser, $_xslt, $xslt_file);
536 my $base = $self->base || '';
537 my $root = $self->root || '';
538 my $search = $self->search || '';
539 my $lib = $self->lib || '-';
543 $_parser ||= new XML::LibXML;
544 $_xslt ||= new XML::LibXSLT;
547 OpenSRF::Utils::SettingsClient
549 ->config_value( dirs => 'xsl' ).$self->{xsl};
551 # parse the MODS xslt ...
552 my $atom2html_xslt = $_xslt->parse_stylesheet( $_parser->parse_file($xslt_file) );
554 my $new_doc = $atom2html_xslt->transform(
556 base_dir => "'$root'",
558 searchTerms => "'$search'",
561 return $new_doc->toString(1);
564 package OpenILS::WWW::SuperCat::Feed::htmlcard::item;
565 use base 'OpenILS::WWW::SuperCat::Feed::marcxml::item';
567 package OpenILS::WWW::SuperCat::Feed::htmlholdings;
568 use base 'OpenILS::WWW::SuperCat::Feed::htmlcard';
572 my $self = $class->SUPER::new;
573 $self->{xsl} = "/MARC21slim2HTMLCard-holdings.xsl";
577 package OpenILS::WWW::SuperCat::Feed::htmlholdings::item;
578 use base 'OpenILS::WWW::SuperCat::Feed::htmlcard::item';