/** * Simplifies the BPMN XML by empty collections of attributes, child elements and extension elements. */ public void cleanEmptyElements() { // Remove empty attributes list. if (attributes != null && attributes.isEmpty()) { attributes = null; } if (elements != null) { // Recursively clean child elements. for (XmlElement childElement : elements) { childElement.cleanEmptyElements(); } // Remove empty child elements list. if (elements.isEmpty()) { elements = null; } } }
/** * Simplifies the BPMN XML by empty collections of attributes, child elements and extension elements. */ public void cleanEmptyElements() { // Remove empty attributes list. if (attributes != null && attributes.isEmpty()) { attributes = null; } if (elements != null) { // Recursively clean child elements. for (XmlElement childElement : elements) { childElement.cleanEmptyElements(); } // Remove empty child elements list. if (elements.isEmpty()) { elements = null; } } }
/** * Cleans up parsed BPMN to remove empty elements, and the BPMN element itself if empty, used after BPMN import. */ public void cleanUnparsedBpmn() { if (bpmn != null) { bpmn.cleanEmptyElements(); if (bpmn.isEmpty()) { bpmn = null; } } }
/** * Cleans up parsed BPMN to remove empty elements, and the BPMN element itself if empty, used after BPMN import. */ public void cleanUnparsedBpmn() { if (bpmn != null) { bpmn.cleanEmptyElements(); if (bpmn.isEmpty()) { bpmn = null; } } }
/** * The BPMN <code>definitions</code> element includes the document’s XML namespace declarations. * Ideally, namespaces should be read in a stack, so that each element can add new namespaces. * The addPrefixes() should then be refactored to pushPrefixes and popPrefixes. * The current implementation assumes that all namespaces are defined in the root element. */ protected AbstractWorkflow readDefinitions(XmlElement definitionsXml) { AbstractWorkflow workflow = null; if (definitionsXml.elements != null) { Iterator<XmlElement> iterator = definitionsXml.elements.iterator(); while (iterator.hasNext()) { XmlElement definitionElement = iterator.next(); boolean processAlreadyParsed = workflow != null; if (definitionElement.is(BPMN_URI, "process") && !processAlreadyParsed) { iterator.remove(); workflow = readWorkflow(definitionElement); } } } if (workflow == null) { workflow = new ExecutableWorkflow(); } readDiagram(workflow, definitionsXml); definitionsXml.cleanEmptyElements(); workflow.property(KEY_DEFINITIONS, definitionsXml); return workflow; }
@Test public void testCleanEmptyAttributes() { root.attributes = new HashMap<>(); root.cleanEmptyElements(); assertNull(root.attributes); }
@Test public void testCleanEmptyElements() { root.elements = new ArrayList<>(); root.cleanEmptyElements(); assertNull(root.elements); }
@Test public void testCleanEmptyChild() { XmlElement childElement = new XmlElement(); childElement.setName(Bpmn.BPMN_URI, "startEvent"); childElement.attributes = new HashMap<>(); childElement.elements = new ArrayList<>(); root.addElement(childElement); root.cleanEmptyElements(); assertNull(childElement.attributes); assertNull(childElement.elements); } }