Example usage for javax.xml.stream XMLStreamWriter writeEndElement

List of usage examples for javax.xml.stream XMLStreamWriter writeEndElement

Introduction

In this page you can find the example usage for javax.xml.stream XMLStreamWriter writeEndElement.

Prototype

public void writeEndElement() throws XMLStreamException;

Source Link

Document

Writes an end tag to the output relying on the internal state of the writer to determine the prefix and local name of the event.

Usage

From source file:org.flowable.bpmn.converter.BaseBpmnXMLConverter.java

protected void writeCancelDefinition(Event parentEvent, CancelEventDefinition cancelEventDefinition,
        XMLStreamWriter xtw) throws Exception {
    xtw.writeStartElement(ELEMENT_EVENT_CANCELDEFINITION);
    boolean didWriteExtensionStartElement = BpmnXMLUtil.writeExtensionElements(cancelEventDefinition, false,
            xtw);//from  w w  w. ja  v a2 s  .co  m
    if (didWriteExtensionStartElement) {
        xtw.writeEndElement();
    }
    xtw.writeEndElement();
}

From source file:org.flowable.bpmn.converter.BaseBpmnXMLConverter.java

protected void writeTerminateDefinition(Event parentEvent, TerminateEventDefinition terminateDefinition,
        XMLStreamWriter xtw) throws Exception {
    xtw.writeStartElement(ELEMENT_EVENT_TERMINATEDEFINITION);

    if (terminateDefinition.isTerminateAll()) {
        writeQualifiedAttribute(ATTRIBUTE_TERMINATE_ALL, "true", xtw);
    }/*from  w  w  w  .  j  a v a 2  s  .  c om*/

    if (terminateDefinition.isTerminateMultiInstance()) {
        writeQualifiedAttribute(ATTRIBUTE_TERMINATE_MULTI_INSTANCE, "true", xtw);
    }

    boolean didWriteExtensionStartElement = BpmnXMLUtil.writeExtensionElements(terminateDefinition, false, xtw);
    if (didWriteExtensionStartElement) {
        xtw.writeEndElement();
    }
    xtw.writeEndElement();
}

From source file:org.flowable.bpmn.converter.BpmnXMLConverter.java

public byte[] convertToXML(BpmnModel model, String encoding) {
    try {/*  w w w  .j  a v  a 2s.  c  o m*/

        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

        XMLOutputFactory xof = XMLOutputFactory.newInstance();
        OutputStreamWriter out = new OutputStreamWriter(outputStream, encoding);

        XMLStreamWriter writer = xof.createXMLStreamWriter(out);
        XMLStreamWriter xtw = new IndentingXMLStreamWriter(writer);

        DefinitionsRootExport.writeRootElement(model, xtw, encoding);
        CollaborationExport.writePools(model, xtw);
        DataStoreExport.writeDataStores(model, xtw);
        SignalAndMessageDefinitionExport.writeSignalsAndMessages(model, xtw);

        for (Process process : model.getProcesses()) {

            if (process.getFlowElements().isEmpty() && process.getLanes().isEmpty()) {
                // empty process, ignore it
                continue;
            }

            ProcessExport.writeProcess(process, xtw);

            for (FlowElement flowElement : process.getFlowElements()) {
                createXML(flowElement, model, xtw);
            }

            for (Artifact artifact : process.getArtifacts()) {
                createXML(artifact, model, xtw);
            }

            // end process element
            xtw.writeEndElement();
        }

        BPMNDIExport.writeBPMNDI(model, xtw);

        // end definitions root element
        xtw.writeEndElement();
        xtw.writeEndDocument();

        xtw.flush();

        outputStream.close();

        xtw.close();

        return outputStream.toByteArray();

    } catch (Exception e) {
        LOGGER.error("Error writing BPMN XML", e);
        throw new XMLException("Error writing BPMN XML", e);
    }
}

From source file:org.flowable.bpmn.converter.BpmnXMLConverter.java

