blob: 4a8b1c4fcffeff4ea9b5c11c63d49af9ba51dd35 [file] [log] [blame]
Meki Cherkaouib0365a72012-02-18 00:59:57 -08001var MARK_LEN=512;
2var DEBUG_MAX_LEN = 32768;
3
4var BinaryXMLDecoder = new BinaryXMLDecoder(_Istream){
5 this.Istream = _Istream;
6
7};
8
9
10BinaryXMLDecoder.prototype.readStartElement =function(
11 //String
12 startTag,
13 //TreeMap<String, String>
14 attributes) {
15
16 try {
17 BinaryXMLCodec.TypeAndVal tv = BinaryXMLCodec.decodeTypeAndVal(this.Istream);
18
19 if (null == tv) {
20 throw new Exception("Expected start element: " + startTag + " got something not a tag.");
21 }
22
23 String decodedTag = null;
24
25 if (tv.type() == BinaryXMLCodec.XML_TAG) {
26
27 decodedTag = BinaryXMLCodec.decodeUString(this.Istream, tv.val()+1);
28
29 } else if (tv.type() == BinaryXMLCodec.XML_DTAG) {
30 decodedTag = tagToString(tv.val());
31 }
32
33 if ((null == decodedTag) || (!decodedTag.equals(startTag))) {
34 throw new Exception("Expected start element: " + startTag + " got: " + decodedTag + "(" + tv.val() + ")");
35 }
36
37 if (null != attributes) {
38 readAttributes(attributes);
39 }
40
41 } catch (e) {
42 throw new Exception("readStartElement", e);
43 }
44};
45
46BinaryXMLDecoder.prototype.readAttributes = function(
47 //TreeMap<String,String>
48 attributes){
49
50 if (null == attributes) {
51 return;
52 }
53
54 try {
55
56 BinaryXMLCodec.TypeAndVal nextTV = BinaryXMLCodec.peekTypeAndVal(_istream);
57
58 while ((null != nextTV) && ((BinaryXMLCodec.XML_ATTR == nextTV.type()) ||
59 (BinaryXMLCodec.XML_DATTR == nextTV.type()))) {
60
61 BinaryXMLCodec.TypeAndVal thisTV = BinaryXMLCodec.decodeTypeAndVal(this.Istream);
62
63 var attributeName = null;
64 if (BinaryXMLCodec.XML_ATTR == thisTV.type()) {
65
66 attributeName = BinaryXMLCodec.decodeUString(_istream, thisTV.val()+1);
67
68 } else if (BinaryXMLCodec.XML_DATTR == thisTV.type()) {
69 // DKS TODO are attributes same or different dictionary?
70 attributeName = tagToString(thisTV.val());
71 if (null == attributeName) {
72 throw new ContentDecodingException("Unknown DATTR value" + thisTV.val());
73 }
74 }
75
76 var attributeValue = BinaryXMLCodec.decodeUString(_istream);
77
78 attributes.put(attributeName, attributeValue);
79
80 nextTV = BinaryXMLCodec.peekTypeAndVal(_istream);
81 }
82
83 } catch ( e) {
84
85 throw new ContentDecodingException("readStartElement", e);
86 }
87};
88
89//TODO