trunk/XMLv2__NodeList.st
changeset 0 5057afe1ec87
equal deleted inserted replaced
-1:000000000000 0:5057afe1ec87
       
     1 "{ Package: 'stx:goodies/xmlsuite' }"
       
     2 
       
     3 "{ NameSpace: XMLv2 }"
       
     4 
       
     5 OrderedCollection subclass:#NodeList
       
     6 	instanceVariableNames:''
       
     7 	classVariableNames:''
       
     8 	poolDictionaries:''
       
     9 	category:'XML Suite-DOM3'
       
    10 !
       
    11 
       
    12 
       
    13 !NodeList methodsFor:'DOM3 interface'!
       
    14 
       
    15 item:index
       
    16 
       
    17     ^self at:index + 1
       
    18 
       
    19     "Created: / 08-05-2005 / 18:34:14 / janfrog"
       
    20     "Modified: / 23-12-2005 / 20:37:17 / janfrog"
       
    21 !
       
    22 
       
    23 length
       
    24 
       
    25     ^self size
       
    26 
       
    27     "Created: / 08-05-2005 / 18:34:21 / janfrog"
       
    28 ! !
       
    29 
       
    30 !NodeList methodsFor:'accessing'!
       
    31 
       
    32 nodeWithLocalName:localName 
       
    33 
       
    34     ^self nodeWithLocalName:localName ifAbsent:[nil]
       
    35 
       
    36     "Created: / 16-06-2005 / 15:56:06 / janfrog"
       
    37 !
       
    38 
       
    39 nodeWithLocalName:localName ifAbsent:aBlock 
       
    40     |candidates|
       
    41 
       
    42     candidates := self nodesWithLocalName:localName.
       
    43     candidates size > 1 ifTrue:[^ self error:'Multiple nodes with localName ' , localName].
       
    44     candidates size < 1 ifTrue:[^ aBlock value].
       
    45     ^ candidates first
       
    46 
       
    47     "Created: / 16-06-2005 / 15:57:28 / janfrog"
       
    48 !
       
    49 
       
    50 nodesWithLocalName:localName 
       
    51 
       
    52     ^self select:[:node|node localName = localName]
       
    53 
       
    54     "Created: / 16-06-2005 / 15:51:19 / janfrog"
       
    55 !
       
    56 
       
    57 nodesWithURI:uri localName:localName 
       
    58     ^self 
       
    59         detect:[:attr | ((attr ns = uri) and:[ attr localName = localName ]) ]
       
    60         ifNone:[ nil ]
       
    61 
       
    62     "Created: / 16-06-2005 / 15:53:47 / janfrog"
       
    63     "Modified: / 17-06-2005 / 09:51:19 / masca"
       
    64     "Modified: / 23-12-2005 / 15:24:10 / janfrog"
       
    65 !
       
    66 
       
    67 nodesWithURI:uri localName:localName ifNone:aBlock 
       
    68     ^self 
       
    69         detect:[:attr | ((attr tag namespace = uri) and:[ attr tag type = localName ]) ]
       
    70         ifNone:aBlock
       
    71 
       
    72     "Created: / 16-06-2005 / 15:55:31 / janfrog"
       
    73     "Modified: / 17-06-2005 / 09:51:25 / masca"
       
    74 ! !
       
    75 
       
    76 !NodeList methodsFor:'adding & removing'!
       
    77 
       
    78 insert:new after:ref
       
    79 
       
    80     "Inserts new right after ref element. If ref is nil or is not in
       
    81     myself, add to the end (append)"
       
    82 
       
    83     | idx |
       
    84 
       
    85     idx := self identityIndexOf:ref.
       
    86     idx == 0 
       
    87         ifTrue:[self addLast:new]
       
    88         ifFalse:[self add:new afterIndex:idx]
       
    89 
       
    90     "Created: / 18-06-2005 / 21:55:12 / janfrog"
       
    91 !
       
    92 
       
    93 insert:new before:ref
       
    94 
       
    95     "Inserts new right after ref element. If ref is nil or is not in
       
    96     myself, add to the end (append)"
       
    97 
       
    98     | idx |
       
    99 
       
   100     idx := self identityIndexOf:ref.
       
   101     idx == 0 
       
   102         ifTrue:[self addLast:new]
       
   103         ifFalse:[self add:new beforeIndex:idx]
       
   104 
       
   105     "Created: / 18-06-2005 / 21:55:12 / janfrog"
       
   106 ! !
       
   107 
       
   108 !NodeList class methodsFor:'documentation'!
       
   109 
       
   110 version
       
   111     ^ '$Header: /opt/data/cvs/stx/goodies/xmlsuite/XMLv2__NodeList.st,v 1.2 2005-12-25 10:54:59 vranyj1 Exp $'
       
   112 ! !