/[suikacvs]/markup/html/whatpm/Whatpm/NanoDOM.pm
Suika

Contents of /markup/html/whatpm/Whatpm/NanoDOM.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.26 - (hide annotations) (download)
Sun Oct 19 06:14:57 2008 UTC (16 years ago) by wakaba
Branch: MAIN
Changes since 1.25: +7 -2 lines
++ whatpm/t/ChangeLog	19 Oct 2008 06:14:42 -0000
2008-10-19  Wakaba  <wakaba@suika.fam.cx>

	* XML-Parser.t: "xml/entities-1.dat" and "xml/entities-2.dat"
	added.  Support for the "#entities" directive.

++ whatpm/t/xml/ChangeLog	19 Oct 2008 06:11:59 -0000
	* entities-1.dat, entities-2.dat: New test data files.

2008-10-19  Wakaba  <wakaba@suika.fam.cx>

++ whatpm/Whatpm/ChangeLog	19 Oct 2008 06:12:27 -0000
2008-10-19  Wakaba  <wakaba@suika.fam.cx>

	* NanoDOM.pm (notation_name): New attribute.

	* NanoDOM.pm (public_id, system_id): New attributes.a
++ whatpm/Whatpm/HTML/ChangeLog	19 Oct 2008 06:13:03 -0000
	* Dumper.pm: Dump text content of Entity nodes.

	* Tokenizer.pm.src: Support for <!ENTITY ... NDATA>.

2008-10-19  Wakaba  <wakaba@suika.fam.cx>

++ whatpm/Whatpm/XML/ChangeLog	19 Oct 2008 06:14:05 -0000
2008-10-19  Wakaba  <wakaba@suika.fam.cx>

	* Parser.pm.src (_tree_in_subset): General and parameter entities
	implemented.

