rhack 1.2.1 → 1.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +13 -5
- data/README.md +21 -9
- data/ext/curb/curb.c +977 -977
- data/ext/curb/curb.h +52 -52
- data/ext/curb/curb_config.h +270 -270
- data/ext/curb/curb_easy.c +3437 -3434
- data/ext/curb/curb_easy.h +94 -94
- data/ext/curb/curb_errors.c +647 -647
- data/ext/curb/curb_errors.h +129 -129
- data/ext/curb/curb_macros.h +162 -162
- data/ext/curb/curb_multi.c +704 -702
- data/ext/curb/curb_multi.h +26 -26
- data/ext/curb/curb_postfield.c +523 -523
- data/ext/curb/curb_postfield.h +40 -40
- data/ext/curb/curb_upload.c +80 -80
- data/ext/curb/curb_upload.h +30 -30
- data/ext/curb-original/curb.c +977 -977
- data/ext/curb-original/curb.h +52 -52
- data/ext/curb-original/curb_config.h +238 -238
- data/ext/curb-original/curb_easy.c +3404 -3404
- data/ext/curb-original/curb_easy.h +90 -90
- data/ext/curb-original/curb_errors.c +647 -647
- data/ext/curb-original/curb_errors.h +129 -129
- data/ext/curb-original/curb_macros.h +159 -159
- data/ext/curb-original/curb_multi.c +633 -633
- data/ext/curb-original/curb_multi.h +26 -26
- data/ext/curb-original/curb_postfield.c +523 -523
- data/ext/curb-original/curb_postfield.h +40 -40
- data/ext/curb-original/curb_upload.c +80 -80
- data/ext/curb-original/curb_upload.h +30 -30
- data/lib/rhack/clients/base.rb +61 -10
- data/lib/rhack/clients/oauth.rb +4 -4
- data/lib/rhack/curl/easy.rb +1 -0
- data/lib/rhack/curl/global.rb +2 -0
- data/lib/rhack/curl/response.rb +4 -2
- data/lib/rhack/frame.rb +70 -32
- data/lib/rhack/js/browser/env.js +697 -697
- data/lib/rhack/js/browser/jquery.js +7180 -7180
- data/lib/rhack/js/browser/xmlsax.js +1564 -1564
- data/lib/rhack/js/browser/xmlw3cdom_1.js +1443 -1443
- data/lib/rhack/js/browser/xmlw3cdom_2.js +2744 -2744
- data/lib/rhack/page.rb +227 -68
- data/lib/rhack/scout.rb +52 -26
- data/lib/rhack/scout_squad.rb +10 -2
- data/lib/rhack/version.rb +1 -1
- data/rhack.gemspec +1 -1
- metadata +17 -17
@@ -1,1564 +1,1564 @@
|
|
1
|
-
// =========================================================================
|
2
|
-
//
|
3
|
-
// xmlsax.js - an XML SAX parser in JavaScript.
|
4
|
-
//
|
5
|
-
// version 3.1
|
6
|
-
//
|
7
|
-
// =========================================================================
|
8
|
-
//
|
9
|
-
// Copyright (C) 2001 - 2002 David Joham (djoham@yahoo.com) and Scott Severtson
|
10
|
-
//
|
11
|
-
// This library is free software; you can redistribute it and/or
|
12
|
-
// modify it under the terms of the GNU Lesser General Public
|
13
|
-
// License as published by the Free Software Foundation; either
|
14
|
-
// version 2.1 of the License, or (at your option) any later version.
|
15
|
-
|
16
|
-
// This library is distributed in the hope that it will be useful,
|
17
|
-
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18
|
-
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
19
|
-
// Lesser General Public License for more details.
|
20
|
-
|
21
|
-
// You should have received a copy of the GNU Lesser General Public
|
22
|
-
// License along with this library; if not, write to the Free Software
|
23
|
-
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
24
|
-
//
|
25
|
-
//
|
26
|
-
// Visit the XML for <SCRIPT> home page at http://xmljs.sourceforge.net
|
27
|
-
//
|
28
|
-
|
29
|
-
// CONSTANTS
|
30
|
-
|
31
|
-
// =========================================================================
|
32
|
-
// =========================================================================
|
33
|
-
// =========================================================================
|
34
|
-
var whitespace = "\n\r\t ";
|
35
|
-
|
36
|
-
|
37
|
-
/***************************************************************************************************************
|
38
|
-
XMLP is a pull-based parser. The calling application passes in a XML string
|
39
|
-
to the constructor, then repeatedly calls .next() to parse the next segment.
|
40
|
-
.next() returns a flag indicating what type of segment was found, and stores
|
41
|
-
data temporarily in couple member variables (name, content, array of
|
42
|
-
attributes), which can be accessed by several .get____() methods.
|
43
|
-
|
44
|
-
Basically, XMLP is the lowest common denominator parser - an very simple
|
45
|
-
API which other wrappers can be built against.
|
46
|
-
*****************************************************************************************************************/
|
47
|
-
|
48
|
-
|
49
|
-
XMLP = function(strXML) {
|
50
|
-
/*******************************************************************************************************************
|
51
|
-
function: this is the constructor to the XMLP Object
|
52
|
-
|
53
|
-
Author: Scott Severtson
|
54
|
-
|
55
|
-
Description:
|
56
|
-
Instantiates and initializes the object
|
57
|
-
*********************************************************************************************************************/
|
58
|
-
// Normalize line breaks
|
59
|
-
strXML = SAXStrings.replace(strXML, null, null, "\r\n", "\n");
|
60
|
-
strXML = SAXStrings.replace(strXML, null, null, "\r", "\n");
|
61
|
-
|
62
|
-
this.m_xml = strXML;
|
63
|
-
this.m_iP = 0;
|
64
|
-
this.m_iState = XMLP._STATE_PROLOG;
|
65
|
-
this.m_stack = new Stack();
|
66
|
-
this._clearAttributes();
|
67
|
-
|
68
|
-
} // end XMLP constructor
|
69
|
-
|
70
|
-
|
71
|
-
// CONSTANTS (these must be below the constructor)
|
72
|
-
|
73
|
-
// =========================================================================
|
74
|
-
// =========================================================================
|
75
|
-
// =========================================================================
|
76
|
-
|
77
|
-
XMLP._NONE = 0;
|
78
|
-
XMLP._ELM_B = 1;
|
79
|
-
XMLP._ELM_E = 2;
|
80
|
-
XMLP._ELM_EMP = 3;
|
81
|
-
XMLP._ATT = 4;
|
82
|
-
XMLP._TEXT = 5;
|
83
|
-
XMLP._ENTITY = 6;
|
84
|
-
XMLP._PI = 7;
|
85
|
-
XMLP._CDATA = 8;
|
86
|
-
XMLP._COMMENT = 9;
|
87
|
-
XMLP._DTD = 10;
|
88
|
-
XMLP._ERROR = 11;
|
89
|
-
|
90
|
-
XMLP._CONT_XML = 0;
|
91
|
-
XMLP._CONT_ALT = 1;
|
92
|
-
|
93
|
-
XMLP._ATT_NAME = 0;
|
94
|
-
XMLP._ATT_VAL = 1;
|
95
|
-
|
96
|
-
XMLP._STATE_PROLOG = 1;
|
97
|
-
XMLP._STATE_DOCUMENT = 2;
|
98
|
-
XMLP._STATE_MISC = 3;
|
99
|
-
|
100
|
-
XMLP._errs = new Array();
|
101
|
-
XMLP._errs[XMLP.ERR_CLOSE_PI = 0 ] = "PI: missing closing sequence";
|
102
|
-
XMLP._errs[XMLP.ERR_CLOSE_DTD = 1 ] = "DTD: missing closing sequence";
|
103
|
-
XMLP._errs[XMLP.ERR_CLOSE_COMMENT = 2 ] = "Comment: missing closing sequence";
|
104
|
-
XMLP._errs[XMLP.ERR_CLOSE_CDATA = 3 ] = "CDATA: missing closing sequence";
|
105
|
-
XMLP._errs[XMLP.ERR_CLOSE_ELM = 4 ] = "Element: missing closing sequence";
|
106
|
-
XMLP._errs[XMLP.ERR_CLOSE_ENTITY = 5 ] = "Entity: missing closing sequence";
|
107
|
-
XMLP._errs[XMLP.ERR_PI_TARGET = 6 ] = "PI: target is required";
|
108
|
-
XMLP._errs[XMLP.ERR_ELM_EMPTY = 7 ] = "Element: cannot be both empty and closing";
|
109
|
-
XMLP._errs[XMLP.ERR_ELM_NAME = 8 ] = "Element: name must immediatly follow \"<\"";
|
110
|
-
XMLP._errs[XMLP.ERR_ELM_LT_NAME = 9 ] = "Element: \"<\" not allowed in element names";
|
111
|
-
XMLP._errs[XMLP.ERR_ATT_VALUES = 10] = "Attribute: values are required and must be in quotes";
|
112
|
-
XMLP._errs[XMLP.ERR_ATT_LT_NAME = 11] = "Element: \"<\" not allowed in attribute names";
|
113
|
-
XMLP._errs[XMLP.ERR_ATT_LT_VALUE = 12] = "Attribute: \"<\" not allowed in attribute values";
|
114
|
-
XMLP._errs[XMLP.ERR_ATT_DUP = 13] = "Attribute: duplicate attributes not allowed";
|
115
|
-
XMLP._errs[XMLP.ERR_ENTITY_UNKNOWN = 14] = "Entity: unknown entity";
|
116
|
-
XMLP._errs[XMLP.ERR_INFINITELOOP = 15] = "Infininte loop";
|
117
|
-
XMLP._errs[XMLP.ERR_DOC_STRUCTURE = 16] = "Document: only comments, processing instructions, or whitespace allowed outside of document element";
|
118
|
-
XMLP._errs[XMLP.ERR_ELM_NESTING = 17] = "Element: must be nested correctly";
|
119
|
-
|
120
|
-
// =========================================================================
|
121
|
-
// =========================================================================
|
122
|
-
// =========================================================================
|
123
|
-
|
124
|
-
|
125
|
-
XMLP.prototype._addAttribute = function(name, value) {
|
126
|
-
/*******************************************************************************************************************
|
127
|
-
function: _addAttribute
|
128
|
-
|
129
|
-
Author: Scott Severtson
|
130
|
-
*********************************************************************************************************************/
|
131
|
-
this.m_atts[this.m_atts.length] = new Array(name, value);
|
132
|
-
} // end function _addAttribute
|
133
|
-
|
134
|
-
|
135
|
-
XMLP.prototype._checkStructure = function(iEvent) {
|
136
|
-
/*******************************************************************************************************************
|
137
|
-
function: _checkStructure
|
138
|
-
|
139
|
-
Author: Scott Severtson
|
140
|
-
*********************************************************************************************************************/
|
141
|
-
|
142
|
-
if(XMLP._STATE_PROLOG == this.m_iState) {
|
143
|
-
if((XMLP._TEXT == iEvent) || (XMLP._ENTITY == iEvent)) {
|
144
|
-
if(SAXStrings.indexOfNonWhitespace(this.getContent(), this.getContentBegin(), this.getContentEnd()) != -1) {
|
145
|
-
return this._setErr(XMLP.ERR_DOC_STRUCTURE);
|
146
|
-
}
|
147
|
-
}
|
148
|
-
|
149
|
-
if((XMLP._ELM_B == iEvent) || (XMLP._ELM_EMP == iEvent)) {
|
150
|
-
this.m_iState = XMLP._STATE_DOCUMENT;
|
151
|
-
// Don't return - fall through to next state
|
152
|
-
}
|
153
|
-
}
|
154
|
-
if(XMLP._STATE_DOCUMENT == this.m_iState) {
|
155
|
-
if((XMLP._ELM_B == iEvent) || (XMLP._ELM_EMP == iEvent)) {
|
156
|
-
this.m_stack.push(this.getName());
|
157
|
-
}
|
158
|
-
|
159
|
-
if((XMLP._ELM_E == iEvent) || (XMLP._ELM_EMP == iEvent)) {
|
160
|
-
var strTop = this.m_stack.pop();
|
161
|
-
if((strTop == null) || (strTop != this.getName())) {
|
162
|
-
return this._setErr(XMLP.ERR_ELM_NESTING);
|
163
|
-
}
|
164
|
-
}
|
165
|
-
|
166
|
-
if(this.m_stack.count() == 0) {
|
167
|
-
this.m_iState = XMLP._STATE_MISC;
|
168
|
-
return iEvent;
|
169
|
-
}
|
170
|
-
}
|
171
|
-
if(XMLP._STATE_MISC == this.m_iState) {
|
172
|
-
if((XMLP._ELM_B == iEvent) || (XMLP._ELM_E == iEvent) || (XMLP._ELM_EMP == iEvent) || (XMLP.EVT_DTD == iEvent)) {
|
173
|
-
return this._setErr(XMLP.ERR_DOC_STRUCTURE);
|
174
|
-
}
|
175
|
-
|
176
|
-
if((XMLP._TEXT == iEvent) || (XMLP._ENTITY == iEvent)) {
|
177
|
-
if(SAXStrings.indexOfNonWhitespace(this.getContent(), this.getContentBegin(), this.getContentEnd()) != -1) {
|
178
|
-
return this._setErr(XMLP.ERR_DOC_STRUCTURE);
|
179
|
-
}
|
180
|
-
}
|
181
|
-
}
|
182
|
-
|
183
|
-
return iEvent;
|
184
|
-
|
185
|
-
} // end function _checkStructure
|
186
|
-
|
187
|
-
|
188
|
-
XMLP.prototype._clearAttributes = function() {
|
189
|
-
/*******************************************************************************************************************
|
190
|
-
function: _clearAttributes
|
191
|
-
|
192
|
-
Author: Scott Severtson
|
193
|
-
*********************************************************************************************************************/
|
194
|
-
this.m_atts = new Array();
|
195
|
-
} // end function _clearAttributes
|
196
|
-
|
197
|
-
|
198
|
-
XMLP.prototype._findAttributeIndex = function(name) {
|
199
|
-
/*******************************************************************************************************************
|
200
|
-
function: findAttributeIndex
|
201
|
-
|
202
|
-
Author: Scott Severtson
|
203
|
-
*********************************************************************************************************************/
|
204
|
-
for(var i = 0; i < this.m_atts.length; i++) {
|
205
|
-
if(this.m_atts[i][XMLP._ATT_NAME] == name) {
|
206
|
-
return i;
|
207
|
-
}
|
208
|
-
}
|
209
|
-
return -1;
|
210
|
-
|
211
|
-
} // end function _findAttributeIndex
|
212
|
-
|
213
|
-
|
214
|
-
XMLP.prototype.getAttributeCount = function() {
|
215
|
-
/*******************************************************************************************************************
|
216
|
-
function: getAttributeCount
|
217
|
-
|
218
|
-
Author: Scott Severtson
|
219
|
-
*********************************************************************************************************************/
|
220
|
-
|
221
|
-
return this.m_atts ? this.m_atts.length : 0;
|
222
|
-
|
223
|
-
} // end function getAttributeCount()
|
224
|
-
|
225
|
-
|
226
|
-
XMLP.prototype.getAttributeName = function(index) {
|
227
|
-
/*******************************************************************************************************************
|
228
|
-
function: getAttributeName
|
229
|
-
|
230
|
-
Author: Scott Severtson
|
231
|
-
*********************************************************************************************************************/
|
232
|
-
|
233
|
-
return ((index < 0) || (index >= this.m_atts.length)) ? null : this.m_atts[index][XMLP._ATT_NAME];
|
234
|
-
|
235
|
-
} //end function getAttributeName
|
236
|
-
|
237
|
-
|
238
|
-
XMLP.prototype.getAttributeValue = function(index) {
|
239
|
-
/*******************************************************************************************************************
|
240
|
-
function: getAttributeValue
|
241
|
-
|
242
|
-
Author: Scott Severtson
|
243
|
-
*********************************************************************************************************************/
|
244
|
-
|
245
|
-
return ((index < 0) || (index >= this.m_atts.length)) ? null : __unescapeString(this.m_atts[index][XMLP._ATT_VAL]);
|
246
|
-
|
247
|
-
} // end function getAttributeValue
|
248
|
-
|
249
|
-
|
250
|
-
XMLP.prototype.getAttributeValueByName = function(name) {
|
251
|
-
/*******************************************************************************************************************
|
252
|
-
function: getAttributeValueByName
|
253
|
-
|
254
|
-
Author: Scott Severtson
|
255
|
-
*********************************************************************************************************************/
|
256
|
-
|
257
|
-
return this.getAttributeValue(this._findAttributeIndex(name));
|
258
|
-
|
259
|
-
} // end function getAttributeValueByName
|
260
|
-
|
261
|
-
|
262
|
-
XMLP.prototype.getColumnNumber = function() {
|
263
|
-
/*******************************************************************************************************************
|
264
|
-
function: getColumnNumber
|
265
|
-
|
266
|
-
Author: Scott Severtson
|
267
|
-
*********************************************************************************************************************/
|
268
|
-
|
269
|
-
return SAXStrings.getColumnNumber(this.m_xml, this.m_iP);
|
270
|
-
|
271
|
-
} // end function getColumnNumber
|
272
|
-
|
273
|
-
|
274
|
-
XMLP.prototype.getContent = function() {
|
275
|
-
/*******************************************************************************************************************
|
276
|
-
function: getContent
|
277
|
-
|
278
|
-
Author: Scott Severtson
|
279
|
-
*********************************************************************************************************************/
|
280
|
-
|
281
|
-
return (this.m_cSrc == XMLP._CONT_XML) ? this.m_xml : this.m_cAlt;
|
282
|
-
|
283
|
-
} //end function getContent
|
284
|
-
|
285
|
-
|
286
|
-
XMLP.prototype.getContentBegin = function() {
|
287
|
-
/*******************************************************************************************************************
|
288
|
-
function: getContentBegin
|
289
|
-
|
290
|
-
Author: Scott Severtson
|
291
|
-
*********************************************************************************************************************/
|
292
|
-
|
293
|
-
return this.m_cB;
|
294
|
-
|
295
|
-
} //end function getContentBegin
|
296
|
-
|
297
|
-
|
298
|
-
XMLP.prototype.getContentEnd = function() {
|
299
|
-
/*******************************************************************************************************************
|
300
|
-
function: getContentEnd
|
301
|
-
|
302
|
-
Author: Scott Severtson
|
303
|
-
*********************************************************************************************************************/
|
304
|
-
|
305
|
-
return this.m_cE;
|
306
|
-
|
307
|
-
} // end function getContentEnd
|
308
|
-
|
309
|
-
|
310
|
-
XMLP.prototype.getLineNumber = function() {
|
311
|
-
/*******************************************************************************************************************
|
312
|
-
function: getLineNumber
|
313
|
-
|
314
|
-
Author: Scott Severtson
|
315
|
-
*********************************************************************************************************************/
|
316
|
-
|
317
|
-
return SAXStrings.getLineNumber(this.m_xml, this.m_iP);
|
318
|
-
|
319
|
-
} // end function getLineNumber
|
320
|
-
|
321
|
-
|
322
|
-
XMLP.prototype.getName = function() {
|
323
|
-
/*******************************************************************************************************************
|
324
|
-
function: getName
|
325
|
-
|
326
|
-
Author: Scott Severtson
|
327
|
-
*********************************************************************************************************************/
|
328
|
-
|
329
|
-
return this.m_name;
|
330
|
-
|
331
|
-
} // end function getName()
|
332
|
-
|
333
|
-
|
334
|
-
XMLP.prototype.next = function() {
|
335
|
-
/*******************************************************************************************************************
|
336
|
-
function: next
|
337
|
-
|
338
|
-
Author: Scott Severtson
|
339
|
-
*********************************************************************************************************************/
|
340
|
-
|
341
|
-
return this._checkStructure(this._parse());
|
342
|
-
|
343
|
-
} // end function next()
|
344
|
-
|
345
|
-
|
346
|
-
XMLP.prototype._parse = function() {
|
347
|
-
/*******************************************************************************************************************
|
348
|
-
function: _parse
|
349
|
-
|
350
|
-
Author: Scott Severtson
|
351
|
-
*********************************************************************************************************************/
|
352
|
-
|
353
|
-
if(this.m_iP == this.m_xml.length) {
|
354
|
-
return XMLP._NONE;
|
355
|
-
}
|
356
|
-
|
357
|
-
if(this.m_iP == this.m_xml.indexOf("<?", this.m_iP)) {
|
358
|
-
return this._parsePI (this.m_iP + 2);
|
359
|
-
}
|
360
|
-
else if(this.m_iP == this.m_xml.indexOf("<!DOCTYPE", this.m_iP)) {
|
361
|
-
return this._parseDTD (this.m_iP + 9);
|
362
|
-
}
|
363
|
-
else if(this.m_iP == this.m_xml.indexOf("<!--", this.m_iP)) {
|
364
|
-
return this._parseComment(this.m_iP + 4);
|
365
|
-
}
|
366
|
-
else if(this.m_iP == this.m_xml.indexOf("<![CDATA[", this.m_iP)) {
|
367
|
-
return this._parseCDATA (this.m_iP + 9);
|
368
|
-
}
|
369
|
-
else if(this.m_iP == this.m_xml.indexOf("<", this.m_iP)) {
|
370
|
-
return this._parseElement(this.m_iP + 1);
|
371
|
-
}
|
372
|
-
else if(this.m_iP == this.m_xml.indexOf("&", this.m_iP)) {
|
373
|
-
return this._parseEntity (this.m_iP + 1);
|
374
|
-
}
|
375
|
-
else{
|
376
|
-
return this._parseText (this.m_iP);
|
377
|
-
}
|
378
|
-
|
379
|
-
|
380
|
-
} // end function _parse
|
381
|
-
|
382
|
-
|
383
|
-
XMLP.prototype._parseAttribute = function(iB, iE) {
|
384
|
-
/*******************************************************************************************************************
|
385
|
-
function: _parseAttribute
|
386
|
-
|
387
|
-
Author: Scott Severtson
|
388
|
-
*********************************************************************************************************************/
|
389
|
-
var iNB, iNE, iEq, iVB, iVE;
|
390
|
-
var cQuote, strN, strV;
|
391
|
-
|
392
|
-
this.m_cAlt = ""; //resets the value so we don't use an old one by accident (see testAttribute7 in the test suite)
|
393
|
-
|
394
|
-
iNB = SAXStrings.indexOfNonWhitespace(this.m_xml, iB, iE);
|
395
|
-
if((iNB == -1) ||(iNB >= iE)) {
|
396
|
-
return iNB;
|
397
|
-
}
|
398
|
-
|
399
|
-
iEq = this.m_xml.indexOf("=", iNB);
|
400
|
-
if((iEq == -1) || (iEq > iE)) {
|
401
|
-
return this._setErr(XMLP.ERR_ATT_VALUES);
|
402
|
-
}
|
403
|
-
|
404
|
-
iNE = SAXStrings.lastIndexOfNonWhitespace(this.m_xml, iNB, iEq);
|
405
|
-
|
406
|
-
iVB = SAXStrings.indexOfNonWhitespace(this.m_xml, iEq + 1, iE);
|
407
|
-
if((iVB == -1) ||(iVB > iE)) {
|
408
|
-
return this._setErr(XMLP.ERR_ATT_VALUES);
|
409
|
-
}
|
410
|
-
|
411
|
-
cQuote = this.m_xml.charAt(iVB);
|
412
|
-
if(SAXStrings.QUOTES.indexOf(cQuote) == -1) {
|
413
|
-
return this._setErr(XMLP.ERR_ATT_VALUES);
|
414
|
-
}
|
415
|
-
|
416
|
-
iVE = this.m_xml.indexOf(cQuote, iVB + 1);
|
417
|
-
if((iVE == -1) ||(iVE > iE)) {
|
418
|
-
return this._setErr(XMLP.ERR_ATT_VALUES);
|
419
|
-
}
|
420
|
-
|
421
|
-
strN = this.m_xml.substring(iNB, iNE + 1);
|
422
|
-
strV = this.m_xml.substring(iVB + 1, iVE);
|
423
|
-
|
424
|
-
if(strN.indexOf("<") != -1) {
|
425
|
-
return this._setErr(XMLP.ERR_ATT_LT_NAME);
|
426
|
-
}
|
427
|
-
|
428
|
-
if(strV.indexOf("<") != -1) {
|
429
|
-
return this._setErr(XMLP.ERR_ATT_LT_VALUE);
|
430
|
-
}
|
431
|
-
|
432
|
-
strV = SAXStrings.replace(strV, null, null, "\n", " ");
|
433
|
-
strV = SAXStrings.replace(strV, null, null, "\t", " ");
|
434
|
-
iRet = this._replaceEntities(strV);
|
435
|
-
if(iRet == XMLP._ERROR) {
|
436
|
-
return iRet;
|
437
|
-
}
|
438
|
-
|
439
|
-
strV = this.m_cAlt;
|
440
|
-
|
441
|
-
if(this._findAttributeIndex(strN) == -1) {
|
442
|
-
this._addAttribute(strN, strV);
|
443
|
-
}
|
444
|
-
else {
|
445
|
-
return this._setErr(XMLP.ERR_ATT_DUP);
|
446
|
-
}
|
447
|
-
|
448
|
-
this.m_iP = iVE + 2;
|
449
|
-
|
450
|
-
return XMLP._ATT;
|
451
|
-
|
452
|
-
} // end function _parseAttribute
|
453
|
-
|
454
|
-
|
455
|
-
XMLP.prototype._parseCDATA = function(iB) {
|
456
|
-
/*******************************************************************************************************************
|
457
|
-
function: _parseCDATA
|
458
|
-
|
459
|
-
Author: Scott Severtson
|
460
|
-
*********************************************************************************************************************/
|
461
|
-
var iE = this.m_xml.indexOf("]]>", iB);
|
462
|
-
if (iE == -1) {
|
463
|
-
return this._setErr(XMLP.ERR_CLOSE_CDATA);
|
464
|
-
}
|
465
|
-
|
466
|
-
this._setContent(XMLP._CONT_XML, iB, iE);
|
467
|
-
|
468
|
-
this.m_iP = iE + 3;
|
469
|
-
|
470
|
-
return XMLP._CDATA;
|
471
|
-
|
472
|
-
} // end function _parseCDATA
|
473
|
-
|
474
|
-
|
475
|
-
XMLP.prototype._parseComment = function(iB) {
|
476
|
-
/*******************************************************************************************************************
|
477
|
-
function: _parseComment
|
478
|
-
|
479
|
-
Author: Scott Severtson
|
480
|
-
*********************************************************************************************************************/
|
481
|
-
var iE = this.m_xml.indexOf("-" + "->", iB);
|
482
|
-
if (iE == -1) {
|
483
|
-
return this._setErr(XMLP.ERR_CLOSE_COMMENT);
|
484
|
-
}
|
485
|
-
|
486
|
-
this._setContent(XMLP._CONT_XML, iB, iE);
|
487
|
-
|
488
|
-
this.m_iP = iE + 3;
|
489
|
-
|
490
|
-
return XMLP._COMMENT;
|
491
|
-
|
492
|
-
} // end function _parseComment
|
493
|
-
|
494
|
-
|
495
|
-
XMLP.prototype._parseDTD = function(iB) {
|
496
|
-
/*******************************************************************************************************************
|
497
|
-
function: _parseDTD
|
498
|
-
|
499
|
-
Author: Scott Severtson
|
500
|
-
*********************************************************************************************************************/
|
501
|
-
|
502
|
-
// Eat DTD
|
503
|
-
|
504
|
-
var iE, strClose, iInt, iLast;
|
505
|
-
|
506
|
-
iE = this.m_xml.indexOf(">", iB);
|
507
|
-
if(iE == -1) {
|
508
|
-
return this._setErr(XMLP.ERR_CLOSE_DTD);
|
509
|
-
}
|
510
|
-
|
511
|
-
iInt = this.m_xml.indexOf("[", iB);
|
512
|
-
strClose = ((iInt != -1) && (iInt < iE)) ? "]>" : ">";
|
513
|
-
|
514
|
-
while(true) {
|
515
|
-
// DEBUG: Remove
|
516
|
-
if(iE == iLast) {
|
517
|
-
return this._setErr(XMLP.ERR_INFINITELOOP);
|
518
|
-
}
|
519
|
-
|
520
|
-
iLast = iE;
|
521
|
-
// DEBUG: Remove End
|
522
|
-
|
523
|
-
iE = this.m_xml.indexOf(strClose, iB);
|
524
|
-
if(iE == -1) {
|
525
|
-
return this._setErr(XMLP.ERR_CLOSE_DTD);
|
526
|
-
}
|
527
|
-
|
528
|
-
// Make sure it is not the end of a CDATA section
|
529
|
-
if (this.m_xml.substring(iE - 1, iE + 2) != "]]>") {
|
530
|
-
break;
|
531
|
-
}
|
532
|
-
}
|
533
|
-
|
534
|
-
this.m_iP = iE + strClose.length;
|
535
|
-
|
536
|
-
return XMLP._DTD;
|
537
|
-
|
538
|
-
} // end function _parseDTD
|
539
|
-
|
540
|
-
|
541
|
-
XMLP.prototype._parseElement = function(iB) {
|
542
|
-
/*******************************************************************************************************************
|
543
|
-
function: _parseElement
|
544
|
-
|
545
|
-
Author: Scott Severtson
|
546
|
-
*********************************************************************************************************************/
|
547
|
-
var iE, iDE, iNE, iRet;
|
548
|
-
var iType, strN, iLast;
|
549
|
-
|
550
|
-
iDE = iE = this.m_xml.indexOf(">", iB);
|
551
|
-
if(iE == -1) {
|
552
|
-
return this._setErr(XMLP.ERR_CLOSE_ELM);
|
553
|
-
}
|
554
|
-
|
555
|
-
if(this.m_xml.charAt(iB) == "/") {
|
556
|
-
iType = XMLP._ELM_E;
|
557
|
-
iB++;
|
558
|
-
} else {
|
559
|
-
iType = XMLP._ELM_B;
|
560
|
-
}
|
561
|
-
|
562
|
-
if(this.m_xml.charAt(iE - 1) == "/") {
|
563
|
-
if(iType == XMLP._ELM_E) {
|
564
|
-
return this._setErr(XMLP.ERR_ELM_EMPTY);
|
565
|
-
}
|
566
|
-
iType = XMLP._ELM_EMP;
|
567
|
-
iDE--;
|
568
|
-
}
|
569
|
-
|
570
|
-
iDE = SAXStrings.lastIndexOfNonWhitespace(this.m_xml, iB, iDE);
|
571
|
-
|
572
|
-
//djohack
|
573
|
-
//hack to allow for elements with single character names to be recognized
|
574
|
-
|
575
|
-
if (iE - iB != 1 ) {
|
576
|
-
if(SAXStrings.indexOfNonWhitespace(this.m_xml, iB, iDE) != iB) {
|
577
|
-
return this._setErr(XMLP.ERR_ELM_NAME);
|
578
|
-
}
|
579
|
-
}
|
580
|
-
// end hack -- original code below
|
581
|
-
|
582
|
-
/*
|
583
|
-
if(SAXStrings.indexOfNonWhitespace(this.m_xml, iB, iDE) != iB)
|
584
|
-
return this._setErr(XMLP.ERR_ELM_NAME);
|
585
|
-
*/
|
586
|
-
this._clearAttributes();
|
587
|
-
|
588
|
-
iNE = SAXStrings.indexOfWhitespace(this.m_xml, iB, iDE);
|
589
|
-
if(iNE == -1) {
|
590
|
-
iNE = iDE + 1;
|
591
|
-
}
|
592
|
-
else {
|
593
|
-
this.m_iP = iNE;
|
594
|
-
while(this.m_iP < iDE) {
|
595
|
-
// DEBUG: Remove
|
596
|
-
if(this.m_iP == iLast) return this._setErr(XMLP.ERR_INFINITELOOP);
|
597
|
-
iLast = this.m_iP;
|
598
|
-
// DEBUG: Remove End
|
599
|
-
|
600
|
-
|
601
|
-
iRet = this._parseAttribute(this.m_iP, iDE);
|
602
|
-
if(iRet == XMLP._ERROR) return iRet;
|
603
|
-
}
|
604
|
-
}
|
605
|
-
|
606
|
-
strN = this.m_xml.substring(iB, iNE);
|
607
|
-
|
608
|
-
if(strN.indexOf("<") != -1) {
|
609
|
-
return this._setErr(XMLP.ERR_ELM_LT_NAME);
|
610
|
-
}
|
611
|
-
|
612
|
-
this.m_name = strN;
|
613
|
-
this.m_iP = iE + 1;
|
614
|
-
|
615
|
-
return iType;
|
616
|
-
|
617
|
-
} // end function _parseElement
|
618
|
-
|
619
|
-
|
620
|
-
XMLP.prototype._parseEntity = function(iB) {
|
621
|
-
/*******************************************************************************************************************
|
622
|
-
function: _parseEntity
|
623
|
-
|
624
|
-
Author: Scott Severtson
|
625
|
-
*********************************************************************************************************************/
|
626
|
-
var iE = this.m_xml.indexOf(";", iB);
|
627
|
-
if(iE == -1) {
|
628
|
-
return this._setErr(XMLP.ERR_CLOSE_ENTITY);
|
629
|
-
}
|
630
|
-
|
631
|
-
this.m_iP = iE + 1;
|
632
|
-
|
633
|
-
return this._replaceEntity(this.m_xml, iB, iE);
|
634
|
-
|
635
|
-
} // end function _parseEntity
|
636
|
-
|
637
|
-
|
638
|
-
XMLP.prototype._parsePI = function(iB) {
|
639
|
-
/*******************************************************************************************************************
|
640
|
-
function: _parsePI
|
641
|
-
|
642
|
-
Author: Scott Severtson
|
643
|
-
*********************************************************************************************************************/
|
644
|
-
|
645
|
-
var iE, iTB, iTE, iCB, iCE;
|
646
|
-
|
647
|
-
iE = this.m_xml.indexOf("?>", iB);
|
648
|
-
if(iE == -1) {
|
649
|
-
return this._setErr(XMLP.ERR_CLOSE_PI);
|
650
|
-
}
|
651
|
-
|
652
|
-
iTB = SAXStrings.indexOfNonWhitespace(this.m_xml, iB, iE);
|
653
|
-
if(iTB == -1) {
|
654
|
-
return this._setErr(XMLP.ERR_PI_TARGET);
|
655
|
-
}
|
656
|
-
|
657
|
-
iTE = SAXStrings.indexOfWhitespace(this.m_xml, iTB, iE);
|
658
|
-
if(iTE == -1) {
|
659
|
-
iTE = iE;
|
660
|
-
}
|
661
|
-
|
662
|
-
iCB = SAXStrings.indexOfNonWhitespace(this.m_xml, iTE, iE);
|
663
|
-
if(iCB == -1) {
|
664
|
-
iCB = iE;
|
665
|
-
}
|
666
|
-
|
667
|
-
iCE = SAXStrings.lastIndexOfNonWhitespace(this.m_xml, iCB, iE);
|
668
|
-
if(iCE == -1) {
|
669
|
-
iCE = iE - 1;
|
670
|
-
}
|
671
|
-
|
672
|
-
this.m_name = this.m_xml.substring(iTB, iTE);
|
673
|
-
this._setContent(XMLP._CONT_XML, iCB, iCE + 1);
|
674
|
-
this.m_iP = iE + 2;
|
675
|
-
|
676
|
-
return XMLP._PI;
|
677
|
-
|
678
|
-
} // end function _parsePI
|
679
|
-
|
680
|
-
|
681
|
-
XMLP.prototype._parseText = function(iB) {
|
682
|
-
/*******************************************************************************************************************
|
683
|
-
function: _parseText
|
684
|
-
|
685
|
-
Author: Scott Severtson
|
686
|
-
*********************************************************************************************************************/
|
687
|
-
var iE, iEE;
|
688
|
-
|
689
|
-
iE = this.m_xml.indexOf("<", iB);
|
690
|
-
if(iE == -1) {
|
691
|
-
iE = this.m_xml.length;
|
692
|
-
}
|
693
|
-
|
694
|
-
iEE = this.m_xml.indexOf("&", iB);
|
695
|
-
if((iEE != -1) && (iEE <= iE)) {
|
696
|
-
iE = iEE;
|
697
|
-
}
|
698
|
-
|
699
|
-
this._setContent(XMLP._CONT_XML, iB, iE);
|
700
|
-
|
701
|
-
this.m_iP = iE;
|
702
|
-
|
703
|
-
return XMLP._TEXT;
|
704
|
-
|
705
|
-
} // end function _parseText
|
706
|
-
|
707
|
-
|
708
|
-
XMLP.prototype._replaceEntities = function(strD, iB, iE) {
|
709
|
-
/*******************************************************************************************************************
|
710
|
-
function: _replaceEntities
|
711
|
-
|
712
|
-
Author: Scott Severtson
|
713
|
-
*********************************************************************************************************************/
|
714
|
-
if(SAXStrings.isEmpty(strD)) return "";
|
715
|
-
iB = iB || 0;
|
716
|
-
iE = iE || strD.length;
|
717
|
-
|
718
|
-
|
719
|
-
var iEB, iEE, strRet = "";
|
720
|
-
|
721
|
-
iEB = strD.indexOf("&", iB);
|
722
|
-
iEE = iB;
|
723
|
-
|
724
|
-
while((iEB > 0) && (iEB < iE)) {
|
725
|
-
strRet += strD.substring(iEE, iEB);
|
726
|
-
|
727
|
-
iEE = strD.indexOf(";", iEB) + 1;
|
728
|
-
|
729
|
-
if((iEE == 0) || (iEE > iE)) {
|
730
|
-
return this._setErr(XMLP.ERR_CLOSE_ENTITY);
|
731
|
-
}
|
732
|
-
|
733
|
-
iRet = this._replaceEntity(strD, iEB + 1, iEE - 1);
|
734
|
-
if(iRet == XMLP._ERROR) {
|
735
|
-
return iRet;
|
736
|
-
}
|
737
|
-
|
738
|
-
strRet += this.m_cAlt;
|
739
|
-
|
740
|
-
iEB = strD.indexOf("&", iEE);
|
741
|
-
}
|
742
|
-
|
743
|
-
if(iEE != iE) {
|
744
|
-
strRet += strD.substring(iEE, iE);
|
745
|
-
}
|
746
|
-
|
747
|
-
this._setContent(XMLP._CONT_ALT, strRet);
|
748
|
-
|
749
|
-
return XMLP._ENTITY;
|
750
|
-
|
751
|
-
} // end function _replaceEntities
|
752
|
-
|
753
|
-
|
754
|
-
XMLP.prototype._replaceEntity = function(strD, iB, iE) {
|
755
|
-
/*******************************************************************************************************************
|
756
|
-
function: _replaceEntity
|
757
|
-
|
758
|
-
Author: Scott Severtson
|
759
|
-
*********************************************************************************************************************/
|
760
|
-
if(SAXStrings.isEmpty(strD)) return -1;
|
761
|
-
iB = iB || 0;
|
762
|
-
iE = iE || strD.length;
|
763
|
-
|
764
|
-
switch(strD.substring(iB, iE)) {
|
765
|
-
case "amp": strEnt = "&"; break;
|
766
|
-
case "lt": strEnt = "<"; break;
|
767
|
-
case "gt": strEnt = ">"; break;
|
768
|
-
case "apos": strEnt = "'"; break;
|
769
|
-
case "quot": strEnt = "\""; break;
|
770
|
-
default:
|
771
|
-
if(strD.charAt(iB) == "#") {
|
772
|
-
strEnt = String.fromCharCode(parseInt(strD.substring(iB + 1, iE)));
|
773
|
-
} else {
|
774
|
-
return this._setErr(XMLP.ERR_ENTITY_UNKNOWN);
|
775
|
-
}
|
776
|
-
break;
|
777
|
-
}
|
778
|
-
this._setContent(XMLP._CONT_ALT, strEnt);
|
779
|
-
|
780
|
-
return XMLP._ENTITY;
|
781
|
-
} // end function _replaceEntity
|
782
|
-
|
783
|
-
|
784
|
-
XMLP.prototype._setContent = function(iSrc) {
|
785
|
-
/*******************************************************************************************************************
|
786
|
-
function: _setContent
|
787
|
-
|
788
|
-
Author: Scott Severtson
|
789
|
-
*********************************************************************************************************************/
|
790
|
-
var args = arguments;
|
791
|
-
|
792
|
-
if(XMLP._CONT_XML == iSrc) {
|
793
|
-
this.m_cAlt = null;
|
794
|
-
this.m_cB = args[1];
|
795
|
-
this.m_cE = args[2];
|
796
|
-
} else {
|
797
|
-
this.m_cAlt = args[1];
|
798
|
-
this.m_cB = 0;
|
799
|
-
this.m_cE = args[1].length;
|
800
|
-
}
|
801
|
-
this.m_cSrc = iSrc;
|
802
|
-
|
803
|
-
} // end function _setContent
|
804
|
-
|
805
|
-
|
806
|
-
XMLP.prototype._setErr = function(iErr) {
|
807
|
-
/*******************************************************************************************************************
|
808
|
-
function: _setErr
|
809
|
-
|
810
|
-
Author: Scott Severtson
|
811
|
-
*********************************************************************************************************************/
|
812
|
-
var strErr = XMLP._errs[iErr];
|
813
|
-
|
814
|
-
this.m_cAlt = strErr;
|
815
|
-
this.m_cB = 0;
|
816
|
-
this.m_cE = strErr.length;
|
817
|
-
this.m_cSrc = XMLP._CONT_ALT;
|
818
|
-
|
819
|
-
return XMLP._ERROR;
|
820
|
-
|
821
|
-
} // end function _setErr
|
822
|
-
|
823
|
-
|
824
|
-
|
825
|
-
|
826
|
-
|
827
|
-
|
828
|
-
/***************************************************************************************************************
|
829
|
-
SAXDriver is an object that basically wraps an XMLP instance, and provides an
|
830
|
-
event-based interface for parsing. This is the object users interact with when coding
|
831
|
-
with XML for <SCRIPT>
|
832
|
-
*****************************************************************************************************************/
|
833
|
-
|
834
|
-
|
835
|
-
SAXDriver = function() {
|
836
|
-
/*******************************************************************************************************************
|
837
|
-
function: SAXDriver
|
838
|
-
|
839
|
-
Author: Scott Severtson
|
840
|
-
|
841
|
-
Description:
|
842
|
-
This is the constructor for the SAXDriver Object
|
843
|
-
*********************************************************************************************************************/
|
844
|
-
this.m_hndDoc = null;
|
845
|
-
this.m_hndErr = null;
|
846
|
-
this.m_hndLex = null;
|
847
|
-
}
|
848
|
-
|
849
|
-
|
850
|
-
// CONSTANTS (these must be below the constructor)
|
851
|
-
|
852
|
-
// =========================================================================
|
853
|
-
// =========================================================================
|
854
|
-
// =========================================================================
|
855
|
-
SAXDriver.DOC_B = 1;
|
856
|
-
SAXDriver.DOC_E = 2;
|
857
|
-
SAXDriver.ELM_B = 3;
|
858
|
-
SAXDriver.ELM_E = 4;
|
859
|
-
SAXDriver.CHARS = 5;
|
860
|
-
SAXDriver.PI = 6;
|
861
|
-
SAXDriver.CD_B = 7;
|
862
|
-
SAXDriver.CD_E = 8;
|
863
|
-
SAXDriver.CMNT = 9;
|
864
|
-
SAXDriver.DTD_B = 10;
|
865
|
-
SAXDriver.DTD_E = 11;
|
866
|
-
// =========================================================================
|
867
|
-
// =========================================================================
|
868
|
-
// =========================================================================
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
SAXDriver.prototype.parse = function(strD) {
|
873
|
-
/*******************************************************************************************************************
|
874
|
-
function: parse
|
875
|
-
|
876
|
-
Author: Scott Severtson
|
877
|
-
*********************************************************************************************************************/
|
878
|
-
var parser = new XMLP(strD);
|
879
|
-
|
880
|
-
if(this.m_hndDoc && this.m_hndDoc.setDocumentLocator) {
|
881
|
-
this.m_hndDoc.setDocumentLocator(this);
|
882
|
-
}
|
883
|
-
|
884
|
-
this.m_parser = parser;
|
885
|
-
this.m_bErr = false;
|
886
|
-
|
887
|
-
if(!this.m_bErr) {
|
888
|
-
this._fireEvent(SAXDriver.DOC_B);
|
889
|
-
}
|
890
|
-
this._parseLoop();
|
891
|
-
if(!this.m_bErr) {
|
892
|
-
this._fireEvent(SAXDriver.DOC_E);
|
893
|
-
}
|
894
|
-
|
895
|
-
this.m_xml = null;
|
896
|
-
this.m_iP = 0;
|
897
|
-
|
898
|
-
} // end function parse
|
899
|
-
|
900
|
-
|
901
|
-
SAXDriver.prototype.setDocumentHandler = function(hnd) {
|
902
|
-
/*******************************************************************************************************************
|
903
|
-
function: setDocumentHandler
|
904
|
-
|
905
|
-
Author: Scott Severtson
|
906
|
-
*********************************************************************************************************************/
|
907
|
-
|
908
|
-
this.m_hndDoc = hnd;
|
909
|
-
|
910
|
-
} // end function setDocumentHandler
|
911
|
-
|
912
|
-
|
913
|
-
SAXDriver.prototype.setErrorHandler = function(hnd) {
|
914
|
-
/*******************************************************************************************************************
|
915
|
-
function: setErrorHandler
|
916
|
-
|
917
|
-
Author: Scott Severtson
|
918
|
-
*********************************************************************************************************************/
|
919
|
-
|
920
|
-
this.m_hndErr = hnd;
|
921
|
-
|
922
|
-
} // end function setErrorHandler
|
923
|
-
|
924
|
-
|
925
|
-
SAXDriver.prototype.setLexicalHandler = function(hnd) {
|
926
|
-
/*******************************************************************************************************************
|
927
|
-
function: setLexicalHandler
|
928
|
-
|
929
|
-
Author: Scott Severtson
|
930
|
-
*********************************************************************************************************************/
|
931
|
-
|
932
|
-
this.m_hndLex = hnd;
|
933
|
-
|
934
|
-
} // end function setLexicalHandler
|
935
|
-
|
936
|
-
|
937
|
-
/*******************************************************************************************************************
|
938
|
-
LOCATOR/PARSE EXCEPTION INTERFACE
|
939
|
-
*********************************************************************************************************************/
|
940
|
-
|
941
|
-
SAXDriver.prototype.getColumnNumber = function() {
|
942
|
-
/*******************************************************************************************************************
|
943
|
-
function: getSystemId
|
944
|
-
|
945
|
-
Author: Scott Severtson
|
946
|
-
*********************************************************************************************************************/
|
947
|
-
|
948
|
-
return this.m_parser.getColumnNumber();
|
949
|
-
|
950
|
-
} // end function getColumnNumber
|
951
|
-
|
952
|
-
|
953
|
-
SAXDriver.prototype.getLineNumber = function() {
|
954
|
-
/*******************************************************************************************************************
|
955
|
-
function: getLineNumber
|
956
|
-
|
957
|
-
Author: Scott Severtson
|
958
|
-
*********************************************************************************************************************/
|
959
|
-
|
960
|
-
return this.m_parser.getLineNumber();
|
961
|
-
|
962
|
-
} // end function getLineNumber
|
963
|
-
|
964
|
-
|
965
|
-
SAXDriver.prototype.getMessage = function() {
|
966
|
-
/*******************************************************************************************************************
|
967
|
-
function: getMessage
|
968
|
-
|
969
|
-
Author: Scott Severtson
|
970
|
-
*********************************************************************************************************************/
|
971
|
-
|
972
|
-
return this.m_strErrMsg;
|
973
|
-
|
974
|
-
} // end function getMessage
|
975
|
-
|
976
|
-
|
977
|
-
SAXDriver.prototype.getPublicId = function() {
|
978
|
-
/*******************************************************************************************************************
|
979
|
-
function: getPublicID
|
980
|
-
|
981
|
-
Author: Scott Severtson
|
982
|
-
*********************************************************************************************************************/
|
983
|
-
|
984
|
-
return null;
|
985
|
-
|
986
|
-
} // end function getPublicID
|
987
|
-
|
988
|
-
|
989
|
-
SAXDriver.prototype.getSystemId = function() {
|
990
|
-
/*******************************************************************************************************************
|
991
|
-
function: getSystemId
|
992
|
-
|
993
|
-
Author: Scott Severtson
|
994
|
-
*********************************************************************************************************************/
|
995
|
-
|
996
|
-
return null;
|
997
|
-
|
998
|
-
} // end function getSystemId
|
999
|
-
|
1000
|
-
|
1001
|
-
/*******************************************************************************************************************
|
1002
|
-
Attribute List Interface
|
1003
|
-
*********************************************************************************************************************/
|
1004
|
-
|
1005
|
-
SAXDriver.prototype.getLength = function() {
|
1006
|
-
/*******************************************************************************************************************
|
1007
|
-
function: getLength
|
1008
|
-
|
1009
|
-
Author: Scott Severtson
|
1010
|
-
*********************************************************************************************************************/
|
1011
|
-
|
1012
|
-
return this.m_parser.getAttributeCount();
|
1013
|
-
|
1014
|
-
} // end function getAttributeCount
|
1015
|
-
|
1016
|
-
|
1017
|
-
SAXDriver.prototype.getName = function(index) {
|
1018
|
-
/*******************************************************************************************************************
|
1019
|
-
function: getName
|
1020
|
-
|
1021
|
-
Author: Scott Severtson
|
1022
|
-
*********************************************************************************************************************/
|
1023
|
-
|
1024
|
-
return this.m_parser.getAttributeName(index);
|
1025
|
-
|
1026
|
-
} // end function getAttributeName
|
1027
|
-
|
1028
|
-
|
1029
|
-
SAXDriver.prototype.getValue = function(index) {
|
1030
|
-
/*******************************************************************************************************************
|
1031
|
-
function: getValue
|
1032
|
-
|
1033
|
-
Author: Scott Severtson
|
1034
|
-
*********************************************************************************************************************/
|
1035
|
-
|
1036
|
-
return this.m_parser.getAttributeValue(index);
|
1037
|
-
|
1038
|
-
} // end function getAttributeValue
|
1039
|
-
|
1040
|
-
|
1041
|
-
SAXDriver.prototype.getValueByName = function(name) {
|
1042
|
-
/*******************************************************************************************************************
|
1043
|
-
function: getValueByName
|
1044
|
-
|
1045
|
-
Author: Scott Severtson
|
1046
|
-
*********************************************************************************************************************/
|
1047
|
-
|
1048
|
-
return this.m_parser.getAttributeValueByName(name);
|
1049
|
-
|
1050
|
-
} // end function getAttributeValueByName
|
1051
|
-
|
1052
|
-
|
1053
|
-
/*******************************************************************************************************************
|
1054
|
-
Private functions
|
1055
|
-
*********************************************************************************************************************/
|
1056
|
-
|
1057
|
-
SAXDriver.prototype._fireError = function(strMsg) {
|
1058
|
-
/*******************************************************************************************************************
|
1059
|
-
function: _fireError
|
1060
|
-
|
1061
|
-
Author: Scott Severtson
|
1062
|
-
*********************************************************************************************************************/
|
1063
|
-
this.m_strErrMsg = strMsg;
|
1064
|
-
this.m_bErr = true;
|
1065
|
-
|
1066
|
-
if(this.m_hndErr && this.m_hndErr.fatalError) {
|
1067
|
-
this.m_hndErr.fatalError(this);
|
1068
|
-
}
|
1069
|
-
|
1070
|
-
} // end function _fireError
|
1071
|
-
|
1072
|
-
|
1073
|
-
SAXDriver.prototype._fireEvent = function(iEvt) {
|
1074
|
-
/*******************************************************************************************************************
|
1075
|
-
function: _fireEvent
|
1076
|
-
|
1077
|
-
Author: Scott Severtson
|
1078
|
-
*********************************************************************************************************************/
|
1079
|
-
var hnd, func, args = arguments, iLen = args.length - 1;
|
1080
|
-
|
1081
|
-
if(this.m_bErr) return;
|
1082
|
-
|
1083
|
-
if(SAXDriver.DOC_B == iEvt) {
|
1084
|
-
func = "startDocument"; hnd = this.m_hndDoc;
|
1085
|
-
}
|
1086
|
-
else if (SAXDriver.DOC_E == iEvt) {
|
1087
|
-
func = "endDocument"; hnd = this.m_hndDoc;
|
1088
|
-
}
|
1089
|
-
else if (SAXDriver.ELM_B == iEvt) {
|
1090
|
-
func = "startElement"; hnd = this.m_hndDoc;
|
1091
|
-
}
|
1092
|
-
else if (SAXDriver.ELM_E == iEvt) {
|
1093
|
-
func = "endElement"; hnd = this.m_hndDoc;
|
1094
|
-
}
|
1095
|
-
else if (SAXDriver.CHARS == iEvt) {
|
1096
|
-
func = "characters"; hnd = this.m_hndDoc;
|
1097
|
-
}
|
1098
|
-
else if (SAXDriver.PI == iEvt) {
|
1099
|
-
func = "processingInstruction"; hnd = this.m_hndDoc;
|
1100
|
-
}
|
1101
|
-
else if (SAXDriver.CD_B == iEvt) {
|
1102
|
-
func = "startCDATA"; hnd = this.m_hndLex;
|
1103
|
-
}
|
1104
|
-
else if (SAXDriver.CD_E == iEvt) {
|
1105
|
-
func = "endCDATA"; hnd = this.m_hndLex;
|
1106
|
-
}
|
1107
|
-
else if (SAXDriver.CMNT == iEvt) {
|
1108
|
-
func = "comment"; hnd = this.m_hndLex;
|
1109
|
-
}
|
1110
|
-
|
1111
|
-
if(hnd && hnd[func]) {
|
1112
|
-
if(0 == iLen) {
|
1113
|
-
hnd[func]();
|
1114
|
-
}
|
1115
|
-
else if (1 == iLen) {
|
1116
|
-
hnd[func](args[1]);
|
1117
|
-
}
|
1118
|
-
else if (2 == iLen) {
|
1119
|
-
hnd[func](args[1], args[2]);
|
1120
|
-
}
|
1121
|
-
else if (3 == iLen) {
|
1122
|
-
hnd[func](args[1], args[2], args[3]);
|
1123
|
-
}
|
1124
|
-
}
|
1125
|
-
|
1126
|
-
} // end function _fireEvent
|
1127
|
-
|
1128
|
-
|
1129
|
-
SAXDriver.prototype._parseLoop = function(parser) {
|
1130
|
-
/*******************************************************************************************************************
|
1131
|
-
function: _parseLoop
|
1132
|
-
|
1133
|
-
Author: Scott Severtson
|
1134
|
-
*********************************************************************************************************************/
|
1135
|
-
var iEvent, parser;
|
1136
|
-
|
1137
|
-
parser = this.m_parser;
|
1138
|
-
while(!this.m_bErr) {
|
1139
|
-
iEvent = parser.next();
|
1140
|
-
|
1141
|
-
if(iEvent == XMLP._ELM_B) {
|
1142
|
-
this._fireEvent(SAXDriver.ELM_B, parser.getName(), this);
|
1143
|
-
}
|
1144
|
-
else if(iEvent == XMLP._ELM_E) {
|
1145
|
-
this._fireEvent(SAXDriver.ELM_E, parser.getName());
|
1146
|
-
}
|
1147
|
-
else if(iEvent == XMLP._ELM_EMP) {
|
1148
|
-
this._fireEvent(SAXDriver.ELM_B, parser.getName(), this);
|
1149
|
-
this._fireEvent(SAXDriver.ELM_E, parser.getName());
|
1150
|
-
}
|
1151
|
-
else if(iEvent == XMLP._TEXT) {
|
1152
|
-
this._fireEvent(SAXDriver.CHARS, parser.getContent(), parser.getContentBegin(), parser.getContentEnd() - parser.getContentBegin());
|
1153
|
-
}
|
1154
|
-
else if(iEvent == XMLP._ENTITY) {
|
1155
|
-
this._fireEvent(SAXDriver.CHARS, parser.getContent(), parser.getContentBegin(), parser.getContentEnd() - parser.getContentBegin());
|
1156
|
-
}
|
1157
|
-
else if(iEvent == XMLP._PI) {
|
1158
|
-
this._fireEvent(SAXDriver.PI, parser.getName(), parser.getContent().substring(parser.getContentBegin(), parser.getContentEnd()));
|
1159
|
-
}
|
1160
|
-
else if(iEvent == XMLP._CDATA) {
|
1161
|
-
this._fireEvent(SAXDriver.CD_B);
|
1162
|
-
this._fireEvent(SAXDriver.CHARS, parser.getContent(), parser.getContentBegin(), parser.getContentEnd() - parser.getContentBegin());
|
1163
|
-
this._fireEvent(SAXDriver.CD_E);
|
1164
|
-
}
|
1165
|
-
else if(iEvent == XMLP._COMMENT) {
|
1166
|
-
this._fireEvent(SAXDriver.CMNT, parser.getContent(), parser.getContentBegin(), parser.getContentEnd() - parser.getContentBegin());
|
1167
|
-
}
|
1168
|
-
else if(iEvent == XMLP._DTD) {
|
1169
|
-
}
|
1170
|
-
else if(iEvent == XMLP._ERROR) {
|
1171
|
-
this._fireError(parser.getContent());
|
1172
|
-
}
|
1173
|
-
else if(iEvent == XMLP._NONE) {
|
1174
|
-
return;
|
1175
|
-
}
|
1176
|
-
}
|
1177
|
-
|
1178
|
-
} // end function _parseLoop
|
1179
|
-
|
1180
|
-
|
1181
|
-
|
1182
|
-
/***************************************************************************************************************
|
1183
|
-
SAXStrings: a useful object containing string manipulation functions
|
1184
|
-
*****************************************************************************************************************/
|
1185
|
-
|
1186
|
-
|
1187
|
-
SAXStrings = function() {
|
1188
|
-
/*******************************************************************************************************************
|
1189
|
-
function: SAXStrings
|
1190
|
-
|
1191
|
-
Author: Scott Severtson
|
1192
|
-
|
1193
|
-
Description:
|
1194
|
-
This is the constructor of the SAXStrings object
|
1195
|
-
*********************************************************************************************************************/
|
1196
|
-
} // end function SAXStrings
|
1197
|
-
|
1198
|
-
|
1199
|
-
// CONSTANTS (these must be below the constructor)
|
1200
|
-
|
1201
|
-
// =========================================================================
|
1202
|
-
// =========================================================================
|
1203
|
-
// =========================================================================
|
1204
|
-
SAXStrings.WHITESPACE = " \t\n\r";
|
1205
|
-
SAXStrings.QUOTES = "\"'";
|
1206
|
-
// =========================================================================
|
1207
|
-
// =========================================================================
|
1208
|
-
// =========================================================================
|
1209
|
-
|
1210
|
-
|
1211
|
-
SAXStrings.getColumnNumber = function(strD, iP) {
|
1212
|
-
/*******************************************************************************************************************
|
1213
|
-
function: replace
|
1214
|
-
|
1215
|
-
Author: Scott Severtson
|
1216
|
-
*********************************************************************************************************************/
|
1217
|
-
if(SAXStrings.isEmpty(strD)) {
|
1218
|
-
return -1;
|
1219
|
-
}
|
1220
|
-
iP = iP || strD.length;
|
1221
|
-
|
1222
|
-
var arrD = strD.substring(0, iP).split("\n");
|
1223
|
-
var strLine = arrD[arrD.length - 1];
|
1224
|
-
arrD.length--;
|
1225
|
-
var iLinePos = arrD.join("\n").length;
|
1226
|
-
|
1227
|
-
return iP - iLinePos;
|
1228
|
-
|
1229
|
-
} // end function getColumnNumber
|
1230
|
-
|
1231
|
-
|
1232
|
-
SAXStrings.getLineNumber = function(strD, iP) {
|
1233
|
-
/*******************************************************************************************************************
|
1234
|
-
function: getLineNumber
|
1235
|
-
|
1236
|
-
Author: Scott Severtson
|
1237
|
-
*********************************************************************************************************************/
|
1238
|
-
if(SAXStrings.isEmpty(strD)) {
|
1239
|
-
return -1;
|
1240
|
-
}
|
1241
|
-
iP = iP || strD.length;
|
1242
|
-
|
1243
|
-
return strD.substring(0, iP).split("\n").length
|
1244
|
-
} // end function getLineNumber
|
1245
|
-
|
1246
|
-
|
1247
|
-
SAXStrings.indexOfNonWhitespace = function(strD, iB, iE) {
|
1248
|
-
/*******************************************************************************************************************
|
1249
|
-
function: indexOfNonWhitespace
|
1250
|
-
|
1251
|
-
Author: Scott Severtson
|
1252
|
-
*********************************************************************************************************************/
|
1253
|
-
if(SAXStrings.isEmpty(strD)) {
|
1254
|
-
return -1;
|
1255
|
-
}
|
1256
|
-
iB = iB || 0;
|
1257
|
-
iE = iE || strD.length;
|
1258
|
-
|
1259
|
-
for(var i = iB; i < iE; i++){
|
1260
|
-
if(SAXStrings.WHITESPACE.indexOf(strD.charAt(i)) == -1) {
|
1261
|
-
return i;
|
1262
|
-
}
|
1263
|
-
}
|
1264
|
-
return -1;
|
1265
|
-
|
1266
|
-
} // end function indexOfNonWhitespace
|
1267
|
-
|
1268
|
-
|
1269
|
-
SAXStrings.indexOfWhitespace = function(strD, iB, iE) {
|
1270
|
-
/*******************************************************************************************************************
|
1271
|
-
function: indexOfWhitespace
|
1272
|
-
|
1273
|
-
Author: Scott Severtson
|
1274
|
-
*********************************************************************************************************************/
|
1275
|
-
if(SAXStrings.isEmpty(strD)) {
|
1276
|
-
return -1;
|
1277
|
-
}
|
1278
|
-
iB = iB || 0;
|
1279
|
-
iE = iE || strD.length;
|
1280
|
-
|
1281
|
-
for(var i = iB; i < iE; i++) {
|
1282
|
-
if(SAXStrings.WHITESPACE.indexOf(strD.charAt(i)) != -1) {
|
1283
|
-
return i;
|
1284
|
-
}
|
1285
|
-
}
|
1286
|
-
return -1;
|
1287
|
-
} // end function indexOfWhitespace
|
1288
|
-
|
1289
|
-
|
1290
|
-
SAXStrings.isEmpty = function(strD) {
|
1291
|
-
/*******************************************************************************************************************
|
1292
|
-
function: isEmpty
|
1293
|
-
|
1294
|
-
Author: Scott Severtson
|
1295
|
-
*********************************************************************************************************************/
|
1296
|
-
|
1297
|
-
return (strD == null) || (strD.length == 0);
|
1298
|
-
|
1299
|
-
} // end function isEmpty
|
1300
|
-
|
1301
|
-
|
1302
|
-
SAXStrings.lastIndexOfNonWhitespace = function(strD, iB, iE) {
|
1303
|
-
/*******************************************************************************************************************
|
1304
|
-
function: lastIndexOfNonWhiteSpace
|
1305
|
-
|
1306
|
-
Author: Scott Severtson
|
1307
|
-
*********************************************************************************************************************/
|
1308
|
-
if(SAXStrings.isEmpty(strD)) {
|
1309
|
-
return -1;
|
1310
|
-
}
|
1311
|
-
iB = iB || 0;
|
1312
|
-
iE = iE || strD.length;
|
1313
|
-
|
1314
|
-
for(var i = iE - 1; i >= iB; i--){
|
1315
|
-
if(SAXStrings.WHITESPACE.indexOf(strD.charAt(i)) == -1){
|
1316
|
-
return i;
|
1317
|
-
}
|
1318
|
-
}
|
1319
|
-
return -1;
|
1320
|
-
} // end function lastIndexOfNonWhitespace
|
1321
|
-
|
1322
|
-
|
1323
|
-
SAXStrings.replace = function(strD, iB, iE, strF, strR) {
|
1324
|
-
/*******************************************************************************************************************
|
1325
|
-
function: replace
|
1326
|
-
|
1327
|
-
Author: Scott Severtson
|
1328
|
-
*********************************************************************************************************************/
|
1329
|
-
if(SAXStrings.isEmpty(strD)) {
|
1330
|
-
return "";
|
1331
|
-
}
|
1332
|
-
iB = iB || 0;
|
1333
|
-
iE = iE || strD.length;
|
1334
|
-
|
1335
|
-
return strD.substring(iB, iE).split(strF).join(strR);
|
1336
|
-
|
1337
|
-
} // end function replace
|
1338
|
-
|
1339
|
-
|
1340
|
-
|
1341
|
-
/***************************************************************************************************************
|
1342
|
-
Stack: A simple stack class, used for verifying document structure.
|
1343
|
-
*****************************************************************************************************************/
|
1344
|
-
|
1345
|
-
Stack = function() {
|
1346
|
-
/*******************************************************************************************************************
|
1347
|
-
function: Stack
|
1348
|
-
|
1349
|
-
Author: Scott Severtson
|
1350
|
-
|
1351
|
-
Description:
|
1352
|
-
Constructor of the Stack Object
|
1353
|
-
*********************************************************************************************************************/
|
1354
|
-
this.m_arr = new Array();
|
1355
|
-
|
1356
|
-
} // end function Stack
|
1357
|
-
|
1358
|
-
|
1359
|
-
Stack.prototype.clear = function() {
|
1360
|
-
/*******************************************************************************************************************
|
1361
|
-
function: clear
|
1362
|
-
|
1363
|
-
Author: Scott Severtson
|
1364
|
-
*********************************************************************************************************************/
|
1365
|
-
|
1366
|
-
this.m_arr = new Array();
|
1367
|
-
|
1368
|
-
} // end function clear
|
1369
|
-
|
1370
|
-
|
1371
|
-
Stack.prototype.count = function() {
|
1372
|
-
/*******************************************************************************************************************
|
1373
|
-
function: count
|
1374
|
-
|
1375
|
-
Author: Scott Severtson
|
1376
|
-
*********************************************************************************************************************/
|
1377
|
-
|
1378
|
-
return this.m_arr.length;
|
1379
|
-
|
1380
|
-
} // end function count
|
1381
|
-
|
1382
|
-
|
1383
|
-
Stack.prototype.destroy = function() {
|
1384
|
-
/*******************************************************************************************************************
|
1385
|
-
function: destroy
|
1386
|
-
|
1387
|
-
Author: Scott Severtson
|
1388
|
-
*********************************************************************************************************************/
|
1389
|
-
|
1390
|
-
this.m_arr = null;
|
1391
|
-
|
1392
|
-
} // end function destroy
|
1393
|
-
|
1394
|
-
|
1395
|
-
Stack.prototype.peek = function() {
|
1396
|
-
/*******************************************************************************************************************
|
1397
|
-
function: peek
|
1398
|
-
|
1399
|
-
Author: Scott Severtson
|
1400
|
-
*********************************************************************************************************************/
|
1401
|
-
if(this.m_arr.length == 0) {
|
1402
|
-
return null;
|
1403
|
-
}
|
1404
|
-
|
1405
|
-
return this.m_arr[this.m_arr.length - 1];
|
1406
|
-
|
1407
|
-
} // end function peek
|
1408
|
-
|
1409
|
-
|
1410
|
-
Stack.prototype.pop = function() {
|
1411
|
-
/*******************************************************************************************************************
|
1412
|
-
function: pop
|
1413
|
-
|
1414
|
-
Author: Scott Severtson
|
1415
|
-
*********************************************************************************************************************/
|
1416
|
-
if(this.m_arr.length == 0) {
|
1417
|
-
return null;
|
1418
|
-
}
|
1419
|
-
|
1420
|
-
var o = this.m_arr[this.m_arr.length - 1];
|
1421
|
-
this.m_arr.length--;
|
1422
|
-
return o;
|
1423
|
-
|
1424
|
-
} // end function pop
|
1425
|
-
|
1426
|
-
|
1427
|
-
Stack.prototype.push = function(o) {
|
1428
|
-
/*******************************************************************************************************************
|
1429
|
-
function: push
|
1430
|
-
|
1431
|
-
Author: Scott Severtson
|
1432
|
-
*********************************************************************************************************************/
|
1433
|
-
|
1434
|
-
this.m_arr[this.m_arr.length] = o;
|
1435
|
-
|
1436
|
-
} // end function push
|
1437
|
-
|
1438
|
-
|
1439
|
-
|
1440
|
-
// =========================================================================
|
1441
|
-
// =========================================================================
|
1442
|
-
// =========================================================================
|
1443
|
-
|
1444
|
-
// CONVENIENCE FUNCTIONS
|
1445
|
-
|
1446
|
-
// =========================================================================
|
1447
|
-
// =========================================================================
|
1448
|
-
// =========================================================================
|
1449
|
-
|
1450
|
-
function isEmpty(str) {
|
1451
|
-
/*******************************************************************************************************************
|
1452
|
-
function: isEmpty
|
1453
|
-
|
1454
|
-
Author: mike@idle.org
|
1455
|
-
|
1456
|
-
Description:
|
1457
|
-
convenience function to identify an empty string
|
1458
|
-
|
1459
|
-
*********************************************************************************************************************/
|
1460
|
-
return (str==null) || (str.length==0);
|
1461
|
-
|
1462
|
-
} // end function isEmpty
|
1463
|
-
|
1464
|
-
|
1465
|
-
|
1466
|
-
function trim(trimString, leftTrim, rightTrim) {
|
1467
|
-
/*******************************************************************************************************************
|
1468
|
-
function: trim
|
1469
|
-
|
1470
|
-
Author: may106@psu.edu
|
1471
|
-
|
1472
|
-
Description:
|
1473
|
-
helper function to trip a string (trimString) of leading (leftTrim)
|
1474
|
-
and trailing (rightTrim) whitespace
|
1475
|
-
|
1476
|
-
*********************************************************************************************************************/
|
1477
|
-
if (isEmpty(trimString)) {
|
1478
|
-
return "";
|
1479
|
-
}
|
1480
|
-
|
1481
|
-
// the general focus here is on minimal method calls - hence only one
|
1482
|
-
// substring is done to complete the trim.
|
1483
|
-
|
1484
|
-
if (leftTrim == null) {
|
1485
|
-
leftTrim = true;
|
1486
|
-
}
|
1487
|
-
|
1488
|
-
if (rightTrim == null) {
|
1489
|
-
rightTrim = true;
|
1490
|
-
}
|
1491
|
-
|
1492
|
-
var left=0;
|
1493
|
-
var right=0;
|
1494
|
-
var i=0;
|
1495
|
-
var k=0;
|
1496
|
-
|
1497
|
-
|
1498
|
-
// modified to properly handle strings that are all whitespace
|
1499
|
-
if (leftTrim == true) {
|
1500
|
-
while ((i<trimString.length) && (whitespace.indexOf(trimString.charAt(i++))!=-1)) {
|
1501
|
-
left++;
|
1502
|
-
}
|
1503
|
-
}
|
1504
|
-
if (rightTrim == true) {
|
1505
|
-
k=trimString.length-1;
|
1506
|
-
while((k>=left) && (whitespace.indexOf(trimString.charAt(k--))!=-1)) {
|
1507
|
-
right++;
|
1508
|
-
}
|
1509
|
-
}
|
1510
|
-
return trimString.substring(left, trimString.length - right);
|
1511
|
-
} // end function trim
|
1512
|
-
|
1513
|
-
/**
|
1514
|
-
* function __escapeString
|
1515
|
-
*
|
1516
|
-
* author: David Joham djoham@yahoo.com
|
1517
|
-
*
|
1518
|
-
* @param str : string - The string to be escaped
|
1519
|
-
*
|
1520
|
-
* @return : string - The escaped string
|
1521
|
-
*/
|
1522
|
-
function __escapeString(str) {
|
1523
|
-
|
1524
|
-
var escAmpRegEx = /&/g;
|
1525
|
-
var escLtRegEx = /</g;
|
1526
|
-
var escGtRegEx = />/g;
|
1527
|
-
var quotRegEx = /"/g;
|
1528
|
-
var aposRegEx = /'/g;
|
1529
|
-
|
1530
|
-
str = str.replace(escAmpRegEx, "&");
|
1531
|
-
str = str.replace(escLtRegEx, "<");
|
1532
|
-
str = str.replace(escGtRegEx, ">");
|
1533
|
-
str = str.replace(quotRegEx, """);
|
1534
|
-
str = str.replace(aposRegEx, "'");
|
1535
|
-
|
1536
|
-
return str;
|
1537
|
-
}
|
1538
|
-
|
1539
|
-
/**
|
1540
|
-
* function __unescapeString
|
1541
|
-
*
|
1542
|
-
* author: David Joham djoham@yahoo.com
|
1543
|
-
*
|
1544
|
-
* @param str : string - The string to be unescaped
|
1545
|
-
*
|
1546
|
-
* @return : string - The unescaped string
|
1547
|
-
*/
|
1548
|
-
function __unescapeString(str) {
|
1549
|
-
|
1550
|
-
var escAmpRegEx = /&/g;
|
1551
|
-
var escLtRegEx = /</g;
|
1552
|
-
var escGtRegEx = />/g;
|
1553
|
-
var quotRegEx = /"/g;
|
1554
|
-
var aposRegEx = /'/g;
|
1555
|
-
|
1556
|
-
str = str.replace(escAmpRegEx, "&");
|
1557
|
-
str = str.replace(escLtRegEx, "<");
|
1558
|
-
str = str.replace(escGtRegEx, ">");
|
1559
|
-
str = str.replace(quotRegEx, "\"");
|
1560
|
-
str = str.replace(aposRegEx, "'");
|
1561
|
-
|
1562
|
-
return str;
|
1563
|
-
}
|
1564
|
-
|
1
|
+
// =========================================================================
|
2
|
+
//
|
3
|
+
// xmlsax.js - an XML SAX parser in JavaScript.
|
4
|
+
//
|
5
|
+
// version 3.1
|
6
|
+
//
|
7
|
+
// =========================================================================
|
8
|
+
//
|
9
|
+
// Copyright (C) 2001 - 2002 David Joham (djoham@yahoo.com) and Scott Severtson
|
10
|
+
//
|
11
|
+
// This library is free software; you can redistribute it and/or
|
12
|
+
// modify it under the terms of the GNU Lesser General Public
|
13
|
+
// License as published by the Free Software Foundation; either
|
14
|
+
// version 2.1 of the License, or (at your option) any later version.
|
15
|
+
|
16
|
+
// This library is distributed in the hope that it will be useful,
|
17
|
+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18
|
+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
19
|
+
// Lesser General Public License for more details.
|
20
|
+
|
21
|
+
// You should have received a copy of the GNU Lesser General Public
|
22
|
+
// License along with this library; if not, write to the Free Software
|
23
|
+
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
24
|
+
//
|
25
|
+
//
|
26
|
+
// Visit the XML for <SCRIPT> home page at http://xmljs.sourceforge.net
|
27
|
+
//
|
28
|
+
|
29
|
+
// CONSTANTS
|
30
|
+
|
31
|
+
// =========================================================================
|
32
|
+
// =========================================================================
|
33
|
+
// =========================================================================
|
34
|
+
var whitespace = "\n\r\t ";
|
35
|
+
|
36
|
+
|
37
|
+
/***************************************************************************************************************
|
38
|
+
XMLP is a pull-based parser. The calling application passes in a XML string
|
39
|
+
to the constructor, then repeatedly calls .next() to parse the next segment.
|
40
|
+
.next() returns a flag indicating what type of segment was found, and stores
|
41
|
+
data temporarily in couple member variables (name, content, array of
|
42
|
+
attributes), which can be accessed by several .get____() methods.
|
43
|
+
|
44
|
+
Basically, XMLP is the lowest common denominator parser - an very simple
|
45
|
+
API which other wrappers can be built against.
|
46
|
+
*****************************************************************************************************************/
|
47
|
+
|
48
|
+
|
49
|
+
XMLP = function(strXML) {
|
50
|
+
/*******************************************************************************************************************
|
51
|
+
function: this is the constructor to the XMLP Object
|
52
|
+
|
53
|
+
Author: Scott Severtson
|
54
|
+
|
55
|
+
Description:
|
56
|
+
Instantiates and initializes the object
|
57
|
+
*********************************************************************************************************************/
|
58
|
+
// Normalize line breaks
|
59
|
+
strXML = SAXStrings.replace(strXML, null, null, "\r\n", "\n");
|
60
|
+
strXML = SAXStrings.replace(strXML, null, null, "\r", "\n");
|
61
|
+
|
62
|
+
this.m_xml = strXML;
|
63
|
+
this.m_iP = 0;
|
64
|
+
this.m_iState = XMLP._STATE_PROLOG;
|
65
|
+
this.m_stack = new Stack();
|
66
|
+
this._clearAttributes();
|
67
|
+
|
68
|
+
} // end XMLP constructor
|
69
|
+
|
70
|
+
|
71
|
+
// CONSTANTS (these must be below the constructor)
|
72
|
+
|
73
|
+
// =========================================================================
|
74
|
+
// =========================================================================
|
75
|
+
// =========================================================================
|
76
|
+
|
77
|
+
XMLP._NONE = 0;
|
78
|
+
XMLP._ELM_B = 1;
|
79
|
+
XMLP._ELM_E = 2;
|
80
|
+
XMLP._ELM_EMP = 3;
|
81
|
+
XMLP._ATT = 4;
|
82
|
+
XMLP._TEXT = 5;
|
83
|
+
XMLP._ENTITY = 6;
|
84
|
+
XMLP._PI = 7;
|
85
|
+
XMLP._CDATA = 8;
|
86
|
+
XMLP._COMMENT = 9;
|
87
|
+
XMLP._DTD = 10;
|
88
|
+
XMLP._ERROR = 11;
|
89
|
+
|
90
|
+
XMLP._CONT_XML = 0;
|
91
|
+
XMLP._CONT_ALT = 1;
|
92
|
+
|
93
|
+
XMLP._ATT_NAME = 0;
|
94
|
+
XMLP._ATT_VAL = 1;
|
95
|
+
|
96
|
+
XMLP._STATE_PROLOG = 1;
|
97
|
+
XMLP._STATE_DOCUMENT = 2;
|
98
|
+
XMLP._STATE_MISC = 3;
|
99
|
+
|
100
|
+
XMLP._errs = new Array();
|
101
|
+
XMLP._errs[XMLP.ERR_CLOSE_PI = 0 ] = "PI: missing closing sequence";
|
102
|
+
XMLP._errs[XMLP.ERR_CLOSE_DTD = 1 ] = "DTD: missing closing sequence";
|
103
|
+
XMLP._errs[XMLP.ERR_CLOSE_COMMENT = 2 ] = "Comment: missing closing sequence";
|
104
|
+
XMLP._errs[XMLP.ERR_CLOSE_CDATA = 3 ] = "CDATA: missing closing sequence";
|
105
|
+
XMLP._errs[XMLP.ERR_CLOSE_ELM = 4 ] = "Element: missing closing sequence";
|
106
|
+
XMLP._errs[XMLP.ERR_CLOSE_ENTITY = 5 ] = "Entity: missing closing sequence";
|
107
|
+
XMLP._errs[XMLP.ERR_PI_TARGET = 6 ] = "PI: target is required";
|
108
|
+
XMLP._errs[XMLP.ERR_ELM_EMPTY = 7 ] = "Element: cannot be both empty and closing";
|
109
|
+
XMLP._errs[XMLP.ERR_ELM_NAME = 8 ] = "Element: name must immediatly follow \"<\"";
|
110
|
+
XMLP._errs[XMLP.ERR_ELM_LT_NAME = 9 ] = "Element: \"<\" not allowed in element names";
|
111
|
+
XMLP._errs[XMLP.ERR_ATT_VALUES = 10] = "Attribute: values are required and must be in quotes";
|
112
|
+
XMLP._errs[XMLP.ERR_ATT_LT_NAME = 11] = "Element: \"<\" not allowed in attribute names";
|
113
|
+
XMLP._errs[XMLP.ERR_ATT_LT_VALUE = 12] = "Attribute: \"<\" not allowed in attribute values";
|
114
|
+
XMLP._errs[XMLP.ERR_ATT_DUP = 13] = "Attribute: duplicate attributes not allowed";
|
115
|
+
XMLP._errs[XMLP.ERR_ENTITY_UNKNOWN = 14] = "Entity: unknown entity";
|
116
|
+
XMLP._errs[XMLP.ERR_INFINITELOOP = 15] = "Infininte loop";
|
117
|
+
XMLP._errs[XMLP.ERR_DOC_STRUCTURE = 16] = "Document: only comments, processing instructions, or whitespace allowed outside of document element";
|
118
|
+
XMLP._errs[XMLP.ERR_ELM_NESTING = 17] = "Element: must be nested correctly";
|
119
|
+
|
120
|
+
// =========================================================================
|
121
|
+
// =========================================================================
|
122
|
+
// =========================================================================
|
123
|
+
|
124
|
+
|
125
|
+
XMLP.prototype._addAttribute = function(name, value) {
|
126
|
+
/*******************************************************************************************************************
|
127
|
+
function: _addAttribute
|
128
|
+
|
129
|
+
Author: Scott Severtson
|
130
|
+
*********************************************************************************************************************/
|
131
|
+
this.m_atts[this.m_atts.length] = new Array(name, value);
|
132
|
+
} // end function _addAttribute
|
133
|
+
|
134
|
+
|
135
|
+
XMLP.prototype._checkStructure = function(iEvent) {
|
136
|
+
/*******************************************************************************************************************
|
137
|
+
function: _checkStructure
|
138
|
+
|
139
|
+
Author: Scott Severtson
|
140
|
+
*********************************************************************************************************************/
|
141
|
+
|
142
|
+
if(XMLP._STATE_PROLOG == this.m_iState) {
|
143
|
+
if((XMLP._TEXT == iEvent) || (XMLP._ENTITY == iEvent)) {
|
144
|
+
if(SAXStrings.indexOfNonWhitespace(this.getContent(), this.getContentBegin(), this.getContentEnd()) != -1) {
|
145
|
+
return this._setErr(XMLP.ERR_DOC_STRUCTURE);
|
146
|
+
}
|
147
|
+
}
|
148
|
+
|
149
|
+
if((XMLP._ELM_B == iEvent) || (XMLP._ELM_EMP == iEvent)) {
|
150
|
+
this.m_iState = XMLP._STATE_DOCUMENT;
|
151
|
+
// Don't return - fall through to next state
|
152
|
+
}
|
153
|
+
}
|
154
|
+
if(XMLP._STATE_DOCUMENT == this.m_iState) {
|
155
|
+
if((XMLP._ELM_B == iEvent) || (XMLP._ELM_EMP == iEvent)) {
|
156
|
+
this.m_stack.push(this.getName());
|
157
|
+
}
|
158
|
+
|
159
|
+
if((XMLP._ELM_E == iEvent) || (XMLP._ELM_EMP == iEvent)) {
|
160
|
+
var strTop = this.m_stack.pop();
|
161
|
+
if((strTop == null) || (strTop != this.getName())) {
|
162
|
+
return this._setErr(XMLP.ERR_ELM_NESTING);
|
163
|
+
}
|
164
|
+
}
|
165
|
+
|
166
|
+
if(this.m_stack.count() == 0) {
|
167
|
+
this.m_iState = XMLP._STATE_MISC;
|
168
|
+
return iEvent;
|
169
|
+
}
|
170
|
+
}
|
171
|
+
if(XMLP._STATE_MISC == this.m_iState) {
|
172
|
+
if((XMLP._ELM_B == iEvent) || (XMLP._ELM_E == iEvent) || (XMLP._ELM_EMP == iEvent) || (XMLP.EVT_DTD == iEvent)) {
|
173
|
+
return this._setErr(XMLP.ERR_DOC_STRUCTURE);
|
174
|
+
}
|
175
|
+
|
176
|
+
if((XMLP._TEXT == iEvent) || (XMLP._ENTITY == iEvent)) {
|
177
|
+
if(SAXStrings.indexOfNonWhitespace(this.getContent(), this.getContentBegin(), this.getContentEnd()) != -1) {
|
178
|
+
return this._setErr(XMLP.ERR_DOC_STRUCTURE);
|
179
|
+
}
|
180
|
+
}
|
181
|
+
}
|
182
|
+
|
183
|
+
return iEvent;
|
184
|
+
|
185
|
+
} // end function _checkStructure
|
186
|
+
|
187
|
+
|
188
|
+
XMLP.prototype._clearAttributes = function() {
|
189
|
+
/*******************************************************************************************************************
|
190
|
+
function: _clearAttributes
|
191
|
+
|
192
|
+
Author: Scott Severtson
|
193
|
+
*********************************************************************************************************************/
|
194
|
+
this.m_atts = new Array();
|
195
|
+
} // end function _clearAttributes
|
196
|
+
|
197
|
+
|
198
|
+
XMLP.prototype._findAttributeIndex = function(name) {
|
199
|
+
/*******************************************************************************************************************
|
200
|
+
function: findAttributeIndex
|
201
|
+
|
202
|
+
Author: Scott Severtson
|
203
|
+
*********************************************************************************************************************/
|
204
|
+
for(var i = 0; i < this.m_atts.length; i++) {
|
205
|
+
if(this.m_atts[i][XMLP._ATT_NAME] == name) {
|
206
|
+
return i;
|
207
|
+
}
|
208
|
+
}
|
209
|
+
return -1;
|
210
|
+
|
211
|
+
} // end function _findAttributeIndex
|
212
|
+
|
213
|
+
|
214
|
+
XMLP.prototype.getAttributeCount = function() {
|
215
|
+
/*******************************************************************************************************************
|
216
|
+
function: getAttributeCount
|
217
|
+
|
218
|
+
Author: Scott Severtson
|
219
|
+
*********************************************************************************************************************/
|
220
|
+
|
221
|
+
return this.m_atts ? this.m_atts.length : 0;
|
222
|
+
|
223
|
+
} // end function getAttributeCount()
|
224
|
+
|
225
|
+
|
226
|
+
XMLP.prototype.getAttributeName = function(index) {
|
227
|
+
/*******************************************************************************************************************
|
228
|
+
function: getAttributeName
|
229
|
+
|
230
|
+
Author: Scott Severtson
|
231
|
+
*********************************************************************************************************************/
|
232
|
+
|
233
|
+
return ((index < 0) || (index >= this.m_atts.length)) ? null : this.m_atts[index][XMLP._ATT_NAME];
|
234
|
+
|
235
|
+
} //end function getAttributeName
|
236
|
+
|
237
|
+
|
238
|
+
XMLP.prototype.getAttributeValue = function(index) {
|
239
|
+
/*******************************************************************************************************************
|
240
|
+
function: getAttributeValue
|
241
|
+
|
242
|
+
Author: Scott Severtson
|
243
|
+
*********************************************************************************************************************/
|
244
|
+
|
245
|
+
return ((index < 0) || (index >= this.m_atts.length)) ? null : __unescapeString(this.m_atts[index][XMLP._ATT_VAL]);
|
246
|
+
|
247
|
+
} // end function getAttributeValue
|
248
|
+
|
249
|
+
|
250
|
+
XMLP.prototype.getAttributeValueByName = function(name) {
|
251
|
+
/*******************************************************************************************************************
|
252
|
+
function: getAttributeValueByName
|
253
|
+
|
254
|
+
Author: Scott Severtson
|
255
|
+
*********************************************************************************************************************/
|
256
|
+
|
257
|
+
return this.getAttributeValue(this._findAttributeIndex(name));
|
258
|
+
|
259
|
+
} // end function getAttributeValueByName
|
260
|
+
|
261
|
+
|
262
|
+
XMLP.prototype.getColumnNumber = function() {
|
263
|
+
/*******************************************************************************************************************
|
264
|
+
function: getColumnNumber
|
265
|
+
|
266
|
+
Author: Scott Severtson
|
267
|
+
*********************************************************************************************************************/
|
268
|
+
|
269
|
+
return SAXStrings.getColumnNumber(this.m_xml, this.m_iP);
|
270
|
+
|
271
|
+
} // end function getColumnNumber
|
272
|
+
|
273
|
+
|
274
|
+
XMLP.prototype.getContent = function() {
|
275
|
+
/*******************************************************************************************************************
|
276
|
+
function: getContent
|
277
|
+
|
278
|
+
Author: Scott Severtson
|
279
|
+
*********************************************************************************************************************/
|
280
|
+
|
281
|
+
return (this.m_cSrc == XMLP._CONT_XML) ? this.m_xml : this.m_cAlt;
|
282
|
+
|
283
|
+
} //end function getContent
|
284
|
+
|
285
|
+
|
286
|
+
XMLP.prototype.getContentBegin = function() {
|
287
|
+
/*******************************************************************************************************************
|
288
|
+
function: getContentBegin
|
289
|
+
|
290
|
+
Author: Scott Severtson
|
291
|
+
*********************************************************************************************************************/
|
292
|
+
|
293
|
+
return this.m_cB;
|
294
|
+
|
295
|
+
} //end function getContentBegin
|
296
|
+
|
297
|
+
|
298
|
+
XMLP.prototype.getContentEnd = function() {
|
299
|
+
/*******************************************************************************************************************
|
300
|
+
function: getContentEnd
|
301
|
+
|
302
|
+
Author: Scott Severtson
|
303
|
+
*********************************************************************************************************************/
|
304
|
+
|
305
|
+
return this.m_cE;
|
306
|
+
|
307
|
+
} // end function getContentEnd
|
308
|
+
|
309
|
+
|
310
|
+
XMLP.prototype.getLineNumber = function() {
|
311
|
+
/*******************************************************************************************************************
|
312
|
+
function: getLineNumber
|
313
|
+
|
314
|
+
Author: Scott Severtson
|
315
|
+
*********************************************************************************************************************/
|
316
|
+
|
317
|
+
return SAXStrings.getLineNumber(this.m_xml, this.m_iP);
|
318
|
+
|
319
|
+
} // end function getLineNumber
|
320
|
+
|
321
|
+
|
322
|
+
XMLP.prototype.getName = function() {
|
323
|
+
/*******************************************************************************************************************
|
324
|
+
function: getName
|
325
|
+
|
326
|
+
Author: Scott Severtson
|
327
|
+
*********************************************************************************************************************/
|
328
|
+
|
329
|
+
return this.m_name;
|
330
|
+
|
331
|
+
} // end function getName()
|
332
|
+
|
333
|
+
|
334
|
+
XMLP.prototype.next = function() {
|
335
|
+
/*******************************************************************************************************************
|
336
|
+
function: next
|
337
|
+
|
338
|
+
Author: Scott Severtson
|
339
|
+
*********************************************************************************************************************/
|
340
|
+
|
341
|
+
return this._checkStructure(this._parse());
|
342
|
+
|
343
|
+
} // end function next()
|
344
|
+
|
345
|
+
|
346
|
+
XMLP.prototype._parse = function() {
|
347
|
+
/*******************************************************************************************************************
|
348
|
+
function: _parse
|
349
|
+
|
350
|
+
Author: Scott Severtson
|
351
|
+
*********************************************************************************************************************/
|
352
|
+
|
353
|
+
if(this.m_iP == this.m_xml.length) {
|
354
|
+
return XMLP._NONE;
|
355
|
+
}
|
356
|
+
|
357
|
+
if(this.m_iP == this.m_xml.indexOf("<?", this.m_iP)) {
|
358
|
+
return this._parsePI (this.m_iP + 2);
|
359
|
+
}
|
360
|
+
else if(this.m_iP == this.m_xml.indexOf("<!DOCTYPE", this.m_iP)) {
|
361
|
+
return this._parseDTD (this.m_iP + 9);
|
362
|
+
}
|
363
|
+
else if(this.m_iP == this.m_xml.indexOf("<!--", this.m_iP)) {
|
364
|
+
return this._parseComment(this.m_iP + 4);
|
365
|
+
}
|
366
|
+
else if(this.m_iP == this.m_xml.indexOf("<![CDATA[", this.m_iP)) {
|
367
|
+
return this._parseCDATA (this.m_iP + 9);
|
368
|
+
}
|
369
|
+
else if(this.m_iP == this.m_xml.indexOf("<", this.m_iP)) {
|
370
|
+
return this._parseElement(this.m_iP + 1);
|
371
|
+
}
|
372
|
+
else if(this.m_iP == this.m_xml.indexOf("&", this.m_iP)) {
|
373
|
+
return this._parseEntity (this.m_iP + 1);
|
374
|
+
}
|
375
|
+
else{
|
376
|
+
return this._parseText (this.m_iP);
|
377
|
+
}
|
378
|
+
|
379
|
+
|
380
|
+
} // end function _parse
|
381
|
+
|
382
|
+
|
383
|
+
XMLP.prototype._parseAttribute = function(iB, iE) {
|
384
|
+
/*******************************************************************************************************************
|
385
|
+
function: _parseAttribute
|
386
|
+
|
387
|
+
Author: Scott Severtson
|
388
|
+
*********************************************************************************************************************/
|
389
|
+
var iNB, iNE, iEq, iVB, iVE;
|
390
|
+
var cQuote, strN, strV;
|
391
|
+
|
392
|
+
this.m_cAlt = ""; //resets the value so we don't use an old one by accident (see testAttribute7 in the test suite)
|
393
|
+
|
394
|
+
iNB = SAXStrings.indexOfNonWhitespace(this.m_xml, iB, iE);
|
395
|
+
if((iNB == -1) ||(iNB >= iE)) {
|
396
|
+
return iNB;
|
397
|
+
}
|
398
|
+
|
399
|
+
iEq = this.m_xml.indexOf("=", iNB);
|
400
|
+
if((iEq == -1) || (iEq > iE)) {
|
401
|
+
return this._setErr(XMLP.ERR_ATT_VALUES);
|
402
|
+
}
|
403
|
+
|
404
|
+
iNE = SAXStrings.lastIndexOfNonWhitespace(this.m_xml, iNB, iEq);
|
405
|
+
|
406
|
+
iVB = SAXStrings.indexOfNonWhitespace(this.m_xml, iEq + 1, iE);
|
407
|
+
if((iVB == -1) ||(iVB > iE)) {
|
408
|
+
return this._setErr(XMLP.ERR_ATT_VALUES);
|
409
|
+
}
|
410
|
+
|
411
|
+
cQuote = this.m_xml.charAt(iVB);
|
412
|
+
if(SAXStrings.QUOTES.indexOf(cQuote) == -1) {
|
413
|
+
return this._setErr(XMLP.ERR_ATT_VALUES);
|
414
|
+
}
|
415
|
+
|
416
|
+
iVE = this.m_xml.indexOf(cQuote, iVB + 1);
|
417
|
+
if((iVE == -1) ||(iVE > iE)) {
|
418
|
+
return this._setErr(XMLP.ERR_ATT_VALUES);
|
419
|
+
}
|
420
|
+
|
421
|
+
strN = this.m_xml.substring(iNB, iNE + 1);
|
422
|
+
strV = this.m_xml.substring(iVB + 1, iVE);
|
423
|
+
|
424
|
+
if(strN.indexOf("<") != -1) {
|
425
|
+
return this._setErr(XMLP.ERR_ATT_LT_NAME);
|
426
|
+
}
|
427
|
+
|
428
|
+
if(strV.indexOf("<") != -1) {
|
429
|
+
return this._setErr(XMLP.ERR_ATT_LT_VALUE);
|
430
|
+
}
|
431
|
+
|
432
|
+
strV = SAXStrings.replace(strV, null, null, "\n", " ");
|
433
|
+
strV = SAXStrings.replace(strV, null, null, "\t", " ");
|
434
|
+
iRet = this._replaceEntities(strV);
|
435
|
+
if(iRet == XMLP._ERROR) {
|
436
|
+
return iRet;
|
437
|
+
}
|
438
|
+
|
439
|
+
strV = this.m_cAlt;
|
440
|
+
|
441
|
+
if(this._findAttributeIndex(strN) == -1) {
|
442
|
+
this._addAttribute(strN, strV);
|
443
|
+
}
|
444
|
+
else {
|
445
|
+
return this._setErr(XMLP.ERR_ATT_DUP);
|
446
|
+
}
|
447
|
+
|
448
|
+
this.m_iP = iVE + 2;
|
449
|
+
|
450
|
+
return XMLP._ATT;
|
451
|
+
|
452
|
+
} // end function _parseAttribute
|
453
|
+
|
454
|
+
|
455
|
+
XMLP.prototype._parseCDATA = function(iB) {
|
456
|
+
/*******************************************************************************************************************
|
457
|
+
function: _parseCDATA
|
458
|
+
|
459
|
+
Author: Scott Severtson
|
460
|
+
*********************************************************************************************************************/
|
461
|
+
var iE = this.m_xml.indexOf("]]>", iB);
|
462
|
+
if (iE == -1) {
|
463
|
+
return this._setErr(XMLP.ERR_CLOSE_CDATA);
|
464
|
+
}
|
465
|
+
|
466
|
+
this._setContent(XMLP._CONT_XML, iB, iE);
|
467
|
+
|
468
|
+
this.m_iP = iE + 3;
|
469
|
+
|
470
|
+
return XMLP._CDATA;
|
471
|
+
|
472
|
+
} // end function _parseCDATA
|
473
|
+
|
474
|
+
|
475
|
+
XMLP.prototype._parseComment = function(iB) {
|
476
|
+
/*******************************************************************************************************************
|
477
|
+
function: _parseComment
|
478
|
+
|
479
|
+
Author: Scott Severtson
|
480
|
+
*********************************************************************************************************************/
|
481
|
+
var iE = this.m_xml.indexOf("-" + "->", iB);
|
482
|
+
if (iE == -1) {
|
483
|
+
return this._setErr(XMLP.ERR_CLOSE_COMMENT);
|
484
|
+
}
|
485
|
+
|
486
|
+
this._setContent(XMLP._CONT_XML, iB, iE);
|
487
|
+
|
488
|
+
this.m_iP = iE + 3;
|
489
|
+
|
490
|
+
return XMLP._COMMENT;
|
491
|
+
|
492
|
+
} // end function _parseComment
|
493
|
+
|
494
|
+
|
495
|
+
XMLP.prototype._parseDTD = function(iB) {
|
496
|
+
/*******************************************************************************************************************
|
497
|
+
function: _parseDTD
|
498
|
+
|
499
|
+
Author: Scott Severtson
|
500
|
+
*********************************************************************************************************************/
|
501
|
+
|
502
|
+
// Eat DTD
|
503
|
+
|
504
|
+
var iE, strClose, iInt, iLast;
|
505
|
+
|
506
|
+
iE = this.m_xml.indexOf(">", iB);
|
507
|
+
if(iE == -1) {
|
508
|
+
return this._setErr(XMLP.ERR_CLOSE_DTD);
|
509
|
+
}
|
510
|
+
|
511
|
+
iInt = this.m_xml.indexOf("[", iB);
|
512
|
+
strClose = ((iInt != -1) && (iInt < iE)) ? "]>" : ">";
|
513
|
+
|
514
|
+
while(true) {
|
515
|
+
// DEBUG: Remove
|
516
|
+
if(iE == iLast) {
|
517
|
+
return this._setErr(XMLP.ERR_INFINITELOOP);
|
518
|
+
}
|
519
|
+
|
520
|
+
iLast = iE;
|
521
|
+
// DEBUG: Remove End
|
522
|
+
|
523
|
+
iE = this.m_xml.indexOf(strClose, iB);
|
524
|
+
if(iE == -1) {
|
525
|
+
return this._setErr(XMLP.ERR_CLOSE_DTD);
|
526
|
+
}
|
527
|
+
|
528
|
+
// Make sure it is not the end of a CDATA section
|
529
|
+
if (this.m_xml.substring(iE - 1, iE + 2) != "]]>") {
|
530
|
+
break;
|
531
|
+
}
|
532
|
+
}
|
533
|
+
|
534
|
+
this.m_iP = iE + strClose.length;
|
535
|
+
|
536
|
+
return XMLP._DTD;
|
537
|
+
|
538
|
+
} // end function _parseDTD
|
539
|
+
|
540
|
+
|
541
|
+
XMLP.prototype._parseElement = function(iB) {
|
542
|
+
/*******************************************************************************************************************
|
543
|
+
function: _parseElement
|
544
|
+
|
545
|
+
Author: Scott Severtson
|
546
|
+
*********************************************************************************************************************/
|
547
|
+
var iE, iDE, iNE, iRet;
|
548
|
+
var iType, strN, iLast;
|
549
|
+
|
550
|
+
iDE = iE = this.m_xml.indexOf(">", iB);
|
551
|
+
if(iE == -1) {
|
552
|
+
return this._setErr(XMLP.ERR_CLOSE_ELM);
|
553
|
+
}
|
554
|
+
|
555
|
+
if(this.m_xml.charAt(iB) == "/") {
|
556
|
+
iType = XMLP._ELM_E;
|
557
|
+
iB++;
|
558
|
+
} else {
|
559
|
+
iType = XMLP._ELM_B;
|
560
|
+
}
|
561
|
+
|
562
|
+
if(this.m_xml.charAt(iE - 1) == "/") {
|
563
|
+
if(iType == XMLP._ELM_E) {
|
564
|
+
return this._setErr(XMLP.ERR_ELM_EMPTY);
|
565
|
+
}
|
566
|
+
iType = XMLP._ELM_EMP;
|
567
|
+
iDE--;
|
568
|
+
}
|
569
|
+
|
570
|
+
iDE = SAXStrings.lastIndexOfNonWhitespace(this.m_xml, iB, iDE);
|
571
|
+
|
572
|
+
//djohack
|
573
|
+
//hack to allow for elements with single character names to be recognized
|
574
|
+
|
575
|
+
if (iE - iB != 1 ) {
|
576
|
+
if(SAXStrings.indexOfNonWhitespace(this.m_xml, iB, iDE) != iB) {
|
577
|
+
return this._setErr(XMLP.ERR_ELM_NAME);
|
578
|
+
}
|
579
|
+
}
|
580
|
+
// end hack -- original code below
|
581
|
+
|
582
|
+
/*
|
583
|
+
if(SAXStrings.indexOfNonWhitespace(this.m_xml, iB, iDE) != iB)
|
584
|
+
return this._setErr(XMLP.ERR_ELM_NAME);
|
585
|
+
*/
|
586
|
+
this._clearAttributes();
|
587
|
+
|
588
|
+
iNE = SAXStrings.indexOfWhitespace(this.m_xml, iB, iDE);
|
589
|
+
if(iNE == -1) {
|
590
|
+
iNE = iDE + 1;
|
591
|
+
}
|
592
|
+
else {
|
593
|
+
this.m_iP = iNE;
|
594
|
+
while(this.m_iP < iDE) {
|
595
|
+
// DEBUG: Remove
|
596
|
+
if(this.m_iP == iLast) return this._setErr(XMLP.ERR_INFINITELOOP);
|
597
|
+
iLast = this.m_iP;
|
598
|
+
// DEBUG: Remove End
|
599
|
+
|
600
|
+
|
601
|
+
iRet = this._parseAttribute(this.m_iP, iDE);
|
602
|
+
if(iRet == XMLP._ERROR) return iRet;
|
603
|
+
}
|
604
|
+
}
|
605
|
+
|
606
|
+
strN = this.m_xml.substring(iB, iNE);
|
607
|
+
|
608
|
+
if(strN.indexOf("<") != -1) {
|
609
|
+
return this._setErr(XMLP.ERR_ELM_LT_NAME);
|
610
|
+
}
|
611
|
+
|
612
|
+
this.m_name = strN;
|
613
|
+
this.m_iP = iE + 1;
|
614
|
+
|
615
|
+
return iType;
|
616
|
+
|
617
|
+
} // end function _parseElement
|
618
|
+
|
619
|
+
|
620
|
+
XMLP.prototype._parseEntity = function(iB) {
|
621
|
+
/*******************************************************************************************************************
|
622
|
+
function: _parseEntity
|
623
|
+
|
624
|
+
Author: Scott Severtson
|
625
|
+
*********************************************************************************************************************/
|
626
|
+
var iE = this.m_xml.indexOf(";", iB);
|
627
|
+
if(iE == -1) {
|
628
|
+
return this._setErr(XMLP.ERR_CLOSE_ENTITY);
|
629
|
+
}
|
630
|
+
|
631
|
+
this.m_iP = iE + 1;
|
632
|
+
|
633
|
+
return this._replaceEntity(this.m_xml, iB, iE);
|
634
|
+
|
635
|
+
} // end function _parseEntity
|
636
|
+
|
637
|
+
|
638
|
+
XMLP.prototype._parsePI = function(iB) {
|
639
|
+
/*******************************************************************************************************************
|
640
|
+
function: _parsePI
|
641
|
+
|
642
|
+
Author: Scott Severtson
|
643
|
+
*********************************************************************************************************************/
|
644
|
+
|
645
|
+
var iE, iTB, iTE, iCB, iCE;
|
646
|
+
|
647
|
+
iE = this.m_xml.indexOf("?>", iB);
|
648
|
+
if(iE == -1) {
|
649
|
+
return this._setErr(XMLP.ERR_CLOSE_PI);
|
650
|
+
}
|
651
|
+
|
652
|
+
iTB = SAXStrings.indexOfNonWhitespace(this.m_xml, iB, iE);
|
653
|
+
if(iTB == -1) {
|
654
|
+
return this._setErr(XMLP.ERR_PI_TARGET);
|
655
|
+
}
|
656
|
+
|
657
|
+
iTE = SAXStrings.indexOfWhitespace(this.m_xml, iTB, iE);
|
658
|
+
if(iTE == -1) {
|
659
|
+
iTE = iE;
|
660
|
+
}
|
661
|
+
|
662
|
+
iCB = SAXStrings.indexOfNonWhitespace(this.m_xml, iTE, iE);
|
663
|
+
if(iCB == -1) {
|
664
|
+
iCB = iE;
|
665
|
+
}
|
666
|
+
|
667
|
+
iCE = SAXStrings.lastIndexOfNonWhitespace(this.m_xml, iCB, iE);
|
668
|
+
if(iCE == -1) {
|
669
|
+
iCE = iE - 1;
|
670
|
+
}
|
671
|
+
|
672
|
+
this.m_name = this.m_xml.substring(iTB, iTE);
|
673
|
+
this._setContent(XMLP._CONT_XML, iCB, iCE + 1);
|
674
|
+
this.m_iP = iE + 2;
|
675
|
+
|
676
|
+
return XMLP._PI;
|
677
|
+
|
678
|
+
} // end function _parsePI
|
679
|
+
|
680
|
+
|
681
|
+
XMLP.prototype._parseText = function(iB) {
|
682
|
+
/*******************************************************************************************************************
|
683
|
+
function: _parseText
|
684
|
+
|
685
|
+
Author: Scott Severtson
|
686
|
+
*********************************************************************************************************************/
|
687
|
+
var iE, iEE;
|
688
|
+
|
689
|
+
iE = this.m_xml.indexOf("<", iB);
|
690
|
+
if(iE == -1) {
|
691
|
+
iE = this.m_xml.length;
|
692
|
+
}
|
693
|
+
|
694
|
+
iEE = this.m_xml.indexOf("&", iB);
|
695
|
+
if((iEE != -1) && (iEE <= iE)) {
|
696
|
+
iE = iEE;
|
697
|
+
}
|
698
|
+
|
699
|
+
this._setContent(XMLP._CONT_XML, iB, iE);
|
700
|
+
|
701
|
+
this.m_iP = iE;
|
702
|
+
|
703
|
+
return XMLP._TEXT;
|
704
|
+
|
705
|
+
} // end function _parseText
|
706
|
+
|
707
|
+
|
708
|
+
XMLP.prototype._replaceEntities = function(strD, iB, iE) {
|
709
|
+
/*******************************************************************************************************************
|
710
|
+
function: _replaceEntities
|
711
|
+
|
712
|
+
Author: Scott Severtson
|
713
|
+
*********************************************************************************************************************/
|
714
|
+
if(SAXStrings.isEmpty(strD)) return "";
|
715
|
+
iB = iB || 0;
|
716
|
+
iE = iE || strD.length;
|
717
|
+
|
718
|
+
|
719
|
+
var iEB, iEE, strRet = "";
|
720
|
+
|
721
|
+
iEB = strD.indexOf("&", iB);
|
722
|
+
iEE = iB;
|
723
|
+
|
724
|
+
while((iEB > 0) && (iEB < iE)) {
|
725
|
+
strRet += strD.substring(iEE, iEB);
|
726
|
+
|
727
|
+
iEE = strD.indexOf(";", iEB) + 1;
|
728
|
+
|
729
|
+
if((iEE == 0) || (iEE > iE)) {
|
730
|
+
return this._setErr(XMLP.ERR_CLOSE_ENTITY);
|
731
|
+
}
|
732
|
+
|
733
|
+
iRet = this._replaceEntity(strD, iEB + 1, iEE - 1);
|
734
|
+
if(iRet == XMLP._ERROR) {
|
735
|
+
return iRet;
|
736
|
+
}
|
737
|
+
|
738
|
+
strRet += this.m_cAlt;
|
739
|
+
|
740
|
+
iEB = strD.indexOf("&", iEE);
|
741
|
+
}
|
742
|
+
|
743
|
+
if(iEE != iE) {
|
744
|
+
strRet += strD.substring(iEE, iE);
|
745
|
+
}
|
746
|
+
|
747
|
+
this._setContent(XMLP._CONT_ALT, strRet);
|
748
|
+
|
749
|
+
return XMLP._ENTITY;
|
750
|
+
|
751
|
+
} // end function _replaceEntities
|
752
|
+
|
753
|
+
|
754
|
+
XMLP.prototype._replaceEntity = function(strD, iB, iE) {
|
755
|
+
/*******************************************************************************************************************
|
756
|
+
function: _replaceEntity
|
757
|
+
|
758
|
+
Author: Scott Severtson
|
759
|
+
*********************************************************************************************************************/
|
760
|
+
if(SAXStrings.isEmpty(strD)) return -1;
|
761
|
+
iB = iB || 0;
|
762
|
+
iE = iE || strD.length;
|
763
|
+
|
764
|
+
switch(strD.substring(iB, iE)) {
|
765
|
+
case "amp": strEnt = "&"; break;
|
766
|
+
case "lt": strEnt = "<"; break;
|
767
|
+
case "gt": strEnt = ">"; break;
|
768
|
+
case "apos": strEnt = "'"; break;
|
769
|
+
case "quot": strEnt = "\""; break;
|
770
|
+
default:
|
771
|
+
if(strD.charAt(iB) == "#") {
|
772
|
+
strEnt = String.fromCharCode(parseInt(strD.substring(iB + 1, iE)));
|
773
|
+
} else {
|
774
|
+
return this._setErr(XMLP.ERR_ENTITY_UNKNOWN);
|
775
|
+
}
|
776
|
+
break;
|
777
|
+
}
|
778
|
+
this._setContent(XMLP._CONT_ALT, strEnt);
|
779
|
+
|
780
|
+
return XMLP._ENTITY;
|
781
|
+
} // end function _replaceEntity
|
782
|
+
|
783
|
+
|
784
|
+
XMLP.prototype._setContent = function(iSrc) {
|
785
|
+
/*******************************************************************************************************************
|
786
|
+
function: _setContent
|
787
|
+
|
788
|
+
Author: Scott Severtson
|
789
|
+
*********************************************************************************************************************/
|
790
|
+
var args = arguments;
|
791
|
+
|
792
|
+
if(XMLP._CONT_XML == iSrc) {
|
793
|
+
this.m_cAlt = null;
|
794
|
+
this.m_cB = args[1];
|
795
|
+
this.m_cE = args[2];
|
796
|
+
} else {
|
797
|
+
this.m_cAlt = args[1];
|
798
|
+
this.m_cB = 0;
|
799
|
+
this.m_cE = args[1].length;
|
800
|
+
}
|
801
|
+
this.m_cSrc = iSrc;
|
802
|
+
|
803
|
+
} // end function _setContent
|
804
|
+
|
805
|
+
|
806
|
+
XMLP.prototype._setErr = function(iErr) {
|
807
|
+
/*******************************************************************************************************************
|
808
|
+
function: _setErr
|
809
|
+
|
810
|
+
Author: Scott Severtson
|
811
|
+
*********************************************************************************************************************/
|
812
|
+
var strErr = XMLP._errs[iErr];
|
813
|
+
|
814
|
+
this.m_cAlt = strErr;
|
815
|
+
this.m_cB = 0;
|
816
|
+
this.m_cE = strErr.length;
|
817
|
+
this.m_cSrc = XMLP._CONT_ALT;
|
818
|
+
|
819
|
+
return XMLP._ERROR;
|
820
|
+
|
821
|
+
} // end function _setErr
|
822
|
+
|
823
|
+
|
824
|
+
|
825
|
+
|
826
|
+
|
827
|
+
|
828
|
+
/***************************************************************************************************************
|
829
|
+
SAXDriver is an object that basically wraps an XMLP instance, and provides an
|
830
|
+
event-based interface for parsing. This is the object users interact with when coding
|
831
|
+
with XML for <SCRIPT>
|
832
|
+
*****************************************************************************************************************/
|
833
|
+
|
834
|
+
|
835
|
+
SAXDriver = function() {
|
836
|
+
/*******************************************************************************************************************
|
837
|
+
function: SAXDriver
|
838
|
+
|
839
|
+
Author: Scott Severtson
|
840
|
+
|
841
|
+
Description:
|
842
|
+
This is the constructor for the SAXDriver Object
|
843
|
+
*********************************************************************************************************************/
|
844
|
+
this.m_hndDoc = null;
|
845
|
+
this.m_hndErr = null;
|
846
|
+
this.m_hndLex = null;
|
847
|
+
}
|
848
|
+
|
849
|
+
|
850
|
+
// CONSTANTS (these must be below the constructor)
|
851
|
+
|
852
|
+
// =========================================================================
|
853
|
+
// =========================================================================
|
854
|
+
// =========================================================================
|
855
|
+
SAXDriver.DOC_B = 1;
|
856
|
+
SAXDriver.DOC_E = 2;
|
857
|
+
SAXDriver.ELM_B = 3;
|
858
|
+
SAXDriver.ELM_E = 4;
|
859
|
+
SAXDriver.CHARS = 5;
|
860
|
+
SAXDriver.PI = 6;
|
861
|
+
SAXDriver.CD_B = 7;
|
862
|
+
SAXDriver.CD_E = 8;
|
863
|
+
SAXDriver.CMNT = 9;
|
864
|
+
SAXDriver.DTD_B = 10;
|
865
|
+
SAXDriver.DTD_E = 11;
|
866
|
+
// =========================================================================
|
867
|
+
// =========================================================================
|
868
|
+
// =========================================================================
|
869
|
+
|
870
|
+
|
871
|
+
|
872
|
+
SAXDriver.prototype.parse = function(strD) {
|
873
|
+
/*******************************************************************************************************************
|
874
|
+
function: parse
|
875
|
+
|
876
|
+
Author: Scott Severtson
|
877
|
+
*********************************************************************************************************************/
|
878
|
+
var parser = new XMLP(strD);
|
879
|
+
|
880
|
+
if(this.m_hndDoc && this.m_hndDoc.setDocumentLocator) {
|
881
|
+
this.m_hndDoc.setDocumentLocator(this);
|
882
|
+
}
|
883
|
+
|
884
|
+
this.m_parser = parser;
|
885
|
+
this.m_bErr = false;
|
886
|
+
|
887
|
+
if(!this.m_bErr) {
|
888
|
+
this._fireEvent(SAXDriver.DOC_B);
|
889
|
+
}
|
890
|
+
this._parseLoop();
|
891
|
+
if(!this.m_bErr) {
|
892
|
+
this._fireEvent(SAXDriver.DOC_E);
|
893
|
+
}
|
894
|
+
|
895
|
+
this.m_xml = null;
|
896
|
+
this.m_iP = 0;
|
897
|
+
|
898
|
+
} // end function parse
|
899
|
+
|
900
|
+
|
901
|
+
SAXDriver.prototype.setDocumentHandler = function(hnd) {
|
902
|
+
/*******************************************************************************************************************
|
903
|
+
function: setDocumentHandler
|
904
|
+
|
905
|
+
Author: Scott Severtson
|
906
|
+
*********************************************************************************************************************/
|
907
|
+
|
908
|
+
this.m_hndDoc = hnd;
|
909
|
+
|
910
|
+
} // end function setDocumentHandler
|
911
|
+
|
912
|
+
|
913
|
+
SAXDriver.prototype.setErrorHandler = function(hnd) {
|
914
|
+
/*******************************************************************************************************************
|
915
|
+
function: setErrorHandler
|
916
|
+
|
917
|
+
Author: Scott Severtson
|
918
|
+
*********************************************************************************************************************/
|
919
|
+
|
920
|
+
this.m_hndErr = hnd;
|
921
|
+
|
922
|
+
} // end function setErrorHandler
|
923
|
+
|
924
|
+
|
925
|
+
SAXDriver.prototype.setLexicalHandler = function(hnd) {
|
926
|
+
/*******************************************************************************************************************
|
927
|
+
function: setLexicalHandler
|
928
|
+
|
929
|
+
Author: Scott Severtson
|
930
|
+
*********************************************************************************************************************/
|
931
|
+
|
932
|
+
this.m_hndLex = hnd;
|
933
|
+
|
934
|
+
} // end function setLexicalHandler
|
935
|
+
|
936
|
+
|
937
|
+
/*******************************************************************************************************************
|
938
|
+
LOCATOR/PARSE EXCEPTION INTERFACE
|
939
|
+
*********************************************************************************************************************/
|
940
|
+
|
941
|
+
SAXDriver.prototype.getColumnNumber = function() {
|
942
|
+
/*******************************************************************************************************************
|
943
|
+
function: getSystemId
|
944
|
+
|
945
|
+
Author: Scott Severtson
|
946
|
+
*********************************************************************************************************************/
|
947
|
+
|
948
|
+
return this.m_parser.getColumnNumber();
|
949
|
+
|
950
|
+
} // end function getColumnNumber
|
951
|
+
|
952
|
+
|
953
|
+
SAXDriver.prototype.getLineNumber = function() {
|
954
|
+
/*******************************************************************************************************************
|
955
|
+
function: getLineNumber
|
956
|
+
|
957
|
+
Author: Scott Severtson
|
958
|
+
*********************************************************************************************************************/
|
959
|
+
|
960
|
+
return this.m_parser.getLineNumber();
|
961
|
+
|
962
|
+
} // end function getLineNumber
|
963
|
+
|
964
|
+
|
965
|
+
SAXDriver.prototype.getMessage = function() {
|
966
|
+
/*******************************************************************************************************************
|
967
|
+
function: getMessage
|
968
|
+
|
969
|
+
Author: Scott Severtson
|
970
|
+
*********************************************************************************************************************/
|
971
|
+
|
972
|
+
return this.m_strErrMsg;
|
973
|
+
|
974
|
+
} // end function getMessage
|
975
|
+
|
976
|
+
|
977
|
+
SAXDriver.prototype.getPublicId = function() {
|
978
|
+
/*******************************************************************************************************************
|
979
|
+
function: getPublicID
|
980
|
+
|
981
|
+
Author: Scott Severtson
|
982
|
+
*********************************************************************************************************************/
|
983
|
+
|
984
|
+
return null;
|
985
|
+
|
986
|
+
} // end function getPublicID
|
987
|
+
|
988
|
+
|
989
|
+
SAXDriver.prototype.getSystemId = function() {
|
990
|
+
/*******************************************************************************************************************
|
991
|
+
function: getSystemId
|
992
|
+
|
993
|
+
Author: Scott Severtson
|
994
|
+
*********************************************************************************************************************/
|
995
|
+
|
996
|
+
return null;
|
997
|
+
|
998
|
+
} // end function getSystemId
|
999
|
+
|
1000
|
+
|
1001
|
+
/*******************************************************************************************************************
|
1002
|
+
Attribute List Interface
|
1003
|
+
*********************************************************************************************************************/
|
1004
|
+
|
1005
|
+
SAXDriver.prototype.getLength = function() {
|
1006
|
+
/*******************************************************************************************************************
|
1007
|
+
function: getLength
|
1008
|
+
|
1009
|
+
Author: Scott Severtson
|
1010
|
+
*********************************************************************************************************************/
|
1011
|
+
|
1012
|
+
return this.m_parser.getAttributeCount();
|
1013
|
+
|
1014
|
+
} // end function getAttributeCount
|
1015
|
+
|
1016
|
+
|
1017
|
+
SAXDriver.prototype.getName = function(index) {
|
1018
|
+
/*******************************************************************************************************************
|
1019
|
+
function: getName
|
1020
|
+
|
1021
|
+
Author: Scott Severtson
|
1022
|
+
*********************************************************************************************************************/
|
1023
|
+
|
1024
|
+
return this.m_parser.getAttributeName(index);
|
1025
|
+
|
1026
|
+
} // end function getAttributeName
|
1027
|
+
|
1028
|
+
|
1029
|
+
SAXDriver.prototype.getValue = function(index) {
|
1030
|
+
/*******************************************************************************************************************
|
1031
|
+
function: getValue
|
1032
|
+
|
1033
|
+
Author: Scott Severtson
|
1034
|
+
*********************************************************************************************************************/
|
1035
|
+
|
1036
|
+
return this.m_parser.getAttributeValue(index);
|
1037
|
+
|
1038
|
+
} // end function getAttributeValue
|
1039
|
+
|
1040
|
+
|
1041
|
+
SAXDriver.prototype.getValueByName = function(name) {
|
1042
|
+
/*******************************************************************************************************************
|
1043
|
+
function: getValueByName
|
1044
|
+
|
1045
|
+
Author: Scott Severtson
|
1046
|
+
*********************************************************************************************************************/
|
1047
|
+
|
1048
|
+
return this.m_parser.getAttributeValueByName(name);
|
1049
|
+
|
1050
|
+
} // end function getAttributeValueByName
|
1051
|
+
|
1052
|
+
|
1053
|
+
/*******************************************************************************************************************
|
1054
|
+
Private functions
|
1055
|
+
*********************************************************************************************************************/
|
1056
|
+
|
1057
|
+
SAXDriver.prototype._fireError = function(strMsg) {
|
1058
|
+
/*******************************************************************************************************************
|
1059
|
+
function: _fireError
|
1060
|
+
|
1061
|
+
Author: Scott Severtson
|
1062
|
+
*********************************************************************************************************************/
|
1063
|
+
this.m_strErrMsg = strMsg;
|
1064
|
+
this.m_bErr = true;
|
1065
|
+
|
1066
|
+
if(this.m_hndErr && this.m_hndErr.fatalError) {
|
1067
|
+
this.m_hndErr.fatalError(this);
|
1068
|
+
}
|
1069
|
+
|
1070
|
+
} // end function _fireError
|
1071
|
+
|
1072
|
+
|
1073
|
+
SAXDriver.prototype._fireEvent = function(iEvt) {
|
1074
|
+
/*******************************************************************************************************************
|
1075
|
+
function: _fireEvent
|
1076
|
+
|
1077
|
+
Author: Scott Severtson
|
1078
|
+
*********************************************************************************************************************/
|
1079
|
+
var hnd, func, args = arguments, iLen = args.length - 1;
|
1080
|
+
|
1081
|
+
if(this.m_bErr) return;
|
1082
|
+
|
1083
|
+
if(SAXDriver.DOC_B == iEvt) {
|
1084
|
+
func = "startDocument"; hnd = this.m_hndDoc;
|
1085
|
+
}
|
1086
|
+
else if (SAXDriver.DOC_E == iEvt) {
|
1087
|
+
func = "endDocument"; hnd = this.m_hndDoc;
|
1088
|
+
}
|
1089
|
+
else if (SAXDriver.ELM_B == iEvt) {
|
1090
|
+
func = "startElement"; hnd = this.m_hndDoc;
|
1091
|
+
}
|
1092
|
+
else if (SAXDriver.ELM_E == iEvt) {
|
1093
|
+
func = "endElement"; hnd = this.m_hndDoc;
|
1094
|
+
}
|
1095
|
+
else if (SAXDriver.CHARS == iEvt) {
|
1096
|
+
func = "characters"; hnd = this.m_hndDoc;
|
1097
|
+
}
|
1098
|
+
else if (SAXDriver.PI == iEvt) {
|
1099
|
+
func = "processingInstruction"; hnd = this.m_hndDoc;
|
1100
|
+
}
|
1101
|
+
else if (SAXDriver.CD_B == iEvt) {
|
1102
|
+
func = "startCDATA"; hnd = this.m_hndLex;
|
1103
|
+
}
|
1104
|
+
else if (SAXDriver.CD_E == iEvt) {
|
1105
|
+
func = "endCDATA"; hnd = this.m_hndLex;
|
1106
|
+
}
|
1107
|
+
else if (SAXDriver.CMNT == iEvt) {
|
1108
|
+
func = "comment"; hnd = this.m_hndLex;
|
1109
|
+
}
|
1110
|
+
|
1111
|
+
if(hnd && hnd[func]) {
|
1112
|
+
if(0 == iLen) {
|
1113
|
+
hnd[func]();
|
1114
|
+
}
|
1115
|
+
else if (1 == iLen) {
|
1116
|
+
hnd[func](args[1]);
|
1117
|
+
}
|
1118
|
+
else if (2 == iLen) {
|
1119
|
+
hnd[func](args[1], args[2]);
|
1120
|
+
}
|
1121
|
+
else if (3 == iLen) {
|
1122
|
+
hnd[func](args[1], args[2], args[3]);
|
1123
|
+
}
|
1124
|
+
}
|
1125
|
+
|
1126
|
+
} // end function _fireEvent
|
1127
|
+
|
1128
|
+
|
1129
|
+
SAXDriver.prototype._parseLoop = function(parser) {
|
1130
|
+
/*******************************************************************************************************************
|
1131
|
+
function: _parseLoop
|
1132
|
+
|
1133
|
+
Author: Scott Severtson
|
1134
|
+
*********************************************************************************************************************/
|
1135
|
+
var iEvent, parser;
|
1136
|
+
|
1137
|
+
parser = this.m_parser;
|
1138
|
+
while(!this.m_bErr) {
|
1139
|
+
iEvent = parser.next();
|
1140
|
+
|
1141
|
+
if(iEvent == XMLP._ELM_B) {
|
1142
|
+
this._fireEvent(SAXDriver.ELM_B, parser.getName(), this);
|
1143
|
+
}
|
1144
|
+
else if(iEvent == XMLP._ELM_E) {
|
1145
|
+
this._fireEvent(SAXDriver.ELM_E, parser.getName());
|
1146
|
+
}
|
1147
|
+
else if(iEvent == XMLP._ELM_EMP) {
|
1148
|
+
this._fireEvent(SAXDriver.ELM_B, parser.getName(), this);
|
1149
|
+
this._fireEvent(SAXDriver.ELM_E, parser.getName());
|
1150
|
+
}
|
1151
|
+
else if(iEvent == XMLP._TEXT) {
|
1152
|
+
this._fireEvent(SAXDriver.CHARS, parser.getContent(), parser.getContentBegin(), parser.getContentEnd() - parser.getContentBegin());
|
1153
|
+
}
|
1154
|
+
else if(iEvent == XMLP._ENTITY) {
|
1155
|
+
this._fireEvent(SAXDriver.CHARS, parser.getContent(), parser.getContentBegin(), parser.getContentEnd() - parser.getContentBegin());
|
1156
|
+
}
|
1157
|
+
else if(iEvent == XMLP._PI) {
|
1158
|
+
this._fireEvent(SAXDriver.PI, parser.getName(), parser.getContent().substring(parser.getContentBegin(), parser.getContentEnd()));
|
1159
|
+
}
|
1160
|
+
else if(iEvent == XMLP._CDATA) {
|
1161
|
+
this._fireEvent(SAXDriver.CD_B);
|
1162
|
+
this._fireEvent(SAXDriver.CHARS, parser.getContent(), parser.getContentBegin(), parser.getContentEnd() - parser.getContentBegin());
|
1163
|
+
this._fireEvent(SAXDriver.CD_E);
|
1164
|
+
}
|
1165
|
+
else if(iEvent == XMLP._COMMENT) {
|
1166
|
+
this._fireEvent(SAXDriver.CMNT, parser.getContent(), parser.getContentBegin(), parser.getContentEnd() - parser.getContentBegin());
|
1167
|
+
}
|
1168
|
+
else if(iEvent == XMLP._DTD) {
|
1169
|
+
}
|
1170
|
+
else if(iEvent == XMLP._ERROR) {
|
1171
|
+
this._fireError(parser.getContent());
|
1172
|
+
}
|
1173
|
+
else if(iEvent == XMLP._NONE) {
|
1174
|
+
return;
|
1175
|
+
}
|
1176
|
+
}
|
1177
|
+
|
1178
|
+
} // end function _parseLoop
|
1179
|
+
|
1180
|
+
|
1181
|
+
|
1182
|
+
/***************************************************************************************************************
|
1183
|
+
SAXStrings: a useful object containing string manipulation functions
|
1184
|
+
*****************************************************************************************************************/
|
1185
|
+
|
1186
|
+
|
1187
|
+
SAXStrings = function() {
|
1188
|
+
/*******************************************************************************************************************
|
1189
|
+
function: SAXStrings
|
1190
|
+
|
1191
|
+
Author: Scott Severtson
|
1192
|
+
|
1193
|
+
Description:
|
1194
|
+
This is the constructor of the SAXStrings object
|
1195
|
+
*********************************************************************************************************************/
|
1196
|
+
} // end function SAXStrings
|
1197
|
+
|
1198
|
+
|
1199
|
+
// CONSTANTS (these must be below the constructor)
|
1200
|
+
|
1201
|
+
// =========================================================================
|
1202
|
+
// =========================================================================
|
1203
|
+
// =========================================================================
|
1204
|
+
SAXStrings.WHITESPACE = " \t\n\r";
|
1205
|
+
SAXStrings.QUOTES = "\"'";
|
1206
|
+
// =========================================================================
|
1207
|
+
// =========================================================================
|
1208
|
+
// =========================================================================
|
1209
|
+
|
1210
|
+
|
1211
|
+
SAXStrings.getColumnNumber = function(strD, iP) {
|
1212
|
+
/*******************************************************************************************************************
|
1213
|
+
function: replace
|
1214
|
+
|
1215
|
+
Author: Scott Severtson
|
1216
|
+
*********************************************************************************************************************/
|
1217
|
+
if(SAXStrings.isEmpty(strD)) {
|
1218
|
+
return -1;
|
1219
|
+
}
|
1220
|
+
iP = iP || strD.length;
|
1221
|
+
|
1222
|
+
var arrD = strD.substring(0, iP).split("\n");
|
1223
|
+
var strLine = arrD[arrD.length - 1];
|
1224
|
+
arrD.length--;
|
1225
|
+
var iLinePos = arrD.join("\n").length;
|
1226
|
+
|
1227
|
+
return iP - iLinePos;
|
1228
|
+
|
1229
|
+
} // end function getColumnNumber
|
1230
|
+
|
1231
|
+
|
1232
|
+
SAXStrings.getLineNumber = function(strD, iP) {
|
1233
|
+
/*******************************************************************************************************************
|
1234
|
+
function: getLineNumber
|
1235
|
+
|
1236
|
+
Author: Scott Severtson
|
1237
|
+
*********************************************************************************************************************/
|
1238
|
+
if(SAXStrings.isEmpty(strD)) {
|
1239
|
+
return -1;
|
1240
|
+
}
|
1241
|
+
iP = iP || strD.length;
|
1242
|
+
|
1243
|
+
return strD.substring(0, iP).split("\n").length
|
1244
|
+
} // end function getLineNumber
|
1245
|
+
|
1246
|
+
|
1247
|
+
SAXStrings.indexOfNonWhitespace = function(strD, iB, iE) {
|
1248
|
+
/*******************************************************************************************************************
|
1249
|
+
function: indexOfNonWhitespace
|
1250
|
+
|
1251
|
+
Author: Scott Severtson
|
1252
|
+
*********************************************************************************************************************/
|
1253
|
+
if(SAXStrings.isEmpty(strD)) {
|
1254
|
+
return -1;
|
1255
|
+
}
|
1256
|
+
iB = iB || 0;
|
1257
|
+
iE = iE || strD.length;
|
1258
|
+
|
1259
|
+
for(var i = iB; i < iE; i++){
|
1260
|
+
if(SAXStrings.WHITESPACE.indexOf(strD.charAt(i)) == -1) {
|
1261
|
+
return i;
|
1262
|
+
}
|
1263
|
+
}
|
1264
|
+
return -1;
|
1265
|
+
|
1266
|
+
} // end function indexOfNonWhitespace
|
1267
|
+
|
1268
|
+
|
1269
|
+
SAXStrings.indexOfWhitespace = function(strD, iB, iE) {
|
1270
|
+
/*******************************************************************************************************************
|
1271
|
+
function: indexOfWhitespace
|
1272
|
+
|
1273
|
+
Author: Scott Severtson
|
1274
|
+
*********************************************************************************************************************/
|
1275
|
+
if(SAXStrings.isEmpty(strD)) {
|
1276
|
+
return -1;
|
1277
|
+
}
|
1278
|
+
iB = iB || 0;
|
1279
|
+
iE = iE || strD.length;
|
1280
|
+
|
1281
|
+
for(var i = iB; i < iE; i++) {
|
1282
|
+
if(SAXStrings.WHITESPACE.indexOf(strD.charAt(i)) != -1) {
|
1283
|
+
return i;
|
1284
|
+
}
|
1285
|
+
}
|
1286
|
+
return -1;
|
1287
|
+
} // end function indexOfWhitespace
|
1288
|
+
|
1289
|
+
|
1290
|
+
SAXStrings.isEmpty = function(strD) {
|
1291
|
+
/*******************************************************************************************************************
|
1292
|
+
function: isEmpty
|
1293
|
+
|
1294
|
+
Author: Scott Severtson
|
1295
|
+
*********************************************************************************************************************/
|
1296
|
+
|
1297
|
+
return (strD == null) || (strD.length == 0);
|
1298
|
+
|
1299
|
+
} // end function isEmpty
|
1300
|
+
|
1301
|
+
|
1302
|
+
SAXStrings.lastIndexOfNonWhitespace = function(strD, iB, iE) {
|
1303
|
+
/*******************************************************************************************************************
|
1304
|
+
function: lastIndexOfNonWhiteSpace
|
1305
|
+
|
1306
|
+
Author: Scott Severtson
|
1307
|
+
*********************************************************************************************************************/
|
1308
|
+
if(SAXStrings.isEmpty(strD)) {
|
1309
|
+
return -1;
|
1310
|
+
}
|
1311
|
+
iB = iB || 0;
|
1312
|
+
iE = iE || strD.length;
|
1313
|
+
|
1314
|
+
for(var i = iE - 1; i >= iB; i--){
|
1315
|
+
if(SAXStrings.WHITESPACE.indexOf(strD.charAt(i)) == -1){
|
1316
|
+
return i;
|
1317
|
+
}
|
1318
|
+
}
|
1319
|
+
return -1;
|
1320
|
+
} // end function lastIndexOfNonWhitespace
|
1321
|
+
|
1322
|
+
|
1323
|
+
SAXStrings.replace = function(strD, iB, iE, strF, strR) {
|
1324
|
+
/*******************************************************************************************************************
|
1325
|
+
function: replace
|
1326
|
+
|
1327
|
+
Author: Scott Severtson
|
1328
|
+
*********************************************************************************************************************/
|
1329
|
+
if(SAXStrings.isEmpty(strD)) {
|
1330
|
+
return "";
|
1331
|
+
}
|
1332
|
+
iB = iB || 0;
|
1333
|
+
iE = iE || strD.length;
|
1334
|
+
|
1335
|
+
return strD.substring(iB, iE).split(strF).join(strR);
|
1336
|
+
|
1337
|
+
} // end function replace
|
1338
|
+
|
1339
|
+
|
1340
|
+
|
1341
|
+
/***************************************************************************************************************
|
1342
|
+
Stack: A simple stack class, used for verifying document structure.
|
1343
|
+
*****************************************************************************************************************/
|
1344
|
+
|
1345
|
+
Stack = function() {
|
1346
|
+
/*******************************************************************************************************************
|
1347
|
+
function: Stack
|
1348
|
+
|
1349
|
+
Author: Scott Severtson
|
1350
|
+
|
1351
|
+
Description:
|
1352
|
+
Constructor of the Stack Object
|
1353
|
+
*********************************************************************************************************************/
|
1354
|
+
this.m_arr = new Array();
|
1355
|
+
|
1356
|
+
} // end function Stack
|
1357
|
+
|
1358
|
+
|
1359
|
+
Stack.prototype.clear = function() {
|
1360
|
+
/*******************************************************************************************************************
|
1361
|
+
function: clear
|
1362
|
+
|
1363
|
+
Author: Scott Severtson
|
1364
|
+
*********************************************************************************************************************/
|
1365
|
+
|
1366
|
+
this.m_arr = new Array();
|
1367
|
+
|
1368
|
+
} // end function clear
|
1369
|
+
|
1370
|
+
|
1371
|
+
Stack.prototype.count = function() {
|
1372
|
+
/*******************************************************************************************************************
|
1373
|
+
function: count
|
1374
|
+
|
1375
|
+
Author: Scott Severtson
|
1376
|
+
*********************************************************************************************************************/
|
1377
|
+
|
1378
|
+
return this.m_arr.length;
|
1379
|
+
|
1380
|
+
} // end function count
|
1381
|
+
|
1382
|
+
|
1383
|
+
Stack.prototype.destroy = function() {
|
1384
|
+
/*******************************************************************************************************************
|
1385
|
+
function: destroy
|
1386
|
+
|
1387
|
+
Author: Scott Severtson
|
1388
|
+
*********************************************************************************************************************/
|
1389
|
+
|
1390
|
+
this.m_arr = null;
|
1391
|
+
|
1392
|
+
} // end function destroy
|
1393
|
+
|
1394
|
+
|
1395
|
+
Stack.prototype.peek = function() {
|
1396
|
+
/*******************************************************************************************************************
|
1397
|
+
function: peek
|
1398
|
+
|
1399
|
+
Author: Scott Severtson
|
1400
|
+
*********************************************************************************************************************/
|
1401
|
+
if(this.m_arr.length == 0) {
|
1402
|
+
return null;
|
1403
|
+
}
|
1404
|
+
|
1405
|
+
return this.m_arr[this.m_arr.length - 1];
|
1406
|
+
|
1407
|
+
} // end function peek
|
1408
|
+
|
1409
|
+
|
1410
|
+
Stack.prototype.pop = function() {
|
1411
|
+
/*******************************************************************************************************************
|
1412
|
+
function: pop
|
1413
|
+
|
1414
|
+
Author: Scott Severtson
|
1415
|
+
*********************************************************************************************************************/
|
1416
|
+
if(this.m_arr.length == 0) {
|
1417
|
+
return null;
|
1418
|
+
}
|
1419
|
+
|
1420
|
+
var o = this.m_arr[this.m_arr.length - 1];
|
1421
|
+
this.m_arr.length--;
|
1422
|
+
return o;
|
1423
|
+
|
1424
|
+
} // end function pop
|
1425
|
+
|
1426
|
+
|
1427
|
+
Stack.prototype.push = function(o) {
|
1428
|
+
/*******************************************************************************************************************
|
1429
|
+
function: push
|
1430
|
+
|
1431
|
+
Author: Scott Severtson
|
1432
|
+
*********************************************************************************************************************/
|
1433
|
+
|
1434
|
+
this.m_arr[this.m_arr.length] = o;
|
1435
|
+
|
1436
|
+
} // end function push
|
1437
|
+
|
1438
|
+
|
1439
|
+
|
1440
|
+
// =========================================================================
|
1441
|
+
// =========================================================================
|
1442
|
+
// =========================================================================
|
1443
|
+
|
1444
|
+
// CONVENIENCE FUNCTIONS
|
1445
|
+
|
1446
|
+
// =========================================================================
|
1447
|
+
// =========================================================================
|
1448
|
+
// =========================================================================
|
1449
|
+
|
1450
|
+
function isEmpty(str) {
|
1451
|
+
/*******************************************************************************************************************
|
1452
|
+
function: isEmpty
|
1453
|
+
|
1454
|
+
Author: mike@idle.org
|
1455
|
+
|
1456
|
+
Description:
|
1457
|
+
convenience function to identify an empty string
|
1458
|
+
|
1459
|
+
*********************************************************************************************************************/
|
1460
|
+
return (str==null) || (str.length==0);
|
1461
|
+
|
1462
|
+
} // end function isEmpty
|
1463
|
+
|
1464
|
+
|
1465
|
+
|
1466
|
+
function trim(trimString, leftTrim, rightTrim) {
|
1467
|
+
/*******************************************************************************************************************
|
1468
|
+
function: trim
|
1469
|
+
|
1470
|
+
Author: may106@psu.edu
|
1471
|
+
|
1472
|
+
Description:
|
1473
|
+
helper function to trip a string (trimString) of leading (leftTrim)
|
1474
|
+
and trailing (rightTrim) whitespace
|
1475
|
+
|
1476
|
+
*********************************************************************************************************************/
|
1477
|
+
if (isEmpty(trimString)) {
|
1478
|
+
return "";
|
1479
|
+
}
|
1480
|
+
|
1481
|
+
// the general focus here is on minimal method calls - hence only one
|
1482
|
+
// substring is done to complete the trim.
|
1483
|
+
|
1484
|
+
if (leftTrim == null) {
|
1485
|
+
leftTrim = true;
|
1486
|
+
}
|
1487
|
+
|
1488
|
+
if (rightTrim == null) {
|
1489
|
+
rightTrim = true;
|
1490
|
+
}
|
1491
|
+
|
1492
|
+
var left=0;
|
1493
|
+
var right=0;
|
1494
|
+
var i=0;
|
1495
|
+
var k=0;
|
1496
|
+
|
1497
|
+
|
1498
|
+
// modified to properly handle strings that are all whitespace
|
1499
|
+
if (leftTrim == true) {
|
1500
|
+
while ((i<trimString.length) && (whitespace.indexOf(trimString.charAt(i++))!=-1)) {
|
1501
|
+
left++;
|
1502
|
+
}
|
1503
|
+
}
|
1504
|
+
if (rightTrim == true) {
|
1505
|
+
k=trimString.length-1;
|
1506
|
+
while((k>=left) && (whitespace.indexOf(trimString.charAt(k--))!=-1)) {
|
1507
|
+
right++;
|
1508
|
+
}
|
1509
|
+
}
|
1510
|
+
return trimString.substring(left, trimString.length - right);
|
1511
|
+
} // end function trim
|
1512
|
+
|
1513
|
+
/**
|
1514
|
+
* function __escapeString
|
1515
|
+
*
|
1516
|
+
* author: David Joham djoham@yahoo.com
|
1517
|
+
*
|
1518
|
+
* @param str : string - The string to be escaped
|
1519
|
+
*
|
1520
|
+
* @return : string - The escaped string
|
1521
|
+
*/
|
1522
|
+
function __escapeString(str) {
|
1523
|
+
|
1524
|
+
var escAmpRegEx = /&/g;
|
1525
|
+
var escLtRegEx = /</g;
|
1526
|
+
var escGtRegEx = />/g;
|
1527
|
+
var quotRegEx = /"/g;
|
1528
|
+
var aposRegEx = /'/g;
|
1529
|
+
|
1530
|
+
str = str.replace(escAmpRegEx, "&");
|
1531
|
+
str = str.replace(escLtRegEx, "<");
|
1532
|
+
str = str.replace(escGtRegEx, ">");
|
1533
|
+
str = str.replace(quotRegEx, """);
|
1534
|
+
str = str.replace(aposRegEx, "'");
|
1535
|
+
|
1536
|
+
return str;
|
1537
|
+
}
|
1538
|
+
|
1539
|
+
/**
|
1540
|
+
* function __unescapeString
|
1541
|
+
*
|
1542
|
+
* author: David Joham djoham@yahoo.com
|
1543
|
+
*
|
1544
|
+
* @param str : string - The string to be unescaped
|
1545
|
+
*
|
1546
|
+
* @return : string - The unescaped string
|
1547
|
+
*/
|
1548
|
+
function __unescapeString(str) {
|
1549
|
+
|
1550
|
+
var escAmpRegEx = /&/g;
|
1551
|
+
var escLtRegEx = /</g;
|
1552
|
+
var escGtRegEx = />/g;
|
1553
|
+
var quotRegEx = /"/g;
|
1554
|
+
var aposRegEx = /'/g;
|
1555
|
+
|
1556
|
+
str = str.replace(escAmpRegEx, "&");
|
1557
|
+
str = str.replace(escLtRegEx, "<");
|
1558
|
+
str = str.replace(escGtRegEx, ">");
|
1559
|
+
str = str.replace(quotRegEx, "\"");
|
1560
|
+
str = str.replace(aposRegEx, "'");
|
1561
|
+
|
1562
|
+
return str;
|
1563
|
+
}
|
1564
|
+
|