1 package OpenILS::WWW::SuperCat::Feed;
2 use strict; use warnings;
4 use OpenSRF::EX qw(:try);
15 throw OpenSRF::EX::ERROR ("I need a feed type!") ;
22 $parser = new XML::LibXML if (!$parser);
24 my $self = { doc => $parser->parse_string($xml), items => [] };
26 return bless $self => $class;
32 $self->{type} = $type if ($type);
39 $self->{base} = $base if ($base);
46 $self->{unapi} = $unapi if ($unapi);
47 return $self->{unapi};
52 push @{ $self->{items} }, @_;
57 return @{ $self->{items} } if (wantarray);
58 return $self->{items};
67 for my $node ($self->{doc}->findnodes($xpath)) {
68 $node->appendChild($new);
82 for my $node ($self->{doc}->findnodes($xpath)) {
83 my $new = $self->{doc}->createElement($name) if (!$ns);
84 $new = $self->{doc}->createElementNS($ns,$name) if ($ns);
86 $new->appendChild( $self->{doc}->createTextNode( $text ) )
90 for my $key (keys %$attrs) {
91 $new->setAttribute( $key => $$attrs{$key} );
95 $node->appendChild( $new );
103 my $class = ref($self) || $self;
106 my $item_xml = shift;
107 my $entry = $class->new($item_xml);
109 $entry->base($self->base);
110 $entry->unapi($self->unapi);
112 $self->push_item($entry);
118 for my $root ( $self->{doc}->findnodes($self->{item_xpath}) ) {
119 for my $item ( $self->items ) {
120 $root->appendChild( $item->{doc}->documentElement );
125 return $self->{doc}->toString(1);
134 #----------------------------------------------------------
136 package OpenILS::WWW::SuperCat::Feed::atom;
137 use base 'OpenILS::WWW::SuperCat::Feed';
141 my $self = $class->SUPER::build('<atom:feed xmlns:atom="http://www.w3.org/2005/Atom"/>');
142 $self->{type} = 'application/xml';
143 $self->{item_xpath} = '/atom:feed';
150 $self->_create_node('/atom:feed','http://www.w3.org/2005/Atom','atom:title', $text);
156 $self->_create_node('/atom:feed','http://www.w3.org/2005/Atom','atom:updated', $text);
162 $self->_create_node('/atom:feed','http://www.w3.org/2005/Atom','atom:author');
163 $self->_create_node('/atom:feed/atom:author', 'http://www.w3.org/2005/Atom','atom:name', $text);
170 my $mime = shift || "application/$type+xml";
172 $type = 'self' if ($type eq 'atom');
176 'http://www.w3.org/2005/Atom',
190 $self->_create_node( '/atom:feed', 'http://www.w3.org/2005/Atom', 'atom:id', $id );
193 package OpenILS::WWW::SuperCat::Feed::atom::item;
194 use base 'OpenILS::WWW::SuperCat::Feed::atom';
199 my $self = $class->SUPER::build($xml);
200 $self->{doc}->documentElement->setNamespace('http://www.w3.org/2005/Atom', 'atom');
201 $self->{item_xpath} = '/atom:entry';
202 $self->{type} = 'application/xml';
207 #----------------------------------------------------------
209 package OpenILS::WWW::SuperCat::Feed::rss2;
210 use base 'OpenILS::WWW::SuperCat::Feed';
214 my $self = $class->SUPER::build('<rss version="2.0"><channel/></rss>');
215 $self->{type} = 'application/xml';
216 $self->{item_xpath} = '/rss/channel';
223 $self->_create_node('/rss/channel',undef,'title', $text);
229 $self->_create_node('/rss/channel',undef,'lastBuildDate', $text);
235 $self->_create_node('/rss/channel', undef,'generator', $text);
242 my $mime = shift || "application/$type+xml";
244 $type = 'self' if ($type eq 'rss2');
257 package OpenILS::WWW::SuperCat::Feed::rss2::item;
258 use base 'OpenILS::WWW::SuperCat::Feed::rss2';
263 my $self = $class->SUPER::build($xml);
264 $self->{type} = 'application/xml';
265 $self->{item_xpath} = '/item';
270 #----------------------------------------------------------
272 package OpenILS::WWW::SuperCat::Feed::mods;
273 use base 'OpenILS::WWW::SuperCat::Feed';
277 my $self = $class->SUPER::build('<mods:modsCollection version="3.0" xmlns:mods="http://www.loc.gov/mods/"/>');
278 $self->{type} = 'application/xml';
279 $self->{item_xpath} = '/mods:modsCollection';
283 package OpenILS::WWW::SuperCat::Feed::mods::item;
284 use base 'OpenILS::WWW::SuperCat::Feed::mods';
289 my $self = $class->SUPER::build($xml);
290 $self->{doc}->documentElement->setNamespace('http://www.loc.gov/mods/', 'mods');
291 $self->{type} = 'application/xml';
302 if ($type eq 'unapi' || $type eq 'opac') {
305 'http://www.loc.gov/mods/',
308 { type => 'otherFormat', id => 'link-'.$linkid }
311 "mods:mods/mods:relatedItem[\@id='link-$linkid']",
312 'http://www.loc.gov/mods/',
313 'mods:recordIdentifier',
321 #----------------------------------------------------------
323 package OpenILS::WWW::SuperCat::Feed::marcxml;
324 use base 'OpenILS::WWW::SuperCat::Feed';
328 my $self = $class->SUPER::build('<marc:collection xmlns:marc="http://www.loc.gov/MARC21/slim"/>');
329 $self->{type} = 'application/xml';
330 $self->{item_xpath} = '/marc:collection';
334 package OpenILS::WWW::SuperCat::Feed::marcxml::item;
335 use base 'OpenILS::WWW::SuperCat::Feed::marcxml';
340 my $self = $class->SUPER::build($xml);
341 $self->{doc}->documentElement->setNamespace('http://www.loc.gov/MARC21/slim', 'marc');
342 $self->{type} = 'application/xml';
346 #----------------------------------------------------------
348 package OpenILS::WWW::SuperCat::Feed::html;
349 use base 'OpenILS::WWW::SuperCat::Feed::atom';
353 my $self = $class->SUPER::new;
354 $self->{type} = 'application/xml';
361 my $stuff = $self->SUPER::toString;
362 my $base = $self->base;
363 $stuff =~ s{\n}{\n<?xml-stylesheet href="../../../../os.xsl" type="text/xsl" ?>\n}so;
368 package OpenILS::WWW::SuperCat::Feed::html::item;
369 use base 'OpenILS::WWW::SuperCat::Feed::atom::item';