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->{base} = $base if ($base);
39 $self->{unapi} = $unapi if ($unapi);
40 return $self->{unapi};
45 push @{ $self->{items} }, @_;
50 return @{ $self->{items} } if (wantarray);
51 return $self->{items};
60 for my $node ($self->{doc}->findnodes($xpath)) {
61 $node->appendChild($new);
75 for my $node ($self->{doc}->findnodes($xpath)) {
76 my $new = $self->{doc}->createElement($name) if (!$ns);
77 $new = $self->{doc}->createElementNS($ns,$name) if ($ns);
79 $new->appendChild( $self->{doc}->createTextNode( $text ) )
83 for my $key (keys %$attrs) {
84 $new->setAttribute( $key => $$attrs{$key} );
88 $node->appendChild( $new );
96 my $class = ref($self) || $self;
100 my $entry = $class->new($item_xml);
102 $entry->base($self->base);
103 $entry->unapi($self->unapi);
105 $self->push_item($entry);
111 for my $root ( $self->{doc}->findnodes($self->{item_xpath}) ) {
112 for my $item ( $self->items ) {
113 $root->appendChild( $item->{doc}->documentElement );
118 return $self->{doc}->toString(1);
127 #----------------------------------------------------------
129 package OpenILS::WWW::SuperCat::Feed::atom;
130 use base 'OpenILS::WWW::SuperCat::Feed';
134 my $self = $class->SUPER::build('<atom:feed xmlns:atom="http://www.w3.org/2005/Atom"/>');
135 $self->{type} = 'atom';
136 $self->{item_xpath} = '/atom:feed';
143 $self->_create_node('/atom:feed','http://www.w3.org/2005/Atom','atom:title', $text);
149 $self->_create_node('/atom:feed','http://www.w3.org/2005/Atom','atom:updated', $text);
155 $self->_create_node('/atom:feed','http://www.w3.org/2005/Atom','atom:author');
156 $self->_create_node('/atom:feed/atom:author', 'http://www.w3.org/2005/Atom','atom:name', $text);
163 my $mime = shift || "application/$type+xml";
165 $type = 'self' if ($type eq 'atom');
169 'http://www.w3.org/2005/Atom',
183 $self->_create_node( '/atom:feed', 'http://www.w3.org/2005/Atom', 'atom:id', $id );
186 package OpenILS::WWW::SuperCat::Feed::atom::item;
187 use base 'OpenILS::WWW::SuperCat::Feed::atom';
192 my $self = $class->SUPER::build($xml);
193 $self->{doc}->documentElement->setNamespace('http://www.w3.org/2005/Atom', 'atom');
194 $self->{item_xpath} = '/atom:entry';
195 $self->{type} = 'atom::item';
200 #----------------------------------------------------------
202 package OpenILS::WWW::SuperCat::Feed::rss2;
203 use base 'OpenILS::WWW::SuperCat::Feed';
207 my $self = $class->SUPER::build('<rss version="2.0"><channel/></rss>');
208 $self->{type} = 'rss2';
209 $self->{item_xpath} = '/rss/channel';
216 $self->_create_node('/rss/channel',undef,'title', $text);
222 $self->_create_node('/rss/channel',undef,'lastBuildDate', $text);
228 $self->_create_node('/rss/channel', undef,'generator', $text);
235 my $mime = shift || "application/$type+xml";
237 $type = 'self' if ($type eq 'rss2');
250 package OpenILS::WWW::SuperCat::Feed::rss2::item;
251 use base 'OpenILS::WWW::SuperCat::Feed::rss2';
256 my $self = $class->SUPER::build($xml);
257 $self->{type} = 'atom::item';
258 $self->{item_xpath} = '/item';
263 #----------------------------------------------------------
265 package OpenILS::WWW::SuperCat::Feed::mods;
266 use base 'OpenILS::WWW::SuperCat::Feed';
270 my $self = $class->SUPER::build('<mods:modsCollection version="3.0" xmlns:mods="http://www.loc.gov/mods/"/>');
271 $self->{type} = 'mods';
272 $self->{item_xpath} = '/mods:modsCollection';
276 package OpenILS::WWW::SuperCat::Feed::mods::item;
277 use base 'OpenILS::WWW::SuperCat::Feed::mods';
282 my $self = $class->SUPER::build($xml);
283 $self->{doc}->documentElement->setNamespace('http://www.loc.gov/mods/', 'mods');
284 $self->{type} = 'mods::item';
295 if ($type eq 'unapi' || $type eq 'opac') {
298 'http://www.loc.gov/mods/',
301 { type => 'otherFormat', id => 'link-'.$linkid }
304 "mods:mods/mods:relatedItem[\@id='link-$linkid']",
305 'http://www.loc.gov/mods/',
306 'mods:recordIdentifier',
314 #----------------------------------------------------------
316 package OpenILS::WWW::SuperCat::Feed::html;
317 use base 'OpenILS::WWW::SuperCat::Feed';
321 my $self = $class->SUPER::build('<html><head/><body/></html>');
322 $self->{type} = 'html';
323 $self->{item_xpath} = '/html/body';