|
13 | 13 | * See the License for the specific language governing permissions and
|
14 | 14 | * limitations under the License.
|
15 | 15 | */
|
16 |
| -@file:Suppress("DEPRECATION_ERROR") |
17 | 16 | package kotlin.dom
|
18 | 17 |
|
19 | 18 | import org.w3c.dom.*
|
20 | 19 | import kotlin.collections.*
|
21 | 20 |
|
22 |
| -// DEPRECATED in 1.1-RC, drop after 1.1 |
23 |
| - |
24 |
| -/** Returns the children of the element as a list */ |
25 |
| -@Deprecated("Use childNodes() function with safe call", ReplaceWith("this?.childNodes()?.asList().orEmpty()", "org.w3c.dom.asList"), level = DeprecationLevel.ERROR) |
26 |
| -fun Element?.children(): List<Node> { |
27 |
| - return this?.childNodes?.asList() ?: emptyList() |
28 |
| -} |
29 |
| - |
30 |
| -/** Returns the child elements of this element */ |
31 |
| -@Deprecated("Use childNodes() function with safe call and filter it after", level = DeprecationLevel.ERROR) |
32 |
| -fun Element?.childElements(): List<Element> = this?.childNodes?.filterElements() ?: emptyList() |
33 |
| - |
34 |
| -/** Returns the child elements of this element with the given name. */ |
35 |
| -@Deprecated("Use childNodes() function with safe call and filter it after", level = DeprecationLevel.ERROR) |
36 |
| -fun Element?.childElements(name: String): List<Element> = this?.childNodes?.filterElements()?.filter { it.nodeName == name } ?: emptyList() |
37 |
| - |
38 |
| -/** Returns all the descendant elements given the local element name. */ |
39 |
| -@Deprecated("Use getElementsByTagName() instead", ReplaceWith("getElementsByTagName(localName).asList()", "org.w3c.dom.asList"), level = DeprecationLevel.ERROR) |
40 |
| -fun Element.elements(localName: String = "*"): List<Element> { |
41 |
| - return this.getElementsByTagName(localName).asList() |
42 |
| -} |
43 |
| - |
44 |
| -/** Returns all the descendant elements given the local element name */ |
45 |
| -@JsName("deprecated_document_elements") |
46 |
| -@Deprecated("Use getElementsByTagName() function with safe call", ReplaceWith("this?.getElementsByTagName(localName)?.asList().orEmpty()", "org.w3c.dom.asList"), level = DeprecationLevel.ERROR) |
47 |
| -fun Document?.elements(localName: String = "*"): List<Element> { |
48 |
| - return this?.elements(localName).orEmpty() |
49 |
| -} |
50 |
| - |
51 |
| -/** Returns all the descendant elements given the namespace URI and local element name. */ |
52 |
| -@Deprecated("Use getElementsByTagNameNS() function instead", ReplaceWith("this?.getElementsByTagNameNS(namespaceUri, localName)?.asList().orEmpty()", "org.w3c.dom.asList"), level = DeprecationLevel.ERROR) |
53 |
| -public fun Element.elements(namespaceUri: String, localName: String): List<Element> { |
54 |
| - return this.getElementsByTagNameNS(namespaceUri, localName).asList() |
55 |
| -} |
56 |
| - |
57 |
| -/** Returns all the descendant elements given the namespace URI and local element name */ |
58 |
| -@Deprecated("Use getElementsByTagNameNS() function with safe call", ReplaceWith("this?.getElementsByTagNameNS(namespaceUri, localName)?.asList().orEmpty()", "org.w3c.dom.asList"), level = DeprecationLevel.ERROR) |
59 |
| -fun Document?.elements(namespaceUri: String, localName: String): List<Element> { |
60 |
| - return this?.getElementsByTagNameNS(namespaceUri, localName)?.asList() ?: emptyList() |
61 |
| -} |
62 |
| - |
63 |
| -// END OF DEPRECATED |
64 |
| - |
65 |
| -/** |
66 |
| - * Returns a view of this [NodeList] as a list of elements assuming that it contains only elements. |
67 |
| - * |
68 |
| - * An attempt to get an element with [List.get] indexed accessor of the returned list |
69 |
| - * will result in [ClassCastException] being thrown if that node is not an element. |
70 |
| - * |
71 |
| - * If you want to get a snapshot filtered to contain elements only it's better to use [filterElements] function. |
72 |
| - */ |
73 |
| -@Deprecated("This API is going to be removed, use asList() as a close replacement instead.", ReplaceWith("asList() as List<Element>", "org.w3c.dom.asList"), level = DeprecationLevel.ERROR) |
74 |
| -public fun NodeList.asElementList(): List<Element> = ElementListAsList(this) |
75 |
| - |
76 |
| -/** |
77 |
| - * Returns a list containing only [Element] nodes. |
78 |
| - */ |
79 |
| -@Deprecated("Use filter function instead", ReplaceWith("filter { it.isElement } as List<Element>"), level = DeprecationLevel.ERROR) |
80 |
| -public fun List<Node>.filterElements(): List<Element> { |
81 |
| - @Suppress("UNCHECKED_CAST") |
82 |
| - return filter { it.isElement } as List<Element> |
83 |
| -} |
84 |
| - |
85 |
| -/** |
86 |
| - * Returns a list containing only [Element] nodes. |
87 |
| - */ |
88 |
| -@Deprecated("Use filter function instead", ReplaceWith("asList().filter { it.isElement } as List<Element>", "org.w3c.dom.asList"), level = DeprecationLevel.ERROR) |
89 |
| -public fun NodeList.filterElements(): List<Element> = asList().filterElements() |
90 |
| - |
91 |
| - |
92 |
| - |
93 |
| -private class ElementListAsList(private val nodeList: NodeList) : AbstractList<Element>() { |
94 |
| - override fun get(index: Int): Element { |
95 |
| - val node = nodeList.item(index) |
96 |
| - if (node == null) { |
97 |
| - throw IndexOutOfBoundsException("NodeList does not contain a node at index: " + index) |
98 |
| - } else if (node.nodeType == Node.ELEMENT_NODE) { |
99 |
| - return node as Element |
100 |
| - } else { |
101 |
| - throw ClassCastException("Node is not an Element as expected but is $node") |
102 |
| - } |
103 |
| - } |
104 |
| - |
105 |
| - override val size: Int get() = nodeList.length |
106 |
| -} |
107 |
| - |
108 |
| -/** Returns an [Iterator] over the next siblings of this node. */ |
109 |
| -@Deprecated("This API is going to be removed", level = DeprecationLevel.ERROR) |
110 |
| -public fun Node.nextSiblings(): Iterable<Node> = NextSiblings(this) |
111 |
| - |
112 |
| -private class NextSiblings(private var node: Node) : Iterable<Node> { |
113 |
| - override fun iterator(): Iterator<Node> = object : AbstractIterator<Node>() { |
114 |
| - override fun computeNext(): Unit { |
115 |
| - val nextValue = node.nextSibling |
116 |
| - if (nextValue != null) { |
117 |
| - setNext(nextValue) |
118 |
| - node = nextValue |
119 |
| - } else { |
120 |
| - done() |
121 |
| - } |
122 |
| - } |
123 |
| - } |
124 |
| -} |
125 |
| - |
126 |
| -/** Returns an [Iterator] over the next siblings of this node. */ |
127 |
| -@Deprecated("This API is going to be removed", level = DeprecationLevel.ERROR) |
128 |
| -public fun Node.previousSiblings(): Iterable<Node> = PreviousSiblings(this) |
129 |
| - |
130 |
| -private class PreviousSiblings(private var node: Node) : Iterable<Node> { |
131 |
| - override fun iterator(): Iterator<Node> = object : AbstractIterator<Node>() { |
132 |
| - override fun computeNext(): Unit { |
133 |
| - val nextValue = node.previousSibling |
134 |
| - if (nextValue != null) { |
135 |
| - setNext(nextValue) |
136 |
| - node = nextValue |
137 |
| - } else { |
138 |
| - done() |
139 |
| - } |
140 |
| - } |
141 |
| - } |
142 |
| -} |
143 | 21 |
|
144 | 22 | /**
|
145 | 23 | * Gets a value indicating whether this node is a TEXT_NODE or a CDATA_SECTION_NODE.
|
|
0 commit comments