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

Diff of /messaging/manakai/lib/Message/DOM/Node.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.6 by wakaba, Sat Jun 16 15:27:45 2007 UTC revision 1.7 by wakaba, Sun Jun 17 13:37:40 2007 UTC
# Line 120  sub AUTOLOAD { Line 120  sub AUTOLOAD {
120  ## NOTE: Overridden by |Element|.  ## NOTE: Overridden by |Element|.
121  sub attributes () { undef }  sub attributes () { undef }
122    
123  ## TODO: baseURI  sub base_uri ($) {
124      ## NOTE: Overridden by |Attr|, |CharacterData|, |Document|, |DocumentType|,
125      ## |Element|, |EntityReference|, and |ProcessingInstruction|.
126    
127      local $Error::Depth = $Error::Depth + 1;
128      return $_[0]->owner_document->base_uri;
129    } # base_uri
130    
131  sub child_nodes ($) {  sub child_nodes ($) {
132    ## NOTE: Overridden by |CharacterData|, |ElementTypeDefinition|,    ## NOTE: Overridden by |CharacterData|, |ElementTypeDefinition|,
# Line 206  sub text_content ($;$) { Line 212  sub text_content ($;$) {
212    my $self = $_[0];    my $self = $_[0];
213    
214    if (@_ > 1) {    if (@_ > 1) {
215      if ($$self->{manakai_read_only}) {      if (${$$self->{owner_document} or $self}->{strict_error_checking} and
216            $$self->{manakai_read_only}) {
217        report Message::DOM::DOMException        report Message::DOM::DOMException
218            -object => $self,            -object => $self,
219            -type => 'NO_MODIFICATION_ALLOWED_ERR',            -type => 'NO_MODIFICATION_ALLOWED_ERR',
# Line 243  sub text_content ($;$) { Line 250  sub text_content ($;$) {
250    }    }
251  } # text_content  } # text_content
252    
253    ## |Node| methods
254    
255  ## TODO:  ## TODO:
256  sub is_same_node ($$) {  sub is_same_node ($$) {
257    return $_[0] eq $_[1];    return $_[0] eq $_[1];
# Line 275  sub append_child ($$) { Line 284  sub append_child ($$) {
284      for (0..$#$parent_list) {      for (0..$#$parent_list) {
285        if ($parent_list->[$_] eq $new_child) {        if ($parent_list->[$_] eq $new_child) {
286          splice @$parent_list, $_, 1;          splice @$parent_list, $_, 1;
287            last;
288        }        }
289      }      }
290    }    }
291    push @{$$self->{child_nodes}}, $new_child;    push @{$$self->{child_nodes}}, $new_child;
292    $$new_child->{parent_node} = $self;    $$new_child->{parent_node} = $self;
293    Scalar::Util::weaken ($$new_child->{parent_node});    Scalar::Util::weaken ($$new_child->{parent_node});
294      ## TODO:
295      $$new_child->{owner_document} = $self if $self->node_type == DOCUMENT_NODE;
296    return $new_child;    return $new_child;
297  } # append_child  } # append_child
298    
299    sub manakai_append_text ($$) {
300      ## NOTE: For |Element|, |Attr|, |Entity|, |EntityReference|,
301      ## |DocumentFragment|, and |AttributeDefinition|.  In addition,
302      ## |Document|'s |text_content| might call this attribute.
303      
304      ## NOTE: Overridden by |Document|, |DocumentType|, |CharacterData|,
305      ## |ElementTypeDefinition|, |Notation|, and |ProcessingInstruction|.
306    
307      my $self = $_[0];
308      local $Error::Depth = $Error::Depth + 1;
309      if (@{$$self->{child_nodes}} and
310          $$self->{child_nodes}->[-1]->node_type == TEXT_NODE) {
311        $$self->{child_nodes}->[-1]->manakai_append_text ($_[1]);
312      } else {
313        my $text = ($$self->{owner_document} or $self)->create_text_node ($_[1]);
314        $self->append_child ($text);
315      }
316    } # manakai_append_text
317    
318    sub get_feature {
319      ## TODO:
320      return $_[0];
321    }
322    
323  ## NOTE: Only applied to Elements and Documents  ## NOTE: Only applied to Elements and Documents
324  sub insert_before ($$;$) {  sub insert_before ($$;$) {
325    my ($self, $new_child, $ref_child) = @_;    my ($self, $new_child, $ref_child) = @_;
# Line 292  sub insert_before ($$;$) { Line 328  sub insert_before ($$;$) {
328      for (0..$#$parent_list) {      for (0..$#$parent_list) {
329        if ($parent_list->[$_] eq $new_child) {        if ($parent_list->[$_] eq $new_child) {
330          splice @$parent_list, $_, 1;          splice @$parent_list, $_, 1;
331            last;
332        }        }
333      }      }
334    }    }
# Line 310  sub insert_before ($$;$) { Line 347  sub insert_before ($$;$) {
347    return $new_child;    return $new_child;
348  } # insert_before  } # insert_before
349    
 ## NOTE: For nodeTypes with childNodes  
 sub manakai_append_text ($$) {  
   my $self = shift;  
   local $Error::Depth = $Error::Depth + 1;  
   if (@{$$self->{child_nodes}} and  
       $$self->{child_nodes}->[-1]->node_type == 3) {  
     $$self->{child_nodes}->[-1]->manakai_append_text (shift);  
   } else {  
     my $text = $$self->{owner_document}->create_text_node ($_[0]);  
     $self->append_child ($text);  
   }  
 } # manakai_append_text  
   
