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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.12 - (hide annotations) (download)
Sun Jul 29 08:31:14 2007 UTC (17 years, 4 months ago) by wakaba
Branch: MAIN
CVS Tags: manakai-release-0-4-0, HEAD
Changes since 1.11: +3 -3 lines
++ manakai/lib/Message/DOM/ChangeLog	29 Jul 2007 08:26:38 -0000
	* XDoctype.dis, XDoctype.pm: Removed.

	* CharacterData.pm: Renamed from DOMCharacterData.pm.

	* Document.pm: Renaemd from DOMDocument.pm.

	* Element.pm: Renamed from DOMElement.pm

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

1 wakaba 1.1 package Message::DOM::Text;
2     use strict;
3 wakaba 1.12 our $VERSION=do{my @r=(q$Revision: 1.11 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
4 wakaba 1.1 push our @ISA, 'Message::DOM::CharacterData', 'Message::IF::Text';
5 wakaba 1.12 require Message::DOM::CharacterData;
6 wakaba 1.1
7 wakaba 1.3 ## |Node| attributes
8 wakaba 1.1
9 wakaba 1.3 sub node_name () { '#text' }
10 wakaba 1.2
11 wakaba 1.7 sub node_type () { 3 } # TEXT_NODE
12 wakaba 1.2
13 wakaba 1.5 ## |Text| attributes
14    
15 wakaba 1.3 sub is_element_content_whitespace ($;$) {
16 wakaba 1.5 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 wakaba 1.3 } # is_element_content_whitespace
33 wakaba 1.1
34 wakaba 1.5 sub whole_text ($) {
35     local $Error::Depth = $Error::Depth + 1;
36     my $doc = $_[0]->owner_document;
37     my $tw1 = $doc->create_tree_walker
38     ($doc, 0xFFFFFFFF, sub { # SHOW_ALL ENTITY_REFERENCE_NODE
39 wakaba 1.10 ($_[0]->node_type == 5) ? 3 : 1; # FILTER_SKIP FILTER_ACCEPT
40 wakaba 1.5 }, 1);
41     $tw1->current_node ($_[0]);
42    
43     my $tw2 = $tw1->clone;
44     my $r = $_[0]->node_value;
45    
46     S: while (defined (my $node = $tw1->previous_sibling)) {
47     my $nt = $node->node_type;
48     if ($nt == 3 or $nt == 4) { # TEXT_NODE CDATA_SECTION_NODE
49     $r = $node->node_value . $r;
50     } else {
51     last S;
52     }
53     } # S
54    
55     S: while (defined (my $node = $tw2->next_sibling)) {
56     my $nt = $node->node_type;
57     if ($nt == 3 or $nt == 4) { # TEXT_NODE CDATA_SECTION_NODE
58     $r .= $node->node_value;
59     } else {
60     last S;
61     }
62     } # S
63    
64     return $r;
65    
66     ## TODO: Skipping |DocumentType| is manakai-extension. Document it!
67     } # whole_text
68    
69     ## |Text| methods
70    
71 wakaba 1.8 ## TODO: replace_whole_text
72    
73 wakaba 1.5 sub split_text ($;$) {
74     my $parent = $_[0]->parent_node;
75     if (${${$_[0]}->{owner_document}}->{strict_error_checking}) {
76     if (${$_[0]}->{manakai_read_only}) {
77     report Message::DOM::DOMException
78     -object => $_[0],
79     -type => 'NO_MODIFICATION_ALLOWED_ERR',
80     -subtype => 'READ_ONLY_NODE_ERR';
81     }
82    
83     if (defined $parent and $$parent->{manakai_read_only}) {
84     report Message::DOM::DOMException
85     -object => $_[0],
86     -type => 'NO_MODIFICATION_ALLOWED_ERR',
87     -subtype => 'READ_ONLY_NODE_ERR';
88     }
89     }
90    
91     require Message::DOM::StringExtended;
92     local $Error::Depth = $Error::Depth + 1;
93     my $offset32 = Message::DOM::StringExtended::find_offset32
94     (${$_[0]}->{data}, $_[1]);
95     my $data2 = substr ${$_[0]}->{data}, $offset32;
96    
97     my $r = $_[0]->node_type == 3 # TEXT_NODE
98     ? ${$_[0]}->{owner_document}->create_text_node ($data2)
99     : ${$_[0]}->{owner_document}->create_cdata_section ($data2);
100     $r->is_element_content_whitespace ($_[0]->is_element_content_whitespace);
101     substr (${$_[0]}->{data}, $offset32) = '';
102    
103     if (defined $parent) {
104     $parent->insert_before ($r, $_[0]->next_sibling);
105     }
106    
107     return $r;
108     } # split_text
109    
110 wakaba 1.9 package Message::DOM::Text::CDATASection;
111     push our @ISA, 'Message::DOM::Text', 'Message::IF::CDATASection';
112    
113     ## |Node| attributes
114    
115     sub node_name () { '#cdata-section' }
116    
117     sub node_type () { 4 } # CDATA_SECTION_NODE
118    
119     ## |Text| attribute
120    
121     sub is_element_content_whitespace () { 0 }
122    
123 wakaba 1.1 package Message::IF::Text;
124 wakaba 1.9 package Message::IF::CDATASection;
125 wakaba 1.1
126     package Message::DOM::Document;
127    
128 wakaba 1.9 sub create_cdata_section ($$) {
129     return Message::DOM::Text::CDATASection->____new (@_[0, 1]);
130     } # create_cdata_section
131    
132 wakaba 1.1 sub create_text_node ($$) {
133     return Message::DOM::Text->____new ($_[0], $_[1]);
134     } # create_text_node
135    
136 wakaba 1.5 =head1 LICENSE
137    
138     Copyright 2007 Wakaba <w@suika.fam.cx>
139    
140     This program is free software; you can redistribute it and/or
141     modify it under the same terms as Perl itself.
142    
143     =cut
144    
145 wakaba 1.1 1;
146 wakaba 1.12 ## $Date: 2007/07/29 08:04:42 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24