Update of /cvsroot/net-script/netscript2/src/perl/XML/DOM2 In directory usw-pr-cvs1:/tmp/cvs-serv22682 Modified Files: Attr.pm CDATASection.pm Comment.pm Element.pm NamedNodeMap.pm Node.pm NodeList.pm ProcessingInstruction.pm Text.pm Log Message: * several fixes Index: Attr.pm =================================================================== RCS file: /cvsroot/net-script/netscript2/src/perl/XML/DOM2/Attr.pm,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Attr.pm 2001/12/03 21:16:58 1.1 --- Attr.pm 2002/01/01 17:52:59 1.2 *************** *** 50,54 **** sub name { my ($this) = @_; ! $this -> { m_name }; } --- 50,54 ---- sub name { my ($this) = @_; ! $this -> nodeName(); } *************** *** 81,84 **** --- 81,92 ---- my %params = %{$paramRef}; my $value = $params{"value"}; + + # escape the value + $value =~ s/&/&/g; + $value =~ s/([^a-zA-Z0-9_ .:\/()?=!-\\\[\]])/('&#'.ord($1).';')/eg; + $value =~ s/</</g; + $value =~ s/>/>/g; + $value =~ s/"/"/g; + # clear list of children $this -> childNodes() -> removeAll(); *************** *** 120,123 **** --- 128,161 ---- } } + + sub nodeName { + my ($this) = @_; + $this -> { m_nodeName }; + } + + sub prefix { + my ($this) = @_; + my $name = $this -> nodeName(); + my ($prefix, $localname ) = split( /:/, $name ); + if ( !defined($localname) ) { + return undef; + } + else { + return $prefix; + } + } + + sub localName { + my ($this) = @_; + my $name = $this -> nodeName(); + my ($prefix, $localname ) = split( /:/, $name ); + if ( !defined($localname) ) { + return $prefix; + } + else { + return $localname; + } + } + #/** Index: CDATASection.pm =================================================================== RCS file: /cvsroot/net-script/netscript2/src/perl/XML/DOM2/CDATASection.pm,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** CDATASection.pm 2001/12/03 21:17:45 1.2 --- CDATASection.pm 2002/01/01 17:52:59 1.3 *************** *** 91,92 **** --- 91,96 ---- $this -> data(); } + + sub nodeType { + &CDATA_SECTION_NODE(); + } Index: Comment.pm =================================================================== RCS file: /cvsroot/net-script/netscript2/src/perl/XML/DOM2/Comment.pm,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Comment.pm 2001/12/03 21:17:45 1.2 --- Comment.pm 2002/01/01 17:52:59 1.3 *************** *** 92,93 **** --- 92,97 ---- $this -> data(); } + + sub nodeType { + &COMMENT_NODE(); + } Index: Element.pm =================================================================== RCS file: /cvsroot/net-script/netscript2/src/perl/XML/DOM2/Element.pm,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Element.pm 2001/12/11 22:21:49 1.1 --- Element.pm 2002/01/01 17:52:59 1.2 *************** *** 324,327 **** --- 324,531 ---- #/** + # Adds an new Attribute. If an attribute with that name is + # already present, it's value is changed to be that + # of the parameter. This value is a simple string, which is + # not parsed. Any markup such as syntax to be recognized as + # entity reference is treated as literal text and will be + # appropriately escaped by the implementation. See the DOM + # Level 2 Specification for more information about how to + # create attributes with entity references. + # + # @param a hash containing the following key-value-pairs + # name - the name of the attribute to create / alter + # value - value to set in string form + # @public + #*/ + sub setAttribute { + my ($this, $paramRef) = @_; + my $name = $paramRef -> { "name" }; + my $value = $paramRef -> { "value" }; + + + my $attribute = $this -> getAttribute( $paramRef ); + + if ( defined($attribute) ) { + $attribute -> value ( $paramRef ); + } + else { + $attribute = $this -> ownerDocument() -> createAttribute( $paramRef ); + $attribute -> value( $paramRef ); + $this -> setAttributeNode( { newAttr => $attribute } ); + } + } + + #/** + # Same as setAttribute, but takes qualified name and namespace URI instead. + # + # @param a hash containing the following key-value-pairs + # namespaceURI - the namespace uri of the attribute + # qualifiedName - the qualified name of the attribute + # value - the value to set in string form + # @public + #*/ + sub setAttributeNS { + my ($this, $paramRef) = @_; + my $namespaceURI = $paramRef -> { "namespaceURI" }; + my $qualifiedName = $paramRef -> { "qualifiedName" }; + + my ($prefix, $localname) = split(/:/, $qualifiedName); + + if ( defined( $prefix ) && !defined($localname) ) { + $localname = $prefix; + $prefix = undef; + } + + if ( defined($prefix) && !defined($namespaceURI) ) { + my $exc = XML::DOM2::DOMException -> new ( { + ErrCode => XML::DOM2::DOMException -> NAMESPACE_ERR(), + ErrDesc => "The qualified name has a prefix, but the namespace URI is undef!" + }); + $exc -> raise(); + return; + } + + if ( defined($prefix) && $prefix eq "xml" && + $namespaceURI ne "http://www.w3.org/XML/1998/namespace" ) { + + my $exc = XML::DOM2::DOMException -> new ( { + ErrCode => XML::DOM2::DOMException -> NAMESPACE_ERR(), + ErrDesc => "The prefix is 'xml' but the namespace URI is different from 'http://www.w3.org/XML/1998/namespace'!" + }); + $exc -> raise(); + } + + if ( defined($prefix) && $prefix eq "xmlns" && + $namespaceURI ne "http://www.w3.org/2000/xmlns" ) { + + my $exc = XML::DOM2::DOMException -> new ( { + ErrCode => XML::DOM2::DOMException -> NAMESPACE_ERR(), + ErrDesc => "The prefix is 'xmlns' but the namespace URI is different from 'http://www.w3.org/2000/xmlsn'!" + }); + $exc -> raise(); + } + + my $attribute = $this -> getAttributeNS( $paramRef ); + if ( defined( $attribute ) ) { + $attribute -> value( $paramRef ); + } + else { + $attribute = $this -> ownerDocument() -> createAttributeNS( $paramRef ); + $attribute -> value( $paramRef ); + $this -> setAttributeNodeNS( { newAttr => $attribute } ); + } + } + + #/** + # Adds a new attribute node. If an attribute with the same nodeName is + # already present in the element, it is replaced. + # @param a hash that contains the following key-value-pairs: + # newAttr - the node to add (XML::DOM2::Attr) + # @return the replaced attribute if any + # @public + #*/ + sub setAttributeNode { + my ($this, $paramRef) = @_; + + my $attribute = $paramRef -> { newAttr } ; + + if ( $attribute -> ownerDocument() != $this -> ownerDocument() ) { + my $exc = XML::DOM2::DOMException -> new ( { + ErrCode => XML::DOM2::DOMException -> WRONG_DOCUMENT_ERR(), + ErrDesc => "The Attribute you were trying to add was created with a different document!" + }); + $exc -> raise(); + } + if ( defined( $attribute -> ownerElement() ) && + $attribute -> ownerElement() != $this ) { + + my $exc = XML::DOM2::DOMExcpetion -> new ( { + ErrCode => XML::DOM2::DOMException -> INUSE_ATTRIBUTE_ERR(), + ErrCode => "The Attribute you were trying to add, is an Attribute of another Element!" + } ) + } + + my $old = getAttributeNode( { name => $attribute -> name() } ); + + if ( defined($old) ) { + $this -> removeAttributeNode( { oldAttr => $old} ); + } + + $this -> attributes() -> add( { newNode => $attribute } ); + return $old; + } + + #/** + # Adds a new attribute node. If an attribute with the same local name and + # namespace URI is present, it will be replaced. + # @param a hash that contains the following key-value-pairs: + # newAttr - the node to add (XML::DOM2::Attr) + # @return the replaced attribute. + # @public + #*/ + sub setAttributeNode { + my ($this, $paramRef) = @_; + + my $attribute = $paramRef -> { newAttr } ; + + if ( $attribute -> ownerDocument() != $this -> ownerDocument() ) { + my $exc = XML::DOM2::DOMException -> new ( { + ErrCode => XML::DOM2::DOMException -> WRONG_DOCUMENT_ERR(), + ErrDesc => "The Attribute you were trying to add was created with a different document!" + }); + $exc -> raise(); + } + if ( defined( $attribute -> ownerElement() ) && + $attribute -> ownerElement() != $this ) { + + my $exc = XML::DOM2::DOMExcpetion -> new ( { + ErrCode => XML::DOM2::DOMException -> INUSE_ATTRIBUTE_ERR(), + ErrCode => "The Attribute you were trying to add, is an Attribute of another Element!" + } ) + } + + my $old = getAttributeNodeNS( { + namespaceURI => $attribute -> namespaceURI(), + localName => $attribute -> localName() + } ); + + if ( defined($old) ) { + $this -> removeAttributeNode( { oldAttr => $old} ); + } + + $this -> attributes() -> add( { newNode => $attribute } ); + return $old; + } + + sub nodeName { + my ($this) = @_; + $this -> { m_nodeName }; + } + + sub prefix { + my ($this) = @_; + my $name = $this -> nodeName(); + my ($prefix, $localname ) = split( /:/, $name ); + if ( !defined($localname) ) { + return undef; + } + else { + return $prefix; + } + } + + sub localName { + my ($this) = @_; + my $name = $this -> nodeName(); + my ($prefix, $localname ) = split( /:/, $name ); + if ( !defined($localname) ) { + return $prefix; + } + else { + return $localname; + } + } + + #/** # Returns ELEMENT_NODE #*/ *************** *** 329,330 **** --- 533,536 ---- &ELEMENT_NODE(); } + + 1; Index: NamedNodeMap.pm =================================================================== RCS file: /cvsroot/net-script/netscript2/src/perl/XML/DOM2/NamedNodeMap.pm,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** NamedNodeMap.pm 2001/12/11 22:22:34 1.4 --- NamedNodeMap.pm 2002/01/01 17:52:59 1.5 *************** *** 27,32 **** #/** ! # The constructor. Constructs a NodeList ! # @return an instance of XML::DOM2:NodeList #*/ sub new { --- 27,32 ---- #/** ! # The constructor. Constructs a NamedNodeMap ! # @return an instance of XML::DOM2:NamedNodeMap #*/ sub new { *************** *** 137,141 **** my $found = 0; ! for ( keys( $this -> { m_nodeMap} ) ) { delete $this -> { m_nodeMap } -> { $_ }, $found = 1, last if $this -> { m_nodeMap } -> { $_ } == $node ; --- 137,141 ---- my $found = 0; ! for ( keys( %{ $this -> { m_nodeMap} } ) ) { delete $this -> { m_nodeMap } -> { $_ }, $found = 1, last if $this -> { m_nodeMap } -> { $_ } == $node ; Index: Node.pm =================================================================== RCS file: /cvsroot/net-script/netscript2/src/perl/XML/DOM2/Node.pm,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Node.pm 2001/12/11 22:23:23 1.9 --- Node.pm 2002/01/01 17:52:59 1.10 *************** *** 145,150 **** #*/ sub localName { ! my ($this) = @_; ! $this -> { m_localName }; } --- 145,149 ---- #*/ sub localName { ! undef; } *************** *** 156,160 **** # For nodes of any type other than ELEMENT_NODE and ATTRIBUTE_NODE and # nodes created with a DOM Level 1 method, such as createElement from the ! # Document interface, this is always null. # # @return a scalar holding the namespace URI of this node or undef. --- 155,159 ---- # For nodes of any type other than ELEMENT_NODE and ATTRIBUTE_NODE and # nodes created with a DOM Level 1 method, such as createElement from the ! # Document interface, this is always undef. # # @return a scalar holding the namespace URI of this node or undef. *************** *** 162,166 **** #*/ sub namespaceURI { ! $this -> { m_namespaceURI }; } --- 161,165 ---- #*/ sub namespaceURI { ! undef; } *************** *** 345,353 **** #*/ sub appendChild { - # FIXME: handling for document fragments my ( $this, $paramsRef ) = @_; my %params = %{$paramsRef}; my $newNode = $params{ newChild }; # Check document unless ( $this -> ownerDocument() == $newNode -> ownerDocument() ) { --- 344,362 ---- #*/ sub appendChild { my ( $this, $paramsRef ) = @_; my %params = %{$paramsRef}; my $newNode = $params{ newChild }; + # Handle document fragments + if ( $newNode -> nodeType() == &DOCUMENT_FRAGMENT_NODE() ) { + my $children = $newNode -> childNodes(); + my $l = $children -> length() - 1; + for ( 0..$l ) { + my $child = $children -> item( { "index" => $_ } ); + $this -> appendChild( { newChild => $child } ); + } + return $newNode; + } + # Check document unless ( $this -> ownerDocument() == $newNode -> ownerDocument() ) { *************** *** 461,465 **** #*/ sub insertBefore { - # FIXME: handling for document fragments my ( $this, $paramsRef ) = @_; my %params = %{$paramsRef}; --- 470,473 ---- *************** *** 467,470 **** --- 475,489 ---- my $refNode = $params{ refChild }; + # Handle document fragments + if ( $newNode -> nodeType() == &DOCUMENT_FRAGMENT_NODE() ) { + my $children = $newNode -> childNodes(); + my $l = $children -> length() - 1; + for ( 0..$l ) { + my $child = $children -> item( { "index" => $_ } ); + $this -> insertBefore( { refChild => $refNode, newChild => $child } ); + } + return $newNode; + } + # Check document unless ( $this -> ownerDocument() == $newNode -> ownerDocument() ) { *************** *** 627,631 **** #*/ sub replaceChild { - # FIXME: handling for document fragments my ( $this, $paramsRef ) = @_; my %params = %{$paramsRef}; --- 646,649 ---- *************** *** 633,636 **** --- 651,665 ---- my $refNode = $params{ oldChild }; + # Handle document fragments + if ( $newNode -> nodeType() == &DOCUMENT_FRAGMENT_NODE() ) { + my $children = $newNode -> childNodes(); + my $l = $children -> length() - 1; + for ( 0..$l ) { + my $child = $children -> item( { "index" => $_ } ); + $this -> insertBefore( { refChild => $refNode, newChild => $child } ); + } + return $this -> removeChild( { oldChild => $refNode } ); + } + # Check document unless ( $this -> ownerDocument() == $newNode -> ownerDocument() ) { *************** *** 678,697 **** } - # add node to children - $this -> childNodes() -> insert( { "index" => $index, - node => $newNode } ); - - # set new parent - $newNode -> { m_parentNode } = $this; - # Get the siblings right... - $newNode -> { m_previousSibling } = $refNode -> { m_previousSibling }; - $newNode -> { m_nextSibling } = $refNode -> { m_nextSibling }; - $newNode -> previousSibling() -> { m_nextSibling } = $newNode - if defined($newNode -> previousSibling()); - $newNode -> nextSibling() -> { m_previousSibling } = $newNode - if defined($newNode -> nextSibling()); ! # remove reference node and return it. $this -> removeChild( { oldChild => $refNode } ); } --- 707,734 ---- } ! # add node to children ! $this -> insertBefore( { refChild => $refNode, newChild => $newNode } ); ! # remove old node $this -> removeChild( { oldChild => $refNode } ); + + # This stuff should be done by insertBefore and removeChild... + # Remove this at 30.01.2002 if it works. + # + # $this -> childNodes() -> insert( { "index" => $index, + # node => $newNode } ); + # + # # set new parent + # $newNode -> { m_parentNode } = $this; + # # Get the siblings right... + # $newNode -> { m_previousSibling } = $refNode -> { m_previousSibling }; + # $newNode -> { m_nextSibling } = $refNode -> { m_nextSibling }; + # $newNode -> previousSibling() -> { m_nextSibling } = $newNode + # if defined($newNode -> previousSibling()); + # $newNode -> nextSibling() -> { m_previousSibling } = $newNode + # if defined($newNode -> nextSibling()); + # + # # remove reference node and return it. + # $this -> removeChild( { oldChild => $refNode } ); } Index: NodeList.pm =================================================================== RCS file: /cvsroot/net-script/netscript2/src/perl/XML/DOM2/NodeList.pm,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** NodeList.pm 2001/12/11 22:22:59 1.6 --- NodeList.pm 2002/01/01 17:52:59 1.7 *************** *** 134,138 **** # @not-standard # @param a hash containing the following key-value-pairs ! # index - index to insert the node at ( 0 < index < lenght ) # node - a reference to XML::DOM2::Node # @public --- 134,138 ---- # @not-standard # @param a hash containing the following key-value-pairs ! # index - index to insert the node at ( 0 <= index < lenght ) # node - a reference to XML::DOM2::Node # @public *************** *** 142,149 **** my $index = $paramsRef -> { "index" }; my $node = $paramsRef -> { node }; ! if ( $index < 0 || $index > $this -> length() ) { my $exception = XML::DOM2::DOMException -> new( { ErrCode => XML::DOM2::DOMException -> INDEX_SIZE_ERR(), ! ErrDesc => "The given index is not valid. ( 0 < ".$index." < ". $this -> length() ." )." } --- 142,149 ---- my $index = $paramsRef -> { "index" }; my $node = $paramsRef -> { node }; ! if ( $index < 0 || $index => $this -> length() ) { my $exception = XML::DOM2::DOMException -> new( { ErrCode => XML::DOM2::DOMException -> INDEX_SIZE_ERR(), ! ErrDesc => "The given index is not valid. ( 0 <= ".$index." < ". $this -> length() ." )." } *************** *** 173,177 **** sub indexOf { my ( $this , $paramsRef ) = @_; ! my $startIndex = defined( $params{ "index" } ) ? $params{ "index" } : 0; my $node = $paramsRef -> { node }; my @list = @{ $this -> { m_nodeList } }; --- 173,177 ---- sub indexOf { my ( $this , $paramsRef ) = @_; ! my $startIndex = defined( $paramsRef -> { "index" } ) ? $paramsRef -> { "index" } : 0; my $node = $paramsRef -> { node }; my @list = @{ $this -> { m_nodeList } }; Index: ProcessingInstruction.pm =================================================================== RCS file: /cvsroot/net-script/netscript2/src/perl/XML/DOM2/ProcessingInstruction.pm,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** ProcessingInstruction.pm 2001/12/03 21:18:11 1.1 --- ProcessingInstruction.pm 2002/01/01 17:52:59 1.2 *************** *** 142,143 **** --- 142,147 ---- $this -> data(); } + + sub nodeType { + &PROCESSING_INSTRUCTION_NODE(); + } Index: Text.pm =================================================================== RCS file: /cvsroot/net-script/netscript2/src/perl/XML/DOM2/Text.pm,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Text.pm 2001/12/03 21:17:45 1.2 --- Text.pm 2002/01/01 17:52:59 1.3 *************** *** 149,150 **** --- 149,155 ---- $this -> data(); } + + + sub nodeType() { + &TEXT_NODE(); + } |