/[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.7 - (hide annotations) (download)
Sun Jul 8 13:04:37 2007 UTC (17 years, 4 months ago) by wakaba
Branch: MAIN
Changes since 1.6: +3 -3 lines
++ manakai/t/ChangeLog	8 Jul 2007 13:03:58 -0000
	* DOM-Element.t: Tests for |attributes| are added.

	* DOM-Entity.t: Tests for |is_externally_declared|
	and |input_encoding| are added.

	* DOM-Node.t: Test data for |tag_name| and
	|get_feature| are added.

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

++ manakai/lib/Message/DOM/ChangeLog	8 Jul 2007 13:02:01 -0000
	* Attr.pm (value, node_value): Now it is defined
	as |text_content| itself.

	* AttributeDefinition.pm, ElementTypeDefinition.pm,
	Node.pm (AUTOLOAD): Unused block is removed.

	* CDATASection.pm, DocumentFragment.pm (AUTOLOAD): Removed.  Unused.

	* DocumentType.pm (internal_subset): Implemented.

	* Entity.pm (is_externally_declared, input_encoding,
	xml_version): Implemented.

	* ProcessingInstruction.pm (target, data): Implemented.

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

1 wakaba 1.1 package Message::DOM::Text;
2     use strict;
3 wakaba 1.7 our $VERSION=do{my @r=(q$Revision: 1.6 $=~/\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     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 wakaba 1.1 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 wakaba 1.5 =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 wakaba 1.1 1;
127 wakaba 1.7 ## $Date: 2007/07/08 11:28:45 $

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24