OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | |
2 // for details. All rights reserved. Use of this source code is governed by a | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 class XMLDocumentWrappingImplementation extends DocumentWrappingImplementation | |
6 implements XMLDocument { | |
7 // This really just wants to extend both DocumentWrappingImplementation and | |
8 // XMLElementWrappingImplementation, but since that's not possible we delegate | |
9 // to the latter. | |
10 XMLElement documentEl; | |
11 | |
12 XMLDocumentWrappingImplementation._wrap(documentPtr, ptr) : | |
13 super._wrap(documentPtr, ptr) { | |
14 // We want to wrap the pointer in an XMLElement to use its implementation of | |
15 // various Element methods, but DOMWrapperBase complains if | |
16 // dartObjectLocalStorage is already set. | |
17 ptr.dartObjectLocalStorage = null; | |
18 this.documentEl = new XMLElementWrappingImplementation._wrap(ptr); | |
19 ptr.dartObjectLocalStorage = this; | |
20 } | |
21 | |
22 factory XMLDocumentWrappingImplementation.xml(String xml) { | |
Jacob
2012/02/22 21:55:00
Add a TODO warning that this doesn't work on darti
nweiz
2012/02/23 00:35:06
Done (in XMLDocument.dart so it'll show up in the
| |
23 final parser = new dom.DOMParser(); | |
24 final xmlDoc = LevelDom.wrapDocument( | |
25 parser.parseFromString(xml, 'text/xml')); | |
26 // When XML parsing fails, the browser creates a document containing a | |
27 // PARSERERROR element. We want to throw an exception when parsing fails, | |
28 // but we don't want false positives if the user intends to create a | |
29 // PARSERERROR element for some reason, so we check for that in the input. | |
30 if (!xml.toLowerCase().contains('<parsererror') && | |
Jacob
2012/02/22 21:55:00
is there a less hacky way to do this?
nweiz
2012/02/23 00:35:06
I can't think of one. There doesn't seem to be any
Jacob
2012/02/27 22:01:24
one thought, is the parseerror element always the
nweiz
2012/02/27 22:11:58
The structure varies from browser to browser, so I
| |
31 xmlDoc.query('parsererror') != null) { | |
32 throw new IllegalArgumentException('Error parsing XML: "$xml"'); | |
33 } | |
34 return xmlDoc; | |
35 } | |
36 | |
37 Node get parent() => null; | |
38 | |
39 Node _insertAdjacentNode(String where, Node node) { | |
40 switch (where.toLowerCase()) { | |
41 case "beforebegin": return null; | |
Jacob
2012/02/22 21:55:00
style nit: put returns on the following lines for
nweiz
2012/02/23 00:35:06
Done.
| |
42 case "afterend": return null; | |
43 case "afterbegin": | |
44 this.insertBefore(node, nodes.first); | |
45 return node; | |
46 case "beforeend": | |
47 this.nodes.add(node); | |
48 return node; | |
49 default: | |
50 throw new IllegalArgumentException("Invalid position ${where}"); | |
51 } | |
52 } | |
53 | |
54 XMLElement insertAdjacentElement([String where = null, | |
55 XMLElement element = null]) => this._insertAdjacentNode(where, element); | |
56 | |
57 void insertAdjacentText([String where = null, String text = null]) { | |
58 this._insertAdjacentNode(where, new Text(text)); | |
59 } | |
60 | |
61 void insertAdjacentHTML( | |
62 [String position_OR_where = null, String text = null]) { | |
63 this._insertAdjacentNode( | |
64 position_OR_where, new DocumentFragment.xml(text)); | |
65 } | |
66 | |
67 XMLElement get activeElement() => null; | |
68 | |
69 void set body(Element value) { | |
70 throw new UnsupportedOperationException("XML documents don't have a body."); | |
71 } | |
72 | |
73 String get cookie() { | |
74 throw new UnsupportedOperationException( | |
75 "XML documents don't support cookies."); | |
76 } | |
77 | |
78 void set cookie(String value) { | |
79 throw new UnsupportedOperationException( | |
80 "XML documents don't support cookies."); | |
81 } | |
82 | |
83 String get manifest() => ""; | |
84 | |
85 void set manifest(String value) { | |
86 throw new UnsupportedOperationException( | |
87 "Manifest can't be set for XML documents."); | |
88 } | |
89 | |
90 Set<String> get classes() => documentEl.classes; | |
91 | |
92 ElementList get elements() => documentEl.elements; | |
93 | |
94 // TODO: The type of value should be Collection<Element>. See http://b/5392897 | |
95 void set elements(value) { documentEl.elements = value; } | |
96 | |
97 String get outerHTML() => documentEl.outerHTML; | |
98 | |
99 String get innerHTML() => documentEl.innerHTML; | |
100 | |
101 void set innerHTML(String xml) { documentEl.innerHTML = xml; } | |
102 | |
103 String get contentEditable() => documentEl.contentEditable; | |
104 | |
105 void set contentEditable(String value) { documentEl.contentEditable = value; } | |
106 | |
107 bool get isContentEditable() => documentEl.isContentEditable; | |
108 | |
109 bool get draggable() => documentEl.draggable; | |
110 | |
111 void set draggable(bool value) { documentEl.draggable = value; } | |
112 | |
113 bool get spellcheck() => documentEl.spellcheck; | |
114 | |
115 void set spellcheck(bool value) { documentEl.spellcheck = value; } | |
116 | |
117 bool get hidden() => documentEl.hidden; | |
118 | |
119 void set hidden(bool value) { documentEl.hidden = value; } | |
120 | |
121 int get tabIndex() => documentEl.tabIndex; | |
122 | |
123 void set tabIndex(int value) { documentEl.tabIndex = value; } | |
124 | |
125 String get id() => documentEl.id; | |
126 | |
127 void set id(String value) { documentEl.id = value; } | |
128 | |
129 String get title() => documentEl.title; | |
130 | |
131 void set title(String value) { documentEl.title = value; } | |
132 | |
133 String get webkitdropzone() => documentEl.webkitdropzone; | |
134 | |
135 void set webkitdropzone(String value) { documentEl.webkitdropzone = value; } | |
136 | |
137 String get lang() => documentEl.lang; | |
138 | |
139 void set lang(String value) { documentEl.lang = value; } | |
140 | |
141 String get dir() => documentEl.dir; | |
142 | |
143 void set dir(String value) { documentEl.dir = value; } | |
144 } | |
OLD | NEW |