diff --git a/imixs-workflow-core/src/main/java/org/imixs/workflow/bpmn/BPMNUtil.java b/imixs-workflow-core/src/main/java/org/imixs/workflow/bpmn/BPMNUtil.java index 5cc020c5..f781a473 100644 --- a/imixs-workflow-core/src/main/java/org/imixs/workflow/bpmn/BPMNUtil.java +++ b/imixs-workflow-core/src/main/java/org/imixs/workflow/bpmn/BPMNUtil.java @@ -147,22 +147,10 @@ public static List getItemValueList(Element imixsItemElement) { if (imixsItemElement != null) { // now iterate over all item:values and add each value into the list // - Set 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 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(); @@ -176,7 +164,6 @@ public static List getItemValueList(Element imixsItemElement) { } uniqueValueList.add(value); } - } } @@ -184,6 +171,48 @@ public static List getItemValueList(Element imixsItemElement) { 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 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 findAllCDATA(Element element) { + List 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. @@ -213,21 +242,10 @@ private static List getItemValueList(final BPMNModel model, final Elemen if (imixsItemElement != null) { // now iterate over all item:values and add each value into the list // - Set 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 imixsValueElementList = findAllImixsElements(imixsItemElement, "value"); + if (imixsValueElementList != null) { + for (Element imixsValueElement : imixsValueElementList) { + String value = resolveImixsValueElement(imixsValueElement); // avoid duplicates if (value.contains("|")) { @@ -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. diff --git a/pom.xml b/pom.xml index 3349086a..9bfbeb0a 100644 --- a/pom.xml +++ b/pom.xml @@ -1,4 +1,6 @@ - + 4.0.0 org.imixs.workflow imixs-workflow @@ -22,7 +24,7 @@ 6.0 5.0.0 7.7.3 - 1.2.2 + 1.2.3-SNAPSHOT 22.3.5 5.9.2