protected void createXML(FlowElement flowElement, BpmnModel model, XMLStreamWriter xtw) throws Exception {

    if (flowElement instanceof SubProcess) {

        SubProcess subProcess = (SubProcess) flowElement;
        if (flowElement instanceof Transaction) {
            xtw.writeStartElement(ELEMENT_TRANSACTION);
        } else if (flowElement instanceof AdhocSubProcess) {
            xtw.writeStartElement(ELEMENT_ADHOC_SUBPROCESS);
        } else {/*from   w ww  . j  a va  2s  .c  o  m*/
            xtw.writeStartElement(ELEMENT_SUBPROCESS);
        }

        xtw.writeAttribute(ATTRIBUTE_ID, subProcess.getId());
        if (StringUtils.isNotEmpty(subProcess.getName())) {
            xtw.writeAttribute(ATTRIBUTE_NAME, subProcess.getName());
        } else {
            xtw.writeAttribute(ATTRIBUTE_NAME, "subProcess");
        }

        if (subProcess instanceof EventSubProcess) {
            xtw.writeAttribute(ATTRIBUTE_TRIGGERED_BY, ATTRIBUTE_VALUE_TRUE);

        } else if (subProcess instanceof Transaction == false) {
            if (subProcess.isAsynchronous()) {
                BpmnXMLUtil.writeQualifiedAttribute(ATTRIBUTE_ACTIVITY_ASYNCHRONOUS, ATTRIBUTE_VALUE_TRUE, xtw);
                if (subProcess.isNotExclusive()) {
                    BpmnXMLUtil.writeQualifiedAttribute(ATTRIBUTE_ACTIVITY_EXCLUSIVE, ATTRIBUTE_VALUE_FALSE,
                            xtw);
                }
            }

        } else if (subProcess instanceof AdhocSubProcess) {
            AdhocSubProcess adhocSubProcess = (AdhocSubProcess) subProcess;
            BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_CANCEL_REMAINING_INSTANCES,
                    String.valueOf(adhocSubProcess.isCancelRemainingInstances()), xtw);
            if (StringUtils.isNotEmpty(adhocSubProcess.getOrdering())) {
                BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_ORDERING, adhocSubProcess.getOrdering(), xtw);
            }
        }

        if (StringUtils.isNotEmpty(subProcess.getDocumentation())) {

            xtw.writeStartElement(ELEMENT_DOCUMENTATION);
            xtw.writeCharacters(subProcess.getDocumentation());
            xtw.writeEndElement();
        }

        boolean didWriteExtensionStartElement = FlowableListenerExport.writeListeners(subProcess, false, xtw);

        didWriteExtensionStartElement = BpmnXMLUtil.writeExtensionElements(subProcess,
                didWriteExtensionStartElement, model.getNamespaces(), xtw);
        if (didWriteExtensionStartElement) {
            // closing extensions element
            xtw.writeEndElement();
        }

        MultiInstanceExport.writeMultiInstance(subProcess, xtw);

        if (subProcess instanceof AdhocSubProcess) {
            AdhocSubProcess adhocSubProcess = (AdhocSubProcess) subProcess;
            if (StringUtils.isNotEmpty(adhocSubProcess.getCompletionCondition())) {
                xtw.writeStartElement(ELEMENT_COMPLETION_CONDITION);
                xtw.writeCData(adhocSubProcess.getCompletionCondition());
                xtw.writeEndElement();
            }
        }

        for (FlowElement subElement : subProcess.getFlowElements()) {
            createXML(subElement, model, xtw);
        }

        for (Artifact artifact : subProcess.getArtifacts()) {
            createXML(artifact, model, xtw);
        }

        xtw.writeEndElement();

    } else {

        BaseBpmnXMLConverter converter = convertersToXMLMap.get(flowElement.getClass());

        if (converter == null) {
            throw new XMLException("No converter for " + flowElement.getClass() + " found");
        }

        converter.convertToXML(xtw, flowElement, model);
    }
}

