/[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.23 - (hide annotations) (download)
Fri Oct 17 07:14:29 2008 UTC (16 years ago) by wakaba
Branch: MAIN
Changes since 1.22: +131 -2 lines
++ whatpm/t/ChangeLog	17 Oct 2008 07:14:01 -0000
2008-10-17  Wakaba  <wakaba@suika.fam.cx>

	* XML-Parser.t: "xml/attlists-1.dat" added.

++ whatpm/t/xml/ChangeLog	17 Oct 2008 07:14:24 -0000
2008-10-17  Wakaba  <wakaba@suika.fam.cx>

	* attlists-1.dat: New test data file.

	* doctypes-2.dat: New tests added.

++ whatpm/Whatpm/ChangeLog	17 Oct 2008 07:11:25 -0000
2008-10-17  Wakaba  <wakaba@suika.fam.cx>

	* NanoDOM.pm (node_name): New attribute.
	(ELEMENT_TYPE_DEFINITION_NODE, ATTRIBUTE_DEFINITION_NODE): New
	constants.
	(create_element_type_definition_node, create_attribute_definition,
	create_notation, create_general_entity,
	get_element_type_definition_node,
	set_element_type_definition_node, get_general_entity_node,
	set_general_entity_node, get_notation_node, set_notation_node,
	get_attribute_definition_node, set_attribute_definition_node): New
	methods.
	(element_types, entities, notations, attribute_definitions): New
	attributes.
	(DocumentType): Support for child nodes, entities, notations, and
	element types.
	(Entity, Notation, ElementTypeDefinition, AttributeDefinition):
	New classes.

	* Dumper.pm: Support for general entities, notations, element type
	definitions, and attribute definitions.

++ whatpm/Whatpm/HTML/ChangeLog	17 Oct 2008 07:12:26 -0000
2008-10-17  Wakaba  <wakaba@suika.fam.cx>

	* Tokenizer.pm.src: New token types AtTLIST_TOKEN, ELEMENT_TOKEN,
	GENERAL_ENTITY_TOKEN, PARAMETER_ENTITY_TOKEN, and NOTATION_TOKEN
	are added.  New intertion modes for markup declarations are added.

++ whatpm/Whatpm/XML/ChangeLog	17 Oct 2008 07:13:47 -0000
2008-10-17  Wakaba  <wakaba@suika.fam.cx>

	* Parser.pm.src (_tree_in_subset): Support for ELEMENT_TOKEN,
	ATTLIST_TOKEN, GENERAL_ENTITY_TOKEN, PARAMETER_ENTITY_TOKEN, and
	NOTATION_TOKEN.

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.23 our $VERSION=do{my @r=(q$Revision: 1.22 $=~/\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.18 sub get_user_data ($$) {
156     return $_[0]->{$_[1]};
157     } # get_user_data
158    
159     sub set_user_data ($$;$$) {
160     $_[0]->{$_[1]} = $_[2];
161     } # set_user_data
162    
163 wakaba 1.1 sub ELEMENT_NODE () { 1 }
164     sub ATTRIBUTE_NODE () { 2 }
165     sub TEXT_NODE () { 3 }
166     sub CDATA_SECTION_NODE () { 4 }
167     sub ENTITY_REFERENCE_NODE () { 5 }
168     sub ENTITY_NODE () { 6 }
169     sub PROCESSING_INSTRUCTION_NODE () { 7 }
170     sub COMMENT_NODE () { 8 }
171     sub DOCUMENT_NODE () { 9 }
172     sub DOCUMENT_TYPE_NODE () { 10 }
173     sub DOCUMENT_FRAGMENT_NODE () { 11 }
174     sub NOTATION_NODE () { 12 }
175 wakaba 1.23 sub ELEMENT_TYPE_DEFINITION_NODE () { 81001 }
176     sub ATTRIBUTE_DEFINITION_NODE () { 81002 }
177 wakaba 1.1
178 wakaba 1.2 package Whatpm::NanoDOM::Document;
179     push our @ISA, 'Whatpm::NanoDOM::Node';
180 wakaba 1.1
181     sub new ($) {
182     my $self = shift->SUPER::new;
183     $self->{child_nodes} = [];
184     return $self;
185     } # new
186    
187     ## A manakai extension
188     sub manakai_append_text ($$) {
189     my $self = shift;
190     if (@{$self->{child_nodes}} and
191     $self->{child_nodes}->[-1]->node_type == 3) {
192     $self->{child_nodes}->[-1]->manakai_append_text (shift);
193     } else {
194     my $text = $self->create_text_node (shift);
195     $self->append_child ($text);
196     }
197     } # manakai_append_text
198    
199     sub node_type () { 9 }
200    
201     sub strict_error_checking {
202     return 0;
203     } # strict_error_checking
204    
205     sub create_text_node ($$) {
206     shift;
207 wakaba 1.2 return Whatpm::NanoDOM::Text->new (shift);
208 wakaba 1.1 } # create_text_node
209    
210     sub create_comment ($$) {
211     shift;
212 wakaba 1.2 return Whatpm::NanoDOM::Comment->new (shift);
213 wakaba 1.1 } # create_comment
214    
215     ## The second parameter only supports manakai extended way
216     ## to specify qualified name - "[$prefix, $local_name]"
217 wakaba 1.20 sub create_attribute_ns ($$$) {
218     my ($self, $nsuri, $qn) = @_;
219     return Whatpm::NanoDOM::Attr->new (undef, $nsuri, $qn->[0], $qn->[1], '');
220    
221     ## NOTE: Created attribute node should be set to an element node
222     ## as far as possible. |onwer_document| of the attribute node, for
223     ## example, depends on the definedness of the |owner_element| attribute.
224     } # create_attribute_ns
225    
226     ## The second parameter only supports manakai extended way
227     ## to specify qualified name - "[$prefix, $local_name]"
228 wakaba 1.1 sub create_element_ns ($$$) {
229     my ($self, $nsuri, $qn) = @_;
230 wakaba 1.3 return Whatpm::NanoDOM::Element->new ($self, $nsuri, $qn->[0], $qn->[1]);
231 wakaba 1.1 } # create_element_ns
232    
233     ## A manakai extension
234     sub create_document_type_definition ($$) {
235     shift;
236 wakaba 1.2 return Whatpm::NanoDOM::DocumentType->new (shift);
237 wakaba 1.1 } # create_document_type_definition
238    
239 wakaba 1.23 ## A manakai extension.
240     sub create_element_type_definition ($$) {
241     shift;
242     return Whatpm::NanoDOM::ElementTypeDefinition->new (shift);
243     } # create_element_type_definition
244    
245     ## A manakai extension.
246     sub create_general_entity ($$) {
247     shift;
248     return Whatpm::NanoDOM::Entity->new (shift);
249     } # create_general_entity
250    
251     ## A manakai extension.
252     sub create_notation ($$) {
253     shift;
254     return Whatpm::NanoDOM::Notation->new (shift);
255     } # create_notation
256    
257     ## A manakai extension.
258     sub create_attribute_definition ($$) {
259     shift;
260     return Whatpm::NanoDOM::AttributeDefinition->new (shift);
261     } # create_attribute_definition
262    
263 wakaba 1.22 sub create_processing_instruction ($$$) {
264     return Whatpm::NanoDOM::ProcessingInstruction->new (@_);
265     } # creat_processing_instruction
266    
267 wakaba 1.3 sub implementation ($) {
268     return 'Whatpm::NanoDOM::DOMImplementation';
269     } # implementation
270    
271 wakaba 1.4 sub document_element ($) {
272     my $self = shift;
273     for (@{$self->child_nodes}) {
274     if ($_->node_type == 1) {
275     return $_;
276     }
277     }
278     return undef;
279     } # document_element
280    
281 wakaba 1.21 sub dom_config ($) {
282     return {};
283     } # dom_config
284    
285 wakaba 1.12 sub adopt_node ($$) {
286 wakaba 1.11 my @node = ($_[1]);
287     while (@node) {
288     my $node = shift @node;
289     $node->{owner_document} = $_[0];
290     Scalar::Util::weaken ($node->{owner_document});
291     push @node, @{$node->child_nodes};
292     push @node, @{$node->attributes or []} if $node->can ('attributes');
293     }
294     return $_[1];
295     } # adopt_node
296    
297 wakaba 1.12 sub manakai_is_html ($;$) {
298     if (@_ > 1) {
299     if ($_[1]) {
300     $_[0]->{manakai_is_html} = 1;
301     } else {
302 wakaba 1.13 delete $_[0]->{manakai_is_html};
303 wakaba 1.12 delete $_[0]->{manakai_compat_mode};
304     }
305     }
306     return $_[0]->{manakai_is_html};
307     } # manakai_is_html
308    
309     sub compat_mode ($) {
310     if ($_[0]->{manakai_is_html}) {
311     if ($_[0]->{manakai_compat_mode} eq 'quirks') {
312     return 'BackCompat';
313     }
314     }
315     return 'CSS1Compat';
316     } # compat_mode
317    
318     sub manakai_compat_mode ($;$) {
319     if ($_[0]->{manakai_is_html}) {
320     if (@_ > 1 and defined $_[1] and
321     {'no quirks' => 1, 'limited quirks' => 1, 'quirks' => 1}->{$_[1]}) {
322     $_[0]->{manakai_compat_mode} = $_[1];
323     }
324     return $_[0]->{manakai_compat_mode} || 'no quirks';
325     } else {
326     return 'no quirks';
327     }
328     } # manakai_compat_mode
329    
330 wakaba 1.19 sub manakai_head ($) {
331     my $html = $_[0]->manakai_html;
332     return undef unless defined $html;
333     for my $el (@{$html->child_nodes}) {
334     next unless $el->node_type == 1; # ELEMENT_NODE
335     my $nsuri = $el->namespace_uri;
336     next unless defined $nsuri;
337     next unless $nsuri eq q<http://www.w3.org/1999/xhtml>;
338     next unless $el->manakai_local_name eq 'head';
339     return $el;
340     }
341     return undef;
342     } # manakai_head
343    
344     sub manakai_html ($) {
345     my $de = $_[0]->document_element;
346     my $nsuri = $de->namespace_uri;
347     if (defined $nsuri and $nsuri eq q<http://www.w3.org/1999/xhtml> and
348     $de->manakai_local_name eq 'html') {
349     return $de;
350     } else {
351     return undef;
352     }
353     } # manakai_html
354    
355 wakaba 1.17 sub input_encoding ($;$) {
356     $_[0]->{input_encoding} = $_[1] if @_ > 1;
357     return $_[0]->{input_encoding};
358     }
359    
360     sub manakai_charset ($;$) {
361     $_[0]->{manakai_charset} = $_[1] if @_ > 1;
362     return $_[0]->{manakai_charset};
363     }
364    
365     sub manakai_has_bom ($;$) {
366     $_[0]->{manakai_has_bom} = $_[1] if @_ > 1;
367     return $_[0]->{manakai_has_bom};
368     }
369    
370 wakaba 1.22 sub xml_version ($;$) {
371     $_[0]->{xml_version} = $_[1] if @_ > 1;
372     return $_[0]->{xml_version};
373     }
374    
375     sub xml_encoding ($;$) {
376     $_[0]->{xml_encoding} = $_[1] if @_ > 1;
377     return $_[0]->{xml_encoding};
378     }
379    
380     sub xml_standalone ($;$) {
381     $_[0]->{xml_standalone} = $_[1] if @_ > 1;
382     return $_[0]->{xml_standalone};
383     }
384    
385 wakaba 1.2 package Whatpm::NanoDOM::Element;
386     push our @ISA, 'Whatpm::NanoDOM::Node';
387 wakaba 1.1
388 wakaba 1.3 sub new ($$$$$) {
389 wakaba 1.1 my $self = shift->SUPER::new;
390 wakaba 1.3 $self->{owner_document} = shift;
391     Scalar::Util::weaken ($self->{owner_document});
392 wakaba 1.1 $self->{namespace_uri} = shift;
393     $self->{prefix} = shift;
394     $self->{local_name} = shift;
395     $self->{attributes} = {};
396     $self->{child_nodes} = [];
397     return $self;
398     } # new
399    
400 wakaba 1.3 sub owner_document ($) {
401     return shift->{owner_document};
402     } # owner_document
403    
404 wakaba 1.1 sub clone_node ($$) {
405     my ($self, $deep) = @_; ## NOTE: Deep cloning is not supported
406     my $clone = bless {
407     namespace_uri => $self->{namespace_uri},
408     prefix => $self->{prefix},
409     local_name => $self->{local_name},
410     child_nodes => [],
411     }, ref $self;
412     for my $ns (keys %{$self->{attributes}}) {
413     for my $ln (keys %{$self->{attributes}->{$ns}}) {
414     my $attr = $self->{attributes}->{$ns}->{$ln};
415     $clone->{attributes}->{$ns}->{$ln} = bless {
416     namespace_uri => $attr->{namespace_uri},
417     prefix => $attr->{prefix},
418     local_name => $attr->{local_name},
419     value => $attr->{value},
420     }, ref $self->{attributes}->{$ns}->{$ln};
421     }
422     }
423     return $clone;
424     } # clone
425    
426     ## A manakai extension
427     sub manakai_append_text ($$) {
428     my $self = shift;
429     if (@{$self->{child_nodes}} and
430     $self->{child_nodes}->[-1]->node_type == 3) {
431     $self->{child_nodes}->[-1]->manakai_append_text (shift);
432     } else {
433 wakaba 1.2 my $text = Whatpm::NanoDOM::Text->new (shift);
434 wakaba 1.1 $self->append_child ($text);
435     }
436     } # manakai_append_text
437    
438 wakaba 1.7 sub text_content ($) {
439     my $self = shift;
440     my $r = '';
441     for my $child (@{$self->child_nodes}) {
442     if ($child->can ('data')) {
443     $r .= $child->data;
444     } else {
445     $r .= $child->text_content;
446     }
447     }
448     return $r;
449     } # text_content
450    
451 wakaba 1.1 sub attributes ($) {
452     my $self = shift;
453     my $r = [];
454     ## Order MUST be stable
455     for my $ns (sort {$a cmp $b} keys %{$self->{attributes}}) {
456     for my $ln (sort {$a cmp $b} keys %{$self->{attributes}->{$ns}}) {
457     push @$r, $self->{attributes}->{$ns}->{$ln}
458     if defined $self->{attributes}->{$ns}->{$ln};
459     }
460     }
461     return $r;
462     } # attributes
463    
464 wakaba 1.3 sub local_name ($) { # TODO: HTML5 case
465     return shift->{local_name};
466     } # local_name
467    
468 wakaba 1.4 sub manakai_local_name ($) {
469     return shift->{local_name}; # no case fixing for HTML5
470     } # manakai_local_name
471    
472 wakaba 1.3 sub namespace_uri ($) {
473     return shift->{namespace_uri};
474     } # namespace_uri
475    
476 wakaba 1.4 sub manakai_element_type_match ($$$) {
477     my ($self, $nsuri, $ln) = @_;
478     if (defined $nsuri) {
479     if (defined $self->{namespace_uri} and $nsuri eq $self->{namespace_uri}) {
480     return ($ln eq $self->{local_name});
481     } else {
482     return 0;
483     }
484     } else {
485     if (not defined $self->{namespace_uri}) {
486     return ($ln eq $self->{local_name});
487     } else {
488     return 0;
489     }
490     }
491     } # manakai_element_type_match
492    
493 wakaba 1.1 sub node_type { 1 }
494    
495     ## TODO: HTML5 capitalization
496     sub tag_name ($) {
497     my $self = shift;
498     if (defined $self->{prefix}) {
499     return $self->{prefix} . ':' . $self->{local_name};
500     } else {
501     return $self->{local_name};
502     }
503     } # tag_name
504    
505 wakaba 1.8 sub get_attribute_ns ($$$) {
506     my ($self, $nsuri, $ln) = @_;
507     $nsuri = '' unless defined $nsuri;
508     return defined $self->{attributes}->{$nsuri}->{$ln}
509     ? $self->{attributes}->{$nsuri}->{$ln}->value : undef;
510     } # get_attribute_ns
511    
512 wakaba 1.9 sub get_attribute_node_ns ($$$) {
513     my ($self, $nsuri, $ln) = @_;
514     $nsuri = '' unless defined $nsuri;
515     return $self->{attributes}->{$nsuri}->{$ln};
516     } # get_attribute_node_ns
517    
518 wakaba 1.1 sub has_attribute_ns ($$$) {
519     my ($self, $nsuri, $ln) = @_;
520 wakaba 1.8 $nsuri = '' unless defined $nsuri;
521 wakaba 1.1 return defined $self->{attributes}->{$nsuri}->{$ln};
522     } # has_attribute_ns
523    
524     ## The second parameter only supports manakai extended way
525     ## to specify qualified name - "[$prefix, $local_name]"
526     sub set_attribute_ns ($$$$) {
527     my ($self, $nsuri, $qn, $value) = @_;
528     $self->{attributes}->{$nsuri}->{$qn->[1]}
529 wakaba 1.5 = Whatpm::NanoDOM::Attr->new ($self, $nsuri, $qn->[0], $qn->[1], $value);
530 wakaba 1.1 } # set_attribute_ns
531    
532 wakaba 1.20 sub set_attribute_node_ns ($$) {
533     my $self = shift;
534     my $attr = shift;
535     $self->{attributes}->{$attr->namespace_uri}->{$attr->manakai_local_name}
536     = $attr;
537     $attr->{owner_element} = $self;
538     Scalar::Util::weaken ($attr->{owner_element});
539     } # set_attribute_node_ns
540    
541 wakaba 1.2 package Whatpm::NanoDOM::Attr;
542     push our @ISA, 'Whatpm::NanoDOM::Node';
543 wakaba 1.1
544 wakaba 1.5 sub new ($$$$$$) {
545 wakaba 1.1 my $self = shift->SUPER::new;
546 wakaba 1.5 $self->{owner_element} = shift;
547     Scalar::Util::weaken ($self->{owner_element});
548 wakaba 1.1 $self->{namespace_uri} = shift;
549     $self->{prefix} = shift;
550     $self->{local_name} = shift;
551     $self->{value} = shift;
552     return $self;
553     } # new
554    
555 wakaba 1.5 sub namespace_uri ($) {
556     return shift->{namespace_uri};
557     } # namespace_uri
558    
559     sub manakai_local_name ($) {
560     return shift->{local_name};
561     } # manakai_local_name
562    
563 wakaba 1.1 sub node_type { 2 }
564    
565 wakaba 1.14 sub owner_document ($) {
566     return shift->owner_element->owner_document;
567     } # owner_document
568    
569 wakaba 1.1 ## TODO: HTML5 case stuff?
570     sub name ($) {
571     my $self = shift;
572     if (defined $self->{prefix}) {
573     return $self->{prefix} . ':' . $self->{local_name};
574     } else {
575     return $self->{local_name};
576     }
577     } # name
578    
579 wakaba 1.20 sub value ($;$) {
580     if (@_ > 1) {
581     $_[0]->{value} = $_[1];
582     }
583 wakaba 1.1 return shift->{value};
584     } # value
585    
586 wakaba 1.5 sub owner_element ($) {
587     return shift->{owner_element};
588     } # owner_element
589    
590 wakaba 1.2 package Whatpm::NanoDOM::CharacterData;
591     push our @ISA, 'Whatpm::NanoDOM::Node';
592 wakaba 1.1
593     sub new ($$) {
594     my $self = shift->SUPER::new;
595     $self->{data} = shift;
596     return $self;
597     } # new
598    
599     ## A manakai extension
600     sub manakai_append_text ($$) {
601     my ($self, $s) = @_;
602     $self->{data} .= $s;
603     } # manakai_append_text
604    
605     sub data ($) {
606     return shift->{data};
607     } # data
608    
609 wakaba 1.2 package Whatpm::NanoDOM::Text;
610     push our @ISA, 'Whatpm::NanoDOM::CharacterData';
611 wakaba 1.1
612     sub node_type () { 3 }
613    
614 wakaba 1.2 package Whatpm::NanoDOM::Comment;
615     push our @ISA, 'Whatpm::NanoDOM::CharacterData';
616 wakaba 1.1
617     sub node_type () { 8 }
618    
619 wakaba 1.2 package Whatpm::NanoDOM::DocumentType;
620     push our @ISA, 'Whatpm::NanoDOM::Node';
621 wakaba 1.1
622     sub new ($$) {
623     my $self = shift->SUPER::new;
624     $self->{name} = shift;
625 wakaba 1.23 $self->{element_types} = {};
626     $self->{entities} = {};
627     $self->{notations} = {};
628     $self->{child_nodes} = [];
629 wakaba 1.1 return $self;
630     } # new
631    
632     sub node_type () { 10 }
633    
634     sub name ($) {
635     return shift->{name};
636     } # name
637    
638 wakaba 1.16 sub public_id ($;$) {
639     $_[0]->{public_id} = $_[1] if @_ > 1;
640     return $_[0]->{public_id};
641     } # public_id
642    
643     sub system_id ($;$) {
644     $_[0]->{system_id} = $_[1] if @_ > 1;
645     return $_[0]->{system_id};
646     } # system_id
647    
648 wakaba 1.23 sub element_types ($) {
649     return $_[0]->{element_types};
650     } # element_types
651    
652     sub entities ($) {
653     return $_[0]->{entities};
654     } # entities
655    
656     sub notations ($) {
657     return $_[0]->{notations};
658     } # notations
659    
660     sub get_element_type_definition_node ($$) {
661     return $_[0]->{element_types}->{$_[1]};
662     } # get_element_type_definition_node
663    
664     sub set_element_type_definition_node ($$) {
665     $_[0]->{element_types}->{$_[1]->node_name} = $_[1];
666     } # set_element_type_definition_node
667    
668     sub get_general_entity_node ($$) {
669     return $_[0]->{entities}->{$_[1]};
670     } # get_general_entity_node
671    
672     sub set_general_entity_node ($$) {
673     $_[0]->{entities}->{$_[1]->node_name} = $_[1];
674     } # set_general_entity_node
675    
676     sub get_notation_node ($$) {
677     return $_[0]->{notations}->{$_[1]};
678     } # get_notation_node
679    
680     sub set_notation_node ($$) {
681     $_[0]->{notations}->{$_[1]->node_name} = $_[1];
682     } # set_notation_node
683    
684 wakaba 1.22 package Whatpm::NanoDOM::ProcessingInstruction;
685     push our @ISA, 'Whatpm::NanoDOM::Node';
686    
687     sub new ($$$$) {
688     my $self = shift->SUPER::new;
689     shift;
690     # $self->{owner_document} = shift;
691     # Scalar::Util::weaken ($self->{owner_document});
692     $self->{target} = shift;
693     $self->{data} = shift;
694     return $self;
695     } # new
696    
697     sub node_type () { 7 }
698    
699     sub target ($) {
700     return $_[0]->{target};
701     } # target
702    
703     sub data ($;$) {
704     $_[0]->{data} = $_[1] if @_ > 1;
705     return $_[0]->{data};
706     } # data
707    
708 wakaba 1.23 package Whatpm::NanoDOM::Entity;
709     push our @ISA, 'Whatpm::NanoDOM::Node';
710    
711     sub new ($$) {
712     my $self = shift->SUPER::new;
713     $self->{node_name} = shift;
714     return $self;
715     } # new
716    
717     sub node_type () { 6 }
718    
719     package Whatpm::NanoDOM::Notation;
720     push our @ISA, 'Whatpm::NanoDOM::Node';
721    
722     sub new ($$) {
723     my $self = shift->SUPER::new;
724     $self->{node_name} = shift;
725     return $self;
726     } # new
727    
728     sub node_type () { 12 }
729    
730     package Whatpm::NanoDOM::ElementTypeDefinition;
731     push our @ISA, 'Whatpm::NanoDOM::Node';
732    
733     sub new ($$) {
734     my $self = shift->SUPER::new;
735     $self->{node_name} = shift;
736     $self->{content_model} = '';
737     $self->{attribute_definitions} = {};
738     return $self;
739     } # new
740    
741     sub node_type () { 81001 }
742    
743     sub content_model_text ($;$) {
744     $_[0]->{content_model} = $_[1] if @_ > 1;
745     return $_[0]->{content_model};
746     } # content_model_text
747    
748     sub attribute_definitions ($) { return $_[0]->{attribute_definitions} }
749    
750     sub get_attribute_definition_node ($$) {
751     return $_[0]->{attribute_definitions}->{$_[1]};
752     } # get_attribute_definition_node
753    
754     sub set_attribute_definition_node ($$) {
755     $_[0]->{attribute_definitions}->{$_[1]->node_name} = $_[1];
756     } # set_attribute_definition_node
757    
758     package Whatpm::NanoDOM::AttributeDefinition;
759     push our @ISA, 'Whatpm::NanoDOM::Node';
760    
761     sub new ($$) {
762     my $self = shift->SUPER::new;
763     $self->{node_name} = shift;
764     return $self;
765     } # new
766    
767     sub node_type () { 81002 }
768    
769 wakaba 1.1 =head1 SEE ALSO
770    
771 wakaba 1.22 L<Whatpm::HTML|Whatpm::HTML>
772    
773     L<Whatpm::XML::Parser|Whatpm::XML::Parser>
774    
775     L<Whatpm::ContentChecker|Whatpm::ContentChecker>
776 wakaba 1.1
777     =head1 AUTHOR
778    
779     Wakaba <w@suika.fam.cx>.
780    
781     =head1 LICENSE
782    
783 wakaba 1.22 Copyright 2007-2008 Wakaba <w@suika.fam.cx>
784 wakaba 1.1
785     This library is free software; you can redistribute it
786     and/or modify it under the same terms as Perl itself.
787    
788     =cut
789    
790     1;
791 wakaba 1.23 # $Date: 2008/10/15 04:38:22 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24