envjs19 0.3.8.20101029121421

Sign up to get free protection for your applications and to get access to all the features.
Files changed (279) hide show
  1. data/.jslintrbrc +30 -0
  2. data/.project +17 -0
  3. data/CHANGELOG.rdoc +57 -0
  4. data/DTD/xhtml-lat1.ent +196 -0
  5. data/DTD/xhtml-special.ent +80 -0
  6. data/DTD/xhtml-symbol.ent +237 -0
  7. data/DTD/xhtml.soc +14 -0
  8. data/DTD/xhtml1-frameset.dtd +1235 -0
  9. data/DTD/xhtml1-strict.dtd +978 -0
  10. data/DTD/xhtml1-transitional.dtd +1201 -0
  11. data/DTD/xhtml1.dcl +192 -0
  12. data/Makefile +7 -0
  13. data/Manifest.txt +280 -0
  14. data/README.rdoc +65 -0
  15. data/Rakefile +196 -0
  16. data/Wakefile +11 -0
  17. data/bin/envjsrb +257 -0
  18. data/build.properties +9 -0
  19. data/build.xml +247 -0
  20. data/gm/jquery.js +6002 -0
  21. data/gm/mainx.js +2648 -0
  22. data/gm/sensx.js +135 -0
  23. data/gm/t.js +6 -0
  24. data/gm/x.html +76 -0
  25. data/htmlparser/BrowserTreeBuilder.java +456 -0
  26. data/htmlparser/README +34 -0
  27. data/htmlparser/build.sh +38 -0
  28. data/jsl/jsl +0 -0
  29. data/jsl/jsl.default.conf +129 -0
  30. data/jsl/jsl.exe +0 -0
  31. data/lib/envjs.rb +35 -0
  32. data/lib/envjs/event_loop.js +206 -0
  33. data/lib/envjs/net.rb +3 -0
  34. data/lib/envjs/net/cgi.rb +94 -0
  35. data/lib/envjs/net/file.rb +69 -0
  36. data/lib/envjs/options.rb +11 -0
  37. data/lib/envjs/runtime.rb +346 -0
  38. data/lib/envjs/tempfile.rb +24 -0
  39. data/licenses/GPL-LICENSE.txt +278 -0
  40. data/licenses/MIT-LICENSE.txt +20 -0
  41. data/src/base64.js +80 -0
  42. data/src/build.js +6 -0
  43. data/src/cruft/bad.html +24 -0
  44. data/src/cruft/dom.js +606 -0
  45. data/src/cruft/element.js +297 -0
  46. data/src/cruft/good.html +30 -0
  47. data/src/cruft/good.js +32 -0
  48. data/src/cruft/internal.js +81 -0
  49. data/src/cruft/parser.js +458 -0
  50. data/src/css/properties.js +293 -0
  51. data/src/css/rule.js +22 -0
  52. data/src/css/sizzle.js +717 -0
  53. data/src/css/stylesheet.js +52 -0
  54. data/src/dom/attr.js +55 -0
  55. data/src/dom/cdatasection.js +31 -0
  56. data/src/dom/characterdata.js +119 -0
  57. data/src/dom/comment.js +30 -0
  58. data/src/dom/doctype.js +9 -0
  59. data/src/dom/document.js +1023 -0
  60. data/src/dom/dom.js +134 -0
  61. data/src/dom/element.js +217 -0
  62. data/src/dom/entities.js +273 -0
  63. data/src/dom/exception.js +28 -0
  64. data/src/dom/fragment.js +37 -0
  65. data/src/dom/implementation.js +140 -0
  66. data/src/dom/instruction.js +51 -0
  67. data/src/dom/namednodemap.js +374 -0
  68. data/src/dom/namespace.js +50 -0
  69. data/src/dom/node.js +618 -0
  70. data/src/dom/nodelist.js +195 -0
  71. data/src/dom/parser.js +1207 -0
  72. data/src/dom/text.js +73 -0
  73. data/src/event/event.js +47 -0
  74. data/src/event/mouseevent.js +4 -0
  75. data/src/event/uievent.js +8 -0
  76. data/src/html/a.js +110 -0
  77. data/src/html/anchor.js +80 -0
  78. data/src/html/area.js +57 -0
  79. data/src/html/base.js +26 -0
  80. data/src/html/blockquote-q.js +19 -0
  81. data/src/html/body.js +19 -0
  82. data/src/html/button.js +21 -0
  83. data/src/html/canvas.js +14 -0
  84. data/src/html/col-colgroup.js +49 -0
  85. data/src/html/collection.js +72 -0
  86. data/src/html/cookie.js +153 -0
  87. data/src/html/del-ins.js +25 -0
  88. data/src/html/div.js +28 -0
  89. data/src/html/document.js +364 -0
  90. data/src/html/element.js +382 -0
  91. data/src/html/fieldset.js +19 -0
  92. data/src/html/form.js +484 -0
  93. data/src/html/frame.js +89 -0
  94. data/src/html/frameset.js +25 -0
  95. data/src/html/head.js +44 -0
  96. data/src/html/html.js +0 -0
  97. data/src/html/htmlparser.js +340 -0
  98. data/src/html/iframe.js +26 -0
  99. data/src/html/image.js +0 -0
  100. data/src/html/img.js +62 -0
  101. data/src/html/input-elements.js +307 -0
  102. data/src/html/input.js +65 -0
  103. data/src/html/label.js +26 -0
  104. data/src/html/legend.js +19 -0
  105. data/src/html/link.js +82 -0
  106. data/src/html/map.js +22 -0
  107. data/src/html/meta.js +37 -0
  108. data/src/html/object.js +89 -0
  109. data/src/html/optgroup.js +25 -0
  110. data/src/html/option.js +103 -0
  111. data/src/html/param.js +38 -0
  112. data/src/html/script.js +122 -0
  113. data/src/html/select.js +132 -0
  114. data/src/html/style.js +31 -0
  115. data/src/html/table.js +199 -0
  116. data/src/html/tbody-thead-tfoot.js +92 -0
  117. data/src/html/td-th.js +18 -0
  118. data/src/html/textarea.js +31 -0
  119. data/src/html/title.js +20 -0
  120. data/src/html/tr.js +114 -0
  121. data/src/intro.js +141 -0
  122. data/src/outro.js +70 -0
  123. data/src/parser/html5.detailed.js +10762 -0
  124. data/src/parser/html5.min.js +503 -0
  125. data/src/parser/html5.pretty.js +10815 -0
  126. data/src/parser/intro.js +42 -0
  127. data/src/parser/outro.js +9 -0
  128. data/src/platform/core.js +323 -0
  129. data/src/platform/johnson.js +484 -0
  130. data/src/platform/rhino.js +327 -0
  131. data/src/platform/static/intro.js +41 -0
  132. data/src/platform/static/outro.js +30 -0
  133. data/src/profile/aop.js +238 -0
  134. data/src/profile/profile.js +402 -0
  135. data/src/serializer/xml.js +21 -0
  136. data/src/svg/animatedstring.js +25 -0
  137. data/src/svg/document.js +25 -0
  138. data/src/svg/element.js +22 -0
  139. data/src/svg/locatable.js +17 -0
  140. data/src/svg/rect.js +18 -0
  141. data/src/svg/rectelement.js +24 -0
  142. data/src/svg/stylable.js +49 -0
  143. data/src/svg/svgelement.js +22 -0
  144. data/src/svg/transformable.js +15 -0
  145. data/src/window/css.js +15 -0
  146. data/src/window/dialog.js +16 -0
  147. data/src/window/document.js +28 -0
  148. data/src/window/event.js +265 -0
  149. data/src/window/history.js +62 -0
  150. data/src/window/location.js +156 -0
  151. data/src/window/navigator.js +48 -0
  152. data/src/window/screen.js +53 -0
  153. data/src/window/timer.js +21 -0
  154. data/src/window/window.js +284 -0
  155. data/src/window/xhr.js +135 -0
  156. data/src/xpath/expression.js +49 -0
  157. data/src/xpath/implementation.js +2505 -0
  158. data/src/xpath/result.js +67 -0
  159. data/src/xpath/util.js +551 -0
  160. data/src/xpath/xmltoken.js +149 -0
  161. data/src/xslt/COPYING +34 -0
  162. data/src/xslt/ajaxslt-0.8.1/AUTHORS +1 -0
  163. data/src/xslt/ajaxslt-0.8.1/ChangeLog +136 -0
  164. data/src/xslt/ajaxslt-0.8.1/Makefile +49 -0
  165. data/src/xslt/ajaxslt-0.8.1/README +102 -0
  166. data/src/xslt/ajaxslt-0.8.1/TODO +15 -0
  167. data/src/xslt/ajaxslt-0.8.1/dom.js +566 -0
  168. data/src/xslt/ajaxslt-0.8.1/dom_unittest.html +24 -0
  169. data/src/xslt/ajaxslt-0.8.1/dom_unittest.js +131 -0
  170. data/src/xslt/ajaxslt-0.8.1/simplelog.js +79 -0
  171. data/src/xslt/ajaxslt-0.8.1/test/xpath.html +18 -0
  172. data/src/xslt/ajaxslt-0.8.1/test/xpath_script.js +45 -0
  173. data/src/xslt/ajaxslt-0.8.1/test/xslt.html +58 -0
  174. data/src/xslt/ajaxslt-0.8.1/test/xslt_script.js +33 -0
  175. data/src/xslt/ajaxslt-0.8.1/unittestsuite.html +26 -0
  176. data/src/xslt/ajaxslt-0.8.1/xmltoken.js +149 -0
  177. data/src/xslt/ajaxslt-0.8.1/xmltoken_unittest.html +18 -0
  178. data/src/xslt/ajaxslt-0.8.1/xmltoken_unittest.js +811 -0
  179. data/src/xslt/ajaxslt-0.8.1/xpath_unittest.html +39 -0
  180. data/src/xslt/ajaxslt-0.8.1/xpath_unittest.js +557 -0
  181. data/src/xslt/ajaxslt-0.8.1/xpathdebug.js +234 -0
  182. data/src/xslt/ajaxslt-0.8.1/xslt_unittest.html +138 -0
  183. data/src/xslt/ajaxslt-0.8.1/xslt_unittest.js +68 -0
  184. data/src/xslt/implementation.js +625 -0
  185. data/src/xslt/processor.js +37 -0
  186. data/src/xslt/util.js +449 -0
  187. data/test/base64.js +80 -0
  188. data/test/call-load-test.js +15 -0
  189. data/test/data.js +45 -0
  190. data/test/debug.js +53 -0
  191. data/test/firebug/errorIcon.png +0 -0
  192. data/test/firebug/firebug.css +209 -0
  193. data/test/firebug/firebug.html +23 -0
  194. data/test/firebug/firebug.js +672 -0
  195. data/test/firebug/firebugx.js +10 -0
  196. data/test/firebug/infoIcon.png +0 -0
  197. data/test/firebug/warningIcon.png +0 -0
  198. data/test/fixtures/html/events.html +171 -0
  199. data/test/fixtures/html/iframe1.html +46 -0
  200. data/test/fixtures/html/iframe1a.html +46 -0
  201. data/test/fixtures/html/iframe2.html +45 -0
  202. data/test/fixtures/html/iframe3.html +28 -0
  203. data/test/fixtures/html/iframeN.html +57 -0
  204. data/test/fixtures/html/malformed.html +181 -0
  205. data/test/fixtures/html/scope.html +81 -0
  206. data/test/fixtures/html/trivial.html +19 -0
  207. data/test/fixtures/html/with_js.html +26 -0
  208. data/test/fixtures/images/icon-blue.png +0 -0
  209. data/test/fixtures/js/external_script.js +1 -0
  210. data/test/fixtures/js/script.js +1 -0
  211. data/test/fixtures/js/script_error.js +2 -0
  212. data/test/foo.html +8 -0
  213. data/test/foo.js +40 -0
  214. data/test/html/events.html +171 -0
  215. data/test/html/iframe1.html +46 -0
  216. data/test/html/iframe1a.html +46 -0
  217. data/test/html/iframe2.html +45 -0
  218. data/test/html/iframe3.html +30 -0
  219. data/test/html/iframeN.html +57 -0
  220. data/test/html/malformed.html +181 -0
  221. data/test/html/scope.html +87 -0
  222. data/test/html/script.js +1 -0
  223. data/test/html/trivial.html +19 -0
  224. data/test/html/with_js.html +26 -0
  225. data/test/index.html +328 -0
  226. data/test/java-prototype.js +9 -0
  227. data/test/jquery.js +6002 -0
  228. data/test/primary-tests.js +26 -0
  229. data/test/prototype-test.js +13 -0
  230. data/test/qunit.js +61 -0
  231. data/test/qunit/qunit/qunit.css +17 -0
  232. data/test/qunit/qunit/qunit.js +997 -0
  233. data/test/scope.html +19 -0
  234. data/test/scope.rb +24 -0
  235. data/test/smp/dmathieu/index.html +8 -0
  236. data/test/specs/dist/env.spec.js +1534 -0
  237. data/test/specs/envjs.spec.css +46 -0
  238. data/test/specs/parser/html.js +31 -0
  239. data/test/specs/parser/spec.html +40 -0
  240. data/test/specs/parser/xml.js +31 -0
  241. data/test/specs/qunit.bdd.js +210 -0
  242. data/test/specs/qunit.css +17 -0
  243. data/test/specs/qunit.js +997 -0
  244. data/test/specs/template/spec-0.js +31 -0
  245. data/test/specs/template/spec-1.js +31 -0
  246. data/test/specs/template/spec.html +40 -0
  247. data/test/specs/window/css.js +23 -0
  248. data/test/specs/window/dialog.js +25 -0
  249. data/test/specs/window/document.js +23 -0
  250. data/test/specs/window/event.js +25 -0
  251. data/test/specs/window/history.js +34 -0
  252. data/test/specs/window/location.js +34 -0
  253. data/test/specs/window/navigator.js +71 -0
  254. data/test/specs/window/screen.js +42 -0
  255. data/test/specs/window/spec.html +48 -0
  256. data/test/specs/window/timer.js +26 -0
  257. data/test/specs/window/window.js +53 -0
  258. data/test/specs/xhr/spec.html +47 -0
  259. data/test/specs/xhr/xhr.js +31 -0
  260. data/test/test.js +10 -0
  261. data/test/unit/dom.js +44 -0
  262. data/test/unit/elementmembers.js +92 -0
  263. data/test/unit/events.js +195 -0
  264. data/test/unit/fixtures/external_script.js +1 -0
  265. data/test/unit/form.js +40 -0
  266. data/test/unit/iframe.js +234 -0
  267. data/test/unit/insertion.js +23 -0
  268. data/test/unit/multi-window.js +212 -0
  269. data/test/unit/nu.validator.js +34 -0
  270. data/test/unit/onload.js +90 -0
  271. data/test/unit/parser.js +122 -0
  272. data/test/unit/prototypecompat.js +22 -0
  273. data/test/unit/proxy.js +6 -0
  274. data/test/unit/scope.js +209 -0
  275. data/test/unit/timer.js +115 -0
  276. data/test/unit/window.js +57 -0
  277. data/test/x.js +1 -0
  278. data/test/y.js +1 -0
  279. metadata +367 -0
