-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TH2-3857 #15
Open
eugene-zheltov
wants to merge
51
commits into
dev
Choose a base branch
from
TH2-3857
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
TH2-3857 #15
Changes from all commits
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
e69c873
Self-closing tag and th2-codec error events (#13)
eugene-zheltov 717b38d
[TH2-3778] Set codec version from snapshot with fixes
eugene-zheltov 6ab2f0b
[TH2-3778] Set codec version from snapshot with fixes
eugene-zheltov 75773ee
[TH2-3778] Change verison of codec core
eugene-zheltov d785d78
[TH2-3778] Change verison of codec core
eugene-zheltov 542bde8
[TH2-3778] Change version of codec core
eugene-zheltov a47c0b1
[TH2-3778] Change version of codec core
eugene-zheltov 09e44f9
[TH2-3778] Change version of codec core to 4.7.1-TH2-3778-tmp-2495038…
eugene-zheltov 1e3527b
[TH2-3857] tmp
eugene-zheltov 4764809
[TH2-3857] tmp-2
eugene-zheltov 4f61923
[TH2-3857] tmp-3
eugene-zheltov 8d785c8
[TH2-3857] tmp-4
eugene-zheltov 74c2c5a
[TH2-3857] tmp-4
eugene-zheltov 68f0a0c
[TH2-3857] Successful parsing; to be refactored
eugene-zheltov cec90fe
[TH2-3857] Refactor XMLSchemaCore
eugene-zheltov 16f85d0
[TH2-3857] tmp-5
eugene-zheltov 07d3a28
TH2-3778 (#14)
eugene-zheltov 8cfce4c
[TH2-3857] tmp-6
eugene-zheltov 8cf2d64
[TH2-3857] Fix the absence of some list values
eugene-zheltov 62c3030
[TH2-3857] Remove prints and change xsd processing a bit
eugene-zheltov 24d6d97
[TH2-3857] Disable tests
eugene-zheltov 06e3d3e
[TH2-3857] Minor changes
eugene-zheltov 725b78e
Merge branch 'master' into TH2-3857
eugene-zheltov 0c6a616
[TH2-3857] Move StreamReaderDelegateDecorator
eugene-zheltov 7697106
[TH2-3857] Chagne xsdProperties loading
eugene-zheltov 468a849
[TH2-3857] Add th2-id to the log when th2-codec-xml-via-xsd cannot de…
eugene-zheltov 6e996da
[TH2-3857] Minor changes
eugene-zheltov 90a4ce7
Merge remote-tracking branch 'origin/TH2-3857' into TH2-3857
eugene-zheltov 652cf79
[TH2-3857] tmp
eugene-zheltov c8474de
[TH2-3857] tmp 2
eugene-zheltov 14be420
[TH2-3857] tmp 3
eugene-zheltov 71ff9c2
[TH2-3857] Implement new decoding
eugene-zheltov 17507d0
[TH2-3857] Remove comments
eugene-zheltov 207e5c1
[TH2-3857] Fix repeated elements of lists
eugene-zheltov cba5310
[TH2-3857] Fix missing empty tags
eugene-zheltov 3b6e346
[TH2-3857] Remove usage of XmlPipelineCodec for now
eugene-zheltov fe488b8
[TH2-3857] Remove garbage
eugene-zheltov 8d5a873
[TH2-3857] Fix truncated values
eugene-zheltov cea2111
[TH2-3857] Add missing attributes
eugene-zheltov bbe67f7
[TH2-3857] Disable test
eugene-zheltov 0fb452b
[TH2-3857] Add prefixes to node names
eugene-zheltov 7791388
[TH2-3857] Remove redundant ":" from node names
eugene-zheltov 06dc868
[TH2-3857] Migrated to StAX
Nikita-Smirnov-Exactpro 23f0005
[TH2-3857] Fixed problem related to release sub-nodes
Nikita-Smirnov-Exactpro a6aab96
[TH2-3857] Updated common libraries
Nikita-Smirnov-Exactpro 7a66236
[TH2-3857] Consider empty xmlns property
eugene-zheltov a127615
[TH2-3857] Add a new parameter encodeValidation
eugene-zheltov 3f9843f
[TH2-3857] Update dev-docker-publish.yml and docker-publish.yml
eugene-zheltov 1d327a4
[TH2-3857] Update common version
eugene-zheltov bb17598
[TH2-3857] Update codec-core version
eugene-zheltov 0510415
[TH2-3857] Update slf4j dependencies
eugene-zheltov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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 |
---|---|---|
|
@@ -5,42 +5,15 @@ on: | |
branches-ignore: | ||
- master | ||
- version-* | ||
|
||
- dependabot** | ||
paths-ignore: | ||
- README.md | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- uses: actions/checkout@v2 | ||
# Prepare custom build version | ||
- name: Get branch name | ||
id: branch | ||
run: echo ::set-output name=branch_name::${GITHUB_REF#refs/*/} | ||
- name: Get release_version | ||
id: ver | ||
uses: christian-draeger/[email protected] | ||
with: | ||
path: gradle.properties | ||
property: release_version | ||
- name: Build custom release version | ||
id: release_ver | ||
run: echo ::set-output name=value::"${{ steps.ver.outputs.value }}-${{ steps.branch.outputs.branch_name }}-${{ github.run_id }}" | ||
- name: Show custom release version | ||
run: echo ${{ steps.release_ver.outputs.value }} | ||
# Build and publish image | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v1 | ||
- uses: docker/login-action@v1 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.CR_PAT }} | ||
- run: echo "::set-output name=REPOSITORY_NAME::$(echo '${{ github.repository }}' | awk -F '/' '{print $2}')" | ||
id: meta | ||
- name: Build and push | ||
id: docker_build | ||
uses: docker/build-push-action@v2 | ||
with: | ||
push: true | ||
tags: ghcr.io/${{ github.repository }}:${{ steps.release_ver.outputs.value }} | ||
labels: com.exactpro.th2.${{ steps.meta.outputs.REPOSITORY_NAME }}=${{ steps.ver.outputs.value }} | ||
build-job: | ||
uses: th2-net/.github/.github/workflows/compound-java-dev.yml@main | ||
with: | ||
build-target: 'Docker' | ||
docker-username: ${{ github.actor }} | ||
secrets: | ||
docker-password: ${{ secrets.GITHUB_TOKEN }} |
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 |
---|---|---|
|
@@ -7,31 +7,13 @@ on: | |
- version-* | ||
paths: | ||
- gradle.properties | ||
# - package_info.json | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-20.04 | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v1 | ||
- uses: docker/login-action@v1 | ||
with: | ||
registry: ghcr.io | ||
username: ${{ github.repository_owner }} | ||
password: ${{ secrets.CR_PAT }} | ||
- run: echo "::set-output name=REPOSITORY_NAME::$(echo '${{ github.repository }}' | awk -F '/' '{print $2}')" | ||
id: meta | ||
- name: Read version from gradle.properties | ||
id: read_property | ||
uses: christian-draeger/[email protected] | ||
with: | ||
path: ./gradle.properties | ||
property: release_version | ||
- name: Build and push | ||
id: docker_build | ||
uses: docker/build-push-action@v2 | ||
with: | ||
push: true | ||
tags: ghcr.io/${{ github.repository }}:${{ steps.read_property.outputs.value }} | ||
labels: com.exactpro.th2.${{ steps.meta.outputs.REPOSITORY_NAME }}=${{ steps.read_property.outputs.value }} | ||
build-job: | ||
uses: th2-net/.github/.github/workflows/compound-java.yml@main | ||
with: | ||
build-target: 'Docker' | ||
docker-username: ${{ github.actor }} | ||
secrets: | ||
docker-password: ${{ secrets.GITHUB_TOKEN }} |
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
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
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
145 changes: 145 additions & 0 deletions
145
src/main/kotlin/com/exactpro/th2/codec/xml/NodeContent.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,145 @@ | ||
/* | ||
* Copyright 2022 Exactpro (Exactpro Systems Limited) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.exactpro.th2.codec.xml | ||
|
||
import com.exactpro.th2.common.grpc.Message | ||
import com.exactpro.th2.common.grpc.MessageMetadata | ||
import com.exactpro.th2.common.grpc.Value | ||
import com.exactpro.th2.common.message.addField | ||
import com.exactpro.th2.common.value.toValue | ||
import javax.xml.namespace.QName | ||
|
||
class NodeContent( | ||
private val nodeName: QName, | ||
decorator: XmlCodecStreamReader | ||
) { | ||
private val messageBuilder = Message.newBuilder().apply { | ||
metadata = MessageMetadata.getDefaultInstance() //FIXME: remove | ||
} | ||
private val textSB = StringBuilder() | ||
|
||
private val childNodes: MutableMap<QName, MutableList<NodeContent>> = mutableMapOf() | ||
private var isMessage: Boolean = false | ||
private val isEmpty: Boolean | ||
get() = !isMessage && textSB.isEmpty() | ||
|
||
val name: String = nodeName.toNodeName() | ||
|
||
init { | ||
decorator.namespaceCount.let { size -> | ||
if (size > 0) { | ||
for (i in 0 until size) { | ||
decorator.getNamespaceURI(i).also { value -> | ||
val uri = value ?: "" | ||
val prefix = decorator.namespaceContext.getPrefix(uri) ?: "" | ||
|
||
messageBuilder.addField(makeFieldName(NAMESPACE, prefix, true), uri) | ||
} | ||
} | ||
isMessage = true | ||
} | ||
} | ||
decorator.attributeCount.let { size -> | ||
if (size > 0) { | ||
for (i in 0 until size) { | ||
val localPart = decorator.getAttributeLocalName(i) | ||
val prefix = decorator.getAttributePrefix(i) | ||
|
||
messageBuilder.addField(makeFieldName(prefix, localPart, true), decorator.getAttributeValue(i)) | ||
} | ||
isMessage = true | ||
} | ||
} | ||
} | ||
|
||
fun putChild(name: QName, node: NodeContent) { | ||
childNodes.compute(name) { _, value -> | ||
value | ||
?.apply { add(node) } | ||
?: mutableListOf(node) | ||
} | ||
isMessage = true | ||
} | ||
|
||
fun appendText(text: String) { | ||
if (text.isNotBlank()) { | ||
textSB.append(text) | ||
} | ||
} | ||
|
||
fun release() { | ||
if (isMessage) { | ||
childNodes.forEach { (name, values) -> | ||
try { | ||
val notEmptyValues = values.filterNot(NodeContent::isEmpty) | ||
|
||
if (notEmptyValues.isNotEmpty()) { | ||
val first = notEmptyValues.first() | ||
when (values.size) { // Clarefy type of element: list or single | ||
0 -> error("Sub element $name hasn't got values") | ||
1 -> messageBuilder.addField(first.name, first.toValue()) | ||
else -> messageBuilder.addField( | ||
first.name, | ||
notEmptyValues.asSequence() | ||
.map(NodeContent::toValue) | ||
.toListValue() | ||
) | ||
} | ||
} | ||
} catch (e: RuntimeException) { | ||
throw IllegalStateException("The `$name` field can't be released in the `$nodeName` node", e) | ||
} | ||
} | ||
if(textSB.isNotBlank()) { | ||
messageBuilder.addField(TEXT_FIELD_NAME, textSB.toValue()) | ||
} | ||
} | ||
} | ||
|
||
fun toMessage(): Message { | ||
check(isMessage) { | ||
"The $nodeName node isn't message" | ||
} | ||
return messageBuilder.build() | ||
} | ||
|
||
override fun toString(): String { | ||
return "NodeContent(nodeName=$nodeName, childNodes=$childNodes, text=$textSB)" | ||
} | ||
|
||
private fun Sequence<Value>.toListValue(): Value = Value.newBuilder().apply { | ||
listValueBuilder.apply { | ||
forEach(::addValues) | ||
} | ||
}.build() | ||
|
||
private fun toValue(): Value = if (isMessage) { | ||
messageBuilder.toValue() | ||
} else { | ||
textSB.toValue() | ||
} | ||
|
||
companion object { | ||
private const val NAMESPACE = "xmlns" | ||
private const val TEXT_FIELD_NAME = "#text" | ||
|
||
private fun QName.toNodeName(): String = makeFieldName(prefix, localPart) | ||
|
||
private fun makeFieldName(first: String, second: String, isAttribute: Boolean = false): String { | ||
return "${if (isAttribute) "-" else ""}$first${if (first.isNotBlank() && second.isNotBlank()) ":" else ""}$second" | ||
} | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please write about used technology