From source file:org.flowable.bpmn.converter.CallActivityXMLConverter.java

private boolean writeIOParameters(String elementName, List<IOParameter> parameterList,
        boolean didWriteExtensionStartElement, XMLStreamWriter xtw) throws Exception {

    if (parameterList.isEmpty()) {
        return didWriteExtensionStartElement;
    }//from www  .j a  v a  2s.  c  o  m

    for (IOParameter ioParameter : parameterList) {
        if (didWriteExtensionStartElement == false) {
            xtw.writeStartElement(ELEMENT_EXTENSIONS);
            didWriteExtensionStartElement = true;
        }

        xtw.writeStartElement(FLOWABLE_EXTENSIONS_PREFIX, elementName, FLOWABLE_EXTENSIONS_NAMESPACE);
        if (StringUtils.isNotEmpty(ioParameter.getSource())) {
            writeDefaultAttribute(ATTRIBUTE_IOPARAMETER_SOURCE, ioParameter.getSource(), xtw);
        }
        if (StringUtils.isNotEmpty(ioParameter.getSourceExpression())) {
            writeDefaultAttribute(ATTRIBUTE_IOPARAMETER_SOURCE_EXPRESSION, ioParameter.getSourceExpression(),
                    xtw);
        }
        if (StringUtils.isNotEmpty(ioParameter.getTarget())) {
            writeDefaultAttribute(ATTRIBUTE_IOPARAMETER_TARGET, ioParameter.getTarget(), xtw);
        }

        xtw.writeEndElement();
    }

    return didWriteExtensionStartElement;
}

From source file:org.flowable.bpmn.converter.export.BPMNDIExport.java

