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) { |
| 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 // |
| 31 // TODO(nweiz): This is pretty hacky, it would be nice to this some other |
| 32 // way if we can find one. |
| 33 if (!xml.toLowerCase().contains('<parsererror') && |
| 34 xmlDoc.query('parsererror') != null) { |
| 35 throw new IllegalArgumentException('Error parsing XML: "$xml"'); |
| 36 } |
| 37 return xmlDoc; |
| 38 } |
| 39 |
| 40 Node get parent() => null; |
| 41 |
| 42 Node _insertAdjacentNode(String where, Node node) { |
| 43 switch (where.toLowerCase()) { |
| 44 case "beforebegin": |
| 45 return null; |
| 46 case "afterend": |
| 47 return null; |
| 48 case "afterbegin": |
| 49 this.insertBefore(node, nodes.first); |
| 50 return node; |
| 51 case "beforeend": |
| 52 this.nodes.add(node); |
| 53 return node; |
| 54 default: |
| 55 throw new IllegalArgumentException("Invalid position ${where}"); |
| 56 } |
| 57 } |
| 58 |
| 59 XMLElement insertAdjacentElement([String where = null, |
| 60 XMLElement element = null]) => this._insertAdjacentNode(where, element); |
| 61 |
| 62 void insertAdjacentText([String where = null, String text = null]) { |
| 63 this._insertAdjacentNode(where, new Text(text)); |
| 64 } |
| 65 |
| 66 void insertAdjacentHTML( |
| 67 [String position_OR_where = null, String text = null]) { |
| 68 this._insertAdjacentNode( |
| 69 position_OR_where, new DocumentFragment.xml(text)); |
| 70 } |
| 71 |
| 72 XMLElement get activeElement() => null; |
| 73 |
| 74 void set body(Element value) { |
| 75 throw new UnsupportedOperationException("XML documents don't have a body."); |
| 76 } |
| 77 |
| 78 String get cookie() { |
| 79 throw new UnsupportedOperationException( |
| 80 "XML documents don't support cookies."); |
| 81 } |
| 82 |
| 83 void set cookie(String value) { |
| 84 throw new UnsupportedOperationException( |
| 85 "XML documents don't support cookies."); |
| 86 } |
| 87 |
| 88 String get manifest() => ""; |
| 89 |
| 90 void set manifest(String value) { |
| 91 throw new UnsupportedOperationException( |
| 92 "Manifest can't be set for XML documents."); |
| 93 } |
| 94 |
| 95 Set<String> get classes() => documentEl.classes; |
| 96 |
| 97 ElementList get elements() => documentEl.elements; |
| 98 |
| 99 // TODO: The type of value should be Collection<Element>. See http://b/5392897 |
| 100 void set elements(value) { documentEl.elements = value; } |
| 101 |
| 102 String get outerHTML() => documentEl.outerHTML; |
| 103 |
| 104 String get innerHTML() => documentEl.innerHTML; |
| 105 |
| 106 void set innerHTML(String xml) { documentEl.innerHTML = xml; } |
| 107 |
| 108 String get contentEditable() => documentEl.contentEditable; |
| 109 |
| 110 void set contentEditable(String value) { documentEl.contentEditable = value; } |
| 111 |
| 112 bool get isContentEditable() => documentEl.isContentEditable; |
| 113 |
| 114 bool get draggable() => documentEl.draggable; |
| 115 |
| 116 void set draggable(bool value) { documentEl.draggable = value; } |
| 117 |
| 118 bool get spellcheck() => documentEl.spellcheck; |
| 119 |
| 120 void set spellcheck(bool value) { documentEl.spellcheck = value; } |
| 121 |
| 122 bool get hidden() => documentEl.hidden; |
| 123 |
| 124 void set hidden(bool value) { documentEl.hidden = value; } |
| 125 |
| 126 int get tabIndex() => documentEl.tabIndex; |
| 127 |
| 128 void set tabIndex(int value) { documentEl.tabIndex = value; } |
| 129 |
| 130 String get id() => documentEl.id; |
| 131 |
| 132 void set id(String value) { documentEl.id = value; } |
| 133 |
| 134 String get title() => documentEl.title; |
| 135 |
| 136 void set title(String value) { documentEl.title = value; } |
| 137 |
| 138 String get webkitdropzone() => documentEl.webkitdropzone; |
| 139 |
| 140 void set webkitdropzone(String value) { documentEl.webkitdropzone = value; } |
| 141 |
| 142 String get lang() => documentEl.lang; |
| 143 |
| 144 void set lang(String value) { documentEl.lang = value; } |
| 145 |
| 146 String get dir() => documentEl.dir; |
| 147 |
| 148 void set dir(String value) { documentEl.dir = value; } |
| 149 } |
OLD | NEW |