1 wakaba 1.1 =head1 NAME
2    
3 wakaba 1.2 Whatpm::NanoDOM - A Non-Conforming Implementation of DOM Subset
4 wakaba 1.1
5     =head1 DESCRIPTION
6    
7 wakaba 1.2 The C<Whatpm::NanoDOM> module contains a non-conforming implementation
8 wakaba 1.1 of a subset of DOM. It is the intention that this module is
9 wakaba 1.2 used only for the purpose of testing the C<Whatpm::HTML> module.
10 wakaba 1.1
11     See source code if you would like to know what it does.
12    
13     =cut
14    
15 wakaba 1.2 package Whatpm::NanoDOM;
16 wakaba 1.1 use strict;
17 wakaba 1.26 our $VERSION=do{my @r=(q$Revision: 1.25 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
18 wakaba 1.1
19 wakaba 1.3 require Scalar::Util;
20    
21     package Whatpm::NanoDOM::DOMImplementation;
22    
23     sub create_document ($) {
24     return Whatpm::NanoDOM::Document->new;
25     } # create_document
26    
27 wakaba 1.2 package Whatpm::NanoDOM::Node;
28 wakaba 1.1
29     sub new ($) {
30     my $class = shift;
31     my $self = bless {}, $class;
32     return $self;
33     } # new
34    
35     sub parent_node ($) {
36     return shift->{parent_node};
37     } # parent_node
38    
39 wakaba 1.4 sub manakai_parent_element ($) {
40     my $self = shift;
41     my $parent = $self->{parent_node};
42     while (defined $parent) {
43     if ($parent->node_type == 1) {
44     return $parent;
45     } else {
46     $parent = $parent->{parent_node};
47     }
48     }
49     return undef;
50     } # manakai_parent_element
51    
52 wakaba 1.1 sub child_nodes ($) {
53 wakaba 1.7 return shift->{child_nodes} || [];
54 wakaba 1.1 } # child_nodes
55    
56 wakaba 1.23 sub node_name ($) { return $_[0]->{node_name} }
57    
58 wakaba 1.1 ## NOTE: Only applied to Elements and Documents
59     sub append_child ($$) {
60     my ($self, $new_child) = @_;
61     if (defined $new_child->{parent_node}) {
62     my $parent_list = $new_child->{parent_node}->{child_nodes};
63     for (0..$#$parent_list) {
64     if ($parent_list->[$_] eq $new_child) {
65     splice @$parent_list, $_, 1;
66     }
67     }
68     }
69     push @{$self->{child_nodes}}, $new_child;
70 wakaba 1.3 $new_child->{parent_node} = $self;
71     Scalar::Util::weaken ($new_child->{parent_node});
72 wakaba 1.1 return $new_child;
73     } # append_child
74    
75     ## NOTE: Only applied to Elements and Documents
76     sub insert_before ($$;$) {
77     my ($self, $new_child, $ref_child) = @_;
78     if (defined $new_child->{parent_node}) {
79     my $parent_list = $new_child->{parent_node}->{child_nodes};
80     for (0..$#$parent_list) {
81     if ($parent_list->[$_] eq $new_child) {
82     splice @$parent_list, $_, 1;
83     }
84     }
85     }
86     my $i = @{$self->{child_nodes}};
87     if (defined $ref_child) {
88     for (0..$#{$self->{child_nodes}}) {
89     if ($self->{child_nodes}->[$_] eq $ref_child) {
90     $i = $_;
91     last;
92     }
93     }
94     }
95     splice @{$self->{child_nodes}}, $i, 0, $new_child;
96 wakaba 1.5 $new_child->{parent_node} = $self;
97     Scalar::Util::weaken ($new_child->{parent_node});
98 wakaba 1.1 return $new_child;
99     } # insert_before
100    
101     ## NOTE: Only applied to Elements and Documents
102     sub remove_child ($$) {
103     my ($self, $old_child) = @_;
104     my $parent_list = $self->{child_nodes};
105     for (0..$#$parent_list) {
106     if ($parent_list->[$_] eq $old_child) {
107     splice @$parent_list, $_, 1;
108     }
109     }
110     delete $old_child->{parent_node};
111     return $old_child;
112     } # remove_child
113    
114     ## NOTE: Only applied to Elements and Documents
115     sub has_child_nodes ($) {
116     return @{shift->{child_nodes}} > 0;
117     } # has_child_nodes
118    
119     ## NOTE: Only applied to Elements and Documents
120 wakaba 1.8 sub first_child ($) {
121     my $self = shift;
122     return $self->{child_nodes}->[0];
123     } # first_child
124    
125     ## NOTE: Only applied to Elements and Documents
126 wakaba 1.1 sub last_child ($) {
127     my $self = shift;
128     return @{$self->{child_nodes}} ? $self->{child_nodes}->[-1] : undef;
129     } # last_child
130    
131     ## NOTE: Only applied to Elements and Documents
132     sub previous_sibling ($) {
133     my $self = shift;
134     my $parent = $self->{parent_node};
135     return undef unless defined $parent;
136     my $r;
137     for (@{$parent->{child_nodes}}) {
138     if ($_ eq $self) {
139     return $r;
140     } else {
141     $r = $_;
142     }
143     }
144     return undef;
145     } # previous_sibling
146    
147 wakaba 1.6 sub prefix ($;$) {
148     my $self = shift;
149     if (@_) {
150     $self->{prefix} = shift;
151     }
152     return $self->{prefix};
153     } # prefix
154    
155 wakaba 1.24 sub text_content ($;$) {
156     my $self = shift;
157     if (@_) {
158     @{$self->{child_nodes}} = (); ## NOTE: parent_node not unset.
159     $self->append_child (Whatpm::NanoDOM::Text->new ($_[0]));
160     return unless wantarray;
161     }
162     my $r = '';
163     for my $child (@{$self->child_nodes}) {
164     if ($child->can ('data')) {
165     $r .= $child->data;
166     } else {
167     $r .= $child->text_content;
168     }
169     }
170     return $r;
171     } # text_content
172    
173 wakaba 1.18 sub get_user_data ($$) {
174     return $_[0]->{$_[1]};
175     } # get_user_data
176    
177     sub set_user_data ($$;$$) {
178     $_[0]->{$_[1]} = $_[2];
179     } # set_user_data
180    
181 wakaba 1.1 sub ELEMENT_NODE () { 1 }
182     sub ATTRIBUTE_NODE () { 2 }
183     sub TEXT_NODE () { 3 }
184     sub CDATA_SECTION_NODE () { 4 }
185     sub ENTITY_REFERENCE_NODE () { 5 }
186     sub ENTITY_NODE () { 6 }
187     sub PROCESSING_INSTRUCTION_NODE () { 7 }
188     sub COMMENT_NODE () { 8 }
189     sub DOCUMENT_NODE () { 9 }
190     sub DOCUMENT_TYPE_NODE () { 10 }
191     sub DOCUMENT_FRAGMENT_NODE () { 11 }
192     sub NOTATION_NODE () { 12 }
193 wakaba 1.23 sub ELEMENT_TYPE_DEFINITION_NODE () { 81001 }
194     sub ATTRIBUTE_DEFINITION_NODE () { 81002 }
195 wakaba 1.1
196 wakaba 1.2 package Whatpm::NanoDOM::Document;
197     push our @ISA, 'Whatpm::NanoDOM::Node';
198 wakaba 1.1
199     sub new ($) {
200     my $self = shift->SUPER::new;
201     $self->{child_nodes} = [];
202     return $self;
203     } # new
204    
205     ## A manakai extension
206     sub manakai_append_text ($$) {
207     my $self = shift;
208     if (@{$self->{child_nodes}} and
209     $self->{child_nodes}->[-1]->node_type == 3) {
210     $self->{child_nodes}->[-1]->manakai_append_text (shift);
211     } else {
212     my $text = $self->create_text_node (shift);
213     $self->append_child ($text);
214     }
215     } # manakai_append_text
216    
217     sub node_type () { 9 }
218    
219     sub strict_error_checking {
220     return 0;
221     } # strict_error_checking
222    
223     sub create_text_node ($$) {
224     shift;
225 wakaba 1.2 return Whatpm::NanoDOM::Text->new (shift);
226 wakaba 1.1 } # create_text_node
227    
228     sub create_comment ($$) {
229     shift;
230 wakaba 1.2 return Whatpm::NanoDOM::Comment->new (shift);
231 wakaba 1.1 } # create_comment
232    
233     ## The second parameter only supports manakai extended way
234     ## to specify qualified name - "[$prefix, $local_name]"
235 wakaba 1.20 sub create_attribute_ns ($$$) {
236     my ($self, $nsuri, $qn) = @_;
237     return Whatpm::NanoDOM::Attr->new (undef, $nsuri, $qn->[0], $qn->[1], '');
238    
239     ## NOTE: Created attribute node should be set to an element node
240     ## as far as possible. |onwer_document| of the attribute node, for
241     ## example, depends on the definedness of the |owner_element| attribute.
242     } # create_attribute_ns
243    
244     ## The second parameter only supports manakai extended way
245     ## to specify qualified name - "[$prefix, $local_name]"
246 wakaba 1.1 sub create_element_ns ($$$) {
247     my ($self, $nsuri, $qn) = @_;
248 wakaba 1.3 return Whatpm::NanoDOM::Element->new ($self, $nsuri, $qn->[0], $qn->[1]);
249 wakaba 1.1 } # create_element_ns
250    
251     ## A manakai extension
252     sub create_document_type_definition ($$) {
253     shift;
254 wakaba 1.2 return Whatpm::NanoDOM::DocumentType->new (shift);
255 wakaba 1.1 } # create_document_type_definition
256    
257 wakaba 1.23 ## A manakai extension.
258     sub create_element_type_definition ($$) {
259     shift;
260     return Whatpm::NanoDOM::ElementTypeDefinition->new (shift);
261     } # create_element_type_definition
262    
263     ## A manakai extension.
264     sub create_general_entity ($$) {
265     shift;
266     return Whatpm::NanoDOM::Entity->new (shift);
267     } # create_general_entity
268    
269     ## A manakai extension.
270     sub create_notation ($$) {
271     shift;
272     return Whatpm::NanoDOM::Notation->new (shift);
273     } # create_notation
274    
275     ## A manakai extension.
276     sub create_attribute_definition ($$) {
277     shift;
278     return Whatpm::NanoDOM::AttributeDefinition->new (shift);
279     } # create_attribute_definition
280    
281 wakaba 1.22 sub create_processing_instruction ($$$) {
282     return Whatpm::NanoDOM::ProcessingInstruction->new (@_);
283     } # creat_processing_instruction
284    
285 wakaba 1.3 sub implementation ($) {
286     return 'Whatpm::NanoDOM::DOMImplementation';
287     } # implementation
288    
289 wakaba 1.4 sub document_element ($) {
290     my $self = shift;
291     for (@{$self->child_nodes}) {
292     if ($_->node_type == 1) {
293     return $_;
294     }
295     }
296     return undef;
297     } # document_element
298    
299 wakaba 1.21 sub dom_config ($) {
300     return {};
301     } # dom_config
302    
303 wakaba 1.12 sub adopt_node ($$) {
304 wakaba 1.11 my @node = ($_[1]);
305     while (@node) {
306     my $node = shift @node;
307     $node->{owner_document} = $_[0];
308     Scalar::Util::weaken ($node->{owner_document});
309     push @node, @{$node->child_nodes};
310     push @node, @{$node->attributes or []} if $node->can ('attributes');
311     }
312     return $_[1];
313     } # adopt_node
314    
315 wakaba 1.12 sub manakai_is_html ($;$) {
316     if (@_ > 1) {
317     if ($_[1]) {
318     $_[0]->{manakai_is_html} = 1;
319     } else {
320 wakaba 1.13 delete $_[0]->{manakai_is_html};
321 wakaba 1.12 delete $_[0]->{manakai_compat_mode};
322     }
323     }
324     return $_[0]->{manakai_is_html};
325     } # manakai_is_html
326    
327     sub compat_mode ($) {
328     if ($_[0]->{manakai_is_html}) {
329     if ($_[0]->{manakai_compat_mode} eq 'quirks') {
330     return 'BackCompat';
331     }
332     }
333     return 'CSS1Compat';
334     } # compat_mode
335    
336     sub manakai_compat_mode ($;$) {
337     if ($_[0]->{manakai_is_html}) {
338     if (@_ > 1 and defined $_[1] and
339     {'no quirks' => 1, 'limited quirks' => 1, 'quirks' => 1}->{$_[1]}) {
340     $_[0]->{manakai_compat_mode} = $_[1];
341     }
342     return $_[0]->{manakai_compat_mode} || 'no quirks';
343     } else {
344     return 'no quirks';
345     }
346     } # manakai_compat_mode
347    
348 wakaba 1.19 sub manakai_head ($) {
349     my $html = $_[0]->manakai_html;
350     return undef unless defined $html;
351     for my $el (@{$html->child_nodes}) {
352     next unless $el->node_type == 1; # ELEMENT_NODE
353     my $nsuri = $el->namespace_uri;
354     next unless defined $nsuri;
355     next unless $nsuri eq q<http://www.w3.org/1999/xhtml>;
356     next unless $el->manakai_local_name eq 'head';
357     return $el;
358     }
359     return undef;
360     } # manakai_head
361    
362     sub manakai_html ($) {
363     my $de = $_[0]->document_element;
364     my $nsuri = $de->namespace_uri;
365     if (defined $nsuri and $nsuri eq q<http://www.w3.org/1999/xhtml> and
366     $de->manakai_local_name eq 'html') {
367     return $de;
368     } else {
369     return undef;
370     }
371     } # manakai_html
372    
373 wakaba 1.17 sub input_encoding ($;$) {
374     $_[0]->{input_encoding} = $_[1] if @_ > 1;
375     return $_[0]->{input_encoding};
376     }
377    
378     sub manakai_charset ($;$) {
379     $_[0]->{manakai_charset} = $_[1] if @_ > 1;
380     return $_[0]->{manakai_charset};
381     }
382    
383     sub manakai_has_bom ($;$) {
384     $_[0]->{manakai_has_bom} = $_[1] if @_ > 1;
385     return $_[0]->{manakai_has_bom};
386     }
387    
388 wakaba 1.22 sub xml_version ($;$) {
389     $_[0]->{xml_version} = $_[1] if @_ > 1;
390     return $_[0]->{xml_version};
391     }
392    
393     sub xml_encoding ($;$) {
394     $_[0]->{xml_encoding} = $_[1] if @_ > 1;
395     return $_[0]->{xml_encoding};
396     }
397    
398     sub xml_standalone ($;$) {
399     $_[0]->{xml_standalone} = $_[1] if @_ > 1;
400     return $_[0]->{xml_standalone};
401     }
402    
403 wakaba 1.2 package Whatpm::NanoDOM::Element;
404     push our @ISA, 'Whatpm::NanoDOM::Node';
405 wakaba 1.1
406 wakaba 1.3 sub new ($$$$$) {
407 wakaba 1.1 my $self = shift->SUPER::new;
408 wakaba 1.3 $self->{owner_document} = shift;
409     Scalar::Util::weaken ($self->{owner_document});
410 wakaba 1.1 $self->{namespace_uri} = shift;
411     $self->{prefix} = shift;
412     $self->{local_name} = shift;
413     $self->{attributes} = {};
414     $self->{child_nodes} = [];
415     return $self;
416     } # new
417    
418 wakaba 1.3 sub owner_document ($) {
419     return shift->{owner_document};
420     } # owner_document
421    
422 wakaba 1.1 sub clone_node ($$) {
423     my ($self, $deep) = @_; ## NOTE: Deep cloning is not supported
424     my $clone = bless {
425     namespace_uri => $self->{namespace_uri},
426     prefix => $self->{prefix},
427     local_name => $self->{local_name},
428     child_nodes => [],
429     }, ref $self;
430     for my $ns (keys %{$self->{attributes}}) {
431     for my $ln (keys %{$self->{attributes}->{$ns}}) {
432     my $attr = $self->{attributes}->{$ns}->{$ln};
433     $clone->{attributes}->{$ns}->{$ln} = bless {
434     namespace_uri => $attr->{namespace_uri},
435     prefix => $attr->{prefix},
436     local_name => $attr->{local_name},
437     value => $attr->{value},
438     }, ref $self->{attributes}->{$ns}->{$ln};
439     }
440     }
441     return $clone;
442     } # clone
443    
444     ## A manakai extension
445     sub manakai_append_text ($$) {
446     my $self = shift;
447     if (@{$self->{child_nodes}} and
448     $self->{child_nodes}->[-1]->node_type == 3) {
449     $self->{child_nodes}->[-1]->manakai_append_text (shift);
450     } else {
451 wakaba 1.2 my $text = Whatpm::NanoDOM::Text->new (shift);
452 wakaba 1.1 $self->append_child ($text);
453     }
454     } # manakai_append_text
455    
456     sub attributes ($) {
457     my $self = shift;
458     my $r = [];
459     ## Order MUST be stable
460     for my $ns (sort {$a cmp $b} keys %{$self->{attributes}}) {
461     for my $ln (sort {$a cmp $b} keys %{$self->{attributes}->{$ns}}) {
462     push @$r, $self->{attributes}->{$ns}->{$ln}
463     if defined $self->{attributes}->{$ns}->{$ln};
464     }
465     }
466     return $r;
467     } # attributes
468    
469 wakaba 1.3 sub local_name ($) { # TODO: HTML5 case
470     return shift->{local_name};
471     } # local_name
472    
473 wakaba 1.4 sub manakai_local_name ($) {
474     return shift->{local_name}; # no case fixing for HTML5
475     } # manakai_local_name
476    
477 wakaba 1.3 sub namespace_uri ($) {
478     return shift->{namespace_uri};
479     } # namespace_uri
480    
481 wakaba 1.4 sub manakai_element_type_match ($$$) {
482     my ($self, $nsuri, $ln) = @_;
483     if (defined $nsuri) {
484     if (defined $self->{namespace_uri} and $nsuri eq $self->{namespace_uri}) {
485     return ($ln eq $self->{local_name});
486     } else {
487     return 0;
488     }
489     } else {
490     if (not defined $self->{namespace_uri}) {
491     return ($ln eq $self->{local_name});
492     } else {
493     return 0;
494     }
495     }
496     } # manakai_element_type_match
497    
498 wakaba 1.1 sub node_type { 1 }
499    
500     ## TODO: HTML5 capitalization
501     sub tag_name ($) {
502     my $self = shift;
503     if (defined $self->{prefix}) {
504     return $self->{prefix} . ':' . $self->{local_name};
505     } else {
506     return $self->{local_name};
507     }
508     } # tag_name
509    
510 wakaba 1.8 sub get_attribute_ns ($$$) {
511     my ($self, $nsuri, $ln) = @_;
512     $nsuri = '' unless defined $nsuri;
513     return defined $self->{attributes}->{$nsuri}->{$ln}
514     ? $self->{attributes}->{$nsuri}->{$ln}->value : undef;
515     } # get_attribute_ns
516    
517 wakaba 1.9 sub get_attribute_node_ns ($$$) {
518     my ($self, $nsuri, $ln) = @_;
519     $nsuri = '' unless defined $nsuri;
520     return $self->{attributes}->{$nsuri}->{$ln};
521     } # get_attribute_node_ns
522    
523 wakaba 1.1 sub has_attribute_ns ($$$) {
524     my ($self, $nsuri, $ln) = @_;
525 wakaba 1.8 $nsuri = '' unless defined $nsuri;
526 wakaba 1.1 return defined $self->{attributes}->{$nsuri}->{$ln};
527     } # has_attribute_ns
528    
529     ## The second parameter only supports manakai extended way
530     ## to specify qualified name - "[$prefix, $local_name]"
531     sub set_attribute_ns ($$$$) {
532     my ($self, $nsuri, $qn, $value) = @_;
533     $self->{attributes}->{$nsuri}->{$qn->[1]}
534 wakaba 1.5 = Whatpm::NanoDOM::Attr->new ($self, $nsuri, $qn->[0], $qn->[1], $value);
535 wakaba 1.1 } # set_attribute_ns
536    
537 wakaba 1.20 sub set_attribute_node_ns ($$) {
538     my $self = shift;
539     my $attr = shift;
540     $self->{attributes}->{$attr->namespace_uri}->{$attr->manakai_local_name}
541     = $attr;
542     $attr->{owner_element} = $self;
543     Scalar::Util::weaken ($attr->{owner_element});
544     } # set_attribute_node_ns
545    
546 wakaba 1.2 package Whatpm::NanoDOM::Attr;
547     push our @ISA, 'Whatpm::NanoDOM::Node';
548 wakaba 1.1
549 wakaba 1.5 sub new ($$$$$$) {
550 wakaba 1.1 my $self = shift->SUPER::new;
551 wakaba 1.5 $self->{owner_element} = shift;
552     Scalar::Util::weaken ($self->{owner_element});
553 wakaba 1.1 $self->{namespace_uri} = shift;
554     $self->{prefix} = shift;
555     $self->{local_name} = shift;
556     $self->{value} = shift;
557     return $self;
558     } # new
559    
560 wakaba 1.5 sub namespace_uri ($) {
561     return shift->{namespace_uri};
562     } # namespace_uri
563    
564     sub manakai_local_name ($) {
565     return shift->{local_name};
566     } # manakai_local_name
567    
568 wakaba 1.1 sub node_type { 2 }
569    
570 wakaba 1.14 sub owner_document ($) {
571     return shift->owner_element->owner_document;
572     } # owner_document
573    
574 wakaba 1.1 ## TODO: HTML5 case stuff?
575     sub name ($) {
576     my $self = shift;
577     if (defined $self->{prefix}) {
578     return $self->{prefix} . ':' . $self->{local_name};
579     } else {
580     return $self->{local_name};
581     }
582     } # name
583    
584 wakaba 1.20 sub value ($;$) {
585     if (@_ > 1) {
586     $_[0]->{value} = $_[1];
587     }
588 wakaba 1.1 return shift->{value};
589     } # value
590    
591 wakaba 1.5 sub owner_element ($) {
592     return shift->{owner_element};
593     } # owner_element
594    
595 wakaba 1.2 package Whatpm::NanoDOM::CharacterData;
596     push our @ISA, 'Whatpm::NanoDOM::Node';
597 wakaba 1.1
598     sub new ($$) {
599     my $self = shift->SUPER::new;
600     $self->{data} = shift;
601     return $self;
602     } # new
603    
604     ## A manakai extension
605     sub manakai_append_text ($$) {
606     my ($self, $s) = @_;
607     $self->{data} .= $s;
608     } # manakai_append_text
609    
610     sub data ($) {
611     return shift->{data};
612     } # data
613    
614 wakaba 1.2 package Whatpm::NanoDOM::Text;
615     push our @ISA, 'Whatpm::NanoDOM::CharacterData';
616 wakaba 1.1
617     sub node_type () { 3 }
618    
619 wakaba 1.2 package Whatpm::NanoDOM::Comment;
620     push our @ISA, 'Whatpm::NanoDOM::CharacterData';
621 wakaba 1.1
622     sub node_type () { 8 }
623    
624 wakaba 1.2 package Whatpm::NanoDOM::DocumentType;
625     push our @ISA, 'Whatpm::NanoDOM::Node';
626 wakaba 1.1
627     sub new ($$) {
628     my $self = shift->SUPER::new;
629     $self->{name} = shift;
630 wakaba 1.23 $self->{element_types} = {};
631     $self->{entities} = {};
632     $self->{notations} = {};
633     $self->{child_nodes} = [];
634 wakaba 1.1 return $self;
635     } # new
636    
637     sub node_type () { 10 }
638    
639     sub name ($) {
640     return shift->{name};
641     } # name
642    
643 wakaba 1.16 sub public_id ($;$) {
644     $_[0]->{public_id} = $_[1] if @_ > 1;
645     return $_[0]->{public_id};
646     } # public_id
647    
648     sub system_id ($;$) {
649     $_[0]->{system_id} = $_[1] if @_ > 1;
650     return $_[0]->{system_id};
651     } # system_id
652    
653 wakaba 1.23 sub element_types ($) {
654     return $_[0]->{element_types};
655     } # element_types
656    
657     sub entities ($) {
658     return $_[0]->{entities};
659     } # entities
660    
661     sub notations ($) {
662     return $_[0]->{notations};
663     } # notations
664    
665     sub get_element_type_definition_node ($$) {
666     return $_[0]->{element_types}->{$_[1]};
667     } # get_element_type_definition_node
668    
669     sub set_element_type_definition_node ($$) {
670     $_[0]->{element_types}->{$_[1]->node_name} = $_[1];
671     } # set_element_type_definition_node
672    
673     sub get_general_entity_node ($$) {
674     return $_[0]->{entities}->{$_[1]};
675     } # get_general_entity_node
676    
677     sub set_general_entity_node ($$) {
678     $_[0]->{entities}->{$_[1]->node_name} = $_[1];
679     } # set_general_entity_node
680    
681     sub get_notation_node ($$) {
682     return $_[0]->{notations}->{$_[1]};
683     } # get_notation_node
684    
685     sub set_notation_node ($$) {
686     $_[0]->{notations}->{$_[1]->node_name} = $_[1];
687     } # set_notation_node
688    
689 wakaba 1.22 package Whatpm::NanoDOM::ProcessingInstruction;
690     push our @ISA, 'Whatpm::NanoDOM::Node';
691    
692     sub new ($$$$) {
693     my $self = shift->SUPER::new;
694     shift;
695     # $self->{owner_document} = shift;
696     # Scalar::Util::weaken ($self->{owner_document});
697     $self->{target} = shift;
698     $self->{data} = shift;
699     return $self;
700     } # new
701    
702     sub node_type () { 7 }
703    
704     sub target ($) {
705     return $_[0]->{target};
706     } # target
707    
708     sub data ($;$) {
709     $_[0]->{data} = $_[1] if @_ > 1;
710     return $_[0]->{data};
711     } # data
712    
713 wakaba 1.23 package Whatpm::NanoDOM::Entity;
714     push our @ISA, 'Whatpm::NanoDOM::Node';
715    
716     sub new ($$) {
717     my $self = shift->SUPER::new;
718     $self->{node_name} = shift;
719     return $self;
720     } # new
721    
722     sub node_type () { 6 }
723    
724 wakaba 1.25 sub public_id ($;$) {
725     $_[0]->{public_id} = $_[1] if @_ > 1;
726     return $_[0]->{public_id};
727     } # public_id
728    
729     sub system_id ($;$) {
730     $_[0]->{system_id} = $_[1] if @_ > 1;
731     return $_[0]->{system_id};
732     } # system_id
733    
734 wakaba 1.26 sub notation_name ($;$) {
735     $_[0]->{notation_name} = $_[1] if @_ > 1;
736     return $_[0]->{notation_name};
737     } # notation_name
738    
739 wakaba 1.23 package Whatpm::NanoDOM::Notation;
740     push our @ISA, 'Whatpm::NanoDOM::Node';
741    
742     sub new ($$) {
743     my $self = shift->SUPER::new;
744     $self->{node_name} = shift;
745     return $self;
746     } # new
747    
748     sub node_type () { 12 }
749    
750 wakaba 1.25 sub public_id ($;$) {
751     $_[0]->{public_id} = $_[1] if @_ > 1;
752     return $_[0]->{public_id};
753     } # public_id
754    
755     sub system_id ($;$) {
756     $_[0]->{system_id} = $_[1] if @_ > 1;
757     return $_[0]->{system_id};
758     } # system_id
759    
760 wakaba 1.23 package Whatpm::NanoDOM::ElementTypeDefinition;
761     push our @ISA, 'Whatpm::NanoDOM::Node';
762    
763     sub new ($$) {
764     my $self = shift->SUPER::new;
765     $self->{node_name} = shift;
766     $self->{content_model} = '';
767     $self->{attribute_definitions} = {};
768     return $self;
769     } # new
770    
771     sub node_type () { 81001 }
772    
773     sub content_model_text ($;$) {
774     $_[0]->{content_model} = $_[1] if @_ > 1;
775     return $_[0]->{content_model};
776     } # content_model_text
777    
778     sub attribute_definitions ($) { return $_[0]->{attribute_definitions} }
779    
780     sub get_attribute_definition_node ($$) {
781     return $_[0]->{attribute_definitions}->{$_[1]};
782     } # get_attribute_definition_node
783    
784     sub set_attribute_definition_node ($$) {
785     $_[0]->{attribute_definitions}->{$_[1]->node_name} = $_[1];
786     } # set_attribute_definition_node
787    
788     package Whatpm::NanoDOM::AttributeDefinition;
789     push our @ISA, 'Whatpm::NanoDOM::Node';
790    
791     sub new ($$) {
792     my $self = shift->SUPER::new;
793     $self->{node_name} = shift;
794 wakaba 1.24 $self->{allowed_tokens} = [];
795 wakaba 1.23 return $self;
796     } # new
797    
798     sub node_type () { 81002 }
799    
800 wakaba 1.24 sub allowed_tokens ($) { return $_[0]->{allowed_tokens} }
801    
802     sub default_type ($;$) {
803     $_[0]->{default_type} = $_[1] if @_ > 1;
804     return $_[0]->{default_type} || 0;
805     } # default_type
806    
807     sub declared_type ($;$) {
808     $_[0]->{declared_type} = $_[1] if @_ > 1;
809     return $_[0]->{declared_type} || 0;
810     } # declared_type
811    
812 wakaba 1.1 =head1 SEE ALSO
813    
814 wakaba 1.22 L<Whatpm::HTML|Whatpm::HTML>
815    
816     L<Whatpm::XML::Parser|Whatpm::XML::Parser>
817    
818     L<Whatpm::ContentChecker|Whatpm::ContentChecker>
819 wakaba 1.1
820     =head1 AUTHOR
821    
822     Wakaba <w@suika.fam.cx>.
823    
824     =head1 LICENSE
825    
826 wakaba 1.22 Copyright 2007-2008 Wakaba <w@suika.fam.cx>
827 wakaba 1.1
828     This library is free software; you can redistribute it
829     and/or modify it under the same terms as Perl itself.
830    
831     =cut
832    
833     1;
834 wakaba 1.26 # $Date: 2008/10/18 11:34:49 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24