@@ -5,15 +5,21 @@ import scala.collection.mutable ;
5
5
import scala .collection .Map ;
6
6
7
7
/** class that handles markup - provides callback methods to MarkupParser */
8
- abstract class MarkupHandler [MarkupType ] {
8
+ abstract class MarkupHandler [A ] {
9
9
10
10
/** a stack of prefix namespace mappings */
11
11
protected val prefixStack =
12
12
new mutable.Stack [immutable.Map [String ,String ]]();
13
13
14
14
/** mapping from prefixes to namespaces */
15
15
var namespace : immutable.Map [String ,String ] =
16
- new immutable.TreeMap [String ,String ].update(" " ," " );
16
+ new immutable.TreeMap [String ,String ]
17
+ .update(" " ," " )
18
+ .update(" xml" ," http://www.w3.org/XML/1998/namespace" );
19
+
20
+
21
+ var tmpPrefix : mutable.Map [String , String ] =
22
+ new mutable.HashMap [String ,String ];
17
23
18
24
/** returns prefix of the qualified name if any */
19
25
final def namespacePrefix (name : String ): Option [String ] = {
@@ -23,10 +29,10 @@ abstract class MarkupHandler[MarkupType] {
23
29
24
30
/** removes xmlns attributes from attr as a side effect, and returns a prefix
25
31
* map resulting from them
26
- */
27
- final def namespaceDecl (aMap : mutable.Map [String , AttribValue ]): Map [String , String ] = {
32
+ * /
33
+ final def namespaceDecl1 (aMap: mutable.Map[String, AttribValue]): Map[String, String] = {
28
34
val setNS = new mutable.HashMap[String, String];
29
- /* DEBUG */
35
+ / * DEBUG * /
30
36
val attrIt = aMap.keys;
31
37
while( attrIt.hasNext ) {
32
38
val z = attrIt.next;
@@ -47,40 +53,46 @@ abstract class MarkupHandler[MarkupType] {
47
53
}
48
54
setNS;
49
55
}
56
+ */
57
+
58
+ /** removes xmlns attributes from attr as a side effect, and returns a prefix
59
+ * map resulting from them
60
+ */
61
+ final def internal_namespaceDecl (prefix: String , uri: String ): Unit = {
62
+ tmpPrefix.update(prefix, uri);
63
+ }
50
64
51
65
def attributeCDataValue (pos : int, str: String ): AttribValue ;
52
66
def attributeNamespaceDecl (pos : int, uri : String ): AttribValue ;
53
67
54
- def attribute (pos : int, key : String , value: String ): AttribValue =
55
- if ( key.startsWith(" xmlns" ))
56
- attributeNamespaceDecl(pos, value);
57
- else
58
- attributeCDataValue(pos, value);
68
+ def attribute (pos : int, uri : String , key : String , value: String ): AttribValue =
69
+ attributeCDataValue(pos, value);
59
70
60
71
/** be careful to copy everything from attrMap1, as it will change
61
- * @param attrMap1 the attribute map.
72
+ * @param pos the position in the sourcefile
73
+ * @param uri the namespace uri
74
+ * @param label the tag name
75
+ * @param attrMap1 the attribute map, from Pair(uri,label) to target
76
+ * @param args the children of this element
62
77
*/
63
- def element (pos : int, uri : String , label : String , attrMap1 : mutable.Map [String ,AttribValue ], args : mutable.Buffer [MarkupType ]): Iterable [MarkupType ];
78
+ def element (pos : int, uri : String , label : String , attrMap1 : mutable.Map [Pair [ String ,String ], AttribValue ], args : mutable.Buffer [A ]): Iterable [A ];
64
79
65
- def charData (pos : Int , txt : String ): Iterable [MarkupType ];
66
- def procInstr (pos : Int , target : String , txt : String ): Iterable [MarkupType ];
67
- def comment (pos : Int , comment : String ): Iterable [MarkupType ];
68
- def entityRef (pos : Int , n : String ): Iterable [MarkupType ];
80
+ def charData (pos : Int , txt : String ): Iterable [A ];
81
+ def procInstr (pos : Int , target : String , txt : String ): Iterable [A ];
82
+ def comment (pos : Int , comment : String ): Iterable [A ];
83
+ def entityRef (pos : Int , n : String ): Iterable [A ];
69
84
70
- def text (pos : Int , txt: String ): Iterable [MarkupType ];
85
+ def text (pos : Int , txt: String ): Iterable [A ];
71
86
72
87
73
- def internal_startPrefixMapping (pref : Map [String , String ]) = {
74
- if ( ! pref.isEmpty ) {
75
- this .prefixStack.push( this .namespace );
76
- this .namespace = this .namespace incl pref;
77
- }
88
+ def internal_startPrefixMapping : Unit = {
89
+ this .prefixStack.push( this .namespace );
90
+ this .namespace = this .namespace incl tmpPrefix;
91
+ tmpPrefix.clear;
78
92
}
79
93
80
- def internal_endPrefixMapping (pref : Map [String , String ]): Unit = {
81
- if ( ! pref.isEmpty ) {
82
- this .namespace = prefixStack.pop;
83
- }
94
+ def internal_endPrefixMapping : Unit = {
95
+ this .namespace = prefixStack.pop;
84
96
}
85
97
86
98
}
0 commit comments