/[suikacvs]/messaging/manakai/lib/Message/DOM/EntityReference.pm
Suika

Contents of /messaging/manakai/lib/Message/DOM/EntityReference.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (hide annotations) (download)
Sat Jul 7 11:11:34 2007 UTC (17 years, 4 months ago) by wakaba
Branch: MAIN
Changes since 1.4: +54 -3 lines
++ manakai/t/ChangeLog	7 Jul 2007 11:11:27 -0000
	* DOM-Element.t: New tests for |create_element|
	and |create_element_ns| are added.

	* DOM-EntityReference.t: New tests for |create_entity_reference|
	are added.

	* DOM-Node.t: Test data for |is_element_content_whitespace|
	are added.

2007-07-07  Wakaba  <wakaba@suika.fam.cx>

++ manakai/lib/Message/DOM/ChangeLog	7 Jul 2007 11:10:33 -0000
	* CDATASection.pm (is_element_content_whitespace): New.

	* DOMElement.pm (has_attribute): Alpha version.
	(create_element, create_element_ns): Implemented.

	* DocumentType.pm (get_general_entity_node): Alpha version.

	* EntityReference.pm (create_entity_reference): Implemented.

	* ProcessingInstruction.pm (create_processing_instruction): Implemented.

2007-07-07  Wakaba  <wakaba@suika.fam.cx>

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

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24