core/trunk/XMLv2__NodeList.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Thu, 10 Apr 2008 09:14:47 +0000
changeset 3 7909b6680107
parent 2 06f508a6f55c
child 92 221f73b0615e
permissions -rw-r--r--
Loaded into & commited from 5.3.6

"{ Package: 'stx:goodies/xmlsuite/core' }"

"{ NameSpace: XMLv2 }"

OrderedCollection subclass:#NodeList
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'XML Suite-DOM3'
!


!NodeList methodsFor:'DOM3 interface'!

item:index

    ^self at:index + 1

    "Created: / 08-05-2005 / 18:34:14 / janfrog"
    "Modified: / 23-12-2005 / 20:37:17 / janfrog"
!

length

    ^self size

    "Created: / 08-05-2005 / 18:34:21 / janfrog"
! !

!NodeList methodsFor:'accessing'!

nodeWithLocalName:localName 

    ^self nodeWithLocalName:localName ifAbsent:[nil]

    "Created: / 16-06-2005 / 15:56:06 / janfrog"
!

nodeWithLocalName:localName ifAbsent:aBlock 
    |candidates|

    candidates := self nodesWithLocalName:localName.
    candidates size > 1 ifTrue:[^ self error:'Multiple nodes with localName ' , localName].
    candidates size < 1 ifTrue:[^ aBlock value].
    ^ candidates first

    "Created: / 16-06-2005 / 15:57:28 / janfrog"
!

nodesWithLocalName:localName 

    ^self select:[:node|node localName = localName]

    "Created: / 16-06-2005 / 15:51:19 / janfrog"
!

nodesWithURI:uri localName:localName 
    ^self 
        detect:[:attr | ((attr ns = uri) and:[ attr localName = localName ]) ]
        ifNone:[ nil ]

    "Created: / 16-06-2005 / 15:53:47 / janfrog"
    "Modified: / 17-06-2005 / 09:51:19 / masca"
    "Modified: / 23-12-2005 / 15:24:10 / janfrog"
!

nodesWithURI:uri localName:localName ifNone:aBlock 
    ^self 
        detect:[:attr | ((attr tag namespace = uri) and:[ attr tag type = localName ]) ]
        ifNone:aBlock

    "Created: / 16-06-2005 / 15:55:31 / janfrog"
    "Modified: / 17-06-2005 / 09:51:25 / masca"
! !

!NodeList methodsFor:'adding & removing'!

insert:new after:ref

    "Inserts new right after ref element. If ref is nil or is not in
    myself, add to the end (append)"

    | idx |

    idx := self identityIndexOf:ref.
    idx == 0 
        ifTrue:[self addLast:new]
        ifFalse:[self add:new afterIndex:idx]

    "Created: / 18-06-2005 / 21:55:12 / janfrog"
!

insert:new before:ref

    "Inserts new right after ref element. If ref is nil or is not in
    myself, add to the end (append)"

    | idx |

    idx := self identityIndexOf:ref.
    idx == 0 
        ifTrue:[self addLast:new]
        ifFalse:[self add:new beforeIndex:idx]

    "Created: / 18-06-2005 / 21:55:12 / janfrog"
! !

!NodeList class methodsFor:'documentation'!

version
    ^ '$Header: /opt/data/cvs/stx/goodies/xmlsuite/XMLv2__NodeList.st,v 1.2 2005-12-25 10:54:59 vranyj1 Exp $'
! !