Example usage for javax.xml.stream XMLStreamWriter writeStartElement

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

Introduction

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

Prototype

public void writeStartElement(String localName) throws XMLStreamException;

Source Link

Document

Writes a start tag to the output.

Usage

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  w  ww.  j  ava 2 s .  c om

                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;
            }/*w  w  w .  j  a  v a  2  s. co  m*/

            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;
                }//from   w  w  w.ja va 2  s . c o m

                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;
}

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

public static void writeLanes(Process process, XMLStreamWriter xtw) throws Exception {
    if (!process.getLanes().isEmpty()) {
        xtw.writeStartElement(ELEMENT_LANESET);
        xtw.writeAttribute(ATTRIBUTE_ID, "laneSet_" + process.getId());
        for (Lane lane : process.getLanes()) {
            xtw.writeStartElement(ELEMENT_LANE);
            xtw.writeAttribute(ATTRIBUTE_ID, lane.getId());

            if (StringUtils.isNotEmpty(lane.getName())) {
                xtw.writeAttribute(ATTRIBUTE_NAME, lane.getName());
            }/*from   w  w  w  .  j  a  v  a  2s.c  om*/

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

            for (String flowNodeRef : lane.getFlowReferences()) {
                xtw.writeStartElement(ELEMENT_FLOWNODE_REF);
                xtw.writeCharacters(flowNodeRef);
                xtw.writeEndElement();
            }

            xtw.writeEndElement();
        }
        xtw.writeEndElement();
    }
}

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

@SuppressWarnings("unchecked")
public static void writeProcess(Process process, XMLStreamWriter xtw) throws Exception {
    // start process element
    xtw.writeStartElement(ELEMENT_PROCESS);
    xtw.writeAttribute(ATTRIBUTE_ID, process.getId());

    if (StringUtils.isNotEmpty(process.getName())) {
        xtw.writeAttribute(ATTRIBUTE_NAME, process.getName());
    }/*from  ww w  .j a v a  2s.com*/

    xtw.writeAttribute(ATTRIBUTE_PROCESS_EXECUTABLE, Boolean.toString(process.isExecutable()));

    if (!process.getCandidateStarterUsers().isEmpty()) {
        xtw.writeAttribute(FLOWABLE_EXTENSIONS_PREFIX, FLOWABLE_EXTENSIONS_NAMESPACE,
                ATTRIBUTE_PROCESS_CANDIDATE_USERS,
                BpmnXMLUtil.convertToDelimitedString(process.getCandidateStarterUsers()));
    }

    if (!process.getCandidateStarterGroups().isEmpty()) {
        xtw.writeAttribute(FLOWABLE_EXTENSIONS_PREFIX, FLOWABLE_EXTENSIONS_NAMESPACE,
                ATTRIBUTE_PROCESS_CANDIDATE_GROUPS,
                BpmnXMLUtil.convertToDelimitedString(process.getCandidateStarterGroups()));
    }

    // write custom attributes
    BpmnXMLUtil.writeCustomAttributes(process.getAttributes().values(), xtw, defaultProcessAttributes);

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

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

    boolean didWriteExtensionStartElement = FlowableListenerExport.writeListeners(process, false, xtw);
    didWriteExtensionStartElement = BpmnXMLUtil.writeExtensionElements(process, didWriteExtensionStartElement,
            xtw);

    if (didWriteExtensionStartElement) {
        // closing extensions element
        xtw.writeEndElement();
    }

    LaneExport.writeLanes(process, xtw);
}

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

@Override
protected void writeAdditionalChildElements(BaseElement element, BpmnModel model, XMLStreamWriter xtw)
        throws Exception {
    ScriptTask scriptTask = (ScriptTask) element;
    if (StringUtils.isNotEmpty(scriptTask.getScript())) {
        xtw.writeStartElement(ATTRIBUTE_TASK_SCRIPT_TEXT);
        xtw.writeCData(scriptTask.getScript());
        xtw.writeEndElement();/*from  w  w w  .j  a  va  2  s. c  o  m*/
    }
}

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

