Example usage for javax.xml.stream XMLStreamWriter writeAttribute

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

Introduction

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

Prototype

public void writeAttribute(String localName, String value) throws XMLStreamException;

Source Link

Document

Writes an attribute to the output stream without a prefix.

Usage

From source file:org.activiti.bpmn.converter.export.PoolExport.java

public static void writePools(BpmnModel model, XMLStreamWriter xtw) throws Exception {
    if (model.getPools().size() > 0) {
        xtw.writeStartElement(ELEMENT_COLLABORATION);
        xtw.writeAttribute(ATTRIBUTE_ID, "Collaboration");
        for (Pool pool : model.getPools()) {
            xtw.writeStartElement(ELEMENT_PARTICIPANT);
            xtw.writeAttribute(ATTRIBUTE_ID, pool.getId());
            if (StringUtils.isNotEmpty(pool.getName())) {
                xtw.writeAttribute(ATTRIBUTE_NAME, pool.getName());
            }/*from ww w.j av a 2s  . c  o m*/
            if (StringUtils.isNotEmpty(pool.getProcessRef())) {
                xtw.writeAttribute(ATTRIBUTE_PROCESS_REF, pool.getProcessRef());
            }
            xtw.writeEndElement();
        }
        xtw.writeEndElement();
    }
}

From source file:org.activiti.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());
    }//w  ww .ja  v  a 2 s  .c  om

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

    if (process.getCandidateStarterUsers().size() > 0) {
        xtw.writeAttribute(ACTIVITI_EXTENSIONS_PREFIX, ACTIVITI_EXTENSIONS_NAMESPACE,
                ATTRIBUTE_PROCESS_CANDIDATE_USERS,
                BpmnXMLUtil.convertToDelimitedString(process.getCandidateStarterUsers()));
    }

    if (process.getCandidateStarterGroups().size() > 0) {
        xtw.writeAttribute(ACTIVITI_EXTENSIONS_PREFIX, ACTIVITI_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 = ActivitiListenerExport.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.activiti.bpmn.converter.ServiceTaskXMLConverter.java

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

    if (serviceTask.getCustomProperties().size() > 0) {
        for (CustomProperty customProperty : serviceTask.getCustomProperties()) {

            if (StringUtils.isEmpty(customProperty.getSimpleValue())) {
                continue;
            }/*from  ww w.  jav a2 s.  com*/

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

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

    return didWriteExtensionStartElement;
}

From source file:org.activiti.designer.export.bpmn20.export.BoundaryEventExport.java

public static void createBoundaryEvent(Object object, XMLStreamWriter xtw) throws Exception {
    BoundaryEvent boundaryEvent = (BoundaryEvent) object;
    List<EventDefinition> eventDefinitionList = boundaryEvent.getEventDefinitions();
    if (eventDefinitionList.size() == 1) {

        xtw.writeStartElement("boundaryEvent");
        xtw.writeAttribute("id", boundaryEvent.getId());
        if (boundaryEvent.getName() != null) {
            xtw.writeAttribute("name", boundaryEvent.getName());
        }// www  .  j  a v a 2s  .  c o m
        if (boundaryEvent.isCancelActivity()) {
            xtw.writeAttribute("cancelActivity", "true");
        } else {
            xtw.writeAttribute("cancelActivity", "false");
        }

        if (boundaryEvent.getAttachedToRef() != null) {
            xtw.writeAttribute("attachedToRef", boundaryEvent.getAttachedToRef().getId());
        }

        if (eventDefinitionList.get(0) instanceof TimerEventDefinition) {
            TimerEventDefinition timerDef = (TimerEventDefinition) eventDefinitionList.get(0);

            xtw.writeStartElement("timerEventDefinition");

            if (StringUtils.isNotEmpty(timerDef.getTimeDuration())) {

                xtw.writeStartElement("timeDuration");
                xtw.writeCharacters(timerDef.getTimeDuration());
                xtw.writeEndElement();

            } else if (StringUtils.isNotEmpty(timerDef.getTimeDate())) {

                xtw.writeStartElement("timeDate");
                xtw.writeCharacters(timerDef.getTimeDate());
                xtw.writeEndElement();

            } else if (StringUtils.isNotEmpty(timerDef.getTimeCycle())) {

                xtw.writeStartElement("timeCycle");
                xtw.writeCharacters(timerDef.getTimeCycle());
                xtw.writeEndElement();
            }

            xtw.writeEndElement();

        } else if (eventDefinitionList.get(0) instanceof ErrorEventDefinition) {
            ErrorEventDefinition errorDef = (ErrorEventDefinition) eventDefinitionList.get(0);

            xtw.writeStartElement("errorEventDefinition");

            if (StringUtils.isNotEmpty(errorDef.getErrorCode())) {
                xtw.writeAttribute("errorRef", errorDef.getErrorCode());
            }

            xtw.writeEndElement();

        } else if (eventDefinitionList.get(0) instanceof SignalEventDefinition) {
            SignalEventDefinition signalDef = (SignalEventDefinition) eventDefinitionList.get(0);

            xtw.writeStartElement("signalEventDefinition");

            if (StringUtils.isNotEmpty(signalDef.getSignalRef())) {
                xtw.writeAttribute("signalRef", signalDef.getSignalRef());
            }

            xtw.writeEndElement();
        }

        xtw.writeEndElement();
    }
}

From source file:org.activiti.designer.export.bpmn20.export.CallActivityExport.java

public static void createCallActivity(Object object, XMLStreamWriter xtw) throws Exception {
    CallActivity callActivity = (CallActivity) object;

    // start CallActivity element
    xtw.writeStartElement("callActivity");
    xtw.writeAttribute("id", callActivity.getId());
    if (callActivity.getName() != null) {
        xtw.writeAttribute("name", callActivity.getName());
    }/*from ww w. j  a  va  2  s. co m*/

    DefaultFlowExport.createDefaultFlow(callActivity, xtw);
    AsyncActivityExport.createAsyncAttribute(callActivity, xtw);

    if (callActivity.getCalledElement() != null && callActivity.getCalledElement().length() > 0) {
        xtw.writeAttribute("calledElement", callActivity.getCalledElement());
    }

    if (callActivity.getExecutionListeners().size() > 0 || callActivity.getInParameters().size() > 0
            || callActivity.getOutParameters().size() > 0) {

        xtw.writeStartElement("extensionElements");
    }

    ExecutionListenerExport.createExecutionListenerXML(callActivity.getExecutionListeners(), false, xtw);

    if (callActivity.getInParameters().size() > 0 || callActivity.getOutParameters().size() > 0) {

        for (IOParameter parameter : callActivity.getInParameters()) {
            writeParameter(parameter, "in", xtw);
        }

        for (IOParameter parameter : callActivity.getOutParameters()) {
            writeParameter(parameter, "out", xtw);
        }
    }

    if (callActivity.getExecutionListeners().size() > 0 || callActivity.getInParameters().size() > 0
            || callActivity.getOutParameters().size() > 0) {

        xtw.writeEndElement();
    }

    MultiInstanceExport.createMultiInstance(object, xtw);

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

From source file:org.activiti.designer.export.bpmn20.export.CallActivityExport.java

private static void writeParameter(IOParameter parameter, String name, XMLStreamWriter xtw) throws Exception {
    xtw.writeStartElement(ACTIVITI_EXTENSIONS_PREFIX, name, ACTIVITI_EXTENSIONS_NAMESPACE);
    if (StringUtils.isNotEmpty(parameter.getSourceExpression())) {
        xtw.writeAttribute("sourceExpression", parameter.getSourceExpression());
    } else if (StringUtils.isNotEmpty(parameter.getSource())) {
        xtw.writeAttribute("source", parameter.getSource());
    }/*from   w ww .  jav  a  2s  .  co m*/
    if (StringUtils.isNotEmpty(parameter.getTargetExpression())) {
        xtw.writeAttribute("targetExpression", parameter.getTargetExpression());
    } else if (StringUtils.isNotEmpty(parameter.getTarget())) {
        xtw.writeAttribute("target", parameter.getTarget());
    }
    xtw.writeEndElement();
}

From source file:org.activiti.designer.export.bpmn20.export.DefaultFlowExport.java

public static void createDefaultFlow(FlowElement object, XMLStreamWriter xtw) throws Exception {
    String defaultFlow = null;/*  www  . j a v  a2s . co  m*/
    if (object instanceof Activity) {
        defaultFlow = ((Activity) object).getDefaultFlow();
    } else if (object instanceof Gateway) {
        defaultFlow = ((Gateway) object).getDefaultFlow();
    } else {
        throw new Exception("Invalid element for default flow.  Expected 'Activity', "
                + "'ExclusiveGateway', 'InclusiveGateway', but got: '" + object.getClass());
    }
    if (StringUtils.isNotEmpty(defaultFlow)) {
        xtw.writeAttribute("default", defaultFlow);
    }
}

From source file:org.activiti.designer.export.bpmn20.export.FormPropertiesExport.java

public static void createFormPropertiesXML(List<FormProperty> propertyList, XMLStreamWriter xtw)
        throws Exception {

    for (FormProperty formProperty : propertyList) {
        xtw.writeStartElement(ACTIVITI_EXTENSIONS_PREFIX, "formProperty", ACTIVITI_EXTENSIONS_NAMESPACE);
        xtw.writeAttribute("id", formProperty.getId());
        if (StringUtils.isNotEmpty(formProperty.getName())) {
            xtw.writeAttribute("name", formProperty.getName());
        }/*from   www  . ja v  a  2 s .co  m*/
        if (StringUtils.isNotEmpty(formProperty.getType())) {
            xtw.writeAttribute("type", formProperty.getType());
        }
        if (StringUtils.isNotEmpty(formProperty.getValue())) {
            xtw.writeAttribute("value", formProperty.getValue());
        }
        if (StringUtils.isNotEmpty(formProperty.getExpression())) {
            xtw.writeAttribute("expression", formProperty.getExpression());
        }
        if (StringUtils.isNotEmpty(formProperty.getVariable())) {
            xtw.writeAttribute("variable", formProperty.getVariable());
        }
        if (StringUtils.isNotEmpty(formProperty.getDefaultExpression())) {
            xtw.writeAttribute("default", formProperty.getDefaultExpression());
        }
        if (StringUtils.isNotEmpty(formProperty.getDatePattern())) {
            xtw.writeAttribute("datePattern", formProperty.getDatePattern());
        }
        if (formProperty.getRequired() != null) {
            xtw.writeAttribute("required", formProperty.getRequired().toString().toLowerCase());
        }
        if (formProperty.getReadable() != null) {
            xtw.writeAttribute("readable", formProperty.getReadable().toString().toLowerCase());
        }
        if (formProperty.getWriteable() != null) {
            xtw.writeAttribute("writable", formProperty.getWriteable().toString().toLowerCase());
        }

        if (formProperty.getFormValues().size() > 0) {
            for (FormValue formValue : formProperty.getFormValues()) {
                xtw.writeStartElement(ACTIVITI_EXTENSIONS_PREFIX, "value", ACTIVITI_EXTENSIONS_NAMESPACE);
                xtw.writeAttribute("id", formValue.getId());
                xtw.writeAttribute("name", formValue.getName());
                xtw.writeEndElement();
            }
        }

        xtw.writeEndElement();
    }
}

From source file:org.activiti.designer.export.bpmn20.export.IntermediateCatchEventExport.java

public static void createIntermediateEvent(Object object, XMLStreamWriter xtw) throws Exception {
    IntermediateCatchEvent catchEvent = (IntermediateCatchEvent) object;
    List<EventDefinition> eventDefinitionList = catchEvent.getEventDefinitions();
    if (eventDefinitionList.size() == 1) {
        if (eventDefinitionList.get(0) instanceof TimerEventDefinition) {
            TimerEventDefinition timerDef = (TimerEventDefinition) eventDefinitionList.get(0);
            // start TimerIntermediateCatchEvent element
            xtw.writeStartElement("intermediateCatchEvent");
            xtw.writeAttribute("id", catchEvent.getId());
            if (catchEvent.getName() != null) {
                xtw.writeAttribute("name", catchEvent.getName());
            }//from  w w w  . j a  v  a 2  s. com

            xtw.writeStartElement("timerEventDefinition");

            if (StringUtils.isNotEmpty(timerDef.getTimeDuration())) {

                xtw.writeStartElement("timeDuration");
                xtw.writeCharacters(timerDef.getTimeDuration());
                xtw.writeEndElement();

            } else if (StringUtils.isNotEmpty(timerDef.getTimeDate())) {

                xtw.writeStartElement("timeDate");
                xtw.writeCharacters(timerDef.getTimeDate());
                xtw.writeEndElement();

            } else if (StringUtils.isNotEmpty(timerDef.getTimeCycle())) {

                xtw.writeStartElement("timeCycle");
                xtw.writeCharacters(timerDef.getTimeCycle());
                xtw.writeEndElement();
            }

            xtw.writeEndElement();

            // end TimerIntermediateCatchEvent element
            xtw.writeEndElement();

        } else if (eventDefinitionList.get(0) instanceof SignalEventDefinition) {
            SignalEventDefinition signalDef = (SignalEventDefinition) eventDefinitionList.get(0);

            // start SignalIntermediateCatchEvent element
            xtw.writeStartElement("intermediateCatchEvent");
            xtw.writeAttribute("id", catchEvent.getId());
            if (catchEvent.getName() != null) {
                xtw.writeAttribute("name", catchEvent.getName());
            }

            xtw.writeStartElement("signalEventDefinition");

            if (StringUtils.isNotEmpty(signalDef.getSignalRef())) {
                xtw.writeAttribute("signalRef", signalDef.getSignalRef());
            }

            xtw.writeEndElement();

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

From source file:org.activiti.designer.export.bpmn20.export.IntermediateThrowEventExport.java

public static void createIntermediateEvent(Object object, XMLStreamWriter xtw) throws Exception {
    ThrowEvent throwEvent = (ThrowEvent) object;

    // start IntermediateThrowEvent element
    xtw.writeStartElement("intermediateThrowEvent");
    xtw.writeAttribute("id", throwEvent.getId());
    if (throwEvent.getName() != null) {
        xtw.writeAttribute("name", throwEvent.getName());
    }//from  w w  w. j  a  v  a  2s.  co  m

    List<EventDefinition> eventDefinitionList = throwEvent.getEventDefinitions();
    if (eventDefinitionList.size() == 1) {
        if (eventDefinitionList.get(0) instanceof SignalEventDefinition) {
            SignalEventDefinition signalDef = (SignalEventDefinition) eventDefinitionList.get(0);

            xtw.writeStartElement("signalEventDefinition");

            if (StringUtils.isNotEmpty(signalDef.getSignalRef())) {
                xtw.writeAttribute("signalRef", signalDef.getSignalRef());
            }

            xtw.writeEndElement();
        }
    }

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