Debian Codegraph @

perl/rss-dump.pl

raw symbols SCIP
1 #!/usr/bin/perl -w
2 #
3 # rss-view.pl - Redland RSS 1.0 test program
4 #
5 # Copyright (C) 2000-2003 David Beckett - http://www.dajobe.org/
6 # Copyright (C) 2000-2003 University of Bristol - http://www.bristol.ac.uk/
7 #
8 # This package is Free Software and part of Redland http://librdf.org/
9 #
10 # It is licensed under the following three licenses as alternatives:
11 # 1. GNU Lesser General Public License (LGPL) V2.1 or any newer version
12 # 2. GNU General Public License (GPL) V2 or any newer version
13 # 3. Apache License, V2.0 or any newer version
14 #
15 # You may not use this file except in compliance with at least one of
16 # the above three licenses.
17 #
18 # See LICENSE.html or LICENSE.txt at the top of this package for the
19 # full license terms.
20 #
21 #
22 #
23
24 use strict;
25
26 use RDF::Redland;
27 use RDF::Redland::RSS;
28
29 my(%namespaces)=(
30 # Built in modules
31 'Dublin Core' => 'http://purl.org/dc/elements/1.1/',
32 'Syndication' => 'http://purl.org/rss/1.0/modules/syndication/',
33
34 # Proposed modules from http://purl.org/rss/1.0/modules/proposed/
35 'Changed Page' => 'http://my.theinfo.org/changed/1.0/rss/',
36 'RSS 0.91' => 'http://purl.org/rss/1.0/modules/rss091#',
37 'Threading' => 'http://purl.org/rss/1.0/modules/threading/',
38 'Slash' => 'ttp://purl.org/rss/1.0/modules/slash/',
39 );
40
41
42 die <<"EOT" if @ARGV < 1 || @ARGV > 2;
43 Usage: $0 <RSS URI> [BASE URI>]
44
45 This program excecises the Redland Perl RDF:Redland::RSS module
46 which supports the RSS 1.0 specification http://purl.org/rss/1.0/
47
48 Further information on this format can be found at the RSS-Dev list
49 page at http://groups.yahoo.com/group/rss-dev/
50
51 EOT
52
53 my $uri=$ARGV[0];
54 my $tmp_file=undef;
55 my $source_uri=$uri;
56 my $base_uri=(@ARGV ==2) ? $ARGV[1]: $uri;
57
58 if(0) { # use this code if the parser does not do URIs
59 if($uri !~ m%^file:%) {
60 use URI::URL;
61 use URI::file;
62 use LWP::Simple;
63
64 $tmp_file="/tmp/$0-$$.rss";
65
66 my $perl_uri;
67 eval "\$perl_uri=new URI::URL('$uri')";
68 if($@) {
69 die "$0: URI $uri is not supported by Perl\n";
70 }
71 my $rc=getstore($perl_uri, $tmp_file);
72
73 if(!is_success($rc)) {
74 die "$0: Failed to fetch URI $uri - HTTP error $rc\n";
75 unlink $tmp_file;
76 }
77 $source_uri=URI::file->new($tmp_file)->as_string;
78 }
79 }
80
81 print "Using source URI $source_uri and base URI $base_uri\n";
82
83 my $rss=new RDF::Redland::RSS($source_uri, $base_uri);
84 die "Failed to create RDF::Redland::RSS for URI $uri\n" unless $rss;
85
86 for my $channel ($rss->channels) {
87 print "Found channel with URI ",$channel->uri->as_string,"\n";
88 print " title is ",($channel->title ? $channel->title->literal_value_as_latin1 : 'MISSING'),"\n";
89 print " link is ",($channel->link ? $channel->link->as_string : 'MISSING'),"\n";
90 print " desc is ",$channel->description->literal_value_as_latin1,"\n" if $channel->description;
91
92 while(my($ns_label,$ns_prefix)=each %namespaces) {
93 my(@props)=$channel->properties_with_ns_prefix($ns_prefix);
94 if(@props) {
95 print " $ns_label properties from $ns_prefix found:\n";
96 for my $property (@props) {
97 my $value=$channel->property($property);
98 if($value->is_resource) {
99 print " ",$property->uri->as_string," : URI ",$value->uri->as_string,"\n";
100 } else {
101 print " ",$property->uri->as_string," : ",$value->literal_value_as_latin1,"\n";
102 }
103 }
104 }
105 }
106
107 my(@items)=$channel->items;
108 print " Found ",scalar(@items)," items in channel\n";
109
110 for my $item (@items) {
111 print " Item with URI ",$item->uri->as_string,"\n";
112 print " title is ",($item->title ? $item->title->literal_value_as_latin1 : 'MISSING'),"\n";
113 print " link is ",($item->link ? $item->link->as_string : 'MISSING'),"\n";
114 # RSS 1.0 section 5.5 <item> - description is optional
115 print " desc is ",$item->description->literal_value_as_latin1,"\n" if $item->description;
116
117 my(@props)=$item->properties;
118 print " All properties: ",join(' ', map {$_->uri->as_string} @props),"\n";
119
120 while(my($ns_label,$ns_prefix)=each %namespaces) {
121 my(@props)=$item->properties_with_ns_prefix($ns_prefix);
122 if(@props) {
123 print " $ns_label properties from $ns_prefix found:\n";
124 for my $property (@props) {
125 my $value=$item->property($property);
126 if($value->is_resource) {
127 print " ",$property->uri->as_string," : URI ",$value->uri->as_string,"\n";
128 } else {
129 print " ",$property->uri->as_string," : ",$value->literal_value_as_latin1,"\n";
130 }
131 }
132 }
133 }
134
135 }
136
137 my $image=$channel->image;
138 if($image) {
139 print " Image with URI ",$image->uri->as_string,"\n";
140
141 # RSS 1.0 section 5.4 <image> - If present, nothing optional
142 print " title is ",($image->title ? $image->title->literal_value_as_latin1 : 'MISSING'),"\n";
143 print " link is ",($image->link ? $image->link->as_string : 'MISSING'),"\n";
144 print " url is ",$image->image_url->as_string,"\n" if $image->image_url;
145 }
146
147 my $textinput=$channel->textinput;
148 if($textinput) {
149 print " Textinput with URI ",$textinput->uri->as_string,"\n";
150
151 # RSS 1.0 section 5.6 <textinput> - If present, nothing optional
152 print " title is ",($textinput->title ? $textinput->title->literal_value_as_latin1 : 'MISSING'),"\n";
153 print " link is ",($textinput->link ? $textinput->link->as_string : 'MISSING'),"\n";
154 print " desc is ",($textinput->description ? $textinput->description->literal_value_as_latin1 : 'MISSING'),"\n";
155 print " name is ",($textinput->name ? $textinput->name->as_string : 'MISSING'),"\n";
156 }
157
158 }
159
160 unlink $tmp_file if $tmp_file;