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:nz.co.jsrsolutions.ds3.test.RetrieveTestData.java

private static void serializeQuotes(EodDataProvider eodDataProvider, XMLStreamWriter writer) {

    try {//  w ww  .  j ava 2 s . c  o m
        writer.writeStartElement(XML_NAMESPACE_URI, QUOTES_LOCALNAME);
        writer.writeAttribute(XML_NAMESPACE_URI, TESTEXCHANGE_ATTRNAME, TEST_EXCHANGE);
        writer.writeAttribute(XML_NAMESPACE_URI, TESTSYMBOL_ATTRNAME, TEST_SYMBOL);
        writer.writeCharacters(NEWLINE);

        Calendar startCalendar = Calendar.getInstance();
        startCalendar.add(Calendar.YEAR, HISTORY_YEAR_OFFSET);
        //    startCalendar.add(Calendar.MONTH, HISTORY_MONTH_OFFSET);

        Calendar endCalendar = Calendar.getInstance();

        serialize(eodDataProvider.getQuotes(TEST_EXCHANGE, TEST_SYMBOL, startCalendar, endCalendar,
                DEFAULT_FREQUENCY), QUOTE_QNAME, writer);
        writer.writeEndElement();
        writer.writeCharacters(NEWLINE);
    } catch (XMLStreamException xse) {
        logger.error(xse.toString());
        logger.error(xse);
    } catch (EodDataProviderException edpe) {

        logger.error(edpe.toString());
        logger.error(edpe);

    } finally {

        if (eodDataProvider != null) {

            // eodDataProvider.close();

        }

    }

}

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

