@@ -10,6 +10,7 @@ package scala
10
10
package xml
11
11
package parsing
12
12
13
+ import scala .collection .mutable
13
14
import org .xml .sax .Attributes
14
15
import org .xml .sax .helpers .DefaultHandler
15
16
@@ -38,10 +39,16 @@ abstract class FactoryAdapter extends DefaultHandler with factory.XMLLoader[Node
38
39
var rootElem : Node = null
39
40
40
41
val buffer = new StringBuilder ()
41
- var attribStack = List .empty[MetaData ]
42
- var hStack = List .empty[Node ] // [ element ] contains siblings
43
- var tagStack = List .empty[String ]
44
- var scopeStack = List .empty[NamespaceBinding ]
42
+ var attribs = List .empty[MetaData ]
43
+ var nodes = List .empty[Node ] // [ element ] contains siblings
44
+ var tags = List .empty[String ]
45
+ var scopes = List .empty[NamespaceBinding ]
46
+
47
+ // Fix compatability issues. Add MiMa exclusion rules, instead?
48
+ var attribStack = mutable.Stack (attribs)
49
+ var hStack = mutable.Stack (nodes)
50
+ var tagStack = mutable.Stack (tags)
51
+ var scopeStack = mutable.Stack (scopes)
45
52
46
53
var curTag : String = null
47
54
var capture : Boolean = false
@@ -121,17 +128,17 @@ abstract class FactoryAdapter extends DefaultHandler with factory.XMLLoader[Node
121
128
attributes : Attributes ): Unit =
122
129
{
123
130
captureText()
124
- tagStack = curTag :: tagStack
131
+ tags = curTag :: tags
125
132
curTag = qname
126
133
127
134
val localName = splitName(qname)._2
128
135
capture = nodeContainsText(localName)
129
136
130
- hStack = null :: hStack
137
+ nodes = null :: nodes
131
138
var m : MetaData = Null
132
139
var scpe : NamespaceBinding =
133
- if (scopeStack .isEmpty) TopScope
134
- else scopeStack .head
140
+ if (scopes .isEmpty) TopScope
141
+ else scopes .head
135
142
136
143
for (i <- 0 until attributes.getLength()) {
137
144
val qname = attributes getQName i
@@ -146,16 +153,16 @@ abstract class FactoryAdapter extends DefaultHandler with factory.XMLLoader[Node
146
153
m = Attribute (Option (pre), key, Text (value), m)
147
154
}
148
155
149
- scopeStack = scpe :: scopeStack
150
- attribStack = m :: attribStack
156
+ scopes = scpe :: scopes
157
+ attribs = m :: attribs
151
158
}
152
159
153
160
/**
154
161
* captures text, possibly normalizing whitespace
155
162
*/
156
163
def captureText (): Unit = {
157
164
if (capture && buffer.length > 0 )
158
- hStack = createText(buffer.toString) :: hStack
165
+ nodes = createText(buffer.toString) :: nodes
159
166
160
167
buffer.clear()
161
168
}
@@ -169,24 +176,24 @@ abstract class FactoryAdapter extends DefaultHandler with factory.XMLLoader[Node
169
176
*/
170
177
override def endElement (uri : String , _localName : String , qname : String ): Unit = {
171
178
captureText()
172
- val metaData = attribStack .head
173
- attribStack = attribStack .tail
179
+ val metaData = attribs .head
180
+ attribs = attribs .tail
174
181
175
182
// reverse order to get it right
176
- val v = hStack .takeWhile(_ != null ).reverse
177
- hStack = hStack .dropWhile(_ != null ) match {
183
+ val v = nodes .takeWhile(_ != null ).reverse
184
+ nodes = nodes .dropWhile(_ != null ) match {
178
185
case null :: hs => hs
179
186
case hs => hs
180
187
}
181
188
val (pre, localName) = splitName(qname)
182
- val scp = scopeStack .head
183
- scopeStack = scopeStack .tail
189
+ val scp = scopes .head
190
+ scopes = scopes .tail
184
191
185
192
// create element
186
193
rootElem = createNode(pre, localName, metaData, scp, v)
187
- hStack = rootElem :: hStack
188
- curTag = tagStack .head
189
- tagStack = tagStack .tail
194
+ nodes = rootElem :: nodes
195
+ curTag = tags .head
196
+ tags = tags .tail
190
197
capture = curTag != null && nodeContainsText(curTag) // root level
191
198
}
192
199
@@ -195,6 +202,6 @@ abstract class FactoryAdapter extends DefaultHandler with factory.XMLLoader[Node
195
202
*/
196
203
override def processingInstruction (target : String , data : String ) {
197
204
captureText()
198
- hStack = hStack .reverse_::: (createProcInstr(target, data).toList)
205
+ nodes = nodes .reverse_::: (createProcInstr(target, data).toList)
199
206
}
200
207
}
0 commit comments