rubinium 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. data/CHANGES +7 -0
  2. data/MIT-LICENSE +21 -0
  3. data/README +137 -0
  4. data/Rakefile +139 -0
  5. data/TODO +7 -0
  6. data/doc/examples/rtc_site_live.rb +12 -0
  7. data/doc/examples/rts_main.rb +9 -0
  8. data/doc/examples/rts_shared_code.rb +25 -0
  9. data/lib/rubinium.rb +9 -0
  10. data/lib/rubinium/string.rb +3 -0
  11. data/lib/rubinium/test_base.rb +80 -0
  12. data/lib/rubinium/test_suite.rb +53 -0
  13. data/lib/rubinium/validator.rb +16 -0
  14. data/test/selenium_tests/test_click.rb +22 -0
  15. data/test/selenium_tests/test_open.rb +11 -0
  16. data/test/tc_file_creation.rb +60 -0
  17. data/test/ts_rubinium.rb +1 -0
  18. data/vendor/selenium-0.6.0/install-readme.txt +9 -0
  19. data/vendor/selenium-0.6.0/selenium/SeleneseRunner.html +253 -0
  20. data/vendor/selenium-0.6.0/selenium/SeleniumLog.html +61 -0
  21. data/vendor/selenium-0.6.0/selenium/TestRunner-splash.html +55 -0
  22. data/vendor/selenium-0.6.0/selenium/TestRunner.hta +146 -0
  23. data/vendor/selenium-0.6.0/selenium/TestRunner.html +146 -0
  24. data/vendor/selenium-0.6.0/selenium/devtests/TestClickInFrame.html +58 -0
  25. data/vendor/selenium-0.6.0/selenium/devtests/TestOpenInFrame.html +48 -0
  26. data/vendor/selenium-0.6.0/selenium/devtests/TestOpenInNewWindow.html +78 -0
  27. data/vendor/selenium-0.6.0/selenium/devtests/TestOpenMeta.html +43 -0
  28. data/vendor/selenium-0.6.0/selenium/devtests/TestSuite.html +39 -0
  29. data/vendor/selenium-0.6.0/selenium/devtests/meta/page.html +5 -0
  30. data/vendor/selenium-0.6.0/selenium/dom-images/butmin.gif +0 -0
  31. data/vendor/selenium-0.6.0/selenium/dom-images/butplus.gif +0 -0
  32. data/vendor/selenium-0.6.0/selenium/dom-styles/default.css +298 -0
  33. data/vendor/selenium-0.6.0/selenium/domviewer.html +16 -0
  34. data/vendor/selenium-0.6.0/selenium/html-xpath/carnation.jpg +0 -0
  35. data/vendor/selenium-0.6.0/selenium/html-xpath/example.html +75 -0
  36. data/vendor/selenium-0.6.0/selenium/html-xpath/html-xpath-patched.js +657 -0
  37. data/vendor/selenium-0.6.0/selenium/html-xpath/html-xpath.js +610 -0
  38. data/vendor/selenium-0.6.0/selenium/html-xpath/license.txt +504 -0
  39. data/vendor/selenium-0.6.0/selenium/html-xpath/rainbow.jpg +0 -0
  40. data/vendor/selenium-0.6.0/selenium/htmlutils.js +283 -0
  41. data/vendor/selenium-0.6.0/selenium/index.html +60 -0
  42. data/vendor/selenium-0.6.0/selenium/jsmock/mock-tests.html +205 -0
  43. data/vendor/selenium-0.6.0/selenium/jsmock/mock.js +124 -0
  44. data/vendor/selenium-0.6.0/selenium/selenium-api.js +683 -0
  45. data/vendor/selenium-0.6.0/selenium/selenium-browserbot.js +930 -0
  46. data/vendor/selenium-0.6.0/selenium/selenium-commandhandlers.js +286 -0
  47. data/vendor/selenium-0.6.0/selenium/selenium-domviewer.js +188 -0
  48. data/vendor/selenium-0.6.0/selenium/selenium-executionloop.js +250 -0
  49. data/vendor/selenium-0.6.0/selenium/selenium-fitrunner.js +597 -0
  50. data/vendor/selenium-0.6.0/selenium/selenium-logging.js +88 -0
  51. data/vendor/selenium-0.6.0/selenium/selenium-logo.png +0 -0
  52. data/vendor/selenium-0.6.0/selenium/selenium-tableparser.js +50 -0
  53. data/vendor/selenium-0.6.0/selenium/selenium.css +211 -0
  54. data/vendor/selenium-0.6.0/selenium/tests/ErrorCheckingTestSuite.html +36 -0
  55. data/vendor/selenium-0.6.0/selenium/tests/GoogleTestSearch.html +69 -0
  56. data/vendor/selenium-0.6.0/selenium/tests/GoogleTestSuite.html +32 -0
  57. data/vendor/selenium-0.6.0/selenium/tests/JsUnitSuite.html +38 -0
  58. data/vendor/selenium-0.6.0/selenium/tests/TestClick.html +128 -0
  59. data/vendor/selenium-0.6.0/selenium/tests/TestClickJavascriptHref.html +115 -0
  60. data/vendor/selenium-0.6.0/selenium/tests/TestCommandError.html +79 -0
  61. data/vendor/selenium-0.6.0/selenium/tests/TestConfirmations.html +77 -0
  62. data/vendor/selenium-0.6.0/selenium/tests/TestErrorChecking.html +71 -0
  63. data/vendor/selenium-0.6.0/selenium/tests/TestFailingAssert.html +59 -0
  64. data/vendor/selenium-0.6.0/selenium/tests/TestFailingVerifications.html +198 -0
  65. data/vendor/selenium-0.6.0/selenium/tests/TestFocusOnBlur.html +53 -0
  66. data/vendor/selenium-0.6.0/selenium/tests/TestGoBack.html +81 -0
  67. data/vendor/selenium-0.6.0/selenium/tests/TestImplicitLocators.html +81 -0
  68. data/vendor/selenium-0.6.0/selenium/tests/TestJavascriptParameters.html +91 -0
  69. data/vendor/selenium-0.6.0/selenium/tests/TestLocators.html +161 -0
  70. data/vendor/selenium-0.6.0/selenium/tests/TestModalDialog.html +58 -0
  71. data/vendor/selenium-0.6.0/selenium/tests/TestModalDialogDialog.html +48 -0
  72. data/vendor/selenium-0.6.0/selenium/tests/TestOpen.html +66 -0
  73. data/vendor/selenium-0.6.0/selenium/tests/TestPatternMatching.html +127 -0
  74. data/vendor/selenium-0.6.0/selenium/tests/TestPause.html +78 -0
  75. data/vendor/selenium-0.6.0/selenium/tests/TestPrompting.html +82 -0
  76. data/vendor/selenium-0.6.0/selenium/tests/TestProxy.html +62 -0
  77. data/vendor/selenium-0.6.0/selenium/tests/TestSelect.html +111 -0
  78. data/vendor/selenium-0.6.0/selenium/tests/TestSelectWindow.html +106 -0
  79. data/vendor/selenium-0.6.0/selenium/tests/TestStore.html +165 -0
  80. data/vendor/selenium-0.6.0/selenium/tests/TestSuite-InternetExplorer.html +79 -0
  81. data/vendor/selenium-0.6.0/selenium/tests/TestSuite-Konqueror.html +75 -0
  82. data/vendor/selenium-0.6.0/selenium/tests/TestSuite-Safari.html +75 -0
  83. data/vendor/selenium-0.6.0/selenium/tests/TestSuite.html +75 -0
  84. data/vendor/selenium-0.6.0/selenium/tests/TestType.html +79 -0
  85. data/vendor/selenium-0.6.0/selenium/tests/TestUserExtensions.html +81 -0
  86. data/vendor/selenium-0.6.0/selenium/tests/TestVerifications.html +164 -0
  87. data/vendor/selenium-0.6.0/selenium/tests/TestVerifyAlerts.html +80 -0
  88. data/vendor/selenium-0.6.0/selenium/tests/TestVerifyAlertsFailures.html +108 -0
  89. data/vendor/selenium-0.6.0/selenium/tests/TestVerifyConfirmationFailures.html +86 -0
  90. data/vendor/selenium-0.6.0/selenium/tests/TestVerifyEditable.html +70 -0
  91. data/vendor/selenium-0.6.0/selenium/tests/TestVerifyEditableFailures.html +95 -0
  92. data/vendor/selenium-0.6.0/selenium/tests/TestVisibility.html +91 -0
  93. data/vendor/selenium-0.6.0/selenium/tests/TestVisibilityFailures.html +131 -0
  94. data/vendor/selenium-0.6.0/selenium/tests/TestWait.html +112 -0
  95. data/vendor/selenium-0.6.0/selenium/tests/TestWaitFor.html +63 -0
  96. data/vendor/selenium-0.6.0/selenium/tests/TestWaitInPopupWindow.html +94 -0
  97. data/vendor/selenium-0.6.0/selenium/tests/TestXPathLocators.html +98 -0
  98. data/vendor/selenium-0.6.0/selenium/tests/browserbot/alert-handling-tests.html +79 -0
  99. data/vendor/selenium-0.6.0/selenium/tests/browserbot/assert-tests.html +113 -0
  100. data/vendor/selenium-0.6.0/selenium/tests/browserbot/browserbot-tests.html +123 -0
  101. data/vendor/selenium-0.6.0/selenium/tests/browserbot/command-factory-tests.html +290 -0
  102. data/vendor/selenium-0.6.0/selenium/tests/browserbot/command-handler-tests.html +115 -0
  103. data/vendor/selenium-0.6.0/selenium/tests/browserbot/confirm-handling-tests.html +97 -0
  104. data/vendor/selenium-0.6.0/selenium/tests/browserbot/error-checking-command-tests.html +198 -0
  105. data/vendor/selenium-0.6.0/selenium/tests/browserbot/event-bubble-tests.html +106 -0
  106. data/vendor/selenium-0.6.0/selenium/tests/browserbot/optionlocator-tests.html +180 -0
  107. data/vendor/selenium-0.6.0/selenium/tests/browserbot/pagebot-accessor-tests.html +65 -0
  108. data/vendor/selenium-0.6.0/selenium/tests/browserbot/pagebot-action-tests.html +200 -0
  109. data/vendor/selenium-0.6.0/selenium/tests/browserbot/pagebot-attribute-tests.html +98 -0
  110. data/vendor/selenium-0.6.0/selenium/tests/browserbot/pagebot-locator-tests-include.html +33 -0
  111. data/vendor/selenium-0.6.0/selenium/tests/browserbot/pagebot-locator-tests.html +258 -0
  112. data/vendor/selenium-0.6.0/selenium/tests/browserbot/pagebot-property-tests.html +49 -0
  113. data/vendor/selenium-0.6.0/selenium/tests/browserbot/pattern-matcher-tests.html +66 -0
  114. data/vendor/selenium-0.6.0/selenium/tests/browserbot/selenium-api-tests.html +412 -0
  115. data/vendor/selenium-0.6.0/selenium/tests/browserbot/selenium-parameter-tests.html +98 -0
  116. data/vendor/selenium-0.6.0/selenium/tests/browserbot/suite.html +52 -0
  117. data/vendor/selenium-0.6.0/selenium/tests/browserbot/testloop-handle-error-tests.html +74 -0
  118. data/vendor/selenium-0.6.0/selenium/tests/events/TestButtonEvents.html +72 -0
  119. data/vendor/selenium-0.6.0/selenium/tests/events/TestCheckboxEvents.html +107 -0
  120. data/vendor/selenium-0.6.0/selenium/tests/events/TestFireEvents.html +75 -0
  121. data/vendor/selenium-0.6.0/selenium/tests/events/TestLinkEvents.html +43 -0
  122. data/vendor/selenium-0.6.0/selenium/tests/events/TestRadioEvents.html +149 -0
  123. data/vendor/selenium-0.6.0/selenium/tests/events/TestSelectEvents.html +122 -0
  124. data/vendor/selenium-0.6.0/selenium/tests/events/TestTextEvents.html +87 -0
  125. data/vendor/selenium-0.6.0/selenium/tests/events/readme.txt +26 -0
  126. data/vendor/selenium-0.6.0/selenium/tests/html/banner.gif +0 -0
  127. data/vendor/selenium-0.6.0/selenium/tests/html/test_async_event.html +36 -0
  128. data/vendor/selenium-0.6.0/selenium/tests/html/test_click_javascript_page.html +34 -0
  129. data/vendor/selenium-0.6.0/selenium/tests/html/test_click_page1.html +31 -0
  130. data/vendor/selenium-0.6.0/selenium/tests/html/test_click_page2.html +30 -0
  131. data/vendor/selenium-0.6.0/selenium/tests/html/test_confirm.html +34 -0
  132. data/vendor/selenium-0.6.0/selenium/tests/html/test_dummy_page.html +26 -0
  133. data/vendor/selenium-0.6.0/selenium/tests/html/test_editable.html +36 -0
  134. data/vendor/selenium-0.6.0/selenium/tests/html/test_focus_on_blur.html +33 -0
  135. data/vendor/selenium-0.6.0/selenium/tests/html/test_form_events.html +98 -0
  136. data/vendor/selenium-0.6.0/selenium/tests/html/test_framed_page.html +7 -0
  137. data/vendor/selenium-0.6.0/selenium/tests/html/test_just_text.html +22 -0
  138. data/vendor/selenium-0.6.0/selenium/tests/html/test_locators.html +34 -0
  139. data/vendor/selenium-0.6.0/selenium/tests/html/test_modal_dialog.html +29 -0
  140. data/vendor/selenium-0.6.0/selenium/tests/html/test_modal_dialog_dialog.html +35 -0
  141. data/vendor/selenium-0.6.0/selenium/tests/html/test_open.html +23 -0
  142. data/vendor/selenium-0.6.0/selenium/tests/html/test_prompt.html +34 -0
  143. data/vendor/selenium-0.6.0/selenium/tests/html/test_reload_onchange_page.html +32 -0
  144. data/vendor/selenium-0.6.0/selenium/tests/html/test_select.html +35 -0
  145. data/vendor/selenium-0.6.0/selenium/tests/html/test_select_window.html +29 -0
  146. data/vendor/selenium-0.6.0/selenium/tests/html/test_select_window_popup.html +28 -0
  147. data/vendor/selenium-0.6.0/selenium/tests/html/test_slowloading_page.html +27 -0
  148. data/vendor/selenium-0.6.0/selenium/tests/html/test_store_value.html +23 -0
  149. data/vendor/selenium-0.6.0/selenium/tests/html/test_type_page1.html +37 -0
  150. data/vendor/selenium-0.6.0/selenium/tests/html/test_type_page2.html +61 -0
  151. data/vendor/selenium-0.6.0/selenium/tests/html/test_verifications.html +42 -0
  152. data/vendor/selenium-0.6.0/selenium/tests/html/test_verify_alert.html +46 -0
  153. data/vendor/selenium-0.6.0/selenium/tests/html/test_visibility.html +53 -0
  154. data/vendor/selenium-0.6.0/selenium/tests/readme.txt +1 -0
  155. data/vendor/selenium-0.6.0/selenium/tests/tableparser/tableparser-tests.html +122 -0
  156. data/vendor/selenium-0.6.0/selenium/tests/tinyWebServer.py +70 -0
  157. data/vendor/selenium-0.6.0/selenium/user-extensions.js.sample +62 -0
  158. data/vendor/selenium-0.6.0/selenium/version.txt +1 -0
  159. data/vendor/selenium-0.6.0/selenium/xmlextras.js +153 -0
  160. data/vendor/selenium-0.6.0/selenium/xpath.js +3910 -0
  161. metadata +216 -0
@@ -0,0 +1,610 @@
1
+ /*
2
+ html-xpath, an implementation of DOM Level 3 XPath for Internet Explorer 5+
3
+ Copyright (C) 2004 Dimitri Glazkov
4
+
5
+ This library is free software; you can redistribute it and/or
6
+ modify it under the terms of the GNU Lesser General Public
7
+ License as published by the Free Software Foundation; either
8
+ version 2.1 of the License, or (at your option) any later version.
9
+
10
+ This library is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ Lesser General Public License for more details.
14
+
15
+ You should have received a copy of the GNU Lesser General Public
16
+ License along with this library; if not, write to the Free Software
17
+
18
+ */
19
+
20
+ var isIe = /MSIE [56789]/.test(navigator.userAgent) && (navigator.platform == "Win32");
21
+
22
+ // Mozilla has support by default, we don't have an implementation for the rest
23
+ if (isIe)
24
+ {
25
+ // release number
26
+ document.DomL3XPathRelease = "0.0.3.0";
27
+
28
+ // XPathException
29
+ // An Error object will be thrown, this is just a handler to instantiate that object
30
+ var XPathException = new _XPathExceptionHandler();
31
+ function _XPathExceptionHandler()
32
+ {
33
+ this.INVALID_EXPRESSION_ERR = 51;
34
+ this.TYPE_ERR = 52;
35
+ this.NOT_IMPLEMENTED_ERR = -1;
36
+ this.RUNTIME_ERR = -2;
37
+
38
+ this.ThrowNotImplemented = function(message)
39
+ {
40
+ ThrowError(this.NOT_IMPLEMENTED_ERR, "This functionality is not implemented.", message);
41
+ }
42
+
43
+ this.ThrowInvalidExpression = function(message)
44
+ {
45
+ ThrowError(this.INVALID_EXPRESSION_ERR, "Invalid expression", message);
46
+ }
47
+
48
+ this.ThrowType = function(message)
49
+ {
50
+ ThrowError(this.TYPE_ERR, "Type error", message);
51
+ }
52
+
53
+ this.Throw = function(message)
54
+ {
55
+ ThrowError(this.RUNTIME_ERR, "Run-time error", message);
56
+ }
57
+
58
+ function ThrowError(code, description, message)
59
+ {
60
+ var error = new Error(code, "DOM-L3-XPath " + document.DomL3XPathRelease + ": " + description + (message ? ", \"" + message + "\"": ""));
61
+ error.code = code;
62
+ error.name = "XPathException";
63
+ throw error;
64
+ }
65
+ }
66
+
67
+ // DOMException
68
+ // An Error object will be thrown, this is just a handler to instantiate that object
69
+ var DOMException = new _DOMExceptionHandler();
70
+ function _DOMExceptionHandler()
71
+ {
72
+ this.ThrowInvalidState = function(message)
73
+ {
74
+ ThrowError(13, "The state of the object is no longer valid", message);
75
+ }
76
+
77
+ function ThrowError(code, description, message)
78
+ {
79
+ var error = new Error(code, "DOM : " + description + (message ? ", \"" + message + "\"": ""));
80
+ error.code = code;
81
+ error.name = "DOMException";
82
+ throw error;
83
+ }
84
+ }
85
+
86
+ // XPathEvaluator
87
+ // implemented as document object methods
88
+
89
+ // XPathExpression createExpression(String expression, XPathNSResolver resolver)
90
+ document.createExpression = function
91
+ (
92
+ expression, // String
93
+ resolver // XPathNSResolver
94
+ )
95
+ {
96
+ // returns XPathExpression object
97
+ return new XPathExpression(expression, resolver);
98
+ }
99
+
100
+ // XPathNSResolver createNSResolver(nodeResolver)
101
+ document.createNSResolver = function
102
+ (
103
+ nodeResolver // Node
104
+ )
105
+ {
106
+ // returns XPathNSResolver
107
+ return new XPathNSResolver(nodeResolver);
108
+ }
109
+
110
+ // XPathResult evaluate(String expresison, Node contextNode, XPathNSResolver resolver, Number type, XPathResult result)
111
+ document.evaluate = function
112
+ (
113
+ expression, // String
114
+ contextNode, // Node
115
+ resolver, // XPathNSResolver
116
+ type, // Number
117
+ result // XPathResult
118
+ )
119
+ // can raise XPathException, DOMException
120
+ {
121
+ // return XPathResult
122
+ return document.createExpression(expression, resolver).evaluate(contextNode, type, result);
123
+ }
124
+
125
+ // XPathExpression
126
+ function XPathExpression
127
+ (
128
+ expression, // String
129
+ resolver // XPathNSResolver
130
+ )
131
+ {
132
+ this.expressionString = expression;
133
+ this.resolver = resolver;
134
+
135
+ // XPathResult evaluate(Node contextNode, Number type, XPathResult result)
136
+ this.evaluate = function
137
+ (
138
+ contextNode, // Node
139
+ type, // Number
140
+ result // XPathResult
141
+ )
142
+ // raises XPathException, DOMException
143
+ {
144
+ // return XPathResult
145
+ return (result && result.constructor == XPathResult ? result.initialize(this, contextNode, resolver, type) : new XPathResult(this, contextNode, resolver, type));
146
+ }
147
+
148
+ this.toString = function()
149
+ {
150
+ return "[XPathExpression]";
151
+ }
152
+ }
153
+
154
+ // XPathNSResolver
155
+ function XPathNSResolver(node)
156
+ {
157
+ this.node = node;
158
+
159
+ // String lookupNamespaceURI(String prefix)
160
+ this.lookupNamespaceURI = function
161
+ (
162
+ prefix // String
163
+ )
164
+ {
165
+ XPathException.ThrowNotImplemented();
166
+ // return String
167
+ return null;
168
+ }
169
+
170
+ this.toString = function()
171
+ {
172
+ return "[XPathNSResolver]";
173
+ }
174
+ }
175
+
176
+ // XPathResult
177
+ XPathResult.ANY_TYPE = 0;
178
+ XPathResult.NUMBER_TYPE = 1;
179
+ XPathResult.STRING_TYPE = 2;
180
+ XPathResult.BOOLEAN_TYPE = 3;
181
+ XPathResult.UNORDERED_NODE_ITERATOR_TYPE = 4;
182
+ XPathResult.ORDERED_NODE_ITERATOR_TYPE = 5;
183
+ XPathResult.UNORDERED_SNAPSHOT_TYPE = 6;
184
+ XPathResult.ORDERED_SNAPSHOT_TYPE = 7;
185
+ XPathResult.ANY_UNORDERED_NODE_TYPE = 8;
186
+ XPathResult.FIRST_ORDERED_NODE_TYPE = 9;
187
+
188
+ function XPathResult
189
+ (
190
+ expression, // XPathExpression
191
+ contextNode, // Node
192
+ resolver, // XPathNSResolver
193
+ type // Number
194
+ )
195
+ {
196
+ this.initialize = function(expression, contextNode, resolver, type)
197
+ {
198
+ this._domResult = null;
199
+ this._expression = expression;
200
+ this._contextNode = contextNode;
201
+ this._resolver = resolver;
202
+ if (type)
203
+ {
204
+ this.resultType = type;
205
+ this._isIterator = (type == XPathResult.UNORDERED_NODE_ITERATOR_TYPE ||
206
+ type == XPathResult.ORDERED_NODE_ITERATOR_TYPE ||
207
+ type == XPathResult.ANY_TYPE);
208
+ this._isSnapshot = (type == XPathResult.UNORDERED_SNAPSHOT_TYPE || type == XPathResult.ORDERED_SNAPSHOT_TYPE);
209
+ this._isNodeSet = type > XPathResult.BOOLEAN_TYPE;
210
+ }
211
+ else
212
+ {
213
+ this.resultType = XPathResult.ANY_TYPE;
214
+ this._isIterator = true;
215
+ this._isSnapshot = false;
216
+ this._isNodeSet = true;
217
+ }
218
+ return this;
219
+ }
220
+
221
+ this.initialize(expression, contextNode, resolver, type);
222
+
223
+ this.getInvalidIteratorState = function()
224
+ {
225
+ return documentChangeDetected() || !this._isIterator;
226
+ }
227
+
228
+ this.getSnapshotLength = function()
229
+ // raises XPathException
230
+ {
231
+ if (!this._isSnapshot)
232
+ {
233
+ XPathException.ThrowType("Snapshot is not an expected result type");
234
+ }
235
+ activateResult(this);
236
+ // return Number
237
+ return this._domResult.length;
238
+ }
239
+
240
+ // Node iterateNext()
241
+ this.iterateNext = function()
242
+ // raises XPathException, DOMException
243
+ {
244
+ if (!this._isIterator)
245
+ {
246
+ XPathException.ThrowType("Iterator is not an expected result type");
247
+ }
248
+ activateResult(this);
249
+ if (documentChangeDetected())
250
+ {
251
+ DOMException.ThrowInvalidState("iterateNext");
252
+ }
253
+ // return Node
254
+ return getNextNode(this);
255
+ }
256
+
257
+ // Node snapshotItem(Number index)
258
+ this.snapshotItem = function(index)
259
+ // raises XPathException
260
+ {
261
+ if (!this._isSnapshot)
262
+ {
263
+ XPathException.ThrowType("Snapshot is not an expected result type");
264
+ }
265
+ // return Node
266
+ return getItemNode(this, index);
267
+ }
268
+
269
+ this.toString = function()
270
+ {
271
+ return "[XPathResult]";
272
+ }
273
+
274
+ // returns string value of the result, if result type is STRING_TYPE
275
+ // otherwise throws an XPathException
276
+ this.getStringValue = function()
277
+ {
278
+ if (this.resultType != XPathResult.STRING_TYPE)
279
+ {
280
+ XPathException.ThrowType("The expression can not be converted to return String");
281
+ }
282
+ return getNodeText(this);
283
+ }
284
+
285
+ // returns number value of the result, if the result is NUMBER_TYPE
286
+ // otherwise throws an XPathException
287
+ this.getNumberValue = function()
288
+ {
289
+ if (this.resultType != XPathResult.NUMBER_TYPE)
290
+ {
291
+ XPathException.ThrowType("The expression can not be converted to return Number");
292
+ }
293
+ var number = parseInt(getNodeText(this));
294
+ if (isNaN(number))
295
+ {
296
+ XPathException.ThrowType("The result can not be converted to Number");
297
+ }
298
+ return number;
299
+ }
300
+
301
+ // returns boolean value of the result, if the result is BOOLEAN_TYPE
302
+ // otherwise throws an XPathException
303
+ this.getBooleanValue = function()
304
+ {
305
+ if (this.resultType != XPathResult.BOOLEAN_TYPE)
306
+ {
307
+ XPathException.ThrowType("The expression can not be converted to return Boolean");
308
+ }
309
+
310
+ var
311
+ text = getNodeText(this);
312
+ bool = (text ? text.toLowerCase() : null);
313
+ if (bool == "false" || bool == "true")
314
+ {
315
+ return bool;
316
+ }
317
+ XPathException.ThrowType("The result can not be converted to Boolean");
318
+ }
319
+
320
+ // returns single node, if the result is ANY_UNORDERED_NODE_TYPE or FIRST_ORDERED_NODE_TYPE
321
+ // otherwise throws an XPathException
322
+ this.getSingleNodeValue = function()
323
+ {
324
+ if (this.resultType != XPathResult.ANY_UNORDERED_NODE_TYPE &&
325
+ this.resultType != XPathResult.FIRST_ORDERED_NODE_TYPE)
326
+ {
327
+ XPathException.ThrowType("The expression can not be converted to return single Node value");
328
+ }
329
+ return getSingleNode(this);
330
+ }
331
+
332
+ function documentChangeDetected()
333
+ {
334
+ return document._XPathMsxmlDocumentHelper.documentChangeDetected();
335
+ }
336
+
337
+ function getNodeText(result)
338
+ {
339
+ activateResult(result);
340
+ return result._textResult;
341
+ // return ((node = getSingleNode(result)) ? (node.nodeType == 1 ? node.innerText : node.nodeValue) : null);
342
+ }
343
+
344
+ function findNode(result, current)
345
+ {
346
+ switch(current.nodeType)
347
+ {
348
+ case 1: // NODE_ELEMENT
349
+ var id = current.attributes.getNamedItem("id");
350
+ if (id)
351
+ {
352
+ return document.getElementById(id.value);
353
+ }
354
+ XPathException.Throw("unable to locate element in XML tree");
355
+ case 2: // NODE_ATTRIBUTE
356
+ var id = current.selectSingleNode("..").attributes.getNamedItem("id");
357
+ if (id)
358
+ {
359
+ var node = document.getElementById(id.text);
360
+ if (node)
361
+ {
362
+ return node.attributes.getNamedItem(current.nodeName);
363
+ }
364
+ }
365
+ XPathException.Throw("unable to locate attribute in XML tree");
366
+ case 3: // NODE_TEXT
367
+ var id = current.selectSingleNode("..").attributes.getNamedItem("id");
368
+ if (id)
369
+ {
370
+ var node = document.getElementById(id.value);
371
+ if (node)
372
+ {
373
+ for(child in node.childNodes)
374
+ {
375
+ if (child.nodeType == 3 && child.nodeValue == current.nodeValue)
376
+ {
377
+ return child;
378
+ }
379
+ }
380
+ }
381
+ }
382
+ XPathException.Throw("unable to locate text in XML tree");
383
+ }
384
+ XPathException.Throw("unknown node type");
385
+ }
386
+
387
+ function activateResult(result)
388
+ {
389
+ if (!result._domResult)
390
+ {
391
+ try
392
+ {
393
+ var expression = result._expression.expressionString;
394
+
395
+ // adjust expression if contextNode is not a document
396
+ if (result._contextNode != document && expression.indexOf("//") != 0)
397
+ {
398
+
399
+ expression = "//*[@id = '" + result._contextNode.id + "']" +
400
+ (expression.indexOf("/") == 0 ? "" : "/") + expression;
401
+ }
402
+
403
+ if (result._isNodeSet)
404
+ {
405
+ result._domResult = document._XPathMsxmlDocumentHelper.getDom().selectNodes(expression);
406
+ }
407
+ else
408
+ {
409
+ result._domResult = true;
410
+ result._textResult = document._XPathMsxmlDocumentHelper.getTextResult(expression);
411
+ }
412
+
413
+ }
414
+ catch(error)
415
+ {
416
+ alert(error.description);
417
+ XPathException.ThrowInvalidExpression(error.description);
418
+ }
419
+ }
420
+ }
421
+
422
+ function getSingleNode(result)
423
+ {
424
+ var node = getItemNode(result, 0);
425
+ result._domResult = null;
426
+ return node;
427
+ }
428
+
429
+ function getItemNode(result, index)
430
+ {
431
+ activateResult(result);
432
+ var current = result._domResult.item(index);
433
+ return (current ? findNode(result, current) : null);
434
+ }
435
+
436
+ function getNextNode(result)
437
+ {
438
+ var current = result._domResult.nextNode;
439
+ if (current)
440
+ {
441
+ return findNode(result, current);
442
+ }
443
+ result._domResult = null;
444
+ return null;
445
+ }
446
+ }
447
+
448
+ document.reloadDom = function()
449
+ {
450
+ document._XPathMsxmlDocumentHelper.reset();
451
+ }
452
+
453
+ document._XPathMsxmlDocumentHelper = new _XPathMsxmlDocumentHelper();
454
+ function _XPathMsxmlDocumentHelper()
455
+ {
456
+ this.getDom = function()
457
+ {
458
+ activateDom(this);
459
+ return this.dom;
460
+ }
461
+
462
+ this.getXml = function()
463
+ {
464
+ activateDom(this);
465
+ return this.dom.xml;
466
+ }
467
+
468
+ this.getTextResult = function(expression)
469
+ {
470
+ expression = expression.replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "\"");
471
+ var xslText = "<xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\">" +
472
+ "<xsl:output method=\"text\"/><xsl:template match=\"*\"><xsl:value-of select=\"" + expression + "\"/>" +
473
+ "</xsl:template></xsl:stylesheet>";
474
+ var xsl = new ActiveXObject("Msxml2.DOMDocument");
475
+ xsl.loadXML(xslText);
476
+ try
477
+ {
478
+ var result = this.getDom().transformNode(xsl);
479
+ }
480
+ catch(error)
481
+ {
482
+ alert("Error: " + error.description);
483
+ }
484
+ return result;
485
+ }
486
+
487
+ this.reset = function()
488
+ {
489
+ this.dom = null;
490
+ }
491
+
492
+ function onPropertyChangeEventHandler()
493
+ {
494
+ document._propertyChangeDetected = true;
495
+ }
496
+
497
+ this.documentChangeDetected = function()
498
+ {
499
+ return (document.ignoreDocumentChanges ? false : this._currentElementCount != document.all.length || document._propertyChangeDetected);
500
+ }
501
+
502
+ function activateDom(helper)
503
+ {
504
+ if (!helper.dom)
505
+ {
506
+ var dom = new ActiveXObject("Msxml2.DOMDocument");
507
+ dom.async = false;
508
+ dom.resolveExternals = false;
509
+ loadDocument(dom, helper);
510
+ helper.dom = dom;
511
+ helper._currentElementCount = document.all.length;
512
+ document._propertyChangeDetected = false;
513
+ }
514
+ else
515
+ {
516
+ if (helper.documentChangeDetected())
517
+ {
518
+ var dom = helper.dom;
519
+ dom.load("");
520
+ loadDocument(dom, helper);
521
+ helper._currentElementCount = document.all.length;
522
+ document._propertyChangeDetected = false;
523
+ }
524
+ }
525
+ }
526
+
527
+ function loadDocument(dom, helper)
528
+ {
529
+ return loadNode(dom, dom, document.body, helper);
530
+ }
531
+
532
+ function loadNode(dom, domParentNode, node, helper)
533
+ {
534
+ if (node.nodeType == 3)
535
+ {
536
+ domParentNode.appendChild(dom.createTextNode(node.nodeValue));
537
+ }
538
+ else
539
+ {
540
+ var domNode = dom.createElement(node.nodeName.toLowerCase());
541
+ if (!node.id)
542
+ {
543
+ node.id = node.uniqueID;
544
+ }
545
+ domParentNode.appendChild(domNode);
546
+ loadAttributes(dom, domNode, node);
547
+ var length = node.childNodes.length;
548
+ for(var i = 0; i < length; i ++ )
549
+ {
550
+ loadNode(dom, domNode, node.childNodes[i], helper);
551
+ }
552
+ node.attachEvent("onpropertychange", onPropertyChangeEventHandler);
553
+ }
554
+ }
555
+
556
+ function loadAttributes(dom, domParentNode, node)
557
+ {
558
+ for (var i = 0; i < node.attributes.length; i ++ )
559
+ {
560
+ var attribute = node.attributes[i];
561
+ var attributeValue = attribute.nodeValue;
562
+ if (attributeValue && attribute.specified)
563
+ {
564
+ var domAttribute = dom.createAttribute(attribute.nodeName);
565
+ domAttribute.value = attributeValue;
566
+ domParentNode.setAttributeNode(domAttribute);
567
+ }
568
+ }
569
+ }
570
+
571
+ }
572
+ }
573
+ else
574
+ {
575
+ document.reloadDom = function() {}
576
+ XPathResult.prototype.getStringValue = function()
577
+ {
578
+ return this.stringValue;
579
+ }
580
+
581
+ XPathResult.prototype.getNumberValue = function()
582
+ {
583
+ return this.numberValue;
584
+ }
585
+
586
+ XPathResult.prototype.getBooleanValue = function()
587
+ {
588
+ return this.booleanValue;
589
+ }
590
+
591
+ XPathResult.prototype.getSingleNodeValue = function()
592
+ {
593
+ return this.singleNodeValue;
594
+ }
595
+
596
+ XPathResult.prototype.getInvalidIteratorState = function()
597
+ {
598
+ return this.invalidIteratorState;
599
+ }
600
+
601
+ XPathResult.prototype.getSnapshotLength = function()
602
+ {
603
+ return this.snapshotLength;
604
+ }
605
+
606
+ XPathResult.prototype.getResultType = function()
607
+ {
608
+ return this.resultType;
609
+ }
610
+ }