@Override
protected boolean writeExtensionChildElements(BaseElement element, boolean didWriteExtensionStartElement,
        XMLStreamWriter xtw) throws Exception {
    ServiceTask serviceTask = (ServiceTask) element;

    if (!serviceTask.getCustomProperties().isEmpty()) {
        for (CustomProperty customProperty : serviceTask.getCustomProperties()) {

            if (StringUtils.isEmpty(customProperty.getSimpleValue())) {
                continue;
            }/*from  w ww. jav  a2s .c o  m*/

            if (didWriteExtensionStartElement == false) {
                xtw.writeStartElement(ELEMENT_EXTENSIONS);
                didWriteExtensionStartElement = true;
            }
            xtw.writeStartElement(FLOWABLE_EXTENSIONS_PREFIX, ELEMENT_FIELD, FLOWABLE_EXTENSIONS_NAMESPACE);
            xtw.writeAttribute(ATTRIBUTE_FIELD_NAME, customProperty.getName());
            if ((customProperty.getSimpleValue().contains("${")
                    || customProperty.getSimpleValue().contains("#{"))
                    && customProperty.getSimpleValue().contains("}")) {

                xtw.writeStartElement(FLOWABLE_EXTENSIONS_PREFIX, ATTRIBUTE_FIELD_EXPRESSION,
                        FLOWABLE_EXTENSIONS_NAMESPACE);
            } else {
                xtw.writeStartElement(FLOWABLE_EXTENSIONS_PREFIX, ELEMENT_FIELD_STRING,
                        FLOWABLE_EXTENSIONS_NAMESPACE);
            }
            xtw.writeCharacters(customProperty.getSimpleValue());
            xtw.writeEndElement();
            xtw.writeEndElement();
        }
    } else {
        didWriteExtensionStartElement = FieldExtensionExport
                .writeFieldExtensions(serviceTask.getFieldExtensions(), didWriteExtensionStartElement, xtw);
    }

    return didWriteExtensionStartElement;
}

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

@Override
protected boolean writeExtensionChildElements(BaseElement element, boolean didWriteExtensionStartElement,
        XMLStreamWriter xtw) throws Exception {
    UserTask userTask = (UserTask) element;
    didWriteExtensionStartElement = writeFormProperties(userTask, didWriteExtensionStartElement, xtw);
    didWriteExtensionStartElement = writeCustomIdentities(element, didWriteExtensionStartElement, xtw);
    if (!userTask.getCustomProperties().isEmpty()) {
        for (CustomProperty customProperty : userTask.getCustomProperties()) {

            if (StringUtils.isEmpty(customProperty.getSimpleValue())) {
                continue;
            }/*from w  w w.  j a va2  s.  c o m*/

            if (didWriteExtensionStartElement == false) {
                xtw.writeStartElement(ELEMENT_EXTENSIONS);
                didWriteExtensionStartElement = true;
            }
            xtw.writeStartElement(FLOWABLE_EXTENSIONS_PREFIX, customProperty.getName(),
                    FLOWABLE_EXTENSIONS_NAMESPACE);
            xtw.writeCharacters(customProperty.getSimpleValue());
            xtw.writeEndElement();
        }
    }
    return didWriteExtensionStartElement;
}

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

protected boolean writeCustomIdentities(BaseElement element, boolean didWriteExtensionStartElement,
        XMLStreamWriter xtw) throws Exception {
    UserTask userTask = (UserTask) element;
    if (userTask.getCustomUserIdentityLinks().isEmpty() && userTask.getCustomGroupIdentityLinks().isEmpty()) {
        return didWriteExtensionStartElement;
    }//  w w  w  .  j  av a2s .  c  om

    if (didWriteExtensionStartElement == false) {
        xtw.writeStartElement(ELEMENT_EXTENSIONS);
        didWriteExtensionStartElement = true;
    }
    Set<String> identityLinkTypes = new HashSet<String>();
    identityLinkTypes.addAll(userTask.getCustomUserIdentityLinks().keySet());
    identityLinkTypes.addAll(userTask.getCustomGroupIdentityLinks().keySet());
    for (String identityType : identityLinkTypes) {
        writeCustomIdentities(userTask, identityType, userTask.getCustomUserIdentityLinks().get(identityType),
                userTask.getCustomGroupIdentityLinks().get(identityType), xtw);
    }

    return didWriteExtensionStartElement;
}

From source file:org.flowable.cmmn.converter.export.AbstractPlanItemDefinitionExport.java

public static void writeCommonPlanItemDefinitionAttributes(PlanItemDefinition planItemDefinition,
        XMLStreamWriter xtw) throws Exception {
    xtw.writeAttribute(ATTRIBUTE_ID, planItemDefinition.getId());

    if (StringUtils.isNotEmpty(planItemDefinition.getName())) {
        xtw.writeAttribute(ATTRIBUTE_NAME, planItemDefinition.getName());
    }//  w  ww.  ja v  a  2 s.  c om

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

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