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

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

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

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

public static void writeCommonTaskAttributes(XMLStreamWriter xtw, Task task) throws Exception {
    writeCommonPlanItemDefinitionAttributes(task, xtw);

    // Blocking/*w ww  .  j a v a2  s . c  o  m*/
    if (StringUtils.isEmpty(task.getBlockingExpression())) {
        if (!task.isBlocking()) { // if omitted, by default assumed true
            xtw.writeAttribute(ATTRIBUTE_IS_BLOCKING, "false");
        }
    } else {
        xtw.writeAttribute(ATTRIBUTE_IS_BLOCKING, "true");
    }

    // Async
    if (task.isAsync()) {
        xtw.writeAttribute(FLOWABLE_EXTENSIONS_PREFIX, FLOWABLE_EXTENSIONS_NAMESPACE, ATTRIBUTE_IS_ASYNCHRONOUS,
                String.valueOf(task.isAsync()));
    }
    if (task.isExclusive()) {
        xtw.writeAttribute(FLOWABLE_EXTENSIONS_PREFIX, FLOWABLE_EXTENSIONS_NAMESPACE, ATTRIBUTE_IS_EXCLUSIVE,
                String.valueOf(task.isAsync()));
    }
}

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

public static void writeCase(Case caseModel, XMLStreamWriter xtw) throws Exception {
    // start process element
    xtw.writeStartElement(ELEMENT_CASE);
    xtw.writeAttribute(ATTRIBUTE_ID, caseModel.getId());

    if (StringUtils.isNotEmpty(caseModel.getName())) {
        xtw.writeAttribute(ATTRIBUTE_NAME, caseModel.getName());
    }//  w w  w  .j  a va2s . com

    if (StringUtils.isNotEmpty(caseModel.getInitiatorVariableName())) {
        xtw.writeAttribute(FLOWABLE_EXTENSIONS_PREFIX, FLOWABLE_EXTENSIONS_NAMESPACE,
                ATTRIBUTE_INITIATOR_VARIABLE_NAME, caseModel.getInitiatorVariableName());
    }

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

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

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

public static void writeCaseTask(CaseTask caseTask, XMLStreamWriter xtw) throws Exception {
    // start case task element
    xtw.writeStartElement(ELEMENT_CASE_TASK);
    writeCommonTaskAttributes(xtw, caseTask);

    if (StringUtils.isNotEmpty(caseTask.getCaseRef())) {
        xtw.writeAttribute(ATTRIBUTE_CASE_REF, caseTask.getCaseRef());
    }/*  ww w  . ja  v  a  2s .c  om*/

    // end case task element
    xtw.writeEndElement();
}

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

public static void writeCriteriaElements(PlanItem planItem, XMLStreamWriter xtw) throws Exception {
    for (Criterion criterion : planItem.getEntryCriteria()) {
        // start entry criterion element
        xtw.writeStartElement(ELEMENT_ENTRY_CRITERION);
        xtw.writeAttribute(ATTRIBUTE_ID, criterion.getId());

        if (StringUtils.isNotEmpty(criterion.getName())) {
            xtw.writeAttribute(ATTRIBUTE_NAME, criterion.getName());
        }/*w w w. ja  v a  2  s .  c  o m*/

        if (StringUtils.isNotEmpty(criterion.getSentryRef())) {
            xtw.writeAttribute(ATTRIBUTE_SENTRY_REF, criterion.getSentryRef());
        }

        // end entry criterion element
        xtw.writeEndElement();
    }

    for (Criterion criterion : planItem.getExitCriteria()) {
        // start entry criterion element
        xtw.writeStartElement(ELEMENT_EXIT_CRITERION);
        xtw.writeAttribute(ATTRIBUTE_ID, criterion.getId());

        if (StringUtils.isNotEmpty(criterion.getName())) {
            xtw.writeAttribute(ATTRIBUTE_NAME, criterion.getName());
        }

        if (StringUtils.isNotEmpty(criterion.getSentryRef())) {
            xtw.writeAttribute(ATTRIBUTE_SENTRY_REF, criterion.getSentryRef());
        }

        // end entry criterion element
        xtw.writeEndElement();
    }
}

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

public static void writeRootElement(CmmnModel model, XMLStreamWriter xtw, String encoding) throws Exception {
    xtw.writeStartDocument(encoding, "1.0");

    // start definitions root element
    xtw.writeStartElement(ELEMENT_DEFINITIONS);
    xtw.setDefaultNamespace(CMMN_NAMESPACE);
    xtw.writeDefaultNamespace(CMMN_NAMESPACE);
    xtw.writeNamespace(XSI_PREFIX, XSI_NAMESPACE);
    xtw.writeNamespace(FLOWABLE_EXTENSIONS_PREFIX, FLOWABLE_EXTENSIONS_NAMESPACE);
    xtw.writeNamespace(CMMNDI_PREFIX, CMMNDI_NAMESPACE);
    xtw.writeNamespace(OMGDC_PREFIX, OMGDC_NAMESPACE);
    xtw.writeNamespace(OMGDI_PREFIX, OMGDI_NAMESPACE);
    for (String prefix : model.getNamespaces().keySet()) {
        if (!defaultNamespaces.contains(prefix) && StringUtils.isNotEmpty(prefix))
            xtw.writeNamespace(prefix, model.getNamespaces().get(prefix));
    }/* w  w w.jav  a2 s .c o m*/
    if (StringUtils.isNotEmpty(model.getTargetNamespace())) {
        xtw.writeAttribute(ATTRIBUTE_TARGET_NAMESPACE, model.getTargetNamespace());
    } else {
        xtw.writeAttribute(ATTRIBUTE_TARGET_NAMESPACE, CASE_NAMESPACE);
    }
}

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

public static boolean writeFieldExtensions(List<FieldExtension> fieldExtensions,
        boolean didWriteExtensionElement, XMLStreamWriter xtw) throws XMLStreamException {
    if (fieldExtensions.size() > 0) {
        if (!didWriteExtensionElement) {
            xtw.writeStartElement(CmmnXmlConstants.ELEMENT_EXTENSION_ELEMENTS);
            didWriteExtensionElement = true;
        }/*w  ww.  ja  v a 2s  . c om*/

        for (FieldExtension fieldExtension : fieldExtensions) {
            xtw.writeStartElement(CmmnXmlConstants.FLOWABLE_EXTENSIONS_PREFIX, CmmnXmlConstants.ELEMENT_FIELD,
                    CmmnXmlConstants.FLOWABLE_EXTENSIONS_NAMESPACE);
            xtw.writeAttribute(CmmnXmlConstants.ATTRIBUTE_NAME, fieldExtension.getFieldName());

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

    return didWriteExtensionElement;
}

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

public static void writePlanItem(PlanItem planItem, XMLStreamWriter xtw) throws Exception {
    // start plan item element
    xtw.writeStartElement(ELEMENT_PLAN_ITEM);
    xtw.writeAttribute(ATTRIBUTE_ID, planItem.getId());

    if (StringUtils.isNotEmpty(planItem.getName())) {
        xtw.writeAttribute(ATTRIBUTE_NAME, planItem.getName());
    }/*from w  w  w . j  ava  2 s  .  c  o  m*/

    if (StringUtils.isNotEmpty(planItem.getDefinitionRef())) {
        xtw.writeAttribute(ATTRIBUTE_DEFINITION_REF, planItem.getDefinitionRef());
    }

    if (StringUtils.isNotEmpty(planItem.getDocumentation())) {
        xtw.writeStartElement(ELEMENT_DOCUMENTATION);
        xtw.writeCharacters(planItem.getDocumentation());
        xtw.writeEndElement();
    }
    if (planItem.getItemControl() != null) {
        xtw.writeStartElement(ELEMENT_ITEM_CONTROL);
        RepetitionRule repetitionRule = planItem.getItemControl().getRepetitionRule();
        if (repetitionRule != null) {
            xtw.writeStartElement(ELEMENT_REPETITION_RULE);
            if (StringUtils.isNotEmpty(repetitionRule.getRepetitionCounterVariableName())) {
                xtw.writeAttribute(FLOWABLE_EXTENSIONS_PREFIX, FLOWABLE_EXTENSIONS_NAMESPACE,
                        ATTRIBUTE_REPETITION_COUNTER_VARIABLE_NAME,
                        repetitionRule.getRepetitionCounterVariableName());
            }
            if (StringUtils.isNotEmpty(repetitionRule.getCondition())) {
                xtw.writeStartElement(ELEMENT_CONDITION);
                xtw.writeCData(repetitionRule.getCondition());
                xtw.writeEndElement();
            }
            xtw.writeEndElement();
        }
        xtw.writeEndElement();
    }

    CriteriaExport.writeCriteriaElements(planItem, xtw);

    // end plan item element
    xtw.writeEndElement();
}

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

public static void writeSentry(Sentry sentry, XMLStreamWriter xtw) throws Exception {
    // start sentry element
    xtw.writeStartElement(ELEMENT_SENTRY);
    xtw.writeAttribute(ATTRIBUTE_ID, sentry.getId());

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

    for (SentryOnPart sentryOnPart : sentry.getOnParts()) {
        // start sentry on part element
        xtw.writeStartElement(ELEMENT_PLAN_ITEM_ON_PART);

        xtw.writeAttribute(ATTRIBUTE_ID, sentryOnPart.getId());
        xtw.writeAttribute(ATTRIBUTE_SOURCE_REF, sentryOnPart.getSourceRef());

        // start standard event element
        xtw.writeStartElement(ELEMENT_STANDARD_EVENT);
        xtw.writeCharacters(sentryOnPart.getStandardEvent());
        xtw.writeEndElement();

        // end sentry on part element
        xtw.writeEndElement();
    }

    // If part
    if (sentry.getSentryIfPart() != null) {
        xtw.writeStartElement(ELEMENT_IF_PART);
        xtw.writeStartElement(ELEMENT_CONDITION);
        xtw.writeCData(sentry.getSentryIfPart().getCondition());
        xtw.writeEndElement();
        xtw.writeEndElement();
    }

    // end plan item element
    xtw.writeEndElement();
}

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

public static void writeExtensions(TaskWithFieldExtensions task, XMLStreamWriter xtw)
        throws XMLStreamException {
    if (task.getFieldExtensions().size() > 0) {
        xtw.writeStartElement(ELEMENT_EXTENSIONS);

        for (FieldExtension fieldExtension : task.getFieldExtensions()) {
            xtw.writeStartElement(FLOWABLE_EXTENSIONS_PREFIX, ELEMENT_FIELD, FLOWABLE_EXTENSIONS_NAMESPACE);
            xtw.writeAttribute(ATTRIBUTE_NAME, fieldExtension.getFieldName());

            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());
            }//from  w w  w .  j  a v  a2  s . com
            xtw.writeEndElement();
            xtw.writeEndElement();
        }

        xtw.writeEndElement();
    }
}