350  ## NOTE: Only applied to Elements and Documents  ## NOTE: Only applied to Elements and Documents
351  sub remove_child ($$) {  sub remove_child ($$) {
352    my ($self, $old_child) = @_;    my ($self, $old_child) = @_;
# Line 330  sub remove_child ($$) { Line 354  sub remove_child ($$) {
354    for (0..$#$parent_list) {    for (0..$#$parent_list) {
355      if ($parent_list->[$_] eq $old_child) {      if ($parent_list->[$_] eq $old_child) {
356        splice @$parent_list, $_, 1;        splice @$parent_list, $_, 1;
357          last;
358      }      }
359    }    }
360    delete $$old_child->{parent_node};    delete $$old_child->{parent_node};
# Line 342  sub has_child_nodes ($) { Line 367  sub has_child_nodes ($) {
367  } # has_child_nodes  } # has_child_nodes
368    
369  sub manakai_set_read_only ($;$$) {  sub manakai_set_read_only ($;$$) {
370    my ($self, $value, $deep) = @_;    my $value = 1 if $_[1];
371    ## TODO: deep    if ($_[2]) {
372    $$self->{manakai_read_only} = $value;      my @target = ($_[0]);
373        while (@target) {
374          my $target = shift @target;
375          if ($value) {
376            $$target->{manakai_read_only} = 1;
377          } else {
378            delete $$target->{manakai_read_only};
379          }
380          push @target, @{$target->child_nodes};
381          
382          my $nt = $target->node_type;
383          if ($nt == ELEMENT_NODE) {
384            push @target, @{$target->attributes};
385          } elsif ($nt == ELEMENT_TYPE_DEFINITION_NODE) {
386            push @target, @{$target->attribute_definitions};
387          } elsif ($nt == DOCUMENT_TYPE_NODE) {
388            push @target, @{$target->element_types};
389            push @target, @{$target->general_entities};
390            push @target, @{$target->notations};
391          }
392        }
393      } else { # not deep
394        if ($value) {
395          ${$_[0]}->{manakai_read_only} = 1;
396        } else {
397          delete ${$_[0]}->{manakai_read_only};
398        }
399      }
400  } # manakai_set_read_only  } # manakai_set_read_only
401    
402  package Message::IF::Node;  package Message::IF::Node;

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.7

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24