public static void writeBPMNDI(BpmnModel model, XMLStreamWriter xtw) throws Exception {
    // BPMN DI information
    xtw.writeStartElement(BPMNDI_PREFIX, ELEMENT_DI_DIAGRAM, BPMNDI_NAMESPACE);

    String processId = null;//from  w  w  w .j  a v  a  2 s . co m
    if (!model.getPools().isEmpty()) {
        processId = "Collaboration";
    } else {
        processId = model.getMainProcess().getId();
    }

    xtw.writeAttribute(ATTRIBUTE_ID, "BPMNDiagram_" + processId);

    xtw.writeStartElement(BPMNDI_PREFIX, ELEMENT_DI_PLANE, BPMNDI_NAMESPACE);
    xtw.writeAttribute(ATTRIBUTE_DI_BPMNELEMENT, processId);
    xtw.writeAttribute(ATTRIBUTE_ID, "BPMNPlane_" + processId);

    for (String elementId : model.getLocationMap().keySet()) {

        if (model.getFlowElement(elementId) != null || model.getArtifact(elementId) != null
                || model.getPool(elementId) != null || model.getLane(elementId) != null) {

            xtw.writeStartElement(BPMNDI_PREFIX, ELEMENT_DI_SHAPE, BPMNDI_NAMESPACE);
            xtw.writeAttribute(ATTRIBUTE_DI_BPMNELEMENT, elementId);
            xtw.writeAttribute(ATTRIBUTE_ID, "BPMNShape_" + elementId);

            GraphicInfo graphicInfo = model.getGraphicInfo(elementId);
            FlowElement flowElement = model.getFlowElement(elementId);
            if (flowElement instanceof SubProcess && graphicInfo.getExpanded() != null) {
                xtw.writeAttribute(ATTRIBUTE_DI_IS_EXPANDED, String.valueOf(graphicInfo.getExpanded()));
            }

            xtw.writeStartElement(OMGDC_PREFIX, ELEMENT_DI_BOUNDS, OMGDC_NAMESPACE);
            xtw.writeAttribute(ATTRIBUTE_DI_HEIGHT, "" + graphicInfo.getHeight());
            xtw.writeAttribute(ATTRIBUTE_DI_WIDTH, "" + graphicInfo.getWidth());
            xtw.writeAttribute(ATTRIBUTE_DI_X, "" + graphicInfo.getX());
            xtw.writeAttribute(ATTRIBUTE_DI_Y, "" + graphicInfo.getY());
            xtw.writeEndElement();

            xtw.writeEndElement();
        }
    }

    for (String elementId : model.getFlowLocationMap().keySet()) {

        if (model.getFlowElement(elementId) != null || model.getArtifact(elementId) != null
                || model.getMessageFlow(elementId) != null) {

            xtw.writeStartElement(BPMNDI_PREFIX, ELEMENT_DI_EDGE, BPMNDI_NAMESPACE);
            xtw.writeAttribute(ATTRIBUTE_DI_BPMNELEMENT, elementId);
            xtw.writeAttribute(ATTRIBUTE_ID, "BPMNEdge_" + elementId);

            List<GraphicInfo> graphicInfoList = model.getFlowLocationGraphicInfo(elementId);
            for (GraphicInfo graphicInfo : graphicInfoList) {
                xtw.writeStartElement(OMGDI_PREFIX, ELEMENT_DI_WAYPOINT, OMGDI_NAMESPACE);
                xtw.writeAttribute(ATTRIBUTE_DI_X, "" + graphicInfo.getX());
                xtw.writeAttribute(ATTRIBUTE_DI_Y, "" + graphicInfo.getY());
                xtw.writeEndElement();
            }

            GraphicInfo labelGraphicInfo = model.getLabelGraphicInfo(elementId);
            FlowElement flowElement = model.getFlowElement(elementId);
            MessageFlow messageFlow = null;
            if (flowElement == null) {
                messageFlow = model.getMessageFlow(elementId);
            }

            boolean hasName = false;
            if (flowElement != null && StringUtils.isNotEmpty(flowElement.getName())) {
                hasName = true;

            } else if (messageFlow != null && StringUtils.isNotEmpty(messageFlow.getName())) {
                hasName = true;
            }

            if (labelGraphicInfo != null && hasName) {
                xtw.writeStartElement(BPMNDI_PREFIX, ELEMENT_DI_LABEL, BPMNDI_NAMESPACE);
                xtw.writeStartElement(OMGDC_PREFIX, ELEMENT_DI_BOUNDS, OMGDC_NAMESPACE);
                xtw.writeAttribute(ATTRIBUTE_DI_HEIGHT, "" + labelGraphicInfo.getHeight());
                xtw.writeAttribute(ATTRIBUTE_DI_WIDTH, "" + labelGraphicInfo.getWidth());
                xtw.writeAttribute(ATTRIBUTE_DI_X, "" + labelGraphicInfo.getX());
                xtw.writeAttribute(ATTRIBUTE_DI_Y, "" + labelGraphicInfo.getY());
                xtw.writeEndElement();
                xtw.writeEndElement();
            }

            xtw.writeEndElement();
        }
    }

    // end BPMN DI elements
    xtw.writeEndElement();
    xtw.writeEndElement();
}

From source file:org.flowable.bpmn.converter.export.FailedJobRetryCountExport.java

public static void writeFailedJobRetryCount(Activity activity, XMLStreamWriter xtw) throws Exception {
    String failedJobRetryCycle = activity.getFailedJobRetryTimeCycleValue();
    if (failedJobRetryCycle != null) {

        if (StringUtils.isNotEmpty(failedJobRetryCycle)) {
            xtw.writeStartElement(FLOWABLE_EXTENSIONS_PREFIX, FAILED_JOB_RETRY_TIME_CYCLE,
                    FLOWABLE_EXTENSIONS_NAMESPACE);
            xtw.writeCharacters(failedJobRetryCycle);
            xtw.writeEndElement();
        }/*from  w w  w  .  ja  va 2 s .  co  m*/
    }
}

From source file:org.flowable.bpmn.converter.export.FieldExtensionExport.java