public void convertToXML(XMLStreamWriter xtw, BaseElement baseElement, BpmnModel model) throws Exception {
    xtw.writeStartElement(getXMLElementName());
    boolean didWriteExtensionStartElement = false;
    writeDefaultAttribute(ATTRIBUTE_ID, baseElement.getId(), xtw);
    if (baseElement instanceof FlowElement) {
        writeDefaultAttribute(ATTRIBUTE_NAME, ((FlowElement) baseElement).getName(), xtw);
    }//  ww  w  .  java 2s  .  c o  m

    if (baseElement instanceof Activity) {
        final Activity activity = (Activity) baseElement;
        if (activity.isAsynchronous()) {
            writeQualifiedAttribute(ATTRIBUTE_ACTIVITY_ASYNCHRONOUS, ATTRIBUTE_VALUE_TRUE, xtw);
            if (activity.isNotExclusive()) {
                writeQualifiedAttribute(ATTRIBUTE_ACTIVITY_EXCLUSIVE, ATTRIBUTE_VALUE_FALSE, xtw);
            }
        }
        if (activity.isForCompensation()) {
            writeDefaultAttribute(ATTRIBUTE_ACTIVITY_ISFORCOMPENSATION, ATTRIBUTE_VALUE_TRUE, xtw);
        }
        if (StringUtils.isNotEmpty(activity.getDefaultFlow())) {
            FlowElement defaultFlowElement = model.getFlowElement(activity.getDefaultFlow());
            if (defaultFlowElement instanceof SequenceFlow) {
                writeDefaultAttribute(ATTRIBUTE_DEFAULT, activity.getDefaultFlow(), xtw);
            }
        }
    }

    if (baseElement instanceof Gateway) {
        final Gateway gateway = (Gateway) baseElement;
        if (gateway.isAsynchronous()) {
            writeQualifiedAttribute(ATTRIBUTE_ACTIVITY_ASYNCHRONOUS, ATTRIBUTE_VALUE_TRUE, xtw);
            if (gateway.isNotExclusive()) {
                writeQualifiedAttribute(ATTRIBUTE_ACTIVITY_EXCLUSIVE, ATTRIBUTE_VALUE_FALSE, xtw);
            }
        }
        if (StringUtils.isNotEmpty(gateway.getDefaultFlow())) {
            FlowElement defaultFlowElement = model.getFlowElement(gateway.getDefaultFlow());
            if (defaultFlowElement instanceof SequenceFlow) {
                writeDefaultAttribute(ATTRIBUTE_DEFAULT, gateway.getDefaultFlow(), xtw);
            }
        }
    }

    writeAdditionalAttributes(baseElement, model, xtw);

    if (baseElement instanceof FlowElement) {
        final FlowElement flowElement = (FlowElement) baseElement;
        if (StringUtils.isNotEmpty(flowElement.getDocumentation())) {

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

    didWriteExtensionStartElement = writeExtensionChildElements(baseElement, didWriteExtensionStartElement,
            xtw);
    didWriteExtensionStartElement = writeListeners(baseElement, didWriteExtensionStartElement, xtw);
    didWriteExtensionStartElement = BpmnXMLUtil.writeExtensionElements(baseElement,
            didWriteExtensionStartElement, model.getNamespaces(), xtw);
    if (baseElement instanceof Activity) {
        final Activity activity = (Activity) baseElement;
        FailedJobRetryCountExport.writeFailedJobRetryCount(activity, xtw);

    }

    if (didWriteExtensionStartElement) {
        xtw.writeEndElement();
    }

    if (baseElement instanceof Activity) {
        final Activity activity = (Activity) baseElement;
        MultiInstanceExport.writeMultiInstance(activity, xtw);

    }

    writeAdditionalChildElements(baseElement, model, xtw);

    xtw.writeEndElement();
}

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

protected boolean writeFormProperties(FlowElement flowElement, boolean didWriteExtensionStartElement,
        XMLStreamWriter xtw) throws Exception {

    List<FormProperty> propertyList = null;
    if (flowElement instanceof UserTask) {
        propertyList = ((UserTask) flowElement).getFormProperties();
    } else if (flowElement instanceof StartEvent) {
        propertyList = ((StartEvent) flowElement).getFormProperties();
    }//from  www  .  j  av  a  2  s.  c  o m

    if (propertyList != null) {

        for (FormProperty property : propertyList) {

            if (StringUtils.isNotEmpty(property.getId())) {

                if (didWriteExtensionStartElement == false) {
                    xtw.writeStartElement(ELEMENT_EXTENSIONS);
                    didWriteExtensionStartElement = true;
                }

                xtw.writeStartElement(ACTIVITI_EXTENSIONS_PREFIX, ELEMENT_FORMPROPERTY,
                        ACTIVITI_EXTENSIONS_NAMESPACE);
                writeDefaultAttribute(ATTRIBUTE_FORM_ID, property.getId(), xtw);

                writeDefaultAttribute(ATTRIBUTE_FORM_NAME, property.getName(), xtw);
                writeDefaultAttribute(ATTRIBUTE_FORM_TYPE, property.getType(), xtw);
                writeDefaultAttribute(ATTRIBUTE_FORM_EXPRESSION, property.getExpression(), xtw);
                writeDefaultAttribute(ATTRIBUTE_FORM_VARIABLE, property.getVariable(), xtw);
                writeDefaultAttribute(ATTRIBUTE_FORM_DEFAULT, property.getDefaultExpression(), xtw);
                writeDefaultAttribute(ATTRIBUTE_FORM_DATEPATTERN, property.getDatePattern(), xtw);
                if (property.isReadable() == false) {
                    writeDefaultAttribute(ATTRIBUTE_FORM_READABLE, ATTRIBUTE_VALUE_FALSE, xtw);
                }
                if (property.isWriteable() == false) {
                    writeDefaultAttribute(ATTRIBUTE_FORM_WRITABLE, ATTRIBUTE_VALUE_FALSE, xtw);
                }
                if (property.isRequired()) {
                    writeDefaultAttribute(ATTRIBUTE_FORM_REQUIRED, ATTRIBUTE_VALUE_TRUE, xtw);
                }

                for (FormValue formValue : property.getFormValues()) {
                    if (StringUtils.isNotEmpty(formValue.getId())) {
                        xtw.writeStartElement(ACTIVITI_EXTENSIONS_PREFIX, ELEMENT_VALUE,
                                ACTIVITI_EXTENSIONS_NAMESPACE);
                        xtw.writeAttribute(ATTRIBUTE_ID, formValue.getId());
                        xtw.writeAttribute(ATTRIBUTE_NAME, formValue.getName());
                        xtw.writeEndElement();
                    }
                }

                xtw.writeEndElement();
            }
        }
    }

    return didWriteExtensionStartElement;
}

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

protected void writeTimerDefinition(Event parentEvent, TimerEventDefinition timerDefinition,
        XMLStreamWriter xtw) throws Exception {
    xtw.writeStartElement(ELEMENT_EVENT_TIMERDEFINITION);
    boolean didWriteExtensionStartElement = BpmnXMLUtil.writeExtensionElements(timerDefinition, false, xtw);
    if (didWriteExtensionStartElement) {
        xtw.writeEndElement();
    }/*  ww w  .ja va2  s . c o m*/
    if (StringUtils.isNotEmpty(timerDefinition.getTimeDate())) {
        xtw.writeStartElement(ATTRIBUTE_TIMER_DATE);
        xtw.writeCharacters(timerDefinition.getTimeDate());
        xtw.writeEndElement();

    } else if (StringUtils.isNotEmpty(timerDefinition.getTimeCycle())) {
        xtw.writeStartElement(ATTRIBUTE_TIMER_CYCLE);
        xtw.writeCharacters(timerDefinition.getTimeCycle());
        xtw.writeEndElement();

    } else if (StringUtils.isNotEmpty(timerDefinition.getTimeDuration())) {
        xtw.writeStartElement(ATTRIBUTE_TIMER_DURATION);
        xtw.writeCharacters(timerDefinition.getTimeDuration());
        xtw.writeEndElement();
    }

    xtw.writeEndElement();
}

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

protected void writeSignalDefinition(Event parentEvent, SignalEventDefinition signalDefinition,
        XMLStreamWriter xtw) throws Exception {
    xtw.writeStartElement(ELEMENT_EVENT_SIGNALDEFINITION);
    writeDefaultAttribute(ATTRIBUTE_SIGNAL_REF, signalDefinition.getSignalRef(), xtw);
    if (parentEvent instanceof ThrowEvent && signalDefinition.isAsync()) {
        BpmnXMLUtil.writeQualifiedAttribute(ATTRIBUTE_ACTIVITY_ASYNCHRONOUS, "true", xtw);
    }//from   ww w . java2  s.c  o m
    boolean didWriteExtensionStartElement = BpmnXMLUtil.writeExtensionElements(signalDefinition, false, xtw);
    if (didWriteExtensionStartElement) {
        xtw.writeEndElement();
    }
    xtw.writeEndElement();
}

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

protected void writeCompensateDefinition(Event parentEvent, CompensateEventDefinition compensateEventDefinition,
        XMLStreamWriter xtw) throws Exception {
    xtw.writeStartElement(ELEMENT_EVENT_COMPENSATEDEFINITION);
    writeDefaultAttribute(ATTRIBUTE_COMPENSATE_ACTIVITYREF, compensateEventDefinition.getActivityRef(), xtw);
    boolean didWriteExtensionStartElement = BpmnXMLUtil.writeExtensionElements(compensateEventDefinition, false,
            xtw);/*w w  w. ja  v a2  s.  c  o m*/
    if (didWriteExtensionStartElement) {
        xtw.writeEndElement();
    }
    xtw.writeEndElement();
}

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

protected void writeMessageDefinition(Event parentEvent, MessageEventDefinition messageDefinition,
        BpmnModel model, XMLStreamWriter xtw) throws Exception {
    xtw.writeStartElement(ELEMENT_EVENT_MESSAGEDEFINITION);

    String messageRef = messageDefinition.getMessageRef();
    if (StringUtils.isNotEmpty(messageRef)) {
        // remove the namespace from the message id if set
        if (messageRef.startsWith(model.getTargetNamespace())) {
            messageRef = messageRef.replace(model.getTargetNamespace(), "");
            messageRef = messageRef.replaceFirst(":", "");
        } else {/*from  w  ww  . j  a va  2 s  .c  o  m*/
            for (String prefix : model.getNamespaces().keySet()) {
                String namespace = model.getNamespace(prefix);
                if (messageRef.startsWith(namespace)) {
                    messageRef = messageRef.replace(model.getTargetNamespace(), "");
                    messageRef = prefix + messageRef;
                }
            }
        }
    }
    writeDefaultAttribute(ATTRIBUTE_MESSAGE_REF, messageRef, xtw);
    boolean didWriteExtensionStartElement = BpmnXMLUtil.writeExtensionElements(messageDefinition, false, xtw);
    if (didWriteExtensionStartElement) {
        xtw.writeEndElement();
    }
    xtw.writeEndElement();
}

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

protected void writeErrorDefinition(Event parentEvent, ErrorEventDefinition errorDefinition,
        XMLStreamWriter xtw) throws Exception {
    xtw.writeStartElement(ELEMENT_EVENT_ERRORDEFINITION);
    writeDefaultAttribute(ATTRIBUTE_ERROR_REF, errorDefinition.getErrorCode(), xtw);
    boolean didWriteExtensionStartElement = BpmnXMLUtil.writeExtensionElements(errorDefinition, false, xtw);
    if (didWriteExtensionStartElement) {
        xtw.writeEndElement();
    }//from ww  w  .  j  a v  a  2 s  .  c  o m
    xtw.writeEndElement();
}

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

protected void writeTerminateDefinition(Event parentEvent, TerminateEventDefinition terminateDefinition,
        XMLStreamWriter xtw) throws Exception {
    xtw.writeStartElement(ELEMENT_EVENT_TERMINATEDEFINITION);
    boolean didWriteExtensionStartElement = BpmnXMLUtil.writeExtensionElements(terminateDefinition, false, xtw);
    if (didWriteExtensionStartElement) {
        xtw.writeEndElement();
    }//w ww.j a v a  2s  .com
    xtw.writeEndElement();
}

From source file:org.activiti.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);
        SignalAndMessageDefinitionExport.writeSignalsAndMessages(model, xtw);
        PoolExport.writePools(model, xtw);

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

            if (process.getFlowElements().size() == 0 && process.getLanes().size() == 0) {
                // 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);
    }
}