/[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.8 - (hide annotations) (download)
Sat Jul 14 10:00:32 2007 UTC (17 years, 4 months ago) by wakaba
Branch: MAIN
Changes since 1.7: +4 -2 lines
++ manakai/lib/Message/DOM/ChangeLog	14 Jul 2007 10:00:12 -0000
	* DOMConfiguration.pm: Support for |schema-type|
	and |http://suika.fam.cx/www/2006/dom-config/xml-id|.

	* NamedNodeMap (TIEHASH): Were missing.

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

1 wakaba 1.1 package Message::DOM::Text;
2     use strict;
3 wakaba 1.8 our $VERSION=do{my @r=(q$Revision: 1.7 $=~/\d+/g);sprintf "%d."."%02d" x $#r,@r};
4 wakaba 1.1 push our @ISA, 'Message::DOM::CharacterData', 'Message::IF::Text';
5     require Message::DOM::DOMCharacterData; ## TODO: Change to new module name
6    
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     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 wakaba 1.8 ## TODO: replace_whole_text
73    
74 wakaba 1.5 sub split_text ($;$) {
75     my $parent = $_[0]->parent_node;
76     if (${${$_[0]}->{owner_document}}->{strict_error_checking}) {
77     if (${$_[0]}->{manakai_read_only}) {
78     report Message::DOM::DOMException
79     -object => $_[0],
80     -type => 'NO_MODIFICATION_ALLOWED_ERR',
81     -subtype => 'READ_ONLY_NODE_ERR';
82     }
83    
84     if (defined $parent and $$parent->{manakai_read_only}) {
85     report Message::DOM::DOMException
86     -object => $_[0],
87     -type => 'NO_MODIFICATION_ALLOWED_ERR',
88     -subtype => 'READ_ONLY_NODE_ERR';
89     }
90     }
91    
92     require Message::DOM::StringExtended;
93     local $Error::Depth = $Error::Depth + 1;
94     my $offset32 = Message::DOM::StringExtended::find_offset32
95     (${$_[0]}->{data}, $_[1]);
96     my $data2 = substr ${$_[0]}->{data}, $offset32;
97    
98     my $r = $_[0]->node_type == 3 # TEXT_NODE
99     ? ${$_[0]}->{owner_document}->create_text_node ($data2)
100     : ${$_[0]}->{owner_document}->create_cdata_section ($data2);
101     $r->is_element_content_whitespace ($_[0]->is_element_content_whitespace);
102     substr (${$_[0]}->{data}, $offset32) = '';
103    
104     if (defined $parent) {
105     $parent->insert_before ($r, $_[0]->next_sibling);
106     }
107    
108     return $r;
109     } # split_text
110    
111 wakaba 1.1 package Message::IF::Text;
112    
113     package Message::DOM::Document;
114    
115     sub create_text_node ($$) {
116     return Message::DOM::Text->____new ($_[0], $_[1]);
117     } # create_text_node
118    
119 wakaba 1.5 =head1 LICENSE
120    
121     Copyright 2007 Wakaba <w@suika.fam.cx>
122    
123     This program is free software; you can redistribute it and/or
124     modify it under the same terms as Perl itself.
125    
126     =cut
127    
128 wakaba 1.1 1;
129 wakaba 1.8 ## $Date: 2007/07/08 13:04:37 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24