public static boolean writeFieldExtensions(List<FieldExtension> fieldExtensionList,
        boolean didWriteExtensionStartElement, XMLStreamWriter xtw) throws Exception {

    for (FieldExtension fieldExtension : fieldExtensionList) {

        if (StringUtils.isNotEmpty(fieldExtension.getFieldName())) {

            if (StringUtils.isNotEmpty(fieldExtension.getStringValue())
                    || StringUtils.isNotEmpty(fieldExtension.getExpression())) {

                if (didWriteExtensionStartElement == false) {
                    xtw.writeStartElement(ELEMENT_EXTENSIONS);
                    didWriteExtensionStartElement = true;
                }//from ww  w. j a va 2s.com

                xtw.writeStartElement(FLOWABLE_EXTENSIONS_PREFIX, ELEMENT_FIELD, FLOWABLE_EXTENSIONS_NAMESPACE);
                BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_FIELD_NAME, fieldExtension.getFieldName(), xtw);

                if (StringUtils.isNotEmpty(fieldExtension.getStringValue())) {
                    xtw.writeStartElement(FLOWABLE_EXTENSIONS_PREFIX, ELEMENT_FIELD_STRING,
                            FLOWABLE_EXTENSIONS_NAMESPACE);
                    xtw.writeCData(fieldExtension.getStringValue());
                } else {
                    xtw.writeStartElement(FLOWABLE_EXTENSIONS_PREFIX, ATTRIBUTE_FIELD_EXPRESSION,
                            FLOWABLE_EXTENSIONS_NAMESPACE);
                    xtw.writeCData(fieldExtension.getExpression());
                }
                xtw.writeEndElement();
                xtw.writeEndElement();
            }
        }
    }
    return didWriteExtensionStartElement;
}

From source file:org.flowable.bpmn.converter.export.FlowableListenerExport.java

protected static boolean writeEventListeners(List<EventListener> eventListeners,
        boolean didWriteExtensionStartElement, XMLStreamWriter xtw) throws Exception {

    if (eventListeners != null && !eventListeners.isEmpty()) {
        for (EventListener eventListener : eventListeners) {
            if (!didWriteExtensionStartElement) {
                xtw.writeStartElement(ELEMENT_EXTENSIONS);
                didWriteExtensionStartElement = true;
            }//from   w w  w . ja v  a 2s .  c om

            xtw.writeStartElement(FLOWABLE_EXTENSIONS_PREFIX, ELEMENT_EVENT_LISTENER,
                    FLOWABLE_EXTENSIONS_NAMESPACE);
            BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_LISTENER_EVENTS, eventListener.getEvents(), xtw);
            BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_LISTENER_ENTITY_TYPE, eventListener.getEntityType(),
                    xtw);

            if (ImplementationType.IMPLEMENTATION_TYPE_CLASS.equals(eventListener.getImplementationType())) {
                BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_LISTENER_CLASS, eventListener.getImplementation(),
                        xtw);

            } else if (ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION
                    .equals(eventListener.getImplementationType())) {
                BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_LISTENER_DELEGATEEXPRESSION,
                        eventListener.getImplementation(), xtw);

            } else if (ImplementationType.IMPLEMENTATION_TYPE_THROW_SIGNAL_EVENT
                    .equals(eventListener.getImplementationType())) {
                BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_LISTENER_THROW_SIGNAL_EVENT_NAME,
                        eventListener.getImplementation(), xtw);
                BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_LISTENER_THROW_EVENT_TYPE,
                        ATTRIBUTE_LISTENER_THROW_EVENT_TYPE_SIGNAL, xtw);

            } else if (ImplementationType.IMPLEMENTATION_TYPE_THROW_GLOBAL_SIGNAL_EVENT
                    .equals(eventListener.getImplementationType())) {
                BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_LISTENER_THROW_SIGNAL_EVENT_NAME,
                        eventListener.getImplementation(), xtw);
                BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_LISTENER_THROW_EVENT_TYPE,
                        ATTRIBUTE_LISTENER_THROW_EVENT_TYPE_GLOBAL_SIGNAL, xtw);

            } else if (ImplementationType.IMPLEMENTATION_TYPE_THROW_MESSAGE_EVENT
                    .equals(eventListener.getImplementationType())) {
                BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_LISTENER_THROW_MESSAGE_EVENT_NAME,
                        eventListener.getImplementation(), xtw);
                BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_LISTENER_THROW_EVENT_TYPE,
                        ATTRIBUTE_LISTENER_THROW_EVENT_TYPE_MESSAGE, xtw);

            } else if (ImplementationType.IMPLEMENTATION_TYPE_THROW_ERROR_EVENT
                    .equals(eventListener.getImplementationType())) {
                BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_LISTENER_THROW_ERROR_EVENT_CODE,
                        eventListener.getImplementation(), xtw);
                BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_LISTENER_THROW_EVENT_TYPE,
                        ATTRIBUTE_LISTENER_THROW_EVENT_TYPE_ERROR, xtw);
            }

            xtw.writeEndElement();
        }
    }

    return didWriteExtensionStartElement;
}

