1 |
package Message::DOM::EntityReference; |
2 |
use strict; |
3 |
our $VERSION=do{my @r=(q$Revision: 1.6 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r}; |
4 |
push our @ISA, 'Message::DOM::Node', 'Message::IF::EntityReference'; |
5 |
require Message::DOM::Node; |
6 |
|
7 |
sub ____new ($$$) { |
8 |
my $self = shift->SUPER::____new (shift); |
9 |
$$self->{node_name} = $_[0]; |
10 |
$$self->{child_nodes} = []; |
11 |
return $self; |
12 |
} # ____new |
13 |
|
14 |
sub AUTOLOAD { |
15 |
my $method_name = our $AUTOLOAD; |
16 |
$method_name =~ s/.*:://; |
17 |
return if $method_name eq 'DESTROY'; |
18 |
|
19 |
if ({ |
20 |
## Read-only attributes (trivial accessors) |
21 |
node_name => 1, |
22 |
}->{$method_name}) { |
23 |
no strict 'refs'; |
24 |
eval qq{ |
25 |
sub $method_name (\$) { |
26 |
return \${\$_[0]}->{$method_name}; |
27 |
} |
28 |
}; |
29 |
goto &{ $AUTOLOAD }; |
30 |
} elsif ({ |
31 |
## Read-write attributes (boolean, trivial accessors) |
32 |
manakai_expanded => 1, |
33 |
manakai_external => 1, |
34 |
}->{$method_name}) { |
35 |
no strict 'refs'; |
36 |
eval qq{ |
37 |
sub $method_name (\$;\$) { |
38 |
if (\@_ > 1) { |
39 |
if (\${\${\$_[0]}->{owner_document}}->{manakai_strict_error_checking} and |
40 |
\${\$_[0]}->{manakai_read_only}) { |
41 |
report Message::DOM::DOMException |
42 |
-object => \$_[0], |
43 |
-type => 'NO_MODIFICATION_ALLOWED_ERR', |
44 |
-subtype => 'READ_ONLY_NODE_ERR'; |
45 |
} |
46 |
if (\$_[1]) { |
47 |
\${\$_[0]}->{$method_name} = 1; |
48 |
} else { |
49 |
delete \${\$_[0]}->{$method_name}; |
50 |
} |
51 |
} |
52 |
return \${\$_[0]}->{$method_name}; |
53 |
} |
54 |
}; |
55 |
goto &{ $AUTOLOAD }; |
56 |
} else { |
57 |
require Carp; |
58 |
Carp::croak (qq<Can't locate method "$AUTOLOAD">); |
59 |
} |
60 |
} # AUTOLOAD |
61 |
|
62 |
## |Node| attributes |
63 |
|
64 |
sub base_uri ($) { |
65 |
## NOTE: Same as |CharacterData|'s. |
66 |
|
67 |
my $self = $_[0]; |
68 |
local $Error::Depth = $Error::Depth + 1; |
69 |
my $pe = $$self->{parent_node}; |
70 |
while (defined $pe) { |
71 |
my $nt = $pe->node_type; |
72 |
if ($nt == 1 or $nt == 2 or $nt == 6 or $nt == 9 or $nt == 11) { |
73 |
## Element, Attr, Entity, Document, or DocumentFragment |
74 |
return $pe->base_uri; |
75 |
} elsif ($nt == 5) { |
76 |
## EntityReference |
77 |
return $pe->manakai_entity_base_uri if $pe->manakai_external; |
78 |
} |
79 |
$pe = $$pe->{parent_node}; |
80 |
} |
81 |
return $pe->base_uri if $pe; |
82 |
return $$self->{owner_document}->base_uri; |
83 |
} # base_uri |
84 |
|
85 |
sub node_name ($); # read-only trivial accessor |
86 |
|
87 |
sub node_type () { 5 } # ENTITY_REFERENCE_NODE |
88 |
|
89 |
## |EntityReference| attributes |
90 |
|
91 |
sub manakai_entity_base_uri ($;$) { |
92 |
my $self = $_[0]; |
93 |
if (@_ > 1) { |
94 |
if (${$$self->{owner_document}}->{strict_error_checking}) { |
95 |
if ($$self->{manakai_read_only}) { |
96 |
report Message::DOM::DOMException |
97 |
-object => $self, |
98 |
-type => 'NO_MODIFICATION_ALLOWED_ERR', |
99 |
-subtype => 'READ_ONLY_NODE_ERR'; |
100 |
} |
101 |
} |
102 |
if (defined $_[1]) { |
103 |
$$self->{manakai_entity_base_uri} = ''.$_[1]; |
104 |
} else { |
105 |
delete $$self->{manakai_entity_base_uri}; |
106 |
} |
107 |
} |
108 |
|
109 |
if (defined $$self->{manakai_entity_base_uri}) { |
110 |
return $$self->{manakai_entity_base_uri}; |
111 |
} else { |
112 |
local $Error::Depth = $Error::Depth + 1; |
113 |
return $self->base_uri; |
114 |
} |
115 |
} # manakai_entity_base_uri |
116 |
|
117 |
sub manakai_expanded ($;$); |
118 |
|
119 |
sub manakai_external ($;$); |
120 |
|
121 |
package Message::IF::EntityReference; |
122 |
|
123 |
package Message::DOM::Document; |
124 |
|
125 |
sub create_entity_reference ($$) { |
126 |
our $CreateEntityReference_OpenEntity; |
127 |
## TODO: This is Multithread unsafe |
128 |
|
129 |
my $self = $_[0]; |
130 |
my $orig_strict = $self->strict_error_checking; |
131 |
if ($orig_strict) { |
132 |
my $xv = $self->xml_version; |
133 |
if (defined $xv) { |
134 |
if ($xv eq '1.0' and |
135 |
$_[1] =~ /\A\p{InXML_NameStartChar10}\p{InXMLNameChar10}*\z/) { |
136 |
# |
137 |
} elsif ($xv eq '1.1' and |
138 |
$_[1] =~ /\A\p{InXMLNameStartChar11}\p{InXMLNameChar11}*\z/) { |
139 |
# |
140 |
} else { |
141 |
report Message::DOM::DOMException |
142 |
-object => $self, |
143 |
-type => 'INVALID_CHARACTER_ERR', |
144 |
-subtype => 'MALFORMED_NAME_ERR'; |
145 |
} |
146 |
} |
147 |
} |
148 |
|
149 |
my $r = Message::DOM::EntityReference->____new ($self, $_[1]); |
150 |
|
151 |
## Expansion |
152 |
unless ($CreateEntityReference_OpenEntity->{$_[1]}) { |
153 |
local $CreateEntityReference_OpenEntity->{$_[1]} = 1; |
154 |
local $Error::Depth = $Error::Depth + 1; |
155 |
|
156 |
my $doctype = $self->doctype; |
157 |
unless ($doctype) { |
158 |
$r->manakai_set_read_only (1, 1); |
159 |
return $r; |
160 |
} |
161 |
|
162 |
my $ent = $doctype->get_general_entity_node ($_[1]); |
163 |
unless ($ent) { |
164 |
$r->manakai_set_read_only (1, 1); |
165 |
return $r; |
166 |
} |
167 |
|
168 |
$self->strict_error_checking (0); |
169 |
for my $c (@{$ent->child_nodes}) { |
170 |
my $clone = $c->clone_node (1); |
171 |
$r->append_child ($clone); |
172 |
} |
173 |
$r->manakai_expanded ($ent->has_replacement_tree); |
174 |
$self->strict_error_checking ($orig_strict); |
175 |
} |
176 |
$r->manakai_set_read_only (1, 1); |
177 |
return $r; |
178 |
} # create_entity_reference |
179 |
|
180 |
=head1 LICENSE |
181 |
|
182 |
Copyright 2007 Wakaba <w@suika.fam.cx> |
183 |
|
184 |
This program is free software; you can redistribute it and/or |
185 |
modify it under the same terms as Perl itself. |
186 |
|
187 |
=cut |
188 |
|
189 |
1; |
190 |
## $Date: 2007/07/14 09:19:11 $ |