Skip to content

Commit

Permalink
fixed
Browse files Browse the repository at this point in the history
Issue #882
  • Loading branch information
rsoika committed Nov 4, 2024
1 parent 4f0df3d commit f57a82d
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,22 +147,10 @@ public static List<String> getItemValueList(Element imixsItemElement) {
if (imixsItemElement != null) {
// now iterate over all item:values and add each value into the list
// <imixs:value><![CDATA[form_basic]]></imixs:value>
Set<Element> imixsValueElements = findAllImixsElements(imixsItemElement, "value");
if (imixsValueElements != null) {
for (Element imixsItemValue : imixsValueElements) {
String value = null;
// we expect a CDATA, bu we can not be sure
Node cdata = findCDATA(imixsItemValue);
if (cdata != null) {
String cdValue = cdata.getNodeValue();
if (cdValue != null) {
value = cdValue;
}
} else {
// normal text node
value = imixsItemValue.getTextContent();
}

Set<Element> imixsValueElementList = findAllImixsElements(imixsItemElement, "value");
if (imixsValueElementList != null) {
for (Element imixsValueElement : imixsValueElementList) {
String value = resolveImixsValueElement(imixsValueElement);
// avoid duplicates
if (value.contains("|")) {
String valuePart = value.substring(value.indexOf("|") + 1).trim();
Expand All @@ -176,14 +164,55 @@ public static List<String> getItemValueList(Element imixsItemElement) {
}
uniqueValueList.add(value);
}

}

}
}
return uniqueValueList;
}

/**
* This helper method returns the content of a given Imixs Value Node.
* The node can contain multiple CDATA sections!
*
* @return String - can be empty
*/
private static String resolveImixsValueElement(Element imixsItemValue) {
List<Node> cdataNodes = findAllCDATA(imixsItemValue);
// do we have CDATA nodes?
if (!cdataNodes.isEmpty()) {
// Concatenate all CDATA sections
StringBuilder content = new StringBuilder();
for (Node cdata : cdataNodes) {
content.append(cdata.getNodeValue());
}
return content.toString();
} else {
// normal text node, just return the content
return imixsItemValue.getTextContent();
}
}

/**
* Helper method that finds all CDATA nodes within the current element.
* In complex situations there can be nested CDATA sections inside one tag.
*
* @param element
* @return
*/
private static List<Node> findAllCDATA(Element element) {
List<Node> cdataNodes = new ArrayList<>();
NodeList childNodes = element.getChildNodes();

for (int i = 0; i < childNodes.getLength(); i++) {
Node node = childNodes.item(i);
if (node instanceof CDATASection) {
cdataNodes.add(node);
}
}
return cdataNodes;
}

/**
* This helper method returns a value list of all imixs:value elements of an
* imixs:item by a given name.
Expand Down Expand Up @@ -213,21 +242,10 @@ private static List<String> getItemValueList(final BPMNModel model, final Elemen
if (imixsItemElement != null) {
// now iterate over all item:values and add each value into the list
// <imixs:value><![CDATA[form_basic]]></imixs:value>
Set<Element> imixsValueElements = findAllImixsElements(imixsItemElement, "value");
if (imixsValueElements != null) {
for (Element imixsItemValue : imixsValueElements) {
String value = null;
// we expect a CDATA, bu we can not be sure
Node cdata = findCDATA(imixsItemValue);
if (cdata != null) {
String cdValue = cdata.getNodeValue();
if (cdValue != null) {
value = cdValue;
}
} else {
// normal text node
value = imixsItemValue.getTextContent();
}
Set<Element> imixsValueElementList = findAllImixsElements(imixsItemElement, "value");
if (imixsValueElementList != null) {
for (Element imixsValueElement : imixsValueElementList) {
String value = resolveImixsValueElement(imixsValueElement);

// avoid duplicates
if (value.contains("|")) {
Expand Down Expand Up @@ -370,25 +388,6 @@ public static boolean isParallelGatewayElement(BPMNElementNode element) {
return false;
}

/**
* Helper method that finds an optional CDATA node within the current element
* content.
*
* @param element
* @return
*/
private static Node findCDATA(Element element) {
// search CDATA node
NodeList childNodes = element.getChildNodes();
for (int i = 0; i < childNodes.getLength(); i++) {
Node node = childNodes.item(i);
if (node instanceof CDATASection) {
return (CDATASection) node;
}
}
return null;
}

/**
* Returns true if the given node is a an ImixsEvent node with no incoming
* nodes or with one incoming node that comes from a Start event.
Expand Down
6 changes: 4 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.imixs.workflow</groupId>
<artifactId>imixs-workflow</artifactId>
Expand All @@ -22,7 +24,7 @@
<microprofile.version>6.0</microprofile.version>
<microprofile-metrics.version>5.0.0</microprofile-metrics.version>
<lucene.version>7.7.3</lucene.version>
<openbpmn.version>1.2.2</openbpmn.version>
<openbpmn.version>1.2.3-SNAPSHOT</openbpmn.version>
<graalvm.version>22.3.5</graalvm.version>
<!-- test dependencies -->
<junit.jupiter.version>5.9.2</junit.jupiter.version>
Expand Down

0 comments on commit f57a82d

Please sign in to comment.