Example usage for javax.xml.stream XMLStreamWriter writeCharacters

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

Introduction

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

Prototype

public void writeCharacters(String text) throws XMLStreamException;

Source Link

Document

Write text to the output

Usage

From source file:org.activiti.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;
                }/* ww w .  java  2 s .  co  m*/

                xtw.writeStartElement(ACTIVITI_EXTENSIONS_PREFIX, ELEMENT_FIELD, ACTIVITI_EXTENSIONS_NAMESPACE);
                BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_FIELD_NAME, fieldExtension.getFieldName(), xtw);

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

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

public static void writeLanes(Process process, XMLStreamWriter xtw) throws Exception {
    if (process.getLanes().size() > 0) {
        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   ww w.  jav  a2  s  .c  om*/

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

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

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

public static void writeMultiInstance(Activity activity, XMLStreamWriter xtw) throws Exception {
    if (activity.getLoopCharacteristics() != null) {
        MultiInstanceLoopCharacteristics multiInstanceObject = activity.getLoopCharacteristics();
        if (StringUtils.isNotEmpty(multiInstanceObject.getLoopCardinality())
                || StringUtils.isNotEmpty(multiInstanceObject.getInputDataItem())
                || StringUtils.isNotEmpty(multiInstanceObject.getCompletionCondition())) {

            xtw.writeStartElement(ELEMENT_MULTIINSTANCE);
            BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_MULTIINSTANCE_SEQUENTIAL,
                    String.valueOf(multiInstanceObject.isSequential()).toLowerCase(), xtw);
            if (StringUtils.isNotEmpty(multiInstanceObject.getInputDataItem())) {
                BpmnXMLUtil.writeQualifiedAttribute(ATTRIBUTE_MULTIINSTANCE_COLLECTION,
                        multiInstanceObject.getInputDataItem(), xtw);
            }/*from w w  w . jav a 2s .c om*/
            if (StringUtils.isNotEmpty(multiInstanceObject.getElementVariable())) {
                BpmnXMLUtil.writeQualifiedAttribute(ATTRIBUTE_MULTIINSTANCE_VARIABLE,
                        multiInstanceObject.getElementVariable(), xtw);
            }
            if (StringUtils.isNotEmpty(multiInstanceObject.getLoopCardinality())) {
                xtw.writeStartElement(ELEMENT_MULTIINSTANCE_CARDINALITY);
                xtw.writeCharacters(multiInstanceObject.getLoopCardinality());
                xtw.writeEndElement();
            }
            if (StringUtils.isNotEmpty(multiInstanceObject.getCompletionCondition())) {
                xtw.writeStartElement(ELEMENT_MULTIINSTANCE_CONDITION);
                xtw.writeCharacters(multiInstanceObject.getCompletionCondition());
                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 w  w. ja  v a  2s .  c o  m

    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.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.writeCharacters(scriptTask.getScript());
        xtw.writeEndElement();//from w w w . jav a2 s.  co m
    }
}

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;
            }/* w  w  w .ja va2s  .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.bpmn.converter.TextAnnotationXMLConverter.java

@Override
protected void writeAdditionalChildElements(BaseElement element, BpmnModel model, XMLStreamWriter xtw)
        throws Exception {
    TextAnnotation textAnnotation = (TextAnnotation) element;
    if (StringUtils.isNotEmpty(textAnnotation.getText())) {
        xtw.writeStartElement(ELEMENT_TEXT_ANNOTATION_TEXT);
        xtw.writeCharacters(textAnnotation.getText());
        xtw.writeEndElement();/*  w  w  w  .  j  av  a 2s.c  o m*/
    }
}

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());
        }/*w  ww  . jav a2s .  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.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 ww  w  .  j a v  a2  s .c  o m*/

            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.MailTaskExport.java

private static void writeAlfrescoScriptMailTask(AlfrescoMailTask mailTask, XMLStreamWriter xtw)
        throws Exception {

    // start AlfrescoMailTask element
    xtw.writeStartElement("serviceTask");
    xtw.writeAttribute("id", mailTask.getId());
    if (mailTask.getName() != null) {
        xtw.writeAttribute("name", mailTask.getName());
    }//from w w w .j  a v a2  s  .  c o  m
    xtw.writeAttribute(ACTIVITI_EXTENSIONS_PREFIX, ACTIVITI_EXTENSIONS_NAMESPACE, "class",
            "org.alfresco.repo.workflow.activiti.script.AlfrescoScriptDelegate");
    DefaultFlowExport.createDefaultFlow(mailTask, xtw);
    AsyncActivityExport.createAsyncAttribute(mailTask, xtw);

    xtw.writeStartElement("extensionElements");

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

    xtw.writeStartElement(ACTIVITI_EXTENSIONS_PREFIX, "field", ACTIVITI_EXTENSIONS_NAMESPACE);
    xtw.writeAttribute("name", "script");
    xtw.writeStartElement(ACTIVITI_EXTENSIONS_PREFIX, "string", ACTIVITI_EXTENSIONS_NAMESPACE);
    xtw.writeCharacters(createMailScript(mailTask));
    xtw.writeEndElement();
    xtw.writeEndElement();

    xtw.writeEndElement();

    MultiInstanceExport.createMultiInstance(mailTask, xtw);

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