From source file:org.flowable.bpmn.converter.export.FlowableListenerExport.java

private static boolean writeListeners(String xmlElementName, List<FlowableListener> listenerList,
        boolean didWriteExtensionStartElement, XMLStreamWriter xtw) throws Exception {
    if (listenerList != null) {

        for (FlowableListener listener : listenerList) {

            if (StringUtils.isNotEmpty(listener.getEvent())) {

                if (!didWriteExtensionStartElement) {
                    xtw.writeStartElement(ELEMENT_EXTENSIONS);
                    didWriteExtensionStartElement = true;
                }//ww  w  .  j a va 2s  . c om

                xtw.writeStartElement(FLOWABLE_EXTENSIONS_PREFIX, xmlElementName,
                        FLOWABLE_EXTENSIONS_NAMESPACE);
                BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_LISTENER_EVENT, listener.getEvent(), xtw);

                if (ImplementationType.IMPLEMENTATION_TYPE_CLASS.equals(listener.getImplementationType())) {
                    BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_LISTENER_CLASS, listener.getImplementation(),
                            xtw);
                } else if (ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION
                        .equals(listener.getImplementationType())) {
                    BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_LISTENER_EXPRESSION,
                            listener.getImplementation(), xtw);
                } else if (ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION
                        .equals(listener.getImplementationType())) {
                    BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_LISTENER_DELEGATEEXPRESSION,
                            listener.getImplementation(), xtw);
                }

                BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_LISTENER_ON_TRANSACTION,
                        listener.getOnTransaction(), xtw);

                if (ImplementationType.IMPLEMENTATION_TYPE_CLASS
                        .equals(listener.getCustomPropertiesResolverImplementationType())) {
                    BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_LISTENER_CUSTOM_PROPERTIES_RESOLVER_CLASS,
                            listener.getCustomPropertiesResolverImplementation(), xtw);
                } else if (ImplementationType.IMPLEMENTATION_TYPE_EXPRESSION
                        .equals(listener.getCustomPropertiesResolverImplementationType())) {
                    BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_LISTENER_CUSTOM_PROPERTIES_RESOLVER_EXPRESSION,
                            listener.getCustomPropertiesResolverImplementation(), xtw);
                } else if (ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION
                        .equals(listener.getCustomPropertiesResolverImplementationType())) {
                    BpmnXMLUtil.writeDefaultAttribute(
                            ATTRIBUTE_LISTENER_CUSTOM_PROPERTIES_RESOLVER_DELEGATEEXPRESSION,
                            listener.getCustomPropertiesResolverImplementation(), xtw);
                }

                FieldExtensionExport.writeFieldExtensions(listener.getFieldExtensions(), true, xtw);

                xtw.writeEndElement();
            }
        }
    }
    return didWriteExtensionStartElement;
}