48 |
|
|
49 |
sub node_type { 3 } # TEXT_NODE |
sub node_type { 3 } # TEXT_NODE |
50 |
|
|
51 |
|
## |Text| attributes |
52 |
|
|
53 |
sub is_element_content_whitespace ($;$) { |
sub is_element_content_whitespace ($;$) { |
54 |
## TODO: |
if (@_ > 1) { |
55 |
## TODO: Define this attribute setter for CDATASection |
## TODO: Document how setter work |
56 |
return 0; |
if (${$_[0]}->{manakai_read_only}) { |
57 |
|
report Message::DOM::DOMException |
58 |
|
-object => $_[0], |
59 |
|
-type => 'NO_MODIFICATION_ALLOWED_ERR', |
60 |
|
-subtype => 'READ_ONLY_NODE_ERR'; |
61 |
|
} |
62 |
|
|
63 |
|
if ($_[1]) { |
64 |
|
${$_[0]}->{is_element_content_whitespace} = 1; |
65 |
|
} else { |
66 |
|
delete ${$_[0]}->{is_element_content_whitespace}; |
67 |
|
} |
68 |
|
} |
69 |
|
return ${$_[0]}->{is_element_content_whitespace}; |
70 |
} # is_element_content_whitespace |
} # is_element_content_whitespace |
71 |
|
|
72 |
|
sub whole_text ($) { |
73 |
|
require Message::DOM::Traversal; |
74 |
|
local $Error::Depth = $Error::Depth + 1; |
75 |
|
my $doc = $_[0]->owner_document; |
76 |
|
my $tw1 = $doc->create_tree_walker |
77 |
|
($doc, 0xFFFFFFFF, sub { # SHOW_ALL ENTITY_REFERENCE_NODE |
78 |
|
($_[1]->node_type == 5) ? 3 : 1; # FILTER_SKIP FILTER_ACCEPT |
79 |
|
}, 1); |
80 |
|
$tw1->current_node ($_[0]); |
81 |
|
|
82 |
|
my $tw2 = $tw1->clone; |
83 |
|
my $r = $_[0]->node_value; |
84 |
|
|
85 |
|
S: while (defined (my $node = $tw1->previous_sibling)) { |
86 |
|
my $nt = $node->node_type; |
87 |
|
if ($nt == 3 or $nt == 4) { # TEXT_NODE CDATA_SECTION_NODE |
88 |
|
$r = $node->node_value . $r; |
89 |
|
} else { |
90 |
|
last S; |
91 |
|
} |
92 |
|
} # S |
93 |
|
|
94 |
|
S: while (defined (my $node = $tw2->next_sibling)) { |
95 |
|
my $nt = $node->node_type; |
96 |
|
if ($nt == 3 or $nt == 4) { # TEXT_NODE CDATA_SECTION_NODE |
97 |
|
$r .= $node->node_value; |
98 |
|
} else { |
99 |
|
last S; |
100 |
|
} |
101 |
|
} # S |
102 |
|
|
103 |
|
return $r; |
104 |
|
|
105 |
|
## TODO: Skipping |DocumentType| is manakai-extension. Document it! |
106 |
|
} # whole_text |
107 |
|
|
108 |
|
## |Text| methods |
109 |
|
|
110 |
|
sub split_text ($;$) { |
111 |
|
my $parent = $_[0]->parent_node; |
112 |
|
if (${${$_[0]}->{owner_document}}->{strict_error_checking}) { |
113 |
|
if (${$_[0]}->{manakai_read_only}) { |
114 |
|
report Message::DOM::DOMException |
115 |
|
-object => $_[0], |
116 |
|
-type => 'NO_MODIFICATION_ALLOWED_ERR', |
117 |
|
-subtype => 'READ_ONLY_NODE_ERR'; |
118 |
|
} |
119 |
|
|
120 |
|
if (defined $parent and $$parent->{manakai_read_only}) { |
121 |
|
report Message::DOM::DOMException |
122 |
|
-object => $_[0], |
123 |
|
-type => 'NO_MODIFICATION_ALLOWED_ERR', |
124 |
|
-subtype => 'READ_ONLY_NODE_ERR'; |
125 |
|
} |
126 |
|
} |
127 |
|
|
128 |
|
require Message::DOM::StringExtended; |
129 |
|
local $Error::Depth = $Error::Depth + 1; |
130 |
|
my $offset32 = Message::DOM::StringExtended::find_offset32 |
131 |
|
(${$_[0]}->{data}, $_[1]); |
132 |
|
my $data2 = substr ${$_[0]}->{data}, $offset32; |
133 |
|
|
134 |
|
my $r = $_[0]->node_type == 3 # TEXT_NODE |
135 |
|
? ${$_[0]}->{owner_document}->create_text_node ($data2) |
136 |
|
: ${$_[0]}->{owner_document}->create_cdata_section ($data2); |
137 |
|
$r->is_element_content_whitespace ($_[0]->is_element_content_whitespace); |
138 |
|
substr (${$_[0]}->{data}, $offset32) = ''; |
139 |
|
|
140 |
|
if (defined $parent) { |
141 |
|
$parent->insert_before ($r, $_[0]->next_sibling); |
142 |
|
} |
143 |
|
|
144 |
|
return $r; |
145 |
|
} # split_text |
146 |
|
|
147 |
package Message::IF::Text; |
package Message::IF::Text; |
148 |
|
|
149 |
package Message::DOM::Document; |
package Message::DOM::Document; |
152 |
return Message::DOM::Text->____new ($_[0], $_[1]); |
return Message::DOM::Text->____new ($_[0], $_[1]); |
153 |
} # create_text_node |
} # create_text_node |
154 |
|
|
155 |
|
=head1 LICENSE |
156 |
|
|
157 |
|
Copyright 2007 Wakaba <w@suika.fam.cx> |
158 |
|
|
159 |
|
This program is free software; you can redistribute it and/or |
160 |
|
modify it under the same terms as Perl itself. |
161 |
|
|
162 |
|
=cut |
163 |
|
|
164 |
1; |
1; |
|
## License: <http://suika.fam.cx/~wakaba/archive/2004/8/18/license#Perl+MPL> |
|
165 |
## $Date$ |
## $Date$ |