@@ -0,0 +1,195 @@
1
+ $debug("Defining NodeList");
2
+ /*
3
+ * NodeList - DOM Level 2
4
+ */
5
+ /**
6
+ * @class DOMNodeList - provides the abstraction of an ordered collection of nodes
7
+ *
8
+ * @author Jon van Noort (jon@webarcana.com.au)
9
+ *
10
+ * @param ownerDocument : DOMDocument - the ownerDocument
11
+ * @param parentNode : DOMNode - the node that the DOMNodeList is attached to (or null)
12
+ */
13
+ var DOMNodeList = function(ownerDocument, parentNode) {
14
+ this.length = 0;
15
+ this.parentNode = parentNode;
16
+ this.ownerDocument = ownerDocument;
17
+
18
+ this._readonly = false;
19
+
20
+ __setArray__(this, []);
21
+ };
22
+ __extend__(DOMNodeList.prototype, {
23
+ item : function(index) {
24
+ var ret = null;
25
+ //$log("NodeList item("+index+") = " + this[index]);
26
+ if ((index >= 0) && (index < this.length)) { // bounds check
27
+ ret = this[index]; // return selected Node
28
+ }
29
+
30
+ return ret; // if the index is out of bounds, default value null is returned
31
+ },
32
+ get xml() {
33
+ var ret = "";
34
+
35
+ // create string containing the concatenation of the string values of each child
36
+ for (var i=0; i < this.length; i++) {
37
+ if(this[i]){
38
+ if(this[i].nodeType == DOMNode.TEXT_NODE && i>0 && this[i-1].nodeType == DOMNode.TEXT_NODE){
39
+ //add a single space between adjacent text nodes
40
+ ret += " "+this[i].xml;
41
+ }else{
42
+ ret += this[i].xml;
43
+ }
44
+ }
45
+ }
46
+
47
+ return ret;
48
+ },
49
+ toArray: function () {
50
+ var children = [];
51
+ for ( var i=0; i < this.length; i++) {
52
+ children.push (this[i]);
53
+ }
54
+ return children;
55
+ },
56
+ toString: function(){
57
+ return "[ "+(this.length > 0?Array.prototype.join.apply(this, [", "]):"Empty NodeList")+" ]";
58
+ }
59
+ });
60
+
61
+
62
+ /**
63
+ * @method DOMNodeList._findItemIndex - find the item index of the node with the specified internal id
64
+ * @author Jon van Noort (jon@webarcana.com.au)
65
+ * @param id : int - unique internal id
66
+ * @return : int
67
+ */
68
+ var __findItemIndex__ = function (nodelist, id) {
69
+ var ret = -1;
70
+
71
+ // test that id is valid
72
+ if (id > -1) {
73
+ for (var i=0; i<nodelist.length; i++) {
74
+ // compare id to each node's _id
75
+ if (nodelist[i]._id == id) { // found it!
76
+ ret = i;
77
+ break;
78
+ }
79
+ }
80
+ }
81
+
82
+ return ret; // if node is not found, default value -1 is returned
83
+ };
84
+
85
+ /**
86
+ * @method DOMNodeList._insertBefore - insert the specified Node into the NodeList before the specified index
87
+ * Used by DOMNode.insertBefore(). Note: DOMNode.insertBefore() is responsible for Node Pointer surgery
88
+ * DOMNodeList._insertBefore() simply modifies the internal data structure (Array).
89
+ *
90
+ * @author Jon van Noort (jon@webarcana.com.au)
91
+ * @param newChild : DOMNode - the Node to be inserted
92
+ * @param refChildIndex : int - the array index to insert the Node before
93
+ */
94
+ var __insertBefore__ = function(nodelist, newChild, refChildIndex) {
95
+ if ((refChildIndex >= 0) && (refChildIndex <= nodelist.length)) { // bounds check
96
+ if (newChild.nodeType == DOMNode.DOCUMENT_FRAGMENT_NODE) { // node is a DocumentFragment
97
+ // append the children of DocumentFragment
98
+ Array.prototype.splice.apply(nodelist,[refChildIndex, 0].concat(newChild.childNodes.toArray()));
99
+ }
100
+ else {
101
+ // append the newChild
102
+ Array.prototype.splice.apply(nodelist,[refChildIndex, 0, newChild]);
103
+ }
104
+ }
105
+ };
106
+
107
+ /**
108
+ * @method DOMNodeList._replaceChild - replace the specified Node in the NodeList at the specified index
109
+ * Used by DOMNode.replaceChild(). Note: DOMNode.replaceChild() is responsible for Node Pointer surgery
110
+ * DOMNodeList._replaceChild() simply modifies the internal data structure (Array).
111
+ *
112
+ * @author Jon van Noort (jon@webarcana.com.au)
113
+ * @param newChild : DOMNode - the Node to be inserted
114
+ * @param refChildIndex : int - the array index to hold the Node
115
+ */
116
+ var __replaceChild__ = function(nodelist, newChild, refChildIndex) {
117
+ var ret = null;
118
+
119
+ if ((refChildIndex >= 0) && (refChildIndex < nodelist.length)) { // bounds check
120
+ ret = nodelist[refChildIndex]; // preserve old child for return
121
+
122
+ if (newChild.nodeType == DOMNode.DOCUMENT_FRAGMENT_NODE) { // node is a DocumentFragment
123
+ // get array containing children prior to refChild
124
+ Array.prototype.splice.apply(nodelist,[refChildIndex, 1].concat(newChild.childNodes.toArray()));
125
+ }
126
+ else {
127
+ // simply replace node in array (links between Nodes are made at higher level)
128
+ nodelist[refChildIndex] = newChild;
129
+ }
130
+ }
131
+
132
+ return ret; // return replaced node
133
+ };
134
+
135
+ /**
136
+ * @method DOMNodeList._removeChild - remove the specified Node in the NodeList at the specified index
137
+ * Used by DOMNode.removeChild(). Note: DOMNode.removeChild() is responsible for Node Pointer surgery
138
+ * DOMNodeList._replaceChild() simply modifies the internal data structure (Array).
139
+ *
140
+ * @author Jon van Noort (jon@webarcana.com.au)
141
+ * @param refChildIndex : int - the array index holding the Node to be removed
142
+ */
143
+ var __removeChild__ = function(nodelist, refChildIndex) {
144
+ var ret = null;
145
+
146
+ if (refChildIndex > -1) { // found it!
147
+ ret = nodelist[refChildIndex]; // return removed node
148
+
149
+ // rebuild array without removed child
150
+ Array.prototype.splice.apply(nodelist,[refChildIndex, 1]);
151
+ }
152
+
153
+ return ret; // return removed node
154
+ };
155
+
156
+ /**
157
+ * @method DOMNodeList._appendChild - append the specified Node to the NodeList
158
+ * Used by DOMNode.appendChild(). Note: DOMNode.appendChild() is responsible for Node Pointer surgery
159
+ * DOMNodeList._appendChild() simply modifies the internal data structure (Array).
160
+ *
161
+ * @author Jon van Noort (jon@webarcana.com.au)
162
+ * @param newChild : DOMNode - the Node to be inserted
163
+ */
164
+ var __appendChild__ = function(nodelist, newChild) {
165
+ if (newChild.nodeType == DOMNode.DOCUMENT_FRAGMENT_NODE) { // node is a DocumentFragment
166
+ // append the children of DocumentFragment
167
+ Array.prototype.push.apply(nodelist, newChild.childNodes.toArray() );
168
+ } else {
169
+ // simply add node to array (links between Nodes are made at higher level)
170
+ Array.prototype.push.apply(nodelist, [newChild]);
171
+ }
172
+
173
+ };
174
+
175
+ /**
176
+ * @method DOMNodeList._cloneNodes - Returns a NodeList containing clones of the Nodes in this NodeList
177
+ *
178
+ * @author Jon van Noort (jon@webarcana.com.au)
179
+ * @param deep : boolean - If true, recursively clone the subtree under each of the nodes;
180
+ * if false, clone only the nodes themselves (and their attributes, if it is an Element).
181
+ * @param parentNode : DOMNode - the new parent of the cloned NodeList
182
+ * @return : DOMNodeList - NodeList containing clones of the Nodes in this NodeList
183
+ */
184
+ var __cloneNodes__ = function(nodelist, deep, parentNode) {
185
+ var cloneNodeList = new DOMNodeList(nodelist.ownerDocument, parentNode);
186
+
187
+ // create list containing clones of each child
188
+ for (var i=0; i < nodelist.length; i++) {
189
+ __appendChild__(cloneNodeList, nodelist[i].cloneNode(deep));
190
+ }
191
+
192
+ return cloneNodeList;
193
+ };
194
+
195
+ // $w.NodeList = DOMNodeList;
data/src/dom/parser.js ADDED
@@ -0,0 +1,1207 @@
1
+ $debug("Defining DOMParser");
2
+ /*
3
+ * DOMParser
4
+ */
5
+
6
+ var DOMParser = function(){};
7
+ __extend__(DOMParser.prototype,{
8
+ parseFromString: function(xmlString){
9
+ $debug("Parsing XML String: " +xmlString);
10
+ throw new Error("implement when testable");
11
+ return document.implementation.createDocument().loadXML(xmlString);
12
+ }
13
+ });
14
+
15
+ $debug("Initializing Internal DOMParser.");
16
+ //keep one around for internal use
17
+ var $domparser = new DOMParser();
18
+
19
+ // $w.DOMParser = DOMParser;
20
+ // =========================================================================
21
+ //
22
+ // xmlsax.js - an XML SAX parser in JavaScript.
23
+ //
24
+ // version 3.1
25
+ //
26
+ // =========================================================================
27
+ //
28
+ // Copyright (C) 2001 - 2002 David Joham (djoham@yahoo.com) and Scott Severtson
29
+ //
30
+ // This library is free software; you can redistribute it and/or
31
+ // modify it under the terms of the GNU Lesser General Public
32
+ // License as published by the Free Software Foundation; either
33
+ // version 2.1 of the License, or (at your option) any later version.
34
+
35
+ // This library is distributed in the hope that it will be useful,
36
+ // but WITHOUT ANY WARRANTY; without even the implied warranty of
37
+ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
38
+ // Lesser General Public License for more details.
39
+
40
+ // You should have received a copy of the GNU Lesser General Public
41
+ // License along with this library; if not, write to the Free Software
42
+ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
43
+ //
44
+ //
45
+ // Visit the XML for <SCRIPT> home page at http://xmljs.sourceforge.net
46
+ //
47
+
48
+ // CONSTANTS
49
+ var whitespace = "\n\r\t ";
50
+
51
+
52
+ /**
53
+ * function: this is the constructor to the XMLP Object
54
+ * Author: Scott Severtson
55
+ * Description:XMLP is a pull-based parser. The calling application passes in a XML string
56
+ * to the constructor, then repeatedly calls .next() to parse the next segment.
57
+ * .next() returns a flag indicating what type of segment was found, and stores
58
+ * data temporarily in couple member variables (name, content, array of
59
+ * attributes), which can be accessed by several .get____() methods.
60
+ *
61
+ * Basically, XMLP is the lowest common denominator parser - an very simple
62
+ * API which other wrappers can be built against.
63
+ **/
64
+
65
+
66
+ var XMLP = function(strXML) {
67
+ // Normalize line breaks
68
+ strXML = SAXStrings.replace(strXML, null, null, "\r\n", "\n");
69
+ strXML = SAXStrings.replace(strXML, null, null, "\r", "\n");
70
+
71
+ this.m_xml = strXML;
72
+ this.m_iP = 0;
73
+ this.m_iState = XMLP._STATE_PROLOG;
74
+ this.m_stack = new Stack();
75
+ this._clearAttributes();
76
+ this.replaceEntities = true;
77
+ };
78
+
79
+
80
+ // CONSTANTS (these must be below the constructor)
81
+
82
+
83
+ XMLP._NONE = 0;
84
+ XMLP._ELM_B = 1;
85
+ XMLP._ELM_E = 2;
86
+ XMLP._ELM_EMP = 3;
87
+ XMLP._ATT = 4;
88
+ XMLP._TEXT = 5;
89
+ XMLP._ENTITY = 6;
90
+ XMLP._PI = 7;
91
+ XMLP._CDATA = 8;
92
+ XMLP._COMMENT = 9;
93
+ XMLP._DTD = 10;
94
+ XMLP._ERROR = 11;
95
+
96
+ XMLP._CONT_XML = 0;
97
+ XMLP._CONT_ALT = 1;
98
+
99
+ XMLP._ATT_NAME = 0;
100
+ XMLP._ATT_VAL = 1;
101
+
102
+ XMLP._STATE_PROLOG = 1;
103
+ XMLP._STATE_DOCUMENT = 2;
104
+ XMLP._STATE_MISC = 3;
105
+
106
+ XMLP._errs = new Array();
107
+ XMLP._errs[XMLP.ERR_CLOSE_PI = 0 ] = "PI: missing closing sequence";
108
+ XMLP._errs[XMLP.ERR_CLOSE_DTD = 1 ] = "DTD: missing closing sequence";
109
+ XMLP._errs[XMLP.ERR_CLOSE_COMMENT = 2 ] = "Comment: missing closing sequence";
110
+ XMLP._errs[XMLP.ERR_CLOSE_CDATA = 3 ] = "CDATA: missing closing sequence";
111
+ XMLP._errs[XMLP.ERR_CLOSE_ELM = 4 ] = "Element: missing closing sequence";
112
+ XMLP._errs[XMLP.ERR_CLOSE_ENTITY = 5 ] = "Entity: missing closing sequence";
113
+ XMLP._errs[XMLP.ERR_PI_TARGET = 6 ] = "PI: target is required";
114
+ XMLP._errs[XMLP.ERR_ELM_EMPTY = 7 ] = "Element: cannot be both empty and closing";
115
+ XMLP._errs[XMLP.ERR_ELM_NAME = 8 ] = "Element: name must immediatly follow \"<\"";
116
+ XMLP._errs[XMLP.ERR_ELM_LT_NAME = 9 ] = "Element: \"<\" not allowed in element names";
117
+ XMLP._errs[XMLP.ERR_ATT_VALUES = 10] = "Attribute: values are required and must be in quotes";
118
+ XMLP._errs[XMLP.ERR_ATT_LT_NAME = 11] = "Element: \"<\" not allowed in attribute names";
119
+ XMLP._errs[XMLP.ERR_ATT_LT_VALUE = 12] = "Attribute: \"<\" not allowed in attribute values";
120
+ XMLP._errs[XMLP.ERR_ATT_DUP = 13] = "Attribute: duplicate attributes not allowed";
121
+ XMLP._errs[XMLP.ERR_ENTITY_UNKNOWN = 14] = "Entity: unknown entity";
122
+ XMLP._errs[XMLP.ERR_INFINITELOOP = 15] = "Infininte loop";
123
+ XMLP._errs[XMLP.ERR_DOC_STRUCTURE = 16] = "Document: only comments, processing instructions, or whitespace allowed outside of document element";
124
+ XMLP._errs[XMLP.ERR_ELM_NESTING = 17] = "Element: must be nested correctly";
125
+
126
+
127
+
128
+ XMLP.prototype._addAttribute = function(name, value) {
129
+ this.m_atts[this.m_atts.length] = new Array(name, value);
130
+ }
131
+
132
+
133
+ XMLP.prototype._checkStructure = function(iEvent) {
134
+
135
+ if(XMLP._STATE_PROLOG == this.m_iState) {
136
+
137
+ //The prolog is initial state of the document before parsing
138
+ //has really begun. A rigid xml parsing implementation would not
139
+ //allow anything but '<' as the first non-whitespace character
140
+ if((XMLP._TEXT == iEvent) || (XMLP._ENTITY == iEvent)) {
141
+ if(SAXStrings.indexOfNonWhitespace(this.getContent(),
142
+ this.getContentBegin(), this.getContentEnd()) != -1) {
143
+ //TODO: HTML Helper here.
144
+ return this._setErr(XMLP.ERR_DOC_STRUCTURE);
145
+ }
146
+ }
147
+
148
+ if((XMLP._ELM_B == iEvent) || (XMLP._ELM_EMP == iEvent)) {
149
+ this.m_iState = XMLP._STATE_DOCUMENT;
150
+ // Don't return - fall through to next state
151
+ }
152
+
153
+ }
154
+
155
+
156
+ if(XMLP._STATE_DOCUMENT == this.m_iState) {
157
+ //The document is the state that the parser is in after the
158
+ //first element event, and remains in that state until
159
+ //the initial element is closed
160
+ if((XMLP._ELM_B == iEvent) || (XMLP._ELM_EMP == iEvent)) {
161
+ this.m_stack.push(this.getName());
162
+ }
163
+
164
+ if((XMLP._ELM_E == iEvent) || (XMLP._ELM_EMP == iEvent)) {
165
+ var strTop = this.m_stack.pop();
166
+ if((strTop == null) || (strTop != this.getName())) {
167
+ return this._setErr(XMLP.ERR_ELM_NESTING);
168
+ }
169
+ }
170
+
171
+ if(this.m_stack.count() == 0) {
172
+ this.m_iState = XMLP._STATE_MISC;
173
+ return iEvent;
174
+ }
175
+ }
176
+
177
+
178
+ if(XMLP._STATE_MISC == this.m_iState) {
179
+ //The misc parser state occurs after the root element has been
180
+ //closed. basically a rigid xml parser would throw an error
181
+ //for any element or text found after this
182
+ if((XMLP._ELM_B == iEvent) ||
183
+ (XMLP._ELM_E == iEvent) ||
184
+ (XMLP._ELM_EMP == iEvent) ||
185
+ (XMLP.EVT_DTD == iEvent)) {
186
+ //TODO: HTML Helper here.
187
+ return this._setErr(XMLP.ERR_DOC_STRUCTURE);
188
+ }
189
+
190
+ if((XMLP._TEXT == iEvent) || (XMLP._ENTITY == iEvent)) {
191
+ if(SAXStrings.indexOfNonWhitespace(this.getContent(),
192
+ this.getContentBegin(), this.getContentEnd()) != -1) {
193
+ //TODO: HTML Helper here.
194
+ return this._setErr(XMLP.ERR_DOC_STRUCTURE);
195
+ }
196
+ }
197
+ }
198
+
199
+ return iEvent;
200
+
201
+ };
202
+
203
+
204
+ XMLP.prototype._clearAttributes = function() {
205
+ this.m_atts = new Array();
206
+ };
207
+
208
+
209
+ XMLP.prototype._findAttributeIndex = function(name) {
210
+ for(var i = 0; i < this.m_atts.length; i++) {
211
+ if(this.m_atts[i][XMLP._ATT_NAME] == name) {
212
+ return i;
213
+ }
214
+ }
215
+ return -1;
216
+
217
+ };
218
+
219
+
220
+ XMLP.prototype.getAttributeCount = function() {
221
+
222
+ return this.m_atts ? this.m_atts.length : 0;
223
+
224
+ };
225
+
226
+
227
+ XMLP.prototype.getAttributeName = function(index) {
228
+
229
+ return ((index < 0) || (index >= this.m_atts.length)) ?
230
+ null :
231
+ this.m_atts[index][XMLP._ATT_NAME];
232
+
233
+ };
234
+
235
+
236
+ XMLP.prototype.getAttributeValue = function(index) {
237
+
238
+ return ((index < 0) || (index >= this.m_atts.length)) ?
239
+ null :
240
+ __unescapeXML__(this.m_atts[index][XMLP._ATT_VAL]);
241
+
242
+ };
243
+
244
+
245
+ XMLP.prototype.getAttributeValueByName = function(name) {
246
+
247
+ return this.getAttributeValue(this._findAttributeIndex(name));
248
+
249
+ };
250
+
251
+
252
+ XMLP.prototype.getColumnNumber = function() {
253
+
254
+ return SAXStrings.getColumnNumber(this.m_xml, this.m_iP);
255
+
256
+ };
257
+
258
+
259
+ XMLP.prototype.getContent = function() {
260
+
261
+ return (this.m_cSrc == XMLP._CONT_XML) ?
262
+ this.m_xml :
263
+ this.m_cAlt;
264
+
265
+ };
266
+
267
+
268
+ XMLP.prototype.getContentBegin = function() {
269
+
270
+ return this.m_cB;
271
+
272
+ };
273
+
274
+
275
+ XMLP.prototype.getContentEnd = function() {
276
+
277
+ return this.m_cE;
278
+
279
+ };
280
+
281
+
282
+ XMLP.prototype.getLineNumber = function() {
283
+
284
+ return SAXStrings.getLineNumber(this.m_xml, this.m_iP);
285
+
286
+ };
287
+
288
+
289
+ XMLP.prototype.getName = function() {
290
+
291
+ return this.m_name;
292
+
293
+ };
294
+
295
+
296
+ XMLP.prototype.next = function() {
297
+
298
+ return this._checkStructure(this._parse());
299
+
300
+ };
301
+
302
+ XMLP.prototype.appendFragment = function(xmlfragment) {
303
+
304
+ var start = this.m_xml.slice(0,this.m_iP);
305
+ var end = this.m_xml.slice(this.m_iP);
306
+ this.m_xml = start+xmlfragment+end;
307
+
308
+ };
309
+
310
+
311
+ XMLP.prototype._parse = function() {
312
+
313
+ if(this.m_iP == this.m_xml.length) {
314
+ return XMLP._NONE;
315
+ }
316
+
317
+ if(this.m_iP == this.m_xml.indexOf("<", this.m_iP)){
318
+ if(this.m_xml.charAt(this.m_iP+1) == "?") {
319
+ return this._parsePI(this.m_iP + 2);
320
+ }
321
+ else if(this.m_xml.charAt(this.m_iP+1) == "!") {
322
+ if(this.m_xml.charAt(this.m_iP+2) == "D") {
323
+ return this._parseDTD(this.m_iP + 9);
324
+ }
325
+ else if(this.m_xml.charAt(this.m_iP+2) == "-") {
326
+ return this._parseComment(this.m_iP + 4);
327
+ }
328
+ else if(this.m_xml.charAt(this.m_iP+2) == "[") {
329
+ return this._parseCDATA(this.m_iP + 9);
330
+ }
331
+ }
332
+ else{
333
+
334
+ return this._parseElement(this.m_iP + 1);
335
+ }
336
+ }
337
+ else if(this.m_iP == this.m_xml.indexOf("&", this.m_iP)) {
338
+ return this._parseEntity(this.m_iP + 1);
339
+ }
340
+ else{
341
+
342
+ return this._parseText(this.m_iP);
343
+ }
344
+
345
+
346
+ }
347
+
348
+
349
+ XMLP.prototype._parseAttribute = function(iB, iE) {
350
+ var iNB, iNE, iEq, iVB, iVE;
351
+ var cQuote, strN, strV;
352
+
353
+ //resets the value so we don't use an old one by
354
+ //accident (see testAttribute7 in the test suite)
355
+ this.m_cAlt = "";
356
+
357
+ iNB = SAXStrings.indexOfNonWhitespace(this.m_xml, iB, iE);
358
+ if((iNB == -1) ||(iNB >= iE)) {
359
+ return iNB;
360
+ }
361
+
362
+ iEq = this.m_xml.indexOf("=", iNB);
363
+ if((iEq == -1) || (iEq > iE)) {
364
+ return this._setErr(XMLP.ERR_ATT_VALUES);
365
+ }
366
+
367
+ iNE = SAXStrings.lastIndexOfNonWhitespace(this.m_xml, iNB, iEq);
368
+
369
+ iVB = SAXStrings.indexOfNonWhitespace(this.m_xml, iEq + 1, iE);
370
+ if((iVB == -1) ||(iVB > iE)) {
371
+ return this._setErr(XMLP.ERR_ATT_VALUES);
372
+ }
373
+
374
+ cQuote = this.m_xml.charAt(iVB);
375
+ if(_SAXStrings.QUOTES.indexOf(cQuote) == -1) {
376
+ return this._setErr(XMLP.ERR_ATT_VALUES);
377
+ }
378
+
379
+ iVE = this.m_xml.indexOf(cQuote, iVB + 1);
380
+ if((iVE == -1) ||(iVE > iE)) {
381
+ return this._setErr(XMLP.ERR_ATT_VALUES);
382
+ }
383
+
384
+ strN = this.m_xml.substring(iNB, iNE + 1);
385
+ strV = this.m_xml.substring(iVB + 1, iVE);
386
+
387
+ if(strN.indexOf("<") != -1) {
388
+ return this._setErr(XMLP.ERR_ATT_LT_NAME);
389
+ }
390
+
391
+ if(strV.indexOf("<") != -1) {
392
+ return this._setErr(XMLP.ERR_ATT_LT_VALUE);
393
+ }
394
+
395
+ strV = SAXStrings.replace(strV, null, null, "\n", " ");
396
+ strV = SAXStrings.replace(strV, null, null, "\t", " ");
397
+ iRet = this._replaceEntities(strV);
398
+ if(iRet == XMLP._ERROR) {
399
+ return iRet;
400
+ }
401
+
402
+ strV = this.m_cAlt;
403
+
404
+ if(this._findAttributeIndex(strN) == -1) {
405
+ this._addAttribute(strN, strV);
406
+ }else {
407
+ return this._setErr(XMLP.ERR_ATT_DUP);
408
+ }
409
+
410
+ this.m_iP = iVE + 2;
411
+
412
+ return XMLP._ATT;
413
+
414
+ }
415
+
416
+
417
+ XMLP.prototype._parseCDATA = function(iB) {
418
+ var iE = this.m_xml.indexOf("]]>", iB);
419
+ if (iE == -1) {
420
+ return this._setErr(XMLP.ERR_CLOSE_CDATA);
421
+ }
422
+
423
+ this._setContent(XMLP._CONT_XML, iB, iE);
424
+
425
+ this.m_iP = iE + 3;
426
+
427
+ return XMLP._CDATA;
428
+
429
+ }
430
+
431
+
432
+ XMLP.prototype._parseComment = function(iB) {
433
+ var iE = this.m_xml.indexOf("-" + "->", iB);
434
+ if (iE == -1) {
435
+ return this._setErr(XMLP.ERR_CLOSE_COMMENT);
436
+ }
437
+
438
+ this._setContent(XMLP._CONT_XML, iB, iE);
439
+
440
+ this.m_iP = iE + 3;
441
+
442
+ return XMLP._COMMENT;
443
+
444
+ }
445
+
446
+
447
+ XMLP.prototype._parseDTD = function(iB) {
448
+
449
+ // Eat DTD
450
+
451
+ var iE, strClose, iInt, iLast;
452
+
453
+ iE = this.m_xml.indexOf(">", iB);
454
+ if(iE == -1) {
455
+ return this._setErr(XMLP.ERR_CLOSE_DTD);
456
+ }
457
+
458
+ iInt = this.m_xml.indexOf("[", iB);
459
+ strClose = ((iInt != -1) && (iInt < iE)) ? "]>" : ">";
460
+
461
+ while(true) {
462
+
463
+ iE = this.m_xml.indexOf(strClose, iB);
464
+ if(iE == -1) {
465
+ return this._setErr(XMLP.ERR_CLOSE_DTD);
466
+ }
467
+
468
+ // Make sure it is not the end of a CDATA section
469
+ if (this.m_xml.substring(iE - 1, iE + 2) != "]]>") {
470
+ break;
471
+ }
472
+ }
473
+
474
+ this.m_iP = iE + strClose.length;
475
+
476
+ return XMLP._DTD;
477
+
478
+ }
479
+
480
+
481
+ XMLP.prototype._parseElement = function(iB) {
482
+ var iE, iDE, iNE, iRet;
483
+ var iType, strN, iLast;
484
+
485
+ iDE = iE = this.m_xml.indexOf(">", iB);
486
+ if(iE == -1) {
487
+ return this._setErr(XMLP.ERR_CLOSE_ELM);
488
+ }
489
+
490
+ if(this.m_xml.charAt(iB) == "/") {
491
+ iType = XMLP._ELM_E;
492
+ iB++;
493
+ } else {
494
+ iType = XMLP._ELM_B;
495
+ }
496
+
497
+ if(this.m_xml.charAt(iE - 1) == "/") {
498
+ if(iType == XMLP._ELM_E) {
499
+ return this._setErr(XMLP.ERR_ELM_EMPTY);
500
+ }
501
+ iType = XMLP._ELM_EMP;
502
+ iDE--;
503
+ }
504
+
505
+ iDE = SAXStrings.lastIndexOfNonWhitespace(this.m_xml, iB, iDE);
506
+
507
+ //djohack
508
+ //hack to allow for elements with single character names to be recognized
509
+
510
+ ///if (iE - iB != 1 ) {
511
+ /// if(SAXStrings.indexOfNonWhitespace(this.m_xml, iB, iDE) != iB) {
512
+ /// return this._setErr(XMLP.ERR_ELM_NAME);
513
+ /// }
514
+ ///}
515
+
516
+ // end hack -- original code below
517
+
518
+
519
+ ///if(SAXStrings.indexOfNonWhitespace(this.m_xml, iB, iDE) != iB)
520
+ /// return this._setErr(XMLP.ERR_ELM_NAME);
521
+ ///
522
+ this._clearAttributes();
523
+
524
+ iNE = SAXStrings.indexOfWhitespace(this.m_xml, iB, iDE);
525
+ if(iNE == -1) {
526
+ iNE = iDE + 1;
527
+ }
528
+ else {
529
+ this.m_iP = iNE;
530
+ while(this.m_iP < iDE) {
531
+ // DEBUG: Remove
532
+ //if(this.m_iP == iLast) return this._setErr(XMLP.ERR_INFINITELOOP);
533
+ //iLast = this.m_iP;
534
+ // DEBUG: Remove End
535
+
536
+
537
+ iRet = this._parseAttribute(this.m_iP, iDE);
538
+ if(iRet == XMLP._ERROR) return iRet;
539
+ }
540
+ }
541
+
542
+ strN = this.m_xml.substring(iB, iNE);
543
+
544
+ ///if(strN.indexOf("<") != -1) {
545
+ /// return this._setErr(XMLP.ERR_ELM_LT_NAME);
546
+ ///}s
547
+
548
+ this.m_name = strN;
549
+ this.m_iP = iE + 1;
550
+
551
+ return iType;
552
+
553
+ }
554
+
555
+
556
+ XMLP.prototype._parseEntity = function(iB) {
557
+ var iE = this.m_xml.indexOf(";", iB);
558
+ if(iE == -1) {
559
+ return this._setErr(XMLP.ERR_CLOSE_ENTITY);
560
+ }
561
+
562
+ this.m_iP = iE + 1;
563
+
564
+ return this._replaceEntity(this.m_xml, iB, iE);
565
+
566
+ }
567
+
568
+
569
+ XMLP.prototype._parsePI = function(iB) {
570
+
571
+ var iE, iTB, iTE, iCB, iCE;
572
+
573
+ iE = this.m_xml.indexOf("?>", iB);
574
+ if(iE == -1) {
575
+ return this._setErr(XMLP.ERR_CLOSE_PI);
576
+ }
577
+
578
+ iTB = SAXStrings.indexOfNonWhitespace(this.m_xml, iB, iE);
579
+ if(iTB == -1) {
580
+ return this._setErr(XMLP.ERR_PI_TARGET);
581
+ }
582
+
583
+ iTE = SAXStrings.indexOfWhitespace(this.m_xml, iTB, iE);
584
+ if(iTE == -1) {
585
+ iTE = iE;
586
+ }
587
+
588
+ iCB = SAXStrings.indexOfNonWhitespace(this.m_xml, iTE, iE);
589
+ if(iCB == -1) {
590
+ iCB = iE;
591
+ }
592
+
593
+ iCE = SAXStrings.lastIndexOfNonWhitespace(this.m_xml, iCB, iE);
594
+ if(iCE == -1) {
595
+ iCE = iE - 1;
596
+ }
597
+
598
+ this.m_name = this.m_xml.substring(iTB, iTE);
599
+ this._setContent(XMLP._CONT_XML, iCB, iCE + 1);
600
+ this.m_iP = iE + 2;
601
+
602
+ return XMLP._PI;
603
+
604
+ }
605
+
606
+
607
+ XMLP.prototype._parseText = function(iB) {
608
+ var iE, iEE;
609
+
610
+ iE = this.m_xml.indexOf("<", iB);
611
+ if(iE == -1) {
612
+ iE = this.m_xml.length;
613
+ }
614
+
615
+ if(this.replaceEntities) {
616
+ iEE = this.m_xml.indexOf("&", iB);
617
+ if((iEE != -1) && (iEE <= iE)) {
618
+ iE = iEE;
619
+ }
620
+ }
621
+
622
+ this._setContent(XMLP._CONT_XML, iB, iE);
623
+
624
+ this.m_iP = iE;
625
+
626
+ return XMLP._TEXT;
627
+
628
+ }
629
+
630
+
631
+ XMLP.prototype._replaceEntities = function(strD, iB, iE) {
632
+ if(SAXStrings.isEmpty(strD)) return "";
633
+ iB = iB || 0;
634
+ iE = iE || strD.length;
635
+
636
+
637
+ var iEB, iEE, strRet = "";
638
+
639
+ iEB = strD.indexOf("&", iB);
640
+ iEE = iB;
641
+
642
+ while((iEB > 0) && (iEB < iE)) {
643
+ strRet += strD.substring(iEE, iEB);
644
+
645
+ iEE = strD.indexOf(";", iEB) + 1;
646
+
647
+ if((iEE == 0) || (iEE > iE)) {
648
+ return this._setErr(XMLP.ERR_CLOSE_ENTITY);
649
+ }
650
+
651
+ iRet = this._replaceEntity(strD, iEB + 1, iEE - 1);
652
+ if(iRet == XMLP._ERROR) {
653
+ return iRet;
654
+ }
655
+
656
+ strRet += this.m_cAlt;
657
+
658
+ iEB = strD.indexOf("&", iEE);
659
+ }
660
+
661
+ if(iEE != iE) {
662
+ strRet += strD.substring(iEE, iE);
663
+ }
664
+
665
+ this._setContent(XMLP._CONT_ALT, strRet);
666
+
667
+ return XMLP._ENTITY;
668
+
669
+ }
670
+
671
+
672
+ XMLP.prototype._replaceEntity = function(strD, iB, iE) {
673
+ if(SAXStrings.isEmpty(strD)) return -1;
674
+ iB = iB || 0;
675
+ iE = iE || strD.length;
676
+
677
+
678
+ ent = strD.substring(iB, iE);
679
+ strEnt = $w.$entityDefinitions[ent];
680
+ if (!strEnt) // special case for entity name==JS reserved keyword
681
+ strEnt = $w.$entityDefinitions[ent+"XX"];
682
+ if (!strEnt) {
683
+ if(strD.charAt(iB) == "#")
684
+ strEnt = String.fromCharCode(
685
+ parseInt(strD.substring(iB + 1, iE)))+'';
686
+ else
687
+ return this._setErr(XMLP.ERR_ENTITY_UNKNOWN);
688
+ }
689
+
690
+ this._setContent(XMLP._CONT_ALT, strEnt);
691
+ return XMLP._ENTITY;
692
+ }
693
+
694
+
695
+ XMLP.prototype._setContent = function(iSrc) {
696
+ var args = arguments;
697
+
698
+ if(XMLP._CONT_XML == iSrc) {
699
+ this.m_cAlt = null;
700
+ this.m_cB = args[1];
701
+ this.m_cE = args[2];
702
+ } else {
703
+ this.m_cAlt = args[1];
704
+ this.m_cB = 0;
705
+ this.m_cE = args[1].length;
706
+ }
707
+ this.m_cSrc = iSrc;
708
+
709
+ }
710
+
711
+
712
+ XMLP.prototype._setErr = function(iErr) {
713
+ var strErr = XMLP._errs[iErr];
714
+
715
+ this.m_cAlt = strErr;
716
+ this.m_cB = 0;
717
+ this.m_cE = strErr.length;
718
+ this.m_cSrc = XMLP._CONT_ALT;
719
+
720
+ return XMLP._ERROR;
721
+
722
+ }
723
+
724
+ /**
725
+ * function: SAXDriver
726
+ * Author: Scott Severtson
727
+ * Description:
728
+ * SAXDriver is an object that basically wraps an XMLP instance, and provides an
729
+ * event-based interface for parsing. This is the object users interact with when coding
730
+ * with XML for <SCRIPT>
731
+ **/
732
+
733
+ var SAXDriver = function() {
734
+ this.m_hndDoc = null;
735
+ this.m_hndErr = null;
736
+ this.m_hndLex = null;
737
+ }
738
+
739
+
740
+ // CONSTANTS
741
+ SAXDriver.DOC_B = 1;
742
+ SAXDriver.DOC_E = 2;
743
+ SAXDriver.ELM_B = 3;
744
+ SAXDriver.ELM_E = 4;
745
+ SAXDriver.CHARS = 5;
746
+ SAXDriver.PI = 6;
747
+ SAXDriver.CD_B = 7;
748
+ SAXDriver.CD_E = 8;
749
+ SAXDriver.CMNT = 9;
750
+ SAXDriver.DTD_B = 10;
751
+ SAXDriver.DTD_E = 11;
752
+
753
+
754
+
755
+ SAXDriver.prototype.parse = function(strD) {
756
+ var parser = new XMLP(strD);
757
+
758
+ if(this.m_hndDoc && this.m_hndDoc.setDocumentLocator) {
759
+ this.m_hndDoc.setDocumentLocator(this);
760
+ }
761
+
762
+ this.m_parser = parser;
763
+ this.m_bErr = false;
764
+
765
+ if(!this.m_bErr) {
766
+ this._fireEvent(SAXDriver.DOC_B);
767
+ }
768
+ this._parseLoop();
769
+ if(!this.m_bErr) {
770
+ this._fireEvent(SAXDriver.DOC_E);
771
+ }
772
+
773
+ this.m_xml = null;
774
+ this.m_iP = 0;
775
+
776
+ }
777
+
778
+
779
+ SAXDriver.prototype.setDocumentHandler = function(hnd) {
780
+
781
+ this.m_hndDoc = hnd;
782
+
783
+ }
784
+
785
+
786
+ SAXDriver.prototype.setErrorHandler = function(hnd) {
787
+
788
+ this.m_hndErr = hnd;
789
+
790
+ }
791
+
792
+
793
+ SAXDriver.prototype.setLexicalHandler = function(hnd) {
794
+
795
+ this.m_hndLex = hnd;
796
+
797
+ }
798
+
799
+
800
+
801
+ /// LOCATOR/PARSE EXCEPTION INTERFACE
802
+
803
+
804
+ SAXDriver.prototype.getColumnNumber = function() {
805
+
806
+ return this.m_parser.getColumnNumber();
807
+
808
+ }
809
+
810
+
811
+ SAXDriver.prototype.getLineNumber = function() {
812
+
813
+ return this.m_parser.getLineNumber();
814
+
815
+ }
816
+
817
+
818
+ SAXDriver.prototype.getMessage = function() {
819
+
820
+ return this.m_strErrMsg;
821
+
822
+ }
823
+
824
+
825
+ SAXDriver.prototype.getPublicId = function() {
826
+
827
+ return null;
828
+
829
+ }
830
+
831
+
832
+ SAXDriver.prototype.getSystemId = function() {
833
+
834
+ return null;
835
+
836
+ }
837
+
838
+
839
+
840
+ /// Attribute List Interface
841
+
842
+
843
+ SAXDriver.prototype.getLength = function() {
844
+
845
+ return this.m_parser.getAttributeCount();
846
+
847
+ }
848
+
849
+
850
+ SAXDriver.prototype.getName = function(index) {
851
+
852
+ return this.m_parser.getAttributeName(index);
853
+
854
+ }
855
+
856
+
857
+ SAXDriver.prototype.getValue = function(index) {
858
+
859
+ return this.m_parser.getAttributeValue(index);
860
+
861
+ }
862
+
863
+
864
+ SAXDriver.prototype.getValueByName = function(name) {
865
+
866
+ return this.m_parser.getAttributeValueByName(name);
867
+
868
+ }
869
+
870
+
871
+ /// Private functions
872
+
873
+ SAXDriver.prototype._fireError = function(strMsg) {
874
+ this.m_strErrMsg = strMsg;
875
+ this.m_bErr = true;
876
+
877
+ if(this.m_hndErr && this.m_hndErr.fatalError) {
878
+ this.m_hndErr.fatalError(this);
879
+ }
880
+
881
+ } // end function _fireError
882
+
883
+
884
+ SAXDriver.prototype._fireEvent = function(iEvt) {
885
+ var hnd, func, args = arguments, iLen = args.length - 1;
886
+
887
+ if(this.m_bErr) return;
888
+
889
+ if(SAXDriver.DOC_B == iEvt) {
890
+ func = "startDocument"; hnd = this.m_hndDoc;
891
+ }
892
+ else if (SAXDriver.DOC_E == iEvt) {
893
+ func = "endDocument"; hnd = this.m_hndDoc;
894
+ }
895
+ else if (SAXDriver.ELM_B == iEvt) {
896
+ func = "startElement"; hnd = this.m_hndDoc;
897
+ }
898
+ else if (SAXDriver.ELM_E == iEvt) {
899
+ func = "endElement"; hnd = this.m_hndDoc;
900
+ }
901
+ else if (SAXDriver.CHARS == iEvt) {
902
+ func = "characters"; hnd = this.m_hndDoc;
903
+ }
904
+ else if (SAXDriver.PI == iEvt) {
905
+ func = "processingInstruction"; hnd = this.m_hndDoc;
906
+ }
907
+ else if (SAXDriver.CD_B == iEvt) {
908
+ func = "startCDATA"; hnd = this.m_hndLex;
909
+ }
910
+ else if (SAXDriver.CD_E == iEvt) {
911
+ func = "endCDATA"; hnd = this.m_hndLex;
912
+ }
913
+ else if (SAXDriver.CMNT == iEvt) {
914
+ func = "comment"; hnd = this.m_hndLex;
915
+ }
916
+
917
+ if(hnd && hnd[func]) {
918
+ if(0 == iLen) {
919
+ hnd[func]();
920
+ }
921
+ else if (1 == iLen) {
922
+ hnd[func](args[1]);
923
+ }
924
+ else if (2 == iLen) {
925
+ hnd[func](args[1], args[2]);
926
+ }
927
+ else if (3 == iLen) {
928
+ hnd[func](args[1], args[2], args[3]);
929
+ }
930
+ }
931
+
932
+ } // end function _fireEvent
933
+
934
+
935
+ SAXDriver.prototype._parseLoop = function(parser) {
936
+ var iEvent, parser;
937
+
938
+ parser = this.m_parser;
939
+ while(!this.m_bErr) {
940
+ iEvent = parser.next();
941
+
942
+ if(iEvent == XMLP._ELM_B) {
943
+ this._fireEvent(SAXDriver.ELM_B, parser.getName(), this);
944
+ }
945
+ else if(iEvent == XMLP._ELM_E) {
946
+ this._fireEvent(SAXDriver.ELM_E, parser.getName());
947
+ }
948
+ else if(iEvent == XMLP._ELM_EMP) {
949
+ this._fireEvent(SAXDriver.ELM_B, parser.getName(), this);
950
+ this._fireEvent(SAXDriver.ELM_E, parser.getName());
951
+ }
952
+ else if(iEvent == XMLP._TEXT) {
953
+ this._fireEvent(SAXDriver.CHARS, parser.getContent(), parser.getContentBegin(), parser.getContentEnd() - parser.getContentBegin());
954
+ }
955
+ else if(iEvent == XMLP._ENTITY) {
956
+ this._fireEvent(SAXDriver.CHARS, parser.getContent(), parser.getContentBegin(), parser.getContentEnd() - parser.getContentBegin());
957
+ }
958
+ else if(iEvent == XMLP._PI) {
959
+ this._fireEvent(SAXDriver.PI, parser.getName(), parser.getContent().substring(parser.getContentBegin(), parser.getContentEnd()));
960
+ }
961
+ else if(iEvent == XMLP._CDATA) {
962
+ this._fireEvent(SAXDriver.CD_B);
963
+ this._fireEvent(SAXDriver.CHARS, parser.getContent(), parser.getContentBegin(), parser.getContentEnd() - parser.getContentBegin());
964
+ this._fireEvent(SAXDriver.CD_E);
965
+ }
966
+ else if(iEvent == XMLP._COMMENT) {
967
+ this._fireEvent(SAXDriver.CMNT, parser.getContent(), parser.getContentBegin(), parser.getContentEnd() - parser.getContentBegin());
968
+ }
969
+ else if(iEvent == XMLP._DTD) {
970
+ }
971
+ else if(iEvent == XMLP._ERROR) {
972
+ this._fireError(parser.getContent());
973
+ }
974
+ else if(iEvent == XMLP._NONE) {
975
+ return;
976
+ }
977
+ }
978
+
979
+ } // end function _parseLoop
980
+
981
+ ///
982
+ /// function: SAXStrings
983
+ /// Author: Scott Severtson
984
+ /// Description: a useful object containing string manipulation functions
985
+ ///
986
+
987
+ var _SAXStrings = function() {};
988
+
989
+
990
+ _SAXStrings.WHITESPACE = " \t\n\r";
991
+ _SAXStrings.NONWHITESPACE = /\S/;
992
+ _SAXStrings.QUOTES = "\"'";
993
+
994
+
995
+ _SAXStrings.prototype.getColumnNumber = function(strD, iP) {
996
+ if((strD === null) || (strD.length === 0)) {
997
+ return -1;
998
+ }
999
+ iP = iP || strD.length;
1000
+
1001
+ var arrD = strD.substring(0, iP).split("\n");
1002
+ var strLine = arrD[arrD.length - 1];
1003
+ arrD.length--;
1004
+ var iLinePos = arrD.join("\n").length;
1005
+
1006
+ return iP - iLinePos;
1007
+
1008
+ } // end function getColumnNumber
1009
+
1010
+
1011
+ _SAXStrings.prototype.getLineNumber = function(strD, iP) {
1012
+ if((strD === null) || (strD.length === 0)) {
1013
+ return -1;
1014
+ }
1015
+ iP = iP || strD.length;
1016
+
1017
+ return strD.substring(0, iP).split("\n").length
1018
+ } // end function getLineNumber
1019
+
1020
+
1021
+ _SAXStrings.prototype.indexOfNonWhitespace = function(strD, iB, iE) {
1022
+ if((strD === null) || (strD.length === 0)) {
1023
+ return -1;
1024
+ }
1025
+ iB = iB || 0;
1026
+ iE = iE || strD.length;
1027
+
1028
+ //var i = strD.substring(iB, iE).search(_SAXStrings.NONWHITESPACE);
1029
+ //return i < 0 ? i : iB + i;
1030
+
1031
+ while( strD.charCodeAt(iB++) < 33 );
1032
+ return (iB > iE)?-1:iB-1;
1033
+ ///for(var i = iB; i < iE; i++){
1034
+ /// if(_SAXStrings.WHITESPACE.indexOf(strD.charAt(i)) == -1) {
1035
+ /// return i;
1036
+ /// }
1037
+ ///}
1038
+ ///return -1;
1039
+
1040
+ } // end function indexOfNonWhitespace
1041
+
1042
+
1043
+ _SAXStrings.prototype.indexOfWhitespace = function(strD, iB, iE) {
1044
+ if((strD === null) || (strD.length === 0)) {
1045
+ return -1;
1046
+ }
1047
+ iB = iB || 0;
1048
+ iE = iE || strD.length;
1049
+
1050
+
1051
+ while( strD.charCodeAt(iB++) >= 33 );
1052
+ return (iB > iE)?-1:iB-1;
1053
+
1054
+ ///for(var i = iB; i < iE; i++) {
1055
+ /// if(_SAXStrings.WHITESPACE.indexOf(strD.charAt(i)) != -1) {
1056
+ /// return i;
1057
+ /// }
1058
+ ///}
1059
+ ///return -1;
1060
+ } // end function indexOfWhitespace
1061
+
1062
+
1063
+ _SAXStrings.prototype.isEmpty = function(strD) {
1064
+
1065
+ return (strD == null) || (strD.length == 0);
1066
+
1067
+ }
1068
+
1069
+
1070
+ _SAXStrings.prototype.lastIndexOfNonWhitespace = function(strD, iB, iE) {
1071
+ if((strD === null) || (strD.length === 0)) {
1072
+ return -1;
1073
+ }
1074
+ iB = iB || 0;
1075
+ iE = iE || strD.length;
1076
+
1077
+ while( (iE >= iB) && strD.charCodeAt(--iE) < 33 );
1078
+ return (iE < iB)?-1:iE;
1079
+
1080
+ ///for(var i = iE - 1; i >= iB; i--){
1081
+ /// if(_SAXStrings.WHITESPACE.indexOf(strD.charAt(i)) == -1){
1082
+ /// return i;
1083
+ /// }
1084
+ ///}
1085
+ ///return -1;
1086
+ }
1087
+
1088
+
1089
+ _SAXStrings.prototype.replace = function(strD, iB, iE, strF, strR) {
1090
+ if((strD == null) || (strD.length == 0)) {
1091
+ return "";
1092
+ }
1093
+ iB = iB || 0;
1094
+ iE = iE || strD.length;
1095
+
1096
+ return strD.substring(iB, iE).split(strF).join(strR);
1097
+
1098
+ };
1099
+
1100
+ var SAXStrings = new _SAXStrings();
1101
+
1102
+
1103
+
1104
+ /***************************************************************************************************************
1105
+ Stack: A simple stack class, used for verifying document structure.
1106
+
1107
+ Author: Scott Severtson
1108
+ *****************************************************************************************************************/
1109
+ var Stack = function() {
1110
+ this.m_arr = new Array();
1111
+ };
1112
+ __extend__(Stack.prototype, {
1113
+ clear : function() {
1114
+ this.m_arr = new Array();
1115
+ },
1116
+ count : function() {
1117
+ return this.m_arr.length;
1118
+ },
1119
+ destroy : function() {
1120
+ this.m_arr = null;
1121
+ },
1122
+ peek : function() {
1123
+ if(this.m_arr.length == 0) {
1124
+ return null;
1125
+ }
1126
+ return this.m_arr[this.m_arr.length - 1];
1127
+ },
1128
+ pop : function() {
1129
+ if(this.m_arr.length == 0) {
1130
+ return null;
1131
+ }
1132
+ var o = this.m_arr[this.m_arr.length - 1];
1133
+ this.m_arr.length--;
1134
+ return o;
1135
+ },
1136
+ push : function(o) {
1137
+ this.m_arr[this.m_arr.length] = o;
1138
+ }
1139
+ });
1140
+
1141
+
1142
+ ///
1143
+ /// function: isEmpty
1144
+ /// Author: mike@idle.org
1145
+ /// Description: convenience function to identify an empty string
1146
+ ///
1147
+ function isEmpty(str) {
1148
+ return (str==null) || (str.length==0);
1149
+ };
1150
+
1151
+ /**
1152
+ * function __escapeXML__
1153
+ * author: David Joham djoham@yahoo.com
1154
+ * @param str : string - The string to be escaped
1155
+ * @return : string - The escaped string
1156
+ */
1157
+ var escAmpRegEx = /&(?!(amp;|lt;|gt;|quot|apos;))/g;
1158
+ var escLtRegEx = /</g;
1159
+ var escGtRegEx = />/g;
1160
+ var quotRegEx = /"/g;
1161
+ var aposRegEx = /'/g;
1162
+ function __escapeXML__(str) {
1163
+ str = str.replace(escAmpRegEx, "&amp;").
1164
+ replace(escLtRegEx, "&lt;").
1165
+ replace(escGtRegEx, "&gt;").
1166
+ replace(quotRegEx, "&quot;").
1167
+ replace(aposRegEx, "&apos;");
1168
+
1169
+ return str;
1170
+ };
1171
+ function __escapeHTML5__(str) {
1172
+ str = str.replace(escAmpRegEx, "&amp;").
1173
+ replace(escLtRegEx, "&lt;").
1174
+ replace(escGtRegEx, "&gt;");
1175
+
1176
+ return str;
1177
+ };
1178
+ function __escapeHTML5Atribute__(str) {
1179
+ str = str.replace(escAmpRegEx, "&amp;").
1180
+ replace(escLtRegEx, "&lt;").
1181
+ replace(escGtRegEx, "&gt;").
1182
+ replace(quotRegEx, "&quot;").
1183
+ replace(aposRegEx, "&apos;");
1184
+
1185
+ return str;
1186
+ };
1187
+ /**
1188
+ * function __unescapeXML__
1189
+ * author: David Joham djoham@yahoo.com
1190
+ * @param str : string - The string to be unescaped
1191
+ * @return : string - The unescaped string
1192
+ */
1193
+ var unescAmpRegEx = /&amp;/g;
1194
+ var unescLtRegEx = /&lt;/g;
1195
+ var unescGtRegEx = /&gt;/g;
1196
+ var unquotRegEx = /&quot;/g;
1197
+ var unaposRegEx = /&apos;/g;
1198
+ function __unescapeXML__(str) {
1199
+ str = str.replace(unescAmpRegEx, "&").
1200
+ replace(unescLtRegEx, "<").
1201
+ replace(unescGtRegEx, ">").
1202
+ replace(unquotRegEx, "\"").
1203
+ replace(unaposRegEx, "'");
1204
+
1205
+ return str;
1206
+ };
1207
+