plist 3.0.6 → 3.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.
- package/History.md +10 -0
- package/dist/plist-build.js +3 -0
- package/dist/plist-parse.js +8015 -1988
- package/dist/plist.js +8049 -2019
- package/lib/build.js +3 -0
- package/lib/parse.js +56 -75
- package/package.json +4 -4
- package/.travis.yml +0 -22
- package/lib/xmldom/dom-parser.js +0 -253
- package/lib/xmldom/dom.js +0 -1283
- package/lib/xmldom/entities.js +0 -243
- package/lib/xmldom/sax.js +0 -642
package/lib/build.js
CHANGED
|
@@ -117,6 +117,9 @@ function walk_obj(next, next_child) {
|
|
|
117
117
|
tag_type = (next % 1 === 0) ? 'integer' : 'real';
|
|
118
118
|
next_child.ele(tag_type).txt(next.toString());
|
|
119
119
|
|
|
120
|
+
} else if ('BigInt' == name) {
|
|
121
|
+
next_child.ele('integer').txt(next);
|
|
122
|
+
|
|
120
123
|
} else if ('Date' == name) {
|
|
121
124
|
next_child.ele('date').txt(ISODateString(new Date(next)));
|
|
122
125
|
|
package/lib/parse.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Module dependencies.
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
const { DOMParser } = require("@xmldom/xmldom");
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Module exports.
|
|
@@ -14,7 +14,6 @@ var TEXT_NODE = 3;
|
|
|
14
14
|
var CDATA_NODE = 4;
|
|
15
15
|
var COMMENT_NODE = 8;
|
|
16
16
|
|
|
17
|
-
|
|
18
17
|
/**
|
|
19
18
|
* We ignore raw text (usually whitespace), <!-- xml comments -->,
|
|
20
19
|
* and raw CDATA nodes.
|
|
@@ -24,10 +23,12 @@ var COMMENT_NODE = 8;
|
|
|
24
23
|
* @api private
|
|
25
24
|
*/
|
|
26
25
|
|
|
27
|
-
function shouldIgnoreNode
|
|
28
|
-
return
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
function shouldIgnoreNode(node) {
|
|
27
|
+
return (
|
|
28
|
+
node.nodeType === TEXT_NODE ||
|
|
29
|
+
node.nodeType === COMMENT_NODE ||
|
|
30
|
+
node.nodeType === CDATA_NODE
|
|
31
|
+
);
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
/**
|
|
@@ -40,8 +41,8 @@ function shouldIgnoreNode (node) {
|
|
|
40
41
|
* @returns {Boolean}
|
|
41
42
|
* @api private
|
|
42
43
|
*/
|
|
43
|
-
function isEmptyNode(node){
|
|
44
|
-
if(!node.childNodes || node.childNodes.length === 0) {
|
|
44
|
+
function isEmptyNode(node) {
|
|
45
|
+
if (!node.childNodes || node.childNodes.length === 0) {
|
|
45
46
|
return true;
|
|
46
47
|
} else {
|
|
47
48
|
return false;
|
|
@@ -62,11 +63,11 @@ function invariant(test, message) {
|
|
|
62
63
|
* @api public
|
|
63
64
|
*/
|
|
64
65
|
|
|
65
|
-
function parse
|
|
66
|
-
var doc = new DOMParser().parseFromString(xml);
|
|
66
|
+
function parse(xml) {
|
|
67
|
+
var doc = new DOMParser().parseFromString(xml, "text/xml");
|
|
67
68
|
invariant(
|
|
68
|
-
doc.documentElement.nodeName ===
|
|
69
|
-
|
|
69
|
+
doc.documentElement.nodeName === "plist",
|
|
70
|
+
"malformed document. First element should be <plist>",
|
|
70
71
|
);
|
|
71
72
|
var plist = parsePlistXML(doc.documentElement);
|
|
72
73
|
|
|
@@ -85,143 +86,123 @@ function parse (xml) {
|
|
|
85
86
|
* @api private
|
|
86
87
|
*/
|
|
87
88
|
|
|
88
|
-
function parsePlistXML
|
|
89
|
+
function parsePlistXML(node) {
|
|
89
90
|
var i, new_obj, key, val, new_arr, res, counter, type;
|
|
90
91
|
|
|
91
|
-
if (!node)
|
|
92
|
-
return null;
|
|
92
|
+
if (!node) return null;
|
|
93
93
|
|
|
94
|
-
if (node.nodeName ===
|
|
94
|
+
if (node.nodeName === "plist") {
|
|
95
95
|
new_arr = [];
|
|
96
96
|
if (isEmptyNode(node)) {
|
|
97
97
|
return new_arr;
|
|
98
98
|
}
|
|
99
|
-
for (i=0; i < node.childNodes.length; i++) {
|
|
99
|
+
for (i = 0; i < node.childNodes.length; i++) {
|
|
100
100
|
if (!shouldIgnoreNode(node.childNodes[i])) {
|
|
101
|
-
new_arr.push(
|
|
101
|
+
new_arr.push(parsePlistXML(node.childNodes[i]));
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
return new_arr;
|
|
105
|
-
} else if (node.nodeName ===
|
|
105
|
+
} else if (node.nodeName === "dict") {
|
|
106
106
|
new_obj = {};
|
|
107
107
|
key = null;
|
|
108
108
|
counter = 0;
|
|
109
109
|
if (isEmptyNode(node)) {
|
|
110
110
|
return new_obj;
|
|
111
111
|
}
|
|
112
|
-
for (i=0; i < node.childNodes.length; i++) {
|
|
112
|
+
for (i = 0; i < node.childNodes.length; i++) {
|
|
113
113
|
if (shouldIgnoreNode(node.childNodes[i])) continue;
|
|
114
114
|
if (counter % 2 === 0) {
|
|
115
115
|
invariant(
|
|
116
|
-
node.childNodes[i].nodeName ===
|
|
117
|
-
|
|
116
|
+
node.childNodes[i].nodeName === "key",
|
|
117
|
+
"Missing key while parsing <dict/>.",
|
|
118
118
|
);
|
|
119
119
|
key = parsePlistXML(node.childNodes[i]);
|
|
120
120
|
} else {
|
|
121
121
|
invariant(
|
|
122
|
-
node.childNodes[i].nodeName !==
|
|
123
|
-
'Unexpected key "'
|
|
124
|
-
|
|
125
|
-
|
|
122
|
+
node.childNodes[i].nodeName !== "key",
|
|
123
|
+
'Unexpected key "' +
|
|
124
|
+
parsePlistXML(node.childNodes[i]) +
|
|
125
|
+
'" while parsing <dict/>.',
|
|
126
126
|
);
|
|
127
127
|
new_obj[key] = parsePlistXML(node.childNodes[i]);
|
|
128
128
|
}
|
|
129
129
|
counter += 1;
|
|
130
130
|
}
|
|
131
131
|
if (counter % 2 === 1) {
|
|
132
|
-
new_obj[key] =
|
|
132
|
+
new_obj[key] = "";
|
|
133
133
|
}
|
|
134
|
-
|
|
135
|
-
return new_obj;
|
|
136
134
|
|
|
137
|
-
|
|
135
|
+
return new_obj;
|
|
136
|
+
} else if (node.nodeName === "array") {
|
|
138
137
|
new_arr = [];
|
|
139
138
|
if (isEmptyNode(node)) {
|
|
140
139
|
return new_arr;
|
|
141
140
|
}
|
|
142
|
-
for (i=0; i < node.childNodes.length; i++) {
|
|
141
|
+
for (i = 0; i < node.childNodes.length; i++) {
|
|
143
142
|
if (!shouldIgnoreNode(node.childNodes[i])) {
|
|
144
143
|
res = parsePlistXML(node.childNodes[i]);
|
|
145
144
|
if (null != res) new_arr.push(res);
|
|
146
145
|
}
|
|
147
146
|
}
|
|
148
147
|
return new_arr;
|
|
149
|
-
|
|
150
|
-
} else if (node.nodeName === '#text') {
|
|
148
|
+
} else if (node.nodeName === "#text") {
|
|
151
149
|
// TODO: what should we do with text types? (CDATA sections)
|
|
152
|
-
|
|
153
|
-
} else if (node.nodeName === 'key') {
|
|
150
|
+
} else if (node.nodeName === "key") {
|
|
154
151
|
if (isEmptyNode(node)) {
|
|
155
|
-
return
|
|
152
|
+
return "";
|
|
156
153
|
}
|
|
157
154
|
|
|
158
155
|
invariant(
|
|
159
|
-
node.childNodes[0].nodeValue !==
|
|
160
|
-
|
|
156
|
+
node.childNodes[0].nodeValue !== "__proto__",
|
|
157
|
+
"__proto__ keys can lead to prototype pollution. More details on CVE-2022-22912",
|
|
161
158
|
);
|
|
162
159
|
|
|
163
160
|
return node.childNodes[0].nodeValue;
|
|
164
|
-
} else if (node.nodeName ===
|
|
165
|
-
res =
|
|
161
|
+
} else if (node.nodeName === "string") {
|
|
162
|
+
res = "";
|
|
166
163
|
if (isEmptyNode(node)) {
|
|
167
164
|
return res;
|
|
168
165
|
}
|
|
169
|
-
for (i=0; i < node.childNodes.length; i++) {
|
|
166
|
+
for (i = 0; i < node.childNodes.length; i++) {
|
|
170
167
|
var type = node.childNodes[i].nodeType;
|
|
171
168
|
if (type === TEXT_NODE || type === CDATA_NODE) {
|
|
172
169
|
res += node.childNodes[i].nodeValue;
|
|
173
170
|
}
|
|
174
171
|
}
|
|
175
172
|
return res;
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
invariant(
|
|
179
|
-
!isEmptyNode(node),
|
|
180
|
-
'Cannot parse "" as integer.'
|
|
181
|
-
);
|
|
173
|
+
} else if (node.nodeName === "integer") {
|
|
174
|
+
invariant(!isEmptyNode(node), 'Cannot parse "" as integer.');
|
|
182
175
|
return parseInt(node.childNodes[0].nodeValue, 10);
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
'Cannot parse "" as real.'
|
|
188
|
-
);
|
|
189
|
-
res = '';
|
|
190
|
-
for (i=0; i < node.childNodes.length; i++) {
|
|
176
|
+
} else if (node.nodeName === "real") {
|
|
177
|
+
invariant(!isEmptyNode(node), 'Cannot parse "" as real.');
|
|
178
|
+
res = "";
|
|
179
|
+
for (i = 0; i < node.childNodes.length; i++) {
|
|
191
180
|
if (node.childNodes[i].nodeType === TEXT_NODE) {
|
|
192
181
|
res += node.childNodes[i].nodeValue;
|
|
193
182
|
}
|
|
194
183
|
}
|
|
195
184
|
return parseFloat(res);
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
res = '';
|
|
185
|
+
} else if (node.nodeName === "data") {
|
|
186
|
+
res = "";
|
|
199
187
|
if (isEmptyNode(node)) {
|
|
200
|
-
return Buffer.from(res,
|
|
188
|
+
return Buffer.from(res, "base64");
|
|
201
189
|
}
|
|
202
|
-
for (i=0; i < node.childNodes.length; i++) {
|
|
190
|
+
for (i = 0; i < node.childNodes.length; i++) {
|
|
203
191
|
if (node.childNodes[i].nodeType === TEXT_NODE) {
|
|
204
|
-
res += node.childNodes[i].nodeValue.replace(/\s+/g,
|
|
192
|
+
res += node.childNodes[i].nodeValue.replace(/\s+/g, "");
|
|
205
193
|
}
|
|
206
194
|
}
|
|
207
|
-
return Buffer.from(res,
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
invariant(
|
|
211
|
-
!isEmptyNode(node),
|
|
212
|
-
'Cannot parse "" as Date.'
|
|
213
|
-
)
|
|
195
|
+
return Buffer.from(res, "base64");
|
|
196
|
+
} else if (node.nodeName === "date") {
|
|
197
|
+
invariant(!isEmptyNode(node), 'Cannot parse "" as Date.');
|
|
214
198
|
return new Date(node.childNodes[0].nodeValue);
|
|
215
|
-
|
|
216
|
-
} else if (node.nodeName === 'null') {
|
|
199
|
+
} else if (node.nodeName === "null") {
|
|
217
200
|
return null;
|
|
218
|
-
|
|
219
|
-
} else if (node.nodeName === 'true') {
|
|
201
|
+
} else if (node.nodeName === "true") {
|
|
220
202
|
return true;
|
|
221
|
-
|
|
222
|
-
} else if (node.nodeName === 'false') {
|
|
203
|
+
} else if (node.nodeName === "false") {
|
|
223
204
|
return false;
|
|
224
205
|
} else {
|
|
225
|
-
throw new Error(
|
|
206
|
+
throw new Error("Invalid PLIST tag " + node.nodeName);
|
|
226
207
|
}
|
|
227
208
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "plist",
|
|
3
3
|
"description": "Apple's property list parser/builder for Node.js and browsers",
|
|
4
|
-
"version": "3.
|
|
4
|
+
"version": "3.1.1",
|
|
5
5
|
"author": "Nathan Rajlich <nathan@tootallnate.net>",
|
|
6
6
|
"contributors": [
|
|
7
7
|
"Hans Huebner <hans.huebner@gmail.com>",
|
|
@@ -25,19 +25,19 @@
|
|
|
25
25
|
],
|
|
26
26
|
"main": "index.js",
|
|
27
27
|
"dependencies": {
|
|
28
|
+
"@xmldom/xmldom": "^0.9.10",
|
|
28
29
|
"base64-js": "^1.5.1",
|
|
29
30
|
"xmlbuilder": "^15.1.1"
|
|
30
31
|
},
|
|
31
32
|
"devDependencies": {
|
|
32
33
|
"browserify": "^17.0.0",
|
|
33
|
-
"mocha": "^
|
|
34
|
-
"multiline": "^2.0.0",
|
|
34
|
+
"mocha": "^10.2.0",
|
|
35
35
|
"zuul": "3.12.0"
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
38
|
"test": "make test"
|
|
39
39
|
},
|
|
40
40
|
"engines": {
|
|
41
|
-
"node": ">=
|
|
41
|
+
"node": ">=10.4.0"
|
|
42
42
|
}
|
|
43
43
|
}
|
package/.travis.yml
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
dist: xenial
|
|
2
|
-
os: linux
|
|
3
|
-
language: node_js
|
|
4
|
-
node_js:
|
|
5
|
-
- '6'
|
|
6
|
-
- '7'
|
|
7
|
-
- '8'
|
|
8
|
-
- '9'
|
|
9
|
-
|
|
10
|
-
env:
|
|
11
|
-
global:
|
|
12
|
-
- secure: R4tCAipsC0KdBPin8+rWedqptn0RXksLM20yZ0w8En0hhaglWCiIxA5uKt/6njXp9Q8FEKkVOyWF+yjq74jB6+KUu0dSK30pbmaAHhlXsL5kTWmY9vd7rxwcn1Hdf1sW15NqRX4hvWuIC32cA7vDr+58VPyum+A+yvPJICvgIlw=
|
|
13
|
-
- secure: sfEwCcmUrfFPIRPV8UwdJymRZ8YY20fuJiAlWfOUQSOccNGWB4RbUsD+iyc9XW5qB1kdOqxVkvZ0sKrYo3Uc4k8mhar7+yhP04hfNj4CWAigG3rtTugbar9kSQjwi/yEaTrb4kdP8HRYs5yjrEX/CGwjm3iHGOSyUw5du0PQfbk=
|
|
14
|
-
|
|
15
|
-
jobs:
|
|
16
|
-
include:
|
|
17
|
-
- node_js: '8'
|
|
18
|
-
env: BROWSER_NAME=chrome BROWSER_VERSION=latest
|
|
19
|
-
- node_js: '8'
|
|
20
|
-
env: BROWSER_NAME=firefox BROWSER_VERSION=latest
|
|
21
|
-
- node_js: '8'
|
|
22
|
-
env: BROWSER_NAME=ie BROWSER_VERSION=11
|
package/lib/xmldom/dom-parser.js
DELETED
|
@@ -1,253 +0,0 @@
|
|
|
1
|
-
function DOMParser(options){
|
|
2
|
-
this.options = options ||{locator:{}};
|
|
3
|
-
}
|
|
4
|
-
|
|
5
|
-
DOMParser.prototype.parseFromString = function(source,mimeType){
|
|
6
|
-
var options = this.options;
|
|
7
|
-
var sax = new XMLReader();
|
|
8
|
-
var domBuilder = options.domBuilder || new DOMHandler();//contentHandler and LexicalHandler
|
|
9
|
-
var errorHandler = options.errorHandler;
|
|
10
|
-
var locator = options.locator;
|
|
11
|
-
var defaultNSMap = options.xmlns||{};
|
|
12
|
-
var isHTML = /\/x?html?$/.test(mimeType);//mimeType.toLowerCase().indexOf('html') > -1;
|
|
13
|
-
var entityMap = isHTML?htmlEntity.entityMap:{'lt':'<','gt':'>','amp':'&','quot':'"','apos':"'"};
|
|
14
|
-
if(locator){
|
|
15
|
-
domBuilder.setDocumentLocator(locator)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
sax.errorHandler = buildErrorHandler(errorHandler,domBuilder,locator);
|
|
19
|
-
sax.domBuilder = options.domBuilder || domBuilder;
|
|
20
|
-
if(isHTML){
|
|
21
|
-
defaultNSMap['']= 'http://www.w3.org/1999/xhtml';
|
|
22
|
-
}
|
|
23
|
-
defaultNSMap.xml = defaultNSMap.xml || 'http://www.w3.org/XML/1998/namespace';
|
|
24
|
-
if(source && typeof source === 'string'){
|
|
25
|
-
sax.parse(source,defaultNSMap,entityMap);
|
|
26
|
-
}else{
|
|
27
|
-
sax.errorHandler.error("invalid doc source");
|
|
28
|
-
}
|
|
29
|
-
return domBuilder.doc;
|
|
30
|
-
}
|
|
31
|
-
function buildErrorHandler(errorImpl,domBuilder,locator){
|
|
32
|
-
if(!errorImpl){
|
|
33
|
-
if(domBuilder instanceof DOMHandler){
|
|
34
|
-
return domBuilder;
|
|
35
|
-
}
|
|
36
|
-
errorImpl = domBuilder ;
|
|
37
|
-
}
|
|
38
|
-
var errorHandler = {}
|
|
39
|
-
var isCallback = errorImpl instanceof Function;
|
|
40
|
-
locator = locator||{}
|
|
41
|
-
function build(key){
|
|
42
|
-
var fn = errorImpl[key];
|
|
43
|
-
if(!fn && isCallback){
|
|
44
|
-
fn = errorImpl.length == 2?function(msg){errorImpl(key,msg)}:errorImpl;
|
|
45
|
-
}
|
|
46
|
-
errorHandler[key] = fn && function(msg){
|
|
47
|
-
fn('[xmldom '+key+']\t'+msg+_locator(locator));
|
|
48
|
-
}||function(){};
|
|
49
|
-
}
|
|
50
|
-
build('warning');
|
|
51
|
-
build('error');
|
|
52
|
-
build('fatalError');
|
|
53
|
-
return errorHandler;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
//console.log('#\n\n\n\n\n\n\n####')
|
|
57
|
-
/**
|
|
58
|
-
* +ContentHandler+ErrorHandler
|
|
59
|
-
* +LexicalHandler+EntityResolver2
|
|
60
|
-
* -DeclHandler-DTDHandler
|
|
61
|
-
*
|
|
62
|
-
* DefaultHandler:EntityResolver, DTDHandler, ContentHandler, ErrorHandler
|
|
63
|
-
* DefaultHandler2:DefaultHandler,LexicalHandler, DeclHandler, EntityResolver2
|
|
64
|
-
* @link http://www.saxproject.org/apidoc/org/xml/sax/helpers/DefaultHandler.html
|
|
65
|
-
*/
|
|
66
|
-
function DOMHandler() {
|
|
67
|
-
this.cdata = false;
|
|
68
|
-
}
|
|
69
|
-
function position(locator,node){
|
|
70
|
-
node.lineNumber = locator.lineNumber;
|
|
71
|
-
node.columnNumber = locator.columnNumber;
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* @see org.xml.sax.ContentHandler#startDocument
|
|
75
|
-
* @link http://www.saxproject.org/apidoc/org/xml/sax/ContentHandler.html
|
|
76
|
-
*/
|
|
77
|
-
DOMHandler.prototype = {
|
|
78
|
-
startDocument : function() {
|
|
79
|
-
this.doc = new DOMImplementation().createDocument(null, null, null);
|
|
80
|
-
if (this.locator) {
|
|
81
|
-
this.doc.documentURI = this.locator.systemId;
|
|
82
|
-
}
|
|
83
|
-
},
|
|
84
|
-
startElement:function(namespaceURI, localName, qName, attrs) {
|
|
85
|
-
var doc = this.doc;
|
|
86
|
-
var el = doc.createElementNS(namespaceURI, qName||localName);
|
|
87
|
-
var len = attrs.length;
|
|
88
|
-
appendElement(this, el);
|
|
89
|
-
this.currentElement = el;
|
|
90
|
-
|
|
91
|
-
this.locator && position(this.locator,el)
|
|
92
|
-
for (var i = 0 ; i < len; i++) {
|
|
93
|
-
var namespaceURI = attrs.getURI(i);
|
|
94
|
-
var value = attrs.getValue(i);
|
|
95
|
-
var qName = attrs.getQName(i);
|
|
96
|
-
var attr = doc.createAttributeNS(namespaceURI, qName);
|
|
97
|
-
this.locator &&position(attrs.getLocator(i),attr);
|
|
98
|
-
attr.value = attr.nodeValue = value;
|
|
99
|
-
el.setAttributeNode(attr)
|
|
100
|
-
}
|
|
101
|
-
},
|
|
102
|
-
endElement:function(namespaceURI, localName, qName) {
|
|
103
|
-
var current = this.currentElement
|
|
104
|
-
var tagName = current.tagName;
|
|
105
|
-
this.currentElement = current.parentNode;
|
|
106
|
-
},
|
|
107
|
-
startPrefixMapping:function(prefix, uri) {
|
|
108
|
-
},
|
|
109
|
-
endPrefixMapping:function(prefix) {
|
|
110
|
-
},
|
|
111
|
-
processingInstruction:function(target, data) {
|
|
112
|
-
var ins = this.doc.createProcessingInstruction(target, data);
|
|
113
|
-
this.locator && position(this.locator,ins)
|
|
114
|
-
appendElement(this, ins);
|
|
115
|
-
},
|
|
116
|
-
ignorableWhitespace:function(ch, start, length) {
|
|
117
|
-
},
|
|
118
|
-
characters:function(chars, start, length) {
|
|
119
|
-
chars = _toString.apply(this,arguments)
|
|
120
|
-
//console.log(chars)
|
|
121
|
-
if(chars){
|
|
122
|
-
if (this.cdata) {
|
|
123
|
-
var charNode = this.doc.createCDATASection(chars);
|
|
124
|
-
} else {
|
|
125
|
-
var charNode = this.doc.createTextNode(chars);
|
|
126
|
-
}
|
|
127
|
-
if(this.currentElement){
|
|
128
|
-
this.currentElement.appendChild(charNode);
|
|
129
|
-
}else if(/^\s*$/.test(chars)){
|
|
130
|
-
this.doc.appendChild(charNode);
|
|
131
|
-
//process xml
|
|
132
|
-
}
|
|
133
|
-
this.locator && position(this.locator,charNode)
|
|
134
|
-
}
|
|
135
|
-
},
|
|
136
|
-
skippedEntity:function(name) {
|
|
137
|
-
},
|
|
138
|
-
endDocument:function() {
|
|
139
|
-
this.doc.normalize();
|
|
140
|
-
},
|
|
141
|
-
setDocumentLocator:function (locator) {
|
|
142
|
-
if(this.locator = locator){// && !('lineNumber' in locator)){
|
|
143
|
-
locator.lineNumber = 0;
|
|
144
|
-
}
|
|
145
|
-
},
|
|
146
|
-
//LexicalHandler
|
|
147
|
-
comment:function(chars, start, length) {
|
|
148
|
-
chars = _toString.apply(this,arguments)
|
|
149
|
-
var comm = this.doc.createComment(chars);
|
|
150
|
-
this.locator && position(this.locator,comm)
|
|
151
|
-
appendElement(this, comm);
|
|
152
|
-
},
|
|
153
|
-
|
|
154
|
-
startCDATA:function() {
|
|
155
|
-
//used in characters() methods
|
|
156
|
-
this.cdata = true;
|
|
157
|
-
},
|
|
158
|
-
endCDATA:function() {
|
|
159
|
-
this.cdata = false;
|
|
160
|
-
},
|
|
161
|
-
|
|
162
|
-
startDTD:function(name, publicId, systemId) {
|
|
163
|
-
var impl = this.doc.implementation;
|
|
164
|
-
if (impl && impl.createDocumentType) {
|
|
165
|
-
var dt = impl.createDocumentType(name, publicId, systemId);
|
|
166
|
-
this.locator && position(this.locator,dt)
|
|
167
|
-
appendElement(this, dt);
|
|
168
|
-
}
|
|
169
|
-
},
|
|
170
|
-
/**
|
|
171
|
-
* @see org.xml.sax.ErrorHandler
|
|
172
|
-
* @link http://www.saxproject.org/apidoc/org/xml/sax/ErrorHandler.html
|
|
173
|
-
*/
|
|
174
|
-
warning:function(error) {
|
|
175
|
-
console.warn('[xmldom warning]\t'+error,_locator(this.locator));
|
|
176
|
-
},
|
|
177
|
-
error:function(error) {
|
|
178
|
-
console.error('[xmldom error]\t'+error,_locator(this.locator));
|
|
179
|
-
},
|
|
180
|
-
fatalError:function(error) {
|
|
181
|
-
throw new ParseError(error, this.locator);
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
function _locator(l){
|
|
185
|
-
if(l){
|
|
186
|
-
return '\n@'+(l.systemId ||'')+'#[line:'+l.lineNumber+',col:'+l.columnNumber+']'
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
function _toString(chars,start,length){
|
|
190
|
-
if(typeof chars == 'string'){
|
|
191
|
-
return chars.substr(start,length)
|
|
192
|
-
}else{//java sax connect width xmldom on rhino(what about: "? && !(chars instanceof String)")
|
|
193
|
-
if(chars.length >= start+length || start){
|
|
194
|
-
return new java.lang.String(chars,start,length)+'';
|
|
195
|
-
}
|
|
196
|
-
return chars;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
/*
|
|
201
|
-
* @link http://www.saxproject.org/apidoc/org/xml/sax/ext/LexicalHandler.html
|
|
202
|
-
* used method of org.xml.sax.ext.LexicalHandler:
|
|
203
|
-
* #comment(chars, start, length)
|
|
204
|
-
* #startCDATA()
|
|
205
|
-
* #endCDATA()
|
|
206
|
-
* #startDTD(name, publicId, systemId)
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
* IGNORED method of org.xml.sax.ext.LexicalHandler:
|
|
210
|
-
* #endDTD()
|
|
211
|
-
* #startEntity(name)
|
|
212
|
-
* #endEntity(name)
|
|
213
|
-
*
|
|
214
|
-
*
|
|
215
|
-
* @link http://www.saxproject.org/apidoc/org/xml/sax/ext/DeclHandler.html
|
|
216
|
-
* IGNORED method of org.xml.sax.ext.DeclHandler
|
|
217
|
-
* #attributeDecl(eName, aName, type, mode, value)
|
|
218
|
-
* #elementDecl(name, model)
|
|
219
|
-
* #externalEntityDecl(name, publicId, systemId)
|
|
220
|
-
* #internalEntityDecl(name, value)
|
|
221
|
-
* @link http://www.saxproject.org/apidoc/org/xml/sax/ext/EntityResolver2.html
|
|
222
|
-
* IGNORED method of org.xml.sax.EntityResolver2
|
|
223
|
-
* #resolveEntity(String name,String publicId,String baseURI,String systemId)
|
|
224
|
-
* #resolveEntity(publicId, systemId)
|
|
225
|
-
* #getExternalSubset(name, baseURI)
|
|
226
|
-
* @link http://www.saxproject.org/apidoc/org/xml/sax/DTDHandler.html
|
|
227
|
-
* IGNORED method of org.xml.sax.DTDHandler
|
|
228
|
-
* #notationDecl(name, publicId, systemId) {};
|
|
229
|
-
* #unparsedEntityDecl(name, publicId, systemId, notationName) {};
|
|
230
|
-
*/
|
|
231
|
-
"endDTD,startEntity,endEntity,attributeDecl,elementDecl,externalEntityDecl,internalEntityDecl,resolveEntity,getExternalSubset,notationDecl,unparsedEntityDecl".replace(/\w+/g,function(key){
|
|
232
|
-
DOMHandler.prototype[key] = function(){return null}
|
|
233
|
-
})
|
|
234
|
-
|
|
235
|
-
/* Private static helpers treated below as private instance methods, so don't need to add these to the public API; we might use a Relator to also get rid of non-standard public properties */
|
|
236
|
-
function appendElement (hander,node) {
|
|
237
|
-
if (!hander.currentElement) {
|
|
238
|
-
hander.doc.appendChild(node);
|
|
239
|
-
} else {
|
|
240
|
-
hander.currentElement.appendChild(node);
|
|
241
|
-
}
|
|
242
|
-
}//appendChild and setAttributeNS are preformance key
|
|
243
|
-
|
|
244
|
-
//if(typeof require == 'function'){
|
|
245
|
-
var htmlEntity = require('./entities');
|
|
246
|
-
var sax = require('./sax');
|
|
247
|
-
var XMLReader = sax.XMLReader;
|
|
248
|
-
var ParseError = sax.ParseError;
|
|
249
|
-
var DOMImplementation = exports.DOMImplementation = require('./dom').DOMImplementation;
|
|
250
|
-
exports.XMLSerializer = require('./dom').XMLSerializer ;
|
|
251
|
-
exports.DOMParser = DOMParser;
|
|
252
|
-
exports.__DOMHandler = DOMHandler;
|
|
253
|
-
//}
|