-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Xml parsing support to js platform (#3105)
* First pass at adding Xml parsing support to js platform Likely still need to add tests and samples * Add JS to Parser Node and Element converter Mirrors native impl by returning empty strings when content is unavailable Moves MalformedXMLException out of native code, useful for common case. * Remove unneeded null checks in Parser Last commit handled null management * Add newlines for code linter * Fix namespaceUri bug Undo accidental capture of localName Also remove unneeded null check * Undo grade.properies change Had to disable webpack version number property to run sample * Clean up NodeImpl comments Corrected description * Make NodeList impl lazy Generates only when needed, serves cache after
- Loading branch information
Showing
5 changed files
with
59 additions
and
3 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
.../commonMain/kotlin/org/jetbrains/compose/resources/vector/xmldom/MalformedXMLException.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.jetbrains.compose.resources.vector.xmldom | ||
|
||
/** | ||
* Error throw when parsed XML is malformed | ||
*/ | ||
class MalformedXMLException(message: String?) : Exception(message) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...resources/library/src/jsMain/kotlin/org/jetbrains/compose/resources/xmldom/ElementImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.jetbrains.compose.resources.vector.xmldom | ||
|
||
import org.w3c.dom.Element as DomElement | ||
|
||
internal class ElementImpl(val element: DomElement): NodeImpl(element), Element { | ||
|
||
override val localName: String | ||
get() = element.localName | ||
|
||
override val namespaceURI: String | ||
get() = element.namespaceURI ?: "" | ||
|
||
override fun getAttributeNS(nameSpaceURI: String, localName: String): String = | ||
element.getAttributeNS(nameSpaceURI, localName) ?: "" | ||
|
||
override fun getAttribute(name: String): String = element.getAttribute(name) ?: "" | ||
} |
28 changes: 28 additions & 0 deletions
28
...ts/resources/library/src/jsMain/kotlin/org/jetbrains/compose/resources/xmldom/NodeImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package org.jetbrains.compose.resources.vector.xmldom | ||
|
||
import org.w3c.dom.Node as DomNode | ||
import org.w3c.dom.Element as DomElement | ||
|
||
internal open class NodeImpl(val n: DomNode): Node { | ||
override val nodeName: String | ||
get() = n.nodeName | ||
|
||
override val localName = "" /* localName is not a Node property, only applies to Elements and Attrs */ | ||
|
||
override val namespaceURI = "" /* namespaceURI is not a Node property, only applies to Elements and Attrs */ | ||
|
||
override val childNodes: NodeList by lazy { | ||
object: NodeList { | ||
override fun item(i: Int): Node { | ||
val child = n.childNodes.item(i) | ||
?: throw IndexOutOfBoundsException("no child node accessible at index=$i") | ||
return if (child is DomElement) ElementImpl(child) else NodeImpl(child) | ||
} | ||
|
||
override val length: Int = n.childNodes.length | ||
} | ||
} | ||
|
||
override fun lookupPrefix(namespaceURI: String): String = n.lookupPrefix(namespaceURI) ?: "" | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters