1 |
package Message::DOM::Text; |
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::CharacterData', 'Message::IF::Text'; |
5 |
require Message::DOM::DOMCharacterData; ## TODO: Change to new module name |
6 |
|
7 |
## |Node| attributes |
8 |
|
9 |
sub node_name () { '#text' } |
10 |
|
11 |
sub node_type () { 3 } # TEXT_NODE |
12 |
|
13 |
## |Text| attributes |
14 |
|
15 |
sub is_element_content_whitespace ($;$) { |
16 |
if (@_ > 1) { |
17 |
## TODO: Document how setter work |
18 |
if (${$_[0]}->{manakai_read_only}) { |
19 |
report Message::DOM::DOMException |
20 |
-object => $_[0], |
21 |
-type => 'NO_MODIFICATION_ALLOWED_ERR', |
22 |
-subtype => 'READ_ONLY_NODE_ERR'; |
23 |
} |
24 |
|
25 |
if ($_[1]) { |
26 |
${$_[0]}->{is_element_content_whitespace} = 1; |
27 |
} else { |
28 |
delete ${$_[0]}->{is_element_content_whitespace}; |
29 |
} |
30 |
} |
31 |
return ${$_[0]}->{is_element_content_whitespace}; |
32 |
} # is_element_content_whitespace |
33 |
|
34 |
sub whole_text ($) { |
35 |
require Message::DOM::Traversal; |
36 |
local $Error::Depth = $Error::Depth + 1; |
37 |
my $doc = $_[0]->owner_document; |
38 |
my $tw1 = $doc->create_tree_walker |
39 |
($doc, 0xFFFFFFFF, sub { # SHOW_ALL ENTITY_REFERENCE_NODE |
40 |
($_[1]->node_type == 5) ? 3 : 1; # FILTER_SKIP FILTER_ACCEPT |
41 |
}, 1); |
42 |
$tw1->current_node ($_[0]); |
43 |
|
44 |
my $tw2 = $tw1->clone; |
45 |
my $r = $_[0]->node_value; |
46 |
|
47 |
S: while (defined (my $node = $tw1->previous_sibling)) { |
48 |
my $nt = $node->node_type; |
49 |
if ($nt == 3 or $nt == 4) { # TEXT_NODE CDATA_SECTION_NODE |
50 |
$r = $node->node_value . $r; |
51 |
} else { |
52 |
last S; |
53 |
} |
54 |
} # S |
55 |
|
56 |
S: while (defined (my $node = $tw2->next_sibling)) { |
57 |
my $nt = $node->node_type; |
58 |
if ($nt == 3 or $nt == 4) { # TEXT_NODE CDATA_SECTION_NODE |
59 |
$r .= $node->node_value; |
60 |
} else { |
61 |
last S; |
62 |
} |
63 |
} # S |
64 |
|
65 |
return $r; |
66 |
|
67 |
## TODO: Skipping |DocumentType| is manakai-extension. Document it! |
68 |
} # whole_text |
69 |
|
70 |
## |Text| methods |
71 |
|
72 |
sub split_text ($;$) { |
73 |
my $parent = $_[0]->parent_node; |
74 |
if (${${$_[0]}->{owner_document}}->{strict_error_checking}) { |
75 |
if (${$_[0]}->{manakai_read_only}) { |
76 |
report Message::DOM::DOMException |
77 |
-object => $_[0], |
78 |
-type => 'NO_MODIFICATION_ALLOWED_ERR', |
79 |
-subtype => 'READ_ONLY_NODE_ERR'; |
80 |
} |
81 |
|
82 |
if (defined $parent and $$parent->{manakai_read_only}) { |
83 |
report Message::DOM::DOMException |
84 |
-object => $_[0], |
85 |
-type => 'NO_MODIFICATION_ALLOWED_ERR', |
86 |
-subtype => 'READ_ONLY_NODE_ERR'; |
87 |
} |
88 |
} |
89 |
|
90 |
require Message::DOM::StringExtended; |
91 |
local $Error::Depth = $Error::Depth + 1; |
92 |
my $offset32 = Message::DOM::StringExtended::find_offset32 |
93 |
(${$_[0]}->{data}, $_[1]); |
94 |
my $data2 = substr ${$_[0]}->{data}, $offset32; |
95 |
|
96 |
my $r = $_[0]->node_type == 3 # TEXT_NODE |
97 |
? ${$_[0]}->{owner_document}->create_text_node ($data2) |
98 |
: ${$_[0]}->{owner_document}->create_cdata_section ($data2); |
99 |
$r->is_element_content_whitespace ($_[0]->is_element_content_whitespace); |
100 |
substr (${$_[0]}->{data}, $offset32) = ''; |
101 |
|
102 |
if (defined $parent) { |
103 |
$parent->insert_before ($r, $_[0]->next_sibling); |
104 |
} |
105 |
|
106 |
return $r; |
107 |
} # split_text |
108 |
|
109 |
package Message::IF::Text; |
110 |
|
111 |
package Message::DOM::Document; |
112 |
|
113 |
sub create_text_node ($$) { |
114 |
return Message::DOM::Text->____new ($_[0], $_[1]); |
115 |
} # create_text_node |
116 |
|
117 |
=head1 LICENSE |
118 |
|
119 |
Copyright 2007 Wakaba <w@suika.fam.cx> |
120 |
|
121 |
This program is free software; you can redistribute it and/or |
122 |
modify it under the same terms as Perl itself. |
123 |
|
124 |
=cut |
125 |
|
126 |
1; |
127 |
## $Date: 2007/07/08 11:28:45 $ |