| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
### |
|
3
|
|
|
|
|
|
|
# XML::RDDL - Interface to RDDL (http://www.rddl.org/) |
|
4
|
|
|
|
|
|
|
# Robin Berjon |
|
5
|
|
|
|
|
|
|
# 17/10/2001 - v.0.01 |
|
6
|
|
|
|
|
|
|
### |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package XML::RDDL; |
|
9
|
2
|
|
|
2
|
|
14257
|
use strict; |
|
|
2
|
|
|
|
|
6
|
|
|
|
2
|
|
|
|
|
63
|
|
|
10
|
2
|
|
|
2
|
|
1114
|
use XML::RDDL::Directory qw(); |
|
|
2
|
|
|
|
|
4
|
|
|
|
2
|
|
|
|
|
40
|
|
|
11
|
2
|
|
|
2
|
|
1131
|
use XML::RDDL::Resource qw(); |
|
|
2
|
|
|
|
|
16
|
|
|
|
2
|
|
|
|
|
50
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
|
11
|
use vars qw($VERSION $NS_RDDL $NS_XML $NS_XLINK); |
|
|
2
|
|
|
|
|
3
|
|
|
|
2
|
|
|
|
|
1709
|
|
|
14
|
|
|
|
|
|
|
$VERSION = '1.02'; |
|
15
|
|
|
|
|
|
|
$NS_XML = 'http://www.w3.org/XML/1998/namespace'; |
|
16
|
|
|
|
|
|
|
$NS_RDDL = 'http://www.rddl.org/'; |
|
17
|
|
|
|
|
|
|
$NS_XLINK = 'http://www.w3.org/1999/xlink'; |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
#-------------------------------------------------------------------# |
|
22
|
|
|
|
|
|
|
# constructor |
|
23
|
|
|
|
|
|
|
#-------------------------------------------------------------------# |
|
24
|
|
|
|
|
|
|
sub new { |
|
25
|
1
|
50
|
|
1
|
1
|
19
|
my $class = ref($_[0]) ? ref(shift) : shift; |
|
26
|
1
|
|
|
|
|
3
|
my %opt = @_; |
|
27
|
|
|
|
|
|
|
|
|
28
|
1
|
|
|
|
|
14
|
my $self = { |
|
29
|
|
|
|
|
|
|
xLangStack => [$opt{default_lang}], |
|
30
|
|
|
|
|
|
|
xBaseStack => [$opt{default_base_uri}], |
|
31
|
|
|
|
|
|
|
directory => XML::RDDL::Directory->new, |
|
32
|
|
|
|
|
|
|
}; |
|
33
|
1
|
|
|
|
|
5
|
return bless $self, $class; |
|
34
|
|
|
|
|
|
|
} |
|
35
|
|
|
|
|
|
|
#-------------------------------------------------------------------# |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
#,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,# |
|
39
|
|
|
|
|
|
|
#`,`, SAX2 Handler ,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,# |
|
40
|
|
|
|
|
|
|
#```````````````````````````````````````````````````````````````````# |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
#-------------------------------------------------------------------# |
|
43
|
|
|
|
|
|
|
# start_document & end_document |
|
44
|
|
|
|
|
|
|
#-------------------------------------------------------------------# |
|
45
|
1
|
|
|
1
|
0
|
140519
|
sub start_document { $_[0]->{directory} = XML::RDDL::Directory->new; } |
|
46
|
1
|
|
|
1
|
0
|
240
|
sub end_document { return $_[0]->{directory}; } |
|
47
|
|
|
|
|
|
|
#-------------------------------------------------------------------# |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
#-------------------------------------------------------------------# |
|
50
|
|
|
|
|
|
|
# start_element |
|
51
|
|
|
|
|
|
|
#-------------------------------------------------------------------# |
|
52
|
|
|
|
|
|
|
sub start_element { |
|
53
|
7
|
|
|
7
|
0
|
15563
|
my $self = shift; |
|
54
|
7
|
|
|
|
|
9
|
my $e = shift; |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
# xml:lang and xml:base stacks |
|
57
|
7
|
|
|
|
|
12
|
push @{$self->{xLangStack}}, get_attribute($e, $NS_XML, 'lang'); |
|
|
7
|
|
|
|
|
23
|
|
|
58
|
7
|
|
|
|
|
11
|
push @{$self->{xBaseStack}}, get_attribute($e, $NS_XML, 'base'); |
|
|
7
|
|
|
|
|
17
|
|
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
#deal with rddl:resource |
|
61
|
7
|
100
|
66
|
|
|
45
|
return unless $e->{NamespaceURI} eq $NS_RDDL and $e->{LocalName} eq 'resource'; |
|
62
|
|
|
|
|
|
|
|
|
63
|
3
|
|
50
|
|
|
8
|
my $type = get_attribute($e, $NS_XLINK, 'type') || 'simple'; |
|
64
|
3
|
|
50
|
|
|
7
|
my $embed = get_attribute($e, $NS_XLINK, 'embed') || 'none'; |
|
65
|
3
|
|
50
|
|
|
8
|
my $actu = get_attribute($e, $NS_XLINK, 'actuate') || 'none'; |
|
66
|
3
|
50
|
|
|
|
8
|
die "[RDDL] xlink:type can only be set to 'simple'" if $type ne 'simple'; |
|
67
|
3
|
50
|
|
|
|
8
|
die "[RDDL] xlink:embed can only be set to 'none'" if $embed ne 'none'; |
|
68
|
3
|
50
|
|
|
|
8
|
die "[RDDL] xlink:actuate can only be set to 'none'" if $actu ne 'none'; |
|
69
|
|
|
|
|
|
|
|
|
70
|
3
|
|
50
|
|
|
7
|
my $id = get_attribute($e, '', 'id') || ''; |
|
71
|
3
|
|
50
|
|
|
8
|
my $role = get_attribute($e, $NS_XLINK, 'role') || 'http://www.rddl.org/#resource'; |
|
72
|
3
|
|
50
|
|
|
7
|
my $arcrole = get_attribute($e, $NS_XLINK, 'arcrole') || ''; |
|
73
|
3
|
|
50
|
|
|
7
|
my $href = get_attribute($e, $NS_XLINK, 'href') || ''; |
|
74
|
3
|
|
50
|
|
|
16
|
my $title = get_attribute($e, $NS_XLINK, 'title') || ''; |
|
75
|
|
|
|
|
|
|
|
|
76
|
3
|
|
50
|
|
|
10
|
my $xlang = get_last_defined($self->{xLangStack}) || ''; |
|
77
|
3
|
|
50
|
|
|
9
|
my $xbase = get_last_defined($self->{xBaseStack}) || ''; |
|
78
|
|
|
|
|
|
|
|
|
79
|
3
|
|
|
|
|
25
|
my $res = XML::RDDL::Resource->new( |
|
80
|
|
|
|
|
|
|
id => $id, |
|
81
|
|
|
|
|
|
|
base_uri => $xbase, |
|
82
|
|
|
|
|
|
|
href => $href, |
|
83
|
|
|
|
|
|
|
nature => $role, |
|
84
|
|
|
|
|
|
|
purpose => $arcrole, |
|
85
|
|
|
|
|
|
|
title => $title, |
|
86
|
|
|
|
|
|
|
lang => $xlang, |
|
87
|
|
|
|
|
|
|
); |
|
88
|
3
|
|
|
|
|
17
|
$self->{directory}->add_resource($res); |
|
89
|
|
|
|
|
|
|
} |
|
90
|
|
|
|
|
|
|
#-------------------------------------------------------------------# |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
#-------------------------------------------------------------------# |
|
93
|
|
|
|
|
|
|
# end_element |
|
94
|
|
|
|
|
|
|
#-------------------------------------------------------------------# |
|
95
|
|
|
|
|
|
|
sub end_element { |
|
96
|
7
|
|
|
7
|
0
|
984
|
my $self = shift; |
|
97
|
7
|
|
|
|
|
8
|
pop @{$self->{xLangStack}}; |
|
|
7
|
|
|
|
|
13
|
|
|
98
|
7
|
|
|
|
|
11
|
pop @{$self->{xBaseStack}}; |
|
|
7
|
|
|
|
|
22
|
|
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
#-------------------------------------------------------------------# |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
#,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,# |
|
104
|
|
|
|
|
|
|
#`,`, Misc. Helpers `,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,# |
|
105
|
|
|
|
|
|
|
#```````````````````````````````````````````````````````````````````# |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
#-------------------------------------------------------------------# |
|
108
|
|
|
|
|
|
|
# get_last_defined |
|
109
|
|
|
|
|
|
|
#-------------------------------------------------------------------# |
|
110
|
|
|
|
|
|
|
sub get_last_defined { |
|
111
|
6
|
|
|
6
|
0
|
9
|
my $arr = shift; |
|
112
|
6
|
|
|
|
|
13
|
for my $el (reverse @$arr) { |
|
113
|
10
|
100
|
|
|
|
35
|
return $el if defined $el; |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
#-------------------------------------------------------------------# |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
#-------------------------------------------------------------------# |
|
119
|
|
|
|
|
|
|
# get_attribute |
|
120
|
|
|
|
|
|
|
#-------------------------------------------------------------------# |
|
121
|
|
|
|
|
|
|
sub get_attribute { |
|
122
|
38
|
|
|
38
|
0
|
47
|
my $e = shift; |
|
123
|
38
|
|
|
|
|
91
|
my $ns = shift; |
|
124
|
38
|
|
|
|
|
42
|
my $ln = shift; |
|
125
|
|
|
|
|
|
|
|
|
126
|
38
|
100
|
|
|
|
125
|
if (exists $e->{Attributes}->{"{$ns}$ln"}) { |
|
127
|
21
|
|
|
|
|
103
|
return $e->{Attributes}->{"{$ns}$ln"}->{Value}; |
|
128
|
|
|
|
|
|
|
} |
|
129
|
17
|
|
|
|
|
63
|
return undef; |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
#-------------------------------------------------------------------# |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
1; |
|
136
|
|
|
|
|
|
|
#,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,# |
|
137
|
|
|
|
|
|
|
#`,`, Documentation `,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,`,# |
|
138
|
|
|
|
|
|
|
#```````````````````````````````````````````````````````````````````# |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=pod |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 NAME |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
XML::RDDL - Interface to RDDL (http://www.rddl.org/) |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
use XML::RDDL; |
|
149
|
|
|
|
|
|
|
use MySAX2Driver; |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
my $handler = XML::RDDL->new( |
|
152
|
|
|
|
|
|
|
default_lang => 'en', |
|
153
|
|
|
|
|
|
|
default_base_uri => 'http://foo/doc.xml', |
|
154
|
|
|
|
|
|
|
); |
|
155
|
|
|
|
|
|
|
my $driver = MySAX2Driver->new(Handler => $handler); |
|
156
|
|
|
|
|
|
|
my $rddl = $driver->parse($some_rddl); |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
RDDL (Resource Directory Description Language) is an XML vocabulary |
|
161
|
|
|
|
|
|
|
used to described resources associated with a namespace. It can be |
|
162
|
|
|
|
|
|
|
embedded inside other XML vocabularies (most frequently XHTML). |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
This module is meant to be used as a SAX2 handler that will return a |
|
165
|
|
|
|
|
|
|
Directory instance containing all resource descriptions at the end of |
|
166
|
|
|
|
|
|
|
the parse. |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head1 METHODS |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=over 4 |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=item XML::RDDL->new(%options) |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
Creates an XML::RDDL instance which is a SAX2 handler. The options |
|
175
|
|
|
|
|
|
|
are: |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
- default_lang |
|
178
|
|
|
|
|
|
|
the default language (as described in an xml:lang attribute) to |
|
179
|
|
|
|
|
|
|
be used. It is recommended that this be used if you want to have |
|
180
|
|
|
|
|
|
|
multilingual resources and your document doesn't contain |
|
181
|
|
|
|
|
|
|
sufficient xml:lang attributes. |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
- default_base_uri |
|
184
|
|
|
|
|
|
|
the default base URI (as described in an xml:base attribute) to |
|
185
|
|
|
|
|
|
|
be used (principally in xlink:href resolution). It is recommended |
|
186
|
|
|
|
|
|
|
that this be used if you want to resolve the xlink:hrefs and the |
|
187
|
|
|
|
|
|
|
document doesn't contain the appropriate xml:base attributes. |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=back |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
=head1 AUTHOR |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Robin Berjon, robin@knowscape.com |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
=head1 COPYRIGHT |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
Copyright (c) 2001-2002 Robin Berjon. All rights reserved. This program |
|
198
|
|
|
|
|
|
|
is free software; you can redistribute it and/or modify it under the |
|
199
|
|
|
|
|
|
|
same terms as Perl itself. |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
http://www.rddl.org/, XML::RDDL::Directory, XML::RDDL::Resource, |
|
204
|
|
|
|
|
|
|
XML::RDDL::Driver |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
=cut |
|
207
|
|
|
|
|
|
|
|