trunk/XMLv2__Text.st
changeset 0 5057afe1ec87
equal deleted inserted replaced
-1:000000000000 0:5057afe1ec87
       
     1 "{ Package: 'stx:goodies/xmlsuite' }"
       
     2 
       
     3 "{ NameSpace: XMLv2 }"
       
     4 
       
     5 CharacterData subclass:#Text
       
     6 	instanceVariableNames:''
       
     7 	classVariableNames:''
       
     8 	poolDictionaries:''
       
     9 	category:'XML Suite-DOM3'
       
    10 !
       
    11 
       
    12 
       
    13 !Text methodsFor:'DOM3 helpers'!
       
    14 
       
    15 computeLookupPrefix:arg 
       
    16     "Superclass says that I am responsible to implement this method"
       
    17     
       
    18     self shouldImplement
       
    19 
       
    20     "Created: / 18-06-2005 / 21:13:11 / janfrog"
       
    21 !
       
    22 
       
    23 logicallyAdjacentTextNodes
       
    24 
       
    25     | siblings myIdx idx adjacentNodes |
       
    26     adjacentNodes := NodeList new.
       
    27     siblings := self parent childNodes.
       
    28     myIdx := siblings identityIndexOf:self.
       
    29     idx := myIdx.
       
    30     idx ~= 1 ifTrue:[
       
    31         [ (siblings at:idx - 1) isText ] whileTrue:[
       
    32             idx := idx - 1
       
    33         ]
       
    34     ].
       
    35     [ (siblings at:idx) isText ] whileTrue:[
       
    36         adjacentNodes add:(siblings at:idx).
       
    37         idx := idx + 1
       
    38     ].
       
    39     ^adjacentNodes
       
    40 
       
    41     "Created: / 18-06-2005 / 21:43:36 / janfrog"
       
    42 !
       
    43 
       
    44 textContentOn:aStream 
       
    45     "Superclass says that I am responsible to implement this method"
       
    46 
       
    47     aStream nextPutAll:data
       
    48 
       
    49     "Created: / 18-06-2005 / 20:18:17 / janfrog"
       
    50     "Modified: / 18-10-2005 / 14:53:04 / janfrog"
       
    51 !
       
    52 
       
    53 wholeTextOn:aStream
       
    54 
       
    55     self logicallyAdjacentTextNodes do:[:text|
       
    56         aStream nextPutAll:text data.
       
    57     ].
       
    58 
       
    59     "Created: / 18-06-2005 / 21:41:54 / janfrog"
       
    60 ! !
       
    61 
       
    62 !Text methodsFor:'DOM3 interface'!
       
    63 
       
    64 compareDocumentPosition:arg 
       
    65     "Superclass says that I am responsible to implement this method"
       
    66 
       
    67     self shouldImplement
       
    68 
       
    69     "Created: / 18-06-2005 / 20:18:17 / janfrog"
       
    70 !
       
    71 
       
    72 isElementContentWhitespace
       
    73 
       
    74     ^self data allSatisfy:[:c|c isXMLWhiteSpace]
       
    75 
       
    76     "Created: / 18-06-2005 / 21:32:38 / janfrog"
       
    77 !
       
    78 
       
    79 lookupNamespaceURI:arg 
       
    80     "Superclass says that I am responsible to implement this method"
       
    81 
       
    82     self shouldImplement
       
    83 
       
    84     "Created: / 18-06-2005 / 20:18:17 / janfrog"
       
    85 !
       
    86 
       
    87 nodeName
       
    88 
       
    89     ^'#text'
       
    90 
       
    91     "Created: / 17-06-2005 / 11:35:05 / janfrog"
       
    92 !
       
    93 
       
    94 nodeType
       
    95 
       
    96     ^Node TEXT_NODE
       
    97 
       
    98     "Created: / 17-06-2005 / 11:45:32 / janfrog"
       
    99 !
       
   100 
       
   101 nodeValue
       
   102 
       
   103     ^self data
       
   104 
       
   105     "Created: / 28-12-2005 / 16:56:43 / janfrog"
       
   106 !
       
   107 
       
   108 normalize
       
   109 
       
   110     "Nothing to do for now"
       
   111 
       
   112     "Created: / 18-06-2005 / 20:18:17 / janfrog"
       
   113     "Modified: / 23-12-2005 / 20:54:31 / janfrog"
       
   114 !
       
   115 
       
   116 replaceWholeText:newText
       
   117 
       
   118     self logicallyAdjacentTextNodes do:[:text|
       
   119         text == self ifFalse:[self parent removeChild:text]
       
   120     ].
       
   121     self data:newText.
       
   122 
       
   123     "Created: / 18-06-2005 / 21:47:47 / janfrog"
       
   124 !
       
   125 
       
   126 splitText:offset
       
   127 
       
   128     | before after newText |
       
   129     before := self data copyTo:offset.
       
   130     after := self data copyFrom:offset + 1.
       
   131     self data:before.
       
   132     newText := Text new data:after.
       
   133     self parent insertChild:newText after:self.
       
   134     ^newText
       
   135 
       
   136     "Created: / 18-06-2005 / 21:49:05 / janfrog"
       
   137 !
       
   138 
       
   139 wholeText
       
   140 
       
   141     | s |
       
   142     s := UnicodeString new writeStream.
       
   143     self wholeTextOn:s.
       
   144     ^s contents
       
   145 
       
   146     "Created: / 18-06-2005 / 21:37:24 / janfrog"
       
   147 ! !
       
   148 
       
   149 !Text methodsFor:'accessing'!
       
   150 
       
   151 data
       
   152     ^data
       
   153 
       
   154     "Created: / 18-06-2005 / 21:32:52 / janfrog"
       
   155 !
       
   156 
       
   157 data:aString
       
   158     data := aString
       
   159 
       
   160     "Created: / 18-06-2005 / 21:33:13 / janfrog"
       
   161 ! !
       
   162 
       
   163 !Text methodsFor:'testing'!
       
   164 
       
   165 isIgnorableText
       
   166 
       
   167     ^self data allSatisfy:[:c|c isXMLWhiteSpace]
       
   168 
       
   169     "Created: / 12-12-2006 / 10:31:35 / janfrog"
       
   170 !
       
   171 
       
   172 isText
       
   173     ^ true
       
   174 
       
   175     "Created: / 05-08-2005 / 14:28:08 / janfrog"
       
   176 ! !
       
   177 
       
   178 !Text methodsFor:'visiting'!
       
   179 
       
   180 acceptVisitor:aVisitor 
       
   181     "Double dispatch back to the visitor, passing my type encoded in
       
   182      the selector (visitor pattern)"
       
   183 
       
   184     "stub code automatically generated - please change if required"
       
   185 
       
   186     ^ aVisitor visitText:self
       
   187 
       
   188     "Created: / 05-08-2005 / 13:09:35 / janfrog"
       
   189 ! !
       
   190 
       
   191 !Text class methodsFor:'documentation'!
       
   192 
       
   193 version
       
   194     ^ '$Header: /opt/data/cvs/stx/goodies/xmlsuite/XMLv2__Text.st,v 1.5 2007-01-03 19:58:33 stillj1 Exp $'
       
   195 ! !