envjs 0.1.7 → 0.2.0
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.
- data/.jslintrbrc +29 -0
- data/.project +17 -0
- data/CHANGELOG.rdoc +3 -0
- data/DTD/xhtml-lat1.ent +196 -0
- data/DTD/xhtml-special.ent +80 -0
- data/DTD/xhtml-symbol.ent +237 -0
- data/DTD/xhtml.soc +14 -0
- data/DTD/xhtml1-frameset.dtd +1235 -0
- data/DTD/xhtml1-strict.dtd +978 -0
- data/DTD/xhtml1-transitional.dtd +1201 -0
- data/DTD/xhtml1.dcl +192 -0
- data/Makefile +7 -0
- data/Manifest.txt +287 -0
- data/{README → README.rdoc} +24 -3
- data/Rakefile +196 -0
- data/Wakefile +24 -0
- data/build.properties +9 -0
- data/build.xml +247 -0
- data/gm/jquery.js +6002 -0
- data/gm/mainx.js +2648 -0
- data/gm/sensx.js +135 -0
- data/gm/t.js +6 -0
- data/gm/x.html +76 -0
- data/htmlparser/BrowserTreeBuilder.java +456 -0
- data/htmlparser/README +34 -0
- data/htmlparser/build.sh +38 -0
- data/jsl/jsl +0 -0
- data/jsl/jsl.default.conf +129 -0
- data/jsl/jsl.exe +0 -0
- data/lib/envjs.rb +2 -0
- data/lib/envjs/env.js +22 -3
- data/lib/envjs/event_loop.js +2 -0
- data/lib/envjs/static.js +155 -21
- data/licenses/GPL-LICENSE.txt +278 -0
- data/licenses/MIT-LICENSE.txt +20 -0
- data/src/base64.js +80 -0
- data/src/build.js +6 -0
- data/src/cruft/bad.html +24 -0
- data/src/cruft/dom.js +606 -0
- data/src/cruft/element.js +297 -0
- data/src/cruft/good.html +30 -0
- data/src/cruft/good.js +32 -0
- data/src/cruft/internal.js +81 -0
- data/src/cruft/parser.js +458 -0
- data/src/css/properties.js +293 -0
- data/src/css/rule.js +22 -0
- data/src/css/sizzle.js +717 -0
- data/src/css/stylesheet.js +52 -0
- data/src/dom/attr.js +55 -0
- data/src/dom/cdatasection.js +31 -0
- data/src/dom/characterdata.js +119 -0
- data/src/dom/comment.js +30 -0
- data/src/dom/doctype.js +9 -0
- data/src/dom/document.js +553 -0
- data/src/dom/dom.js +134 -0
- data/src/dom/element.js +217 -0
- data/src/dom/entities.js +273 -0
- data/src/dom/exception.js +28 -0
- data/src/dom/fragment.js +37 -0
- data/src/dom/implementation.js +602 -0
- data/src/dom/instruction.js +51 -0
- data/src/dom/namednodemap.js +374 -0
- data/src/dom/namespace.js +50 -0
- data/src/dom/node.js +618 -0
- data/src/dom/nodelist.js +195 -0
- data/src/dom/parser.js +1207 -0
- data/src/dom/text.js +73 -0
- data/src/event/event.js +39 -0
- data/src/event/mouseevent.js +4 -0
- data/src/event/uievent.js +8 -0
- data/src/html/a.js +110 -0
- data/src/html/anchor.js +80 -0
- data/src/html/area.js +57 -0
- data/src/html/base.js +26 -0
- data/src/html/blockquote-q.js +19 -0
- data/src/html/body.js +19 -0
- data/src/html/button.js +21 -0
- data/src/html/canvas.js +14 -0
- data/src/html/col-colgroup.js +49 -0
- data/src/html/collection.js +72 -0
- data/src/html/cookie.js +151 -0
- data/src/html/del-ins.js +25 -0
- data/src/html/div.js +28 -0
- data/src/html/document.js +359 -0
- data/src/html/element.js +380 -0
- data/src/html/fieldset.js +19 -0
- data/src/html/form.js +484 -0
- data/src/html/frame.js +89 -0
- data/src/html/frameset.js +25 -0
- data/src/html/head.js +44 -0
- data/src/html/html.js +0 -0
- data/src/html/htmlparser.js +340 -0
- data/src/html/iframe.js +26 -0
- data/src/html/image.js +0 -0
- data/src/html/img.js +62 -0
- data/src/html/input-elements.js +307 -0
- data/src/html/input.js +65 -0
- data/src/html/label.js +26 -0
- data/src/html/legend.js +19 -0
- data/src/html/link.js +82 -0
- data/src/html/map.js +22 -0
- data/src/html/meta.js +37 -0
- data/src/html/object.js +89 -0
- data/src/html/optgroup.js +25 -0
- data/src/html/option.js +97 -0
- data/src/html/param.js +38 -0
- data/src/html/script.js +122 -0
- data/src/html/select.js +129 -0
- data/src/html/style.js +31 -0
- data/src/html/table.js +199 -0
- data/src/html/tbody-thead-tfoot.js +91 -0
- data/src/html/td-th.js +18 -0
- data/src/html/textarea.js +25 -0
- data/src/html/title.js +20 -0
- data/src/html/tr.js +114 -0
- data/src/intro.js +141 -0
- data/src/outro.js +70 -0
- data/src/parser/html5.detailed.js +10762 -0
- data/src/parser/html5.min.js +503 -0
- data/src/parser/html5.pretty.js +10815 -0
- data/src/parser/intro.js +42 -0
- data/src/parser/outro.js +9 -0
- data/src/platform/core.js +323 -0
- data/src/platform/johnson.js +479 -0
- data/src/platform/rhino.js +327 -0
- data/src/platform/static/intro.js +41 -0
- data/src/platform/static/outro.js +30 -0
- data/src/profile/aop.js +238 -0
- data/src/profile/profile.js +402 -0
- data/src/serializer/xml.js +21 -0
- data/src/svg/animatedstring.js +25 -0
- data/src/svg/document.js +25 -0
- data/src/svg/element.js +22 -0
- data/src/svg/locatable.js +17 -0
- data/src/svg/rect.js +18 -0
- data/src/svg/rectelement.js +24 -0
- data/src/svg/stylable.js +49 -0
- data/src/svg/svgelement.js +22 -0
- data/src/svg/transformable.js +15 -0
- data/src/window/css.js +15 -0
- data/src/window/dialog.js +16 -0
- data/src/window/document.js +28 -0
- data/src/window/event.js +262 -0
- data/src/window/history.js +62 -0
- data/src/window/location.js +138 -0
- data/src/window/navigator.js +48 -0
- data/src/window/screen.js +53 -0
- data/src/window/timer.js +21 -0
- data/src/window/window.js +284 -0
- data/src/window/xhr.js +127 -0
- data/src/xpath/expression.js +49 -0
- data/src/xpath/implementation.js +2482 -0
- data/src/xpath/result.js +67 -0
- data/src/xpath/util.js +551 -0
- data/src/xpath/xmltoken.js +149 -0
- data/src/xslt/COPYING +34 -0
- data/src/xslt/ajaxslt-0.8.1/AUTHORS +1 -0
- data/src/xslt/ajaxslt-0.8.1/ChangeLog +136 -0
- data/src/xslt/ajaxslt-0.8.1/Makefile +49 -0
- data/src/xslt/ajaxslt-0.8.1/README +102 -0
- data/src/xslt/ajaxslt-0.8.1/TODO +15 -0
- data/src/xslt/ajaxslt-0.8.1/dom.js +566 -0
- data/src/xslt/ajaxslt-0.8.1/dom_unittest.html +24 -0
- data/src/xslt/ajaxslt-0.8.1/dom_unittest.js +131 -0
- data/src/xslt/ajaxslt-0.8.1/simplelog.js +79 -0
- data/src/xslt/ajaxslt-0.8.1/test/xpath.html +18 -0
- data/src/xslt/ajaxslt-0.8.1/test/xpath_script.js +45 -0
- data/src/xslt/ajaxslt-0.8.1/test/xslt.html +58 -0
- data/src/xslt/ajaxslt-0.8.1/test/xslt_script.js +33 -0
- data/src/xslt/ajaxslt-0.8.1/unittestsuite.html +26 -0
- data/src/xslt/ajaxslt-0.8.1/xmltoken.js +149 -0
- data/src/xslt/ajaxslt-0.8.1/xmltoken_unittest.html +18 -0
- data/src/xslt/ajaxslt-0.8.1/xmltoken_unittest.js +811 -0
- data/src/xslt/ajaxslt-0.8.1/xpath_unittest.html +39 -0
- data/src/xslt/ajaxslt-0.8.1/xpath_unittest.js +557 -0
- data/src/xslt/ajaxslt-0.8.1/xpathdebug.js +234 -0
- data/src/xslt/ajaxslt-0.8.1/xslt_unittest.html +138 -0
- data/src/xslt/ajaxslt-0.8.1/xslt_unittest.js +68 -0
- data/src/xslt/implementation.js +625 -0
- data/src/xslt/processor.js +37 -0
- data/src/xslt/util.js +449 -0
- data/test/foo.html +8 -0
- data/test/foo.js +40 -0
- data/test/jquery.js +6002 -0
- data/test/x.js +1 -0
- data/test/y.js +1 -0
- metadata +245 -14
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @class DOMException - raised when an operation is impossible to perform
|
|
3
|
+
* @author Jon van Noort (jon@webarcana.com.au)
|
|
4
|
+
* @param code : int - the exception code (one of the DOMException constants)
|
|
5
|
+
*/
|
|
6
|
+
var DOMException = function(code) {
|
|
7
|
+
this.code = code;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
// DOMException constants
|
|
11
|
+
// Introduced in DOM Level 1:
|
|
12
|
+
DOMException.INDEX_SIZE_ERR = 1;
|
|
13
|
+
DOMException.DOMSTRING_SIZE_ERR = 2;
|
|
14
|
+
DOMException.HIERARCHY_REQUEST_ERR = 3;
|
|
15
|
+
DOMException.WRONG_DOCUMENT_ERR = 4;
|
|
16
|
+
DOMException.INVALID_CHARACTER_ERR = 5;
|
|
17
|
+
DOMException.NO_DATA_ALLOWED_ERR = 6;
|
|
18
|
+
DOMException.NO_MODIFICATION_ALLOWED_ERR = 7;
|
|
19
|
+
DOMException.NOT_FOUND_ERR = 8;
|
|
20
|
+
DOMException.NOT_SUPPORTED_ERR = 9;
|
|
21
|
+
DOMException.INUSE_ATTRIBUTE_ERR = 10;
|
|
22
|
+
|
|
23
|
+
// Introduced in DOM Level 2:
|
|
24
|
+
DOMException.INVALID_STATE_ERR = 11;
|
|
25
|
+
DOMException.SYNTAX_ERR = 12;
|
|
26
|
+
DOMException.INVALID_MODIFICATION_ERR = 13;
|
|
27
|
+
DOMException.NAMESPACE_ERR = 14;
|
|
28
|
+
DOMException.INVALID_ACCESS_ERR = 15;
|
data/src/dom/fragment.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
$debug("Defining DocumentFragment");
|
|
2
|
+
/*
|
|
3
|
+
* DocumentFragment - DOM Level 2
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* @class DOMDocumentFragment - DocumentFragment is a "lightweight" or "minimal" Document object.
|
|
7
|
+
* @extends DOMNode
|
|
8
|
+
* @author Jon van Noort (jon@webarcana.com.au) and David Joham (djoham@yahoo.com)
|
|
9
|
+
* @param ownerDocument : DOMDocument - The Document object associated with this node.
|
|
10
|
+
*/
|
|
11
|
+
var DOMDocumentFragment = function(ownerDocument) {
|
|
12
|
+
this.DOMNode = DOMNode;
|
|
13
|
+
this.DOMNode(ownerDocument);
|
|
14
|
+
this.nodeName = "#document-fragment";
|
|
15
|
+
};
|
|
16
|
+
DOMDocumentFragment.prototype = new DOMNode;
|
|
17
|
+
__extend__(DOMDocumentFragment.prototype,{
|
|
18
|
+
get nodeType(){
|
|
19
|
+
return DOMNode.DOCUMENT_FRAGMENT_NODE;
|
|
20
|
+
},
|
|
21
|
+
get xml(){
|
|
22
|
+
var xml = "",
|
|
23
|
+
count = this.childNodes.length;
|
|
24
|
+
|
|
25
|
+
// create string concatenating the serialized ChildNodes
|
|
26
|
+
for (var i = 0; i < count; i++) {
|
|
27
|
+
xml += this.childNodes.item(i).xml;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return xml;
|
|
31
|
+
},
|
|
32
|
+
toString : function(){
|
|
33
|
+
return "DocumentFragment #"+this._id;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
// $w.DocumentFragment = DOMDocumentFragment;
|
|
@@ -0,0 +1,602 @@
|
|
|
1
|
+
//DOMImplementation
|
|
2
|
+
$debug("Defining DOMImplementation");
|
|
3
|
+
/**
|
|
4
|
+
* @class DOMImplementation - provides a number of methods for performing operations
|
|
5
|
+
* that are independent of any particular instance of the document object model.
|
|
6
|
+
*
|
|
7
|
+
* @author Jon van Noort (jon@webarcana.com.au)
|
|
8
|
+
*/
|
|
9
|
+
var DOMImplementation = function() {
|
|
10
|
+
this.preserveWhiteSpace = false; // by default, ignore whitespace
|
|
11
|
+
this.namespaceAware = true; // by default, handle namespaces
|
|
12
|
+
this.errorChecking = true; // by default, test for exceptions
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
__extend__(DOMImplementation.prototype,{
|
|
16
|
+
// @param feature : string - The package name of the feature to test.
|
|
17
|
+
// the legal only values are "XML" and "CORE" (case-insensitive).
|
|
18
|
+
// @param version : string - This is the version number of the package
|
|
19
|
+
// name to test. In Level 1, this is the string "1.0".*
|
|
20
|
+
// @return : boolean
|
|
21
|
+
hasFeature : function(feature, version) {
|
|
22
|
+
var ret = false;
|
|
23
|
+
if (feature.toLowerCase() == "xml") {
|
|
24
|
+
ret = (!version || (version == "1.0") || (version == "2.0"));
|
|
25
|
+
}
|
|
26
|
+
else if (feature.toLowerCase() == "core") {
|
|
27
|
+
ret = (!version || (version == "2.0"));
|
|
28
|
+
}
|
|
29
|
+
else if (feature == "http://www.w3.org/TR/SVG11/feature#BasicStructure") {
|
|
30
|
+
ret = (version == "1.1");
|
|
31
|
+
}
|
|
32
|
+
return ret;
|
|
33
|
+
},
|
|
34
|
+
createDocumentType : function(qname, publicid, systemid){
|
|
35
|
+
return new DOMDocumentType();
|
|
36
|
+
},
|
|
37
|
+
createDocument : function(nsuri, qname, doctype){
|
|
38
|
+
//TODO - this currently returns an empty doc
|
|
39
|
+
//but needs to handle the args
|
|
40
|
+
return new Document(this, null);
|
|
41
|
+
},
|
|
42
|
+
createHTMLDocument : function(title){
|
|
43
|
+
// N.B. explict window on purpose ...
|
|
44
|
+
var doc = new HTMLDocument(this, window, "");
|
|
45
|
+
var html = doc.createElement("html"); doc.appendChild(html);
|
|
46
|
+
var head = doc.createElement("head"); html.appendChild(head);
|
|
47
|
+
var body = doc.createElement("body"); html.appendChild(body);
|
|
48
|
+
var t = doc.createElement("title"); head.appendChild(t);
|
|
49
|
+
if( title) {
|
|
50
|
+
t.appendChild(doc.createTextNode(title));
|
|
51
|
+
}
|
|
52
|
+
return doc;
|
|
53
|
+
},
|
|
54
|
+
translateErrCode : function(code) {
|
|
55
|
+
//convert DOMException Code to human readable error message;
|
|
56
|
+
var msg = "";
|
|
57
|
+
|
|
58
|
+
switch (code) {
|
|
59
|
+
case DOMException.INDEX_SIZE_ERR : // 1
|
|
60
|
+
msg = "INDEX_SIZE_ERR: Index out of bounds";
|
|
61
|
+
break;
|
|
62
|
+
|
|
63
|
+
case DOMException.DOMSTRING_SIZE_ERR : // 2
|
|
64
|
+
msg = "DOMSTRING_SIZE_ERR: The resulting string is too long to fit in a DOMString";
|
|
65
|
+
break;
|
|
66
|
+
|
|
67
|
+
case DOMException.HIERARCHY_REQUEST_ERR : // 3
|
|
68
|
+
msg = "HIERARCHY_REQUEST_ERR: The Node can not be inserted at this location";
|
|
69
|
+
break;
|
|
70
|
+
|
|
71
|
+
case DOMException.WRONG_DOCUMENT_ERR : // 4
|
|
72
|
+
msg = "WRONG_DOCUMENT_ERR: The source and the destination Documents are not the same";
|
|
73
|
+
break;
|
|
74
|
+
|
|
75
|
+
case DOMException.INVALID_CHARACTER_ERR : // 5
|
|
76
|
+
msg = "INVALID_CHARACTER_ERR: The string contains an invalid character";
|
|
77
|
+
break;
|
|
78
|
+
|
|
79
|
+
case DOMException.NO_DATA_ALLOWED_ERR : // 6
|
|
80
|
+
msg = "NO_DATA_ALLOWED_ERR: This Node / NodeList does not support data";
|
|
81
|
+
break;
|
|
82
|
+
|
|
83
|
+
case DOMException.NO_MODIFICATION_ALLOWED_ERR : // 7
|
|
84
|
+
msg = "NO_MODIFICATION_ALLOWED_ERR: This object cannot be modified";
|
|
85
|
+
break;
|
|
86
|
+
|
|
87
|
+
case DOMException.NOT_FOUND_ERR : // 8
|
|
88
|
+
msg = "NOT_FOUND_ERR: The item cannot be found";
|
|
89
|
+
break;
|
|
90
|
+
|
|
91
|
+
case DOMException.NOT_SUPPORTED_ERR : // 9
|
|
92
|
+
msg = "NOT_SUPPORTED_ERR: This implementation does not support function";
|
|
93
|
+
break;
|
|
94
|
+
|
|
95
|
+
case DOMException.INUSE_ATTRIBUTE_ERR : // 10
|
|
96
|
+
msg = "INUSE_ATTRIBUTE_ERR: The Attribute has already been assigned to another Element";
|
|
97
|
+
break;
|
|
98
|
+
|
|
99
|
+
// Introduced in DOM Level 2:
|
|
100
|
+
case DOMException.INVALID_STATE_ERR : // 11
|
|
101
|
+
msg = "INVALID_STATE_ERR: The object is no longer usable";
|
|
102
|
+
break;
|
|
103
|
+
|
|
104
|
+
case DOMException.SYNTAX_ERR : // 12
|
|
105
|
+
msg = "SYNTAX_ERR: Syntax error";
|
|
106
|
+
break;
|
|
107
|
+
|
|
108
|
+
case DOMException.INVALID_MODIFICATION_ERR : // 13
|
|
109
|
+
msg = "INVALID_MODIFICATION_ERR: Cannot change the type of the object";
|
|
110
|
+
break;
|
|
111
|
+
|
|
112
|
+
case DOMException.NAMESPACE_ERR : // 14
|
|
113
|
+
msg = "NAMESPACE_ERR: The namespace declaration is incorrect";
|
|
114
|
+
break;
|
|
115
|
+
|
|
116
|
+
case DOMException.INVALID_ACCESS_ERR : // 15
|
|
117
|
+
msg = "INVALID_ACCESS_ERR: The object does not support this function";
|
|
118
|
+
break;
|
|
119
|
+
|
|
120
|
+
default :
|
|
121
|
+
msg = "UNKNOWN: Unknown Exception Code ("+ code +")";
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return msg;
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Defined 'globally' to this scope. Remember everything is wrapped in a closure so this doesnt show up
|
|
131
|
+
* in the outer most global scope.
|
|
132
|
+
*/
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* process SAX events
|
|
136
|
+
*
|
|
137
|
+
* @author Jon van Noort (jon@webarcana.com.au), David Joham (djoham@yahoo.com) and Scott Severtson
|
|
138
|
+
*
|
|
139
|
+
* @param impl : DOMImplementation
|
|
140
|
+
* @param doc : DOMDocument - the Document to contain the parsed XML string
|
|
141
|
+
* @param p : XMLP - the SAX Parser
|
|
142
|
+
*
|
|
143
|
+
* @return : DOMDocument
|
|
144
|
+
*/
|
|
145
|
+
|
|
146
|
+
function __parseLoop__(impl, doc, p, isWindowDocument) {
|
|
147
|
+
var iEvt, iNode, iAttr, strName;
|
|
148
|
+
var iNodeParent = doc;
|
|
149
|
+
|
|
150
|
+
var el_close_count = 0;
|
|
151
|
+
|
|
152
|
+
var entitiesList = new Array();
|
|
153
|
+
var textNodesList = new Array();
|
|
154
|
+
|
|
155
|
+
// if namespaceAware, add default namespace
|
|
156
|
+
if (impl.namespaceAware) {
|
|
157
|
+
var iNS = doc.createNamespace(""); // add the default-default namespace
|
|
158
|
+
iNS.value = "http://www.w3.org/2000/xmlns/";
|
|
159
|
+
doc._namespaces.setNamedItem(iNS);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// loop until SAX parser stops emitting events
|
|
163
|
+
var q = 0;
|
|
164
|
+
while(true) {
|
|
165
|
+
// get next event
|
|
166
|
+
iEvt = p.next();
|
|
167
|
+
|
|
168
|
+
if (iEvt == XMLP._ELM_B) { // Begin-Element Event
|
|
169
|
+
var pName = p.getName(); // get the Element name
|
|
170
|
+
pName = trim(pName, true, true); // strip spaces from Element name
|
|
171
|
+
if(pName.toLowerCase() == 'script')
|
|
172
|
+
p.replaceEntities = false;
|
|
173
|
+
|
|
174
|
+
if (!impl.namespaceAware) {
|
|
175
|
+
iNode = doc.createElement(p.getName()); // create the Element
|
|
176
|
+
// add attributes to Element
|
|
177
|
+
for(var i = 0; i < p.getAttributeCount(); i++) {
|
|
178
|
+
strName = p.getAttributeName(i); // get Attribute name
|
|
179
|
+
iAttr = iNode.getAttributeNode(strName); // if Attribute exists, use it
|
|
180
|
+
|
|
181
|
+
if(!iAttr) {
|
|
182
|
+
iAttr = doc.createAttribute(strName); // otherwise create it
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
iAttr.value = p.getAttributeValue(i); // set Attribute value
|
|
186
|
+
iNode.setAttributeNode(iAttr); // attach Attribute to Element
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
else { // Namespace Aware
|
|
190
|
+
// create element (with empty namespaceURI,
|
|
191
|
+
// resolve after namespace 'attributes' have been parsed)
|
|
192
|
+
iNode = doc.createElementNS("", p.getName());
|
|
193
|
+
|
|
194
|
+
// duplicate ParentNode's Namespace definitions
|
|
195
|
+
iNode._namespaces = __cloneNamedNodes__(iNodeParent._namespaces, iNode, true);
|
|
196
|
+
|
|
197
|
+
// add attributes to Element
|
|
198
|
+
for(var i = 0; i < p.getAttributeCount(); i++) {
|
|
199
|
+
strName = p.getAttributeName(i); // get Attribute name
|
|
200
|
+
|
|
201
|
+
// if attribute is a namespace declaration
|
|
202
|
+
if (__isNamespaceDeclaration__(strName)) {
|
|
203
|
+
// parse Namespace Declaration
|
|
204
|
+
var namespaceDec = __parseNSName__(strName);
|
|
205
|
+
|
|
206
|
+
if (strName != "xmlns") {
|
|
207
|
+
iNS = doc.createNamespace(strName); // define namespace
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
iNS = doc.createNamespace(""); // redefine default namespace
|
|
211
|
+
}
|
|
212
|
+
iNS.value = p.getAttributeValue(i); // set value = namespaceURI
|
|
213
|
+
|
|
214
|
+
iNode._namespaces.setNamedItem(iNS); // attach namespace to namespace collection
|
|
215
|
+
}
|
|
216
|
+
else { // otherwise, it is a normal attribute
|
|
217
|
+
iAttr = iNode.getAttributeNode(strName); // if Attribute exists, use it
|
|
218
|
+
|
|
219
|
+
if(!iAttr) {
|
|
220
|
+
iAttr = doc.createAttributeNS("", strName); // otherwise create it
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
iAttr.value = p.getAttributeValue(i); // set Attribute value
|
|
224
|
+
iNode.setAttributeNodeNS(iAttr); // attach Attribute to Element
|
|
225
|
+
|
|
226
|
+
if (__isIdDeclaration__(strName)) {
|
|
227
|
+
iNode.id = p.getAttributeValue(i); // cache ID for getElementById()
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// resolve namespaceURIs for this Element
|
|
233
|
+
if (iNode._namespaces.getNamedItem(iNode.prefix)) {
|
|
234
|
+
iNode.namespaceURI = iNode._namespaces.getNamedItem(iNode.prefix).value;
|
|
235
|
+
} else {
|
|
236
|
+
iNode.namespaceURI = iNodeParent.namespaceURI;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
// for this Element's attributes
|
|
240
|
+
for (var i = 0; i < iNode.attributes.length; i++) {
|
|
241
|
+
if (iNode.attributes.item(i).prefix != "") { // attributes do not have a default namespace
|
|
242
|
+
if (iNode._namespaces.getNamedItem(iNode.attributes.item(i).prefix)) {
|
|
243
|
+
iNode.attributes.item(i).namespaceURI = iNode._namespaces.getNamedItem(iNode.attributes.item(i).prefix).value;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// We didn't know the NS of the node when we created it, which means we created a default DOM object.
|
|
249
|
+
// Now that we know the NS, if there is one, we clone this node so that it'll get created under
|
|
250
|
+
// with the right constructor. This makes things like SVG work. Might be nice not to create twice as
|
|
251
|
+
// as many nodes, but that's painfully given the complexity of namespaces.
|
|
252
|
+
if(iNode.namespaceURI != ""){
|
|
253
|
+
iNode = iNode.cloneNode();
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// if this is the Root Element
|
|
258
|
+
if (iNodeParent.nodeType == DOMNode.DOCUMENT_NODE) {
|
|
259
|
+
iNodeParent._documentElement = iNode; // register this Element as the Document.documentElement
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
iNodeParent.appendChild(iNode); // attach Element to parentNode
|
|
263
|
+
iNodeParent = iNode; // descend one level of the DOM Tree
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
else if(iEvt == XMLP._ELM_E) { // End-Element Event
|
|
267
|
+
iNodeParent = iNodeParent.parentNode; // ascend one level of the DOM Tree
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
else if(iEvt == XMLP._ELM_EMP) { // Empty Element Event
|
|
271
|
+
pName = p.getName(); // get the Element name
|
|
272
|
+
pName = trim(pName, true, true); // strip spaces from Element name
|
|
273
|
+
|
|
274
|
+
if (!impl.namespaceAware) {
|
|
275
|
+
iNode = doc.createElement(pName); // create the Element
|
|
276
|
+
|
|
277
|
+
// add attributes to Element
|
|
278
|
+
for(var i = 0; i < p.getAttributeCount(); i++) {
|
|
279
|
+
strName = p.getAttributeName(i); // get Attribute name
|
|
280
|
+
iAttr = iNode.getAttributeNode(strName); // if Attribute exists, use it
|
|
281
|
+
|
|
282
|
+
if(!iAttr) {
|
|
283
|
+
iAttr = doc.createAttribute(strName); // otherwise create it
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
iAttr.value = p.getAttributeValue(i); // set Attribute value
|
|
287
|
+
iNode.setAttributeNode(iAttr); // attach Attribute to Element
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
else { // Namespace Aware
|
|
291
|
+
// create element (with empty namespaceURI,
|
|
292
|
+
// resolve after namespace 'attributes' have been parsed)
|
|
293
|
+
iNode = doc.createElementNS("", p.getName());
|
|
294
|
+
|
|
295
|
+
// duplicate ParentNode's Namespace definitions
|
|
296
|
+
iNode._namespaces = __cloneNamedNodes__(iNodeParent._namespaces, iNode);
|
|
297
|
+
|
|
298
|
+
// add attributes to Element
|
|
299
|
+
for(var i = 0; i < p.getAttributeCount(); i++) {
|
|
300
|
+
strName = p.getAttributeName(i); // get Attribute name
|
|
301
|
+
|
|
302
|
+
// if attribute is a namespace declaration
|
|
303
|
+
if (__isNamespaceDeclaration__(strName)) {
|
|
304
|
+
// parse Namespace Declaration
|
|
305
|
+
var namespaceDec = __parseNSName__(strName);
|
|
306
|
+
|
|
307
|
+
if (strName != "xmlns") {
|
|
308
|
+
iNS = doc.createNamespace(strName); // define namespace
|
|
309
|
+
}
|
|
310
|
+
else {
|
|
311
|
+
iNS = doc.createNamespace(""); // redefine default namespace
|
|
312
|
+
}
|
|
313
|
+
iNS.value = p.getAttributeValue(i); // set value = namespaceURI
|
|
314
|
+
|
|
315
|
+
iNode._namespaces.setNamedItem(iNS); // attach namespace to namespace collection
|
|
316
|
+
}
|
|
317
|
+
else { // otherwise, it is a normal attribute
|
|
318
|
+
iAttr = iNode.getAttributeNode(strName); // if Attribute exists, use it
|
|
319
|
+
|
|
320
|
+
if(!iAttr) {
|
|
321
|
+
iAttr = doc.createAttributeNS("", strName); // otherwise create it
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
iAttr.value = p.getAttributeValue(i); // set Attribute value
|
|
325
|
+
iNode.setAttributeNodeNS(iAttr); // attach Attribute to Element
|
|
326
|
+
|
|
327
|
+
if (__isIdDeclaration__(strName)) {
|
|
328
|
+
iNode.id = p.getAttributeValue(i); // cache ID for getElementById()
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// resolve namespaceURIs for this Element
|
|
334
|
+
if (iNode._namespaces.getNamedItem(iNode.prefix)) {
|
|
335
|
+
iNode.namespaceURI = iNode._namespaces.getNamedItem(iNode.prefix).value;
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
// for this Element's attributes
|
|
339
|
+
for (var i = 0; i < iNode.attributes.length; i++) {
|
|
340
|
+
if (iNode.attributes.item(i).prefix != "") { // attributes do not have a default namespace
|
|
341
|
+
if (iNode._namespaces.getNamedItem(iNode.attributes.item(i).prefix)) {
|
|
342
|
+
iNode.attributes.item(i).namespaceURI = iNode._namespaces.getNamedItem(iNode.attributes.item(i).prefix).value;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// if this is the Root Element
|
|
349
|
+
if (iNodeParent.nodeType == DOMNode.DOCUMENT_NODE) {
|
|
350
|
+
iNodeParent._documentElement = iNode; // register this Element as the Document.documentElement
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
iNodeParent.appendChild(iNode); // attach Element to parentNode
|
|
354
|
+
}
|
|
355
|
+
else if(iEvt == XMLP._TEXT || iEvt == XMLP._ENTITY) { // TextNode and entity Events
|
|
356
|
+
// get Text content
|
|
357
|
+
var pContent = p.getContent().substring(p.getContentBegin(), p.getContentEnd());
|
|
358
|
+
|
|
359
|
+
if (!impl.preserveWhiteSpace ) {
|
|
360
|
+
if (trim(pContent, true, true) == "") {
|
|
361
|
+
pContent = ""; //this will cause us not to create the text node below
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
if (pContent.length > 0) { // ignore empty TextNodes
|
|
366
|
+
var textNode = doc.createTextNode(pContent);
|
|
367
|
+
iNodeParent.appendChild(textNode); // attach TextNode to parentNode
|
|
368
|
+
|
|
369
|
+
//the sax parser breaks up text nodes when it finds an entity. For
|
|
370
|
+
//example hello<there will fire a text, an entity and another text
|
|
371
|
+
//this sucks for the dom parser because it looks to us in this logic
|
|
372
|
+
//as three text nodes. I fix this by keeping track of the entity nodes
|
|
373
|
+
//and when we're done parsing, calling normalize on their parent to
|
|
374
|
+
//turn the multiple text nodes into one, which is what DOM users expect
|
|
375
|
+
//the code to do this is at the bottom of this function
|
|
376
|
+
if (iEvt == XMLP._ENTITY) {
|
|
377
|
+
entitiesList[entitiesList.length] = textNode;
|
|
378
|
+
}
|
|
379
|
+
else {
|
|
380
|
+
//I can't properly decide how to handle preserve whitespace
|
|
381
|
+
//until the siblings of the text node are built due to
|
|
382
|
+
//the entitiy handling described above. I don't know that this
|
|
383
|
+
//will be all of the text node or not, so trimming is not appropriate
|
|
384
|
+
//at this time. Keep a list of all the text nodes for now
|
|
385
|
+
//and we'll process the preserve whitespace stuff at a later time.
|
|
386
|
+
textNodesList[textNodesList.length] = textNode;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
else if(iEvt == XMLP._PI) { // ProcessingInstruction Event
|
|
391
|
+
// attach ProcessingInstruction to parentNode
|
|
392
|
+
iNodeParent.appendChild(doc.createProcessingInstruction(p.getName(), p.getContent().substring(p.getContentBegin(), p.getContentEnd())));
|
|
393
|
+
}
|
|
394
|
+
else if(iEvt == XMLP._CDATA) { // CDATA Event
|
|
395
|
+
// get CDATA data
|
|
396
|
+
pContent = p.getContent().substring(p.getContentBegin(), p.getContentEnd());
|
|
397
|
+
|
|
398
|
+
if (!impl.preserveWhiteSpace) {
|
|
399
|
+
pContent = trim(pContent, true, true); // trim whitespace
|
|
400
|
+
pContent.replace(/ +/g, ' '); // collapse multiple spaces to 1 space
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
if (pContent.length > 0) { // ignore empty CDATANodes
|
|
404
|
+
iNodeParent.appendChild(doc.createCDATASection(pContent)); // attach CDATA to parentNode
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
else if(iEvt == XMLP._COMMENT) { // Comment Event
|
|
408
|
+
// get COMMENT data
|
|
409
|
+
var pContent = p.getContent().substring(p.getContentBegin(), p.getContentEnd());
|
|
410
|
+
|
|
411
|
+
if (!impl.preserveWhiteSpace) {
|
|
412
|
+
pContent = trim(pContent, true, true); // trim whitespace
|
|
413
|
+
pContent.replace(/ +/g, ' '); // collapse multiple spaces to 1 space
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
if (pContent.length > 0) { // ignore empty CommentNodes
|
|
417
|
+
iNodeParent.appendChild(doc.createComment(pContent)); // attach Comment to parentNode
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
else if(iEvt == XMLP._DTD) { // ignore DTD events
|
|
421
|
+
}
|
|
422
|
+
else if(iEvt == XMLP._ERROR) {
|
|
423
|
+
$error("Fatal Error: " + p.getContent() +
|
|
424
|
+
"\nLine: " + p.getLineNumber() +
|
|
425
|
+
"\nColumn: " + p.getColumnNumber() + "\n");
|
|
426
|
+
throw(new DOMException(DOMException.SYNTAX_ERR));
|
|
427
|
+
}
|
|
428
|
+
else if(iEvt == XMLP._NONE) { // no more events
|
|
429
|
+
//steven woods notes that unclosed tags are rejected elsewhere and this check
|
|
430
|
+
//breaks a table patching routine
|
|
431
|
+
//if (iNodeParent == doc) { // confirm that we have recursed back up to root
|
|
432
|
+
// break;
|
|
433
|
+
//}
|
|
434
|
+
//else {
|
|
435
|
+
// throw(new DOMException(DOMException.SYNTAX_ERR)); // one or more Tags were not closed properly
|
|
436
|
+
//}
|
|
437
|
+
break;
|
|
438
|
+
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
//normalize any entities in the DOM to a single textNode
|
|
443
|
+
for (var i = 0; i < entitiesList.length; i++) {
|
|
444
|
+
var entity = entitiesList[i];
|
|
445
|
+
//its possible (if for example two entities were in the
|
|
446
|
+
//same domnode, that the normalize on the first entitiy
|
|
447
|
+
//will remove the parent for the second. Only do normalize
|
|
448
|
+
//if I can find a parent node
|
|
449
|
+
var parentNode = entity.parentNode;
|
|
450
|
+
if (parentNode) {
|
|
451
|
+
parentNode.normalize();
|
|
452
|
+
|
|
453
|
+
//now do whitespace (if necessary)
|
|
454
|
+
//it was not done for text nodes that have entities
|
|
455
|
+
if(!impl.preserveWhiteSpace) {
|
|
456
|
+
var children = parentNode.childNodes;
|
|
457
|
+
for ( var j = 0; j < children.length; j++) {
|
|
458
|
+
var child = children.item(j);
|
|
459
|
+
if (child.nodeType == DOMNode.TEXT_NODE) {
|
|
460
|
+
var childData = child.data;
|
|
461
|
+
childData.replace(/\s/g, ' ');
|
|
462
|
+
child.data = childData;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
//do the preserve whitespace processing on the rest of the text nodes
|
|
470
|
+
//It's possible (due to the processing above) that the node will have been
|
|
471
|
+
//removed from the tree. Only do whitespace checking if parentNode is not null.
|
|
472
|
+
//This may duplicate the whitespace processing for some nodes that had entities in them
|
|
473
|
+
//but there's no way around that
|
|
474
|
+
if (!impl.preserveWhiteSpace) {
|
|
475
|
+
for (var i = 0; i < textNodesList.length; i++) {
|
|
476
|
+
var node = textNodesList[i];
|
|
477
|
+
if (node.parentNode != null) {
|
|
478
|
+
var nodeData = node.data;
|
|
479
|
+
nodeData.replace(/\s/g, ' ');
|
|
480
|
+
node.data = nodeData;
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
}
|
|
485
|
+
};
|
|
486
|
+
|
|
487
|
+
|
|
488
|
+
/**
|
|
489
|
+
* @method DOMImplementation._isNamespaceDeclaration - Return true, if attributeName is a namespace declaration
|
|
490
|
+
* @author Jon van Noort (jon@webarcana.com.au)
|
|
491
|
+
* @param attributeName : string - the attribute name
|
|
492
|
+
* @return : boolean
|
|
493
|
+
*/
|
|
494
|
+
function __isNamespaceDeclaration__(attributeName) {
|
|
495
|
+
// test if attributeName is 'xmlns'
|
|
496
|
+
return (attributeName.indexOf('xmlns') > -1);
|
|
497
|
+
};
|
|
498
|
+
|
|
499
|
+
/**
|
|
500
|
+
* @method DOMImplementation._isIdDeclaration - Return true, if attributeName is an id declaration
|
|
501
|
+
* @author Jon van Noort (jon@webarcana.com.au)
|
|
502
|
+
* @param attributeName : string - the attribute name
|
|
503
|
+
* @return : boolean
|
|
504
|
+
*/
|
|
505
|
+
function __isIdDeclaration__(attributeName) {
|
|
506
|
+
// test if attributeName is 'id' (case insensitive)
|
|
507
|
+
return attributeName?(attributeName.toLowerCase() == 'id'):false;
|
|
508
|
+
};
|
|
509
|
+
|
|
510
|
+
/**
|
|
511
|
+
* @method DOMImplementation._isValidName - Return true,
|
|
512
|
+
* if name contains no invalid characters
|
|
513
|
+
* @author Jon van Noort (jon@webarcana.com.au)
|
|
514
|
+
* @param name : string - the candidate name
|
|
515
|
+
* @return : boolean
|
|
516
|
+
*/
|
|
517
|
+
function __isValidName__(name) {
|
|
518
|
+
// test if name contains only valid characters
|
|
519
|
+
return name.match(re_validName);
|
|
520
|
+
};
|
|
521
|
+
var re_validName = /^[a-zA-Z_:][a-zA-Z0-9\.\-_:]*$/;
|
|
522
|
+
|
|
523
|
+
/**
|
|
524
|
+
* @method DOMImplementation._isValidString - Return true, if string does not contain any illegal chars
|
|
525
|
+
* All of the characters 0 through 31 and character 127 are nonprinting control characters.
|
|
526
|
+
* With the exception of characters 09, 10, and 13, (Ox09, Ox0A, and Ox0D)
|
|
527
|
+
* Note: different from _isValidName in that ValidStrings may contain spaces
|
|
528
|
+
* @author Jon van Noort (jon@webarcana.com.au)
|
|
529
|
+
* @param name : string - the candidate string
|
|
530
|
+
* @return : boolean
|
|
531
|
+
*/
|
|
532
|
+
function __isValidString__(name) {
|
|
533
|
+
// test that string does not contains invalid characters
|
|
534
|
+
return (name.search(re_invalidStringChars) < 0);
|
|
535
|
+
};
|
|
536
|
+
var re_invalidStringChars = /\x01|\x02|\x03|\x04|\x05|\x06|\x07|\x08|\x0B|\x0C|\x0E|\x0F|\x10|\x11|\x12|\x13|\x14|\x15|\x16|\x17|\x18|\x19|\x1A|\x1B|\x1C|\x1D|\x1E|\x1F|\x7F/;
|
|
537
|
+
|
|
538
|
+
/**
|
|
539
|
+
* @method DOMImplementation._parseNSName - parse the namespace name.
|
|
540
|
+
* if there is no colon, the
|
|
541
|
+
* @author Jon van Noort (jon@webarcana.com.au)
|
|
542
|
+
* @param qualifiedName : string - The qualified name
|
|
543
|
+
* @return : NSName - [
|
|
544
|
+
.prefix : string - The prefix part of the qname
|
|
545
|
+
.namespaceName : string - The namespaceURI part of the qname
|
|
546
|
+
]
|
|
547
|
+
*/
|
|
548
|
+
function __parseNSName__(qualifiedName) {
|
|
549
|
+
var resultNSName = new Object();
|
|
550
|
+
|
|
551
|
+
resultNSName.prefix = qualifiedName; // unless the qname has a namespaceName, the prefix is the entire String
|
|
552
|
+
resultNSName.namespaceName = "";
|
|
553
|
+
|
|
554
|
+
// split on ':'
|
|
555
|
+
var delimPos = qualifiedName.indexOf(':');
|
|
556
|
+
if (delimPos > -1) {
|
|
557
|
+
// get prefix
|
|
558
|
+
resultNSName.prefix = qualifiedName.substring(0, delimPos);
|
|
559
|
+
// get namespaceName
|
|
560
|
+
resultNSName.namespaceName = qualifiedName.substring(delimPos +1, qualifiedName.length);
|
|
561
|
+
}
|
|
562
|
+
return resultNSName;
|
|
563
|
+
};
|
|
564
|
+
|
|
565
|
+
/**
|
|
566
|
+
* @method DOMImplementation._parseQName - parse the qualified name
|
|
567
|
+
* @author Jon van Noort (jon@webarcana.com.au)
|
|
568
|
+
* @param qualifiedName : string - The qualified name
|
|
569
|
+
* @return : QName
|
|
570
|
+
*/
|
|
571
|
+
function __parseQName__(qualifiedName) {
|
|
572
|
+
var resultQName = new Object();
|
|
573
|
+
|
|
574
|
+
resultQName.localName = qualifiedName; // unless the qname has a prefix, the local name is the entire String
|
|
575
|
+
resultQName.prefix = "";
|
|
576
|
+
|
|
577
|
+
// split on ':'
|
|
578
|
+
var delimPos = qualifiedName.indexOf(':');
|
|
579
|
+
|
|
580
|
+
if (delimPos > -1) {
|
|
581
|
+
// get prefix
|
|
582
|
+
resultQName.prefix = qualifiedName.substring(0, delimPos);
|
|
583
|
+
|
|
584
|
+
// get localName
|
|
585
|
+
resultQName.localName = qualifiedName.substring(delimPos +1, qualifiedName.length);
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
return resultQName;
|
|
589
|
+
};
|
|
590
|
+
|
|
591
|
+
if(false){
|
|
592
|
+
$debug("Initializing document.implementation");
|
|
593
|
+
var $implementation = new DOMImplementation();
|
|
594
|
+
// $implementation.namespaceAware = false;
|
|
595
|
+
$implementation.errorChecking = false;
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
// Local Variables:
|
|
599
|
+
// espresso-indent-level:4
|
|
600
|
+
// c-basic-offset:4
|
|
601
|
+
// tab-width:4
|
|
602
|
+
// End:
|