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.activiti.designer.export.srcm.export.MailTaskExport.java

private static void writeServiceMailTask(MailTask mailTask, XMLStreamWriter xtw) throws Exception {

    // start MailTask 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  a2s  . c o  m*/
    DefaultFlowExport.createDefaultFlow(mailTask, xtw);
    AsyncActivityExport.createDefaultFlow(mailTask, xtw);
    xtw.writeAttribute(ACTIVITI_EXTENSIONS_PREFIX, ACTIVITI_EXTENSIONS_NAMESPACE, "type", "mail");

    xtw.writeStartElement("extensionElements");
    ExtensionListenerExport.createExtensionListenerXML(mailTask.getActivitiListeners(), false,
            EXECUTION_LISTENER, xtw);

    if (mailTask.getTo() != null && mailTask.getTo().length() > 0) {
        writeField("to", mailTask.getTo(), xtw);
    }
    if (mailTask.getFrom() != null && mailTask.getFrom().length() > 0) {
        writeField("from", mailTask.getFrom(), xtw);
    }
    if (mailTask.getSubject() != null && mailTask.getSubject().length() > 0) {
        writeField("subject", mailTask.getSubject(), xtw);
    }
    if (mailTask.getCc() != null && mailTask.getCc().length() > 0) {
        writeField("cc", mailTask.getCc(), xtw);
    }
    if (mailTask.getBcc() != null && mailTask.getBcc().length() > 0) {
        writeField("bcc", mailTask.getBcc(), xtw);
    }
    if (mailTask.getHtml() != null && mailTask.getHtml().length() > 0) {
        writeCDataField("html", mailTask.getHtml(), xtw);
    }
    if (mailTask.getText() != null && mailTask.getText().length() > 0) {
        writeCDataField("text", mailTask.getText(), xtw);
    }
    xtw.writeEndElement();

    MultiInstanceExport.createMultiInstance(mailTask, xtw);

    // end MailTask element
    xtw.writeEndElement();

    if (mailTask.getBoundaryEventRefs().size() > 0) {
        for (BoundaryEvent event : mailTask.getBoundaryEventRefs()) {
            BoundaryEventExport.createBoundaryEvent(event, xtw);
        }
    }
}

From source file:org.activiti.designer.export.srcm.export.MultiInstanceExport.java

public static void createMultiInstance(EObject object, XMLStreamWriter xtw) throws Exception {
    Activity activity = (Activity) object;
    if (activity.getLoopCharacteristics() == null)
        return;/*from  ww  w .  j  a va 2s  .c om*/

    MultiInstanceLoopCharacteristics multiInstanceDef = (MultiInstanceLoopCharacteristics) activity
            .getLoopCharacteristics();

    if (StringUtils.isNotEmpty(multiInstanceDef.getInputDataItem())
            || StringUtils.isNotEmpty(multiInstanceDef.getLoopCardinality())
            || StringUtils.isNotEmpty(multiInstanceDef.getCompletionCondition())) {

        // start multiInstance element
        xtw.writeStartElement("multiInstanceLoopCharacteristics");
        xtw.writeAttribute("isSequential", "" + multiInstanceDef.isIsSequential());
        if (multiInstanceDef.getInputDataItem() != null && multiInstanceDef.getInputDataItem().contains("${")) {
            xtw.writeAttribute(ACTIVITI_EXTENSIONS_PREFIX, ACTIVITI_EXTENSIONS_NAMESPACE, "collection",
                    multiInstanceDef.getInputDataItem());
            if (multiInstanceDef.getElementVariable() != null
                    && multiInstanceDef.getElementVariable().length() > 0) {
                xtw.writeAttribute(ACTIVITI_EXTENSIONS_PREFIX, ACTIVITI_EXTENSIONS_NAMESPACE, "elementVariable",
                        multiInstanceDef.getElementVariable());
            }
        }
        if (StringUtils.isNotEmpty(multiInstanceDef.getLoopCardinality())) {
            xtw.writeStartElement("loopCardinality");
            xtw.writeCharacters(multiInstanceDef.getLoopCardinality());
            xtw.writeEndElement();
        }

        if (StringUtils.isNotEmpty(multiInstanceDef.getInputDataItem())
                && multiInstanceDef.getInputDataItem().contains("${") == false) {

            xtw.writeStartElement("loopDataInputRef");
            xtw.writeCharacters(multiInstanceDef.getInputDataItem());
            xtw.writeEndElement();

            if (StringUtils.isNotEmpty(multiInstanceDef.getElementVariable())) {
                xtw.writeStartElement("inputDataItem");
                xtw.writeAttribute("name", multiInstanceDef.getElementVariable());
                xtw.writeEndElement();
            }
        }

        if (StringUtils.isNotEmpty(multiInstanceDef.getCompletionCondition())) {
            xtw.writeStartElement("completionCondition");
            xtw.writeCharacters(multiInstanceDef.getCompletionCondition());
            xtw.writeEndElement();
        }

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

From source file:org.activiti.dmn.converter.util.DmnXMLUtil.java

public static void writeElementDescription(DmnElement dmnElement, XMLStreamWriter xtw) throws Exception {
    if (StringUtils.isNotEmpty(dmnElement.getDescription())
            && !"null".equalsIgnoreCase(dmnElement.getDescription())) {
        xtw.writeStartElement(ELEMENT_DESCRIPTION);
        xtw.writeCharacters(dmnElement.getDescription());
        xtw.writeEndElement();//from ww w . j  a  v a 2  s.  c om
    }
}

From source file:org.activiti.dmn.converter.util.DmnXMLUtil.java

public static boolean writeExtensionElements(DmnElement dmnElement, boolean didWriteExtensionStartElement,
        Map<String, String> namespaceMap, XMLStreamWriter xtw) throws Exception {
    if (!dmnElement.getExtensionElements().isEmpty()) {
        if (didWriteExtensionStartElement == false) {
            xtw.writeStartElement(ELEMENT_EXTENSIONS);
            didWriteExtensionStartElement = true;
        }/*from w ww . j  a v a  2s  .c o m*/

        if (namespaceMap == null) {
            namespaceMap = new HashMap<String, String>();
        }

        for (List<DmnExtensionElement> extensionElements : dmnElement.getExtensionElements().values()) {
            for (DmnExtensionElement extensionElement : extensionElements) {
                writeExtensionElement(extensionElement, namespaceMap, xtw);
            }
        }
    }
    return didWriteExtensionStartElement;
}

From source file:org.activiti.dmn.xml.converter.DmnXMLConverter.java

public byte[] convertToXML(DmnDefinition model, String encoding) {
    try {//ww  w  .j  av a2 s . com

        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

        XMLOutputFactory xof = XMLOutputFactory.newInstance();
        OutputStreamWriter out = new OutputStreamWriter(outputStream, encoding);

        XMLStreamWriter writer = xof.createXMLStreamWriter(out);
        XMLStreamWriter xtw = new IndentingXMLStreamWriter(writer);

        xtw.writeStartElement(ELEMENT_DEFINITIONS);
        xtw.writeDefaultNamespace(DMN_NAMESPACE);
        xtw.writeAttribute(ATTRIBUTE_ID, model.getId());
        if (StringUtils.isNotEmpty(model.getName())) {
            xtw.writeAttribute(ATTRIBUTE_NAME, model.getName());
        }
        xtw.writeAttribute(ATTRIBUTE_NAMESPACE, MODEL_NAMESPACE);

        DmnXMLUtil.writeElementDescription(model, xtw);
        DmnXMLUtil.writeExtensionElements(model, xtw);

        for (ItemDefinition itemDefinition : model.getItemDefinitions()) {
            xtw.writeStartElement(ELEMENT_ITEM_DEFINITION);
            xtw.writeAttribute(ATTRIBUTE_ID, itemDefinition.getId());
            if (StringUtils.isNotEmpty(itemDefinition.getName())) {
                xtw.writeAttribute(ATTRIBUTE_NAME, itemDefinition.getName());
            }

            DmnXMLUtil.writeElementDescription(itemDefinition, xtw);
            DmnXMLUtil.writeExtensionElements(itemDefinition, xtw);

            xtw.writeStartElement(ELEMENT_TYPE_DEFINITION);
            xtw.writeCharacters(itemDefinition.getTypeDefinition());
            xtw.writeEndElement();

            xtw.writeEndElement();
        }

        for (Decision decision : model.getDrgElements()) {
            xtw.writeStartElement(ELEMENT_DECISION);
            xtw.writeAttribute(ATTRIBUTE_ID, decision.getId());
            if (StringUtils.isNotEmpty(decision.getName())) {
                xtw.writeAttribute(ATTRIBUTE_NAME, decision.getName());
            }

            DmnXMLUtil.writeElementDescription(decision, xtw);
            DmnXMLUtil.writeExtensionElements(decision, xtw);

            DecisionTable decisionTable = decision.getDecisionTable();
            xtw.writeStartElement(ELEMENT_DECISION_TABLE);
            xtw.writeAttribute(ATTRIBUTE_ID, decisionTable.getId());

            if (decisionTable.getHitPolicy() != null) {
                xtw.writeAttribute(ATTRIBUTE_HIT_POLICY, decisionTable.getHitPolicy().toString());
            }

            DmnXMLUtil.writeElementDescription(decisionTable, xtw);
            DmnXMLUtil.writeExtensionElements(decisionTable, xtw);

            for (InputClause clause : decisionTable.getInputs()) {
                xtw.writeStartElement(ELEMENT_INPUT_CLAUSE);
                if (StringUtils.isNotEmpty(clause.getId())) {
                    xtw.writeAttribute(ATTRIBUTE_ID, clause.getId());
                }
                if (StringUtils.isNotEmpty(clause.getLabel())) {
                    xtw.writeAttribute(ATTRIBUTE_LABEL, clause.getLabel());
                }

                DmnXMLUtil.writeElementDescription(clause, xtw);
                DmnXMLUtil.writeExtensionElements(clause, xtw);

                if (clause.getInputExpression() != null) {
                    xtw.writeStartElement(ELEMENT_INPUT_EXPRESSION);
                    xtw.writeAttribute(ATTRIBUTE_ID, clause.getInputExpression().getId());

                    if (StringUtils.isNotEmpty(clause.getInputExpression().getTypeRef())) {
                        xtw.writeAttribute(ATTRIBUTE_TYPE_REF, clause.getInputExpression().getTypeRef());
                    }

                    if (StringUtils.isNotEmpty(clause.getInputExpression().getText())) {
                        xtw.writeStartElement(ELEMENT_TEXT);
                        xtw.writeCharacters(clause.getInputExpression().getText());
                        xtw.writeEndElement();
                    }

                    xtw.writeEndElement();
                }

                xtw.writeEndElement();
            }

            for (OutputClause clause : decisionTable.getOutputs()) {
                xtw.writeStartElement(ELEMENT_OUTPUT_CLAUSE);
                if (StringUtils.isNotEmpty(clause.getId())) {
                    xtw.writeAttribute(ATTRIBUTE_ID, clause.getId());
                }
                if (StringUtils.isNotEmpty(clause.getLabel())) {
                    xtw.writeAttribute(ATTRIBUTE_LABEL, clause.getLabel());
                }
                if (StringUtils.isNotEmpty(clause.getName())) {
                    xtw.writeAttribute(ATTRIBUTE_NAME, clause.getName());
                }
                if (StringUtils.isNotEmpty(clause.getTypeRef())) {
                    xtw.writeAttribute(ATTRIBUTE_TYPE_REF, clause.getTypeRef());
                }

                DmnXMLUtil.writeElementDescription(clause, xtw);
                DmnXMLUtil.writeExtensionElements(clause, xtw);

                xtw.writeEndElement();
            }

            for (DecisionRule rule : decisionTable.getRules()) {
                xtw.writeStartElement(ELEMENT_RULE);
                if (StringUtils.isNotEmpty(rule.getId())) {
                    xtw.writeAttribute(ATTRIBUTE_ID, rule.getId());
                }

                DmnXMLUtil.writeElementDescription(rule, xtw);
                DmnXMLUtil.writeExtensionElements(rule, xtw);

                for (RuleInputClauseContainer container : rule.getInputEntries()) {
                    xtw.writeStartElement(ELEMENT_INPUT_ENTRY);
                    xtw.writeAttribute(ATTRIBUTE_ID, container.getInputEntry().getId());

                    xtw.writeStartElement(ELEMENT_TEXT);
                    xtw.writeCharacters(container.getInputEntry().getText());
                    xtw.writeEndElement();

                    xtw.writeEndElement();
                }

                for (RuleOutputClauseContainer container : rule.getOutputEntries()) {
                    xtw.writeStartElement(ELEMENT_OUTPUT_ENTRY);
                    xtw.writeAttribute(ATTRIBUTE_ID, container.getOutputEntry().getId());

                    xtw.writeStartElement(ELEMENT_TEXT);
                    xtw.writeCharacters(container.getOutputEntry().getText());
                    xtw.writeEndElement();

                    xtw.writeEndElement();
                }

                xtw.writeEndElement();
            }

            xtw.writeEndElement();

            xtw.writeEndElement();
        }

        // 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 DmnXMLException("Error writing BPMN XML", e);
    }
}

From source file:org.apache.nifi.authorization.FileAccessPolicyProvider.java

@Override
public String getFingerprint() throws AuthorizationAccessException {
    final List<AccessPolicy> policies = new ArrayList<>(getAccessPolicies());
    Collections.sort(policies, Comparator.comparing(AccessPolicy::getIdentifier));

    XMLStreamWriter writer = null;
    final StringWriter out = new StringWriter();
    try {/*from  w  w w. ja  va 2  s . c om*/
        writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(out);
        writer.writeStartDocument();
        writer.writeStartElement("accessPolicies");

        for (AccessPolicy policy : policies) {
            writePolicy(writer, policy);
        }

        writer.writeEndElement();
        writer.writeEndDocument();
        writer.flush();
    } catch (XMLStreamException e) {
        throw new AuthorizationAccessException("Unable to generate fingerprint", e);
    } finally {
        if (writer != null) {
            try {
                writer.close();
            } catch (XMLStreamException e) {
                // nothing to do here
            }
        }
    }

    return out.toString();
}

From source file:org.apache.nifi.authorization.FileAccessPolicyProvider.java

private void writePolicy(final XMLStreamWriter writer, final AccessPolicy policy) throws XMLStreamException {
    // sort the users for the policy
    List<String> policyUsers = new ArrayList<>(policy.getUsers());
    Collections.sort(policyUsers);

    // sort the groups for this policy
    List<String> policyGroups = new ArrayList<>(policy.getGroups());
    Collections.sort(policyGroups);

    writer.writeStartElement(POLICY_ELEMENT);
    writer.writeAttribute(IDENTIFIER_ATTR, policy.getIdentifier());
    writer.writeAttribute(RESOURCE_ATTR, policy.getResource());
    writer.writeAttribute(ACTIONS_ATTR, policy.getAction().name());

    for (String policyUser : policyUsers) {
        writer.writeStartElement(POLICY_USER_ELEMENT);
        writer.writeAttribute(IDENTIFIER_ATTR, policyUser);
        writer.writeEndElement();/*w ww .j a  va  2  s . co  m*/
    }

    for (String policyGroup : policyGroups) {
        writer.writeStartElement(POLICY_GROUP_ELEMENT);
        writer.writeAttribute(IDENTIFIER_ATTR, policyGroup);
        writer.writeEndElement();
    }

    writer.writeEndElement();
}

From source file:org.apache.nifi.authorization.FileUserGroupProvider.java

@Override
public String getFingerprint() throws AuthorizationAccessException {
    final UserGroupHolder usersAndGroups = userGroupHolder.get();

    final List<User> users = new ArrayList<>(usersAndGroups.getAllUsers());
    Collections.sort(users, Comparator.comparing(User::getIdentifier));

    final List<Group> groups = new ArrayList<>(usersAndGroups.getAllGroups());
    Collections.sort(groups, Comparator.comparing(Group::getIdentifier));

    XMLStreamWriter writer = null;
    final StringWriter out = new StringWriter();
    try {/*  w  w w .jav  a 2  s  . com*/
        writer = XML_OUTPUT_FACTORY.createXMLStreamWriter(out);
        writer.writeStartDocument();
        writer.writeStartElement("tenants");

        for (User user : users) {
            writeUser(writer, user);
        }
        for (Group group : groups) {
            writeGroup(writer, group);
        }

        writer.writeEndElement();
        writer.writeEndDocument();
        writer.flush();
    } catch (XMLStreamException e) {
        throw new AuthorizationAccessException("Unable to generate fingerprint", e);
    } finally {
        if (writer != null) {
            try {
                writer.close();
            } catch (XMLStreamException e) {
                // nothing to do here
            }
        }
    }

    return out.toString();
}

From source file:org.apache.nifi.authorization.FileUserGroupProvider.java

private void writeUser(final XMLStreamWriter writer, final User user) throws XMLStreamException {
    writer.writeStartElement(USER_ELEMENT);
    writer.writeAttribute(IDENTIFIER_ATTR, user.getIdentifier());
    writer.writeAttribute(IDENTITY_ATTR, user.getIdentity());
    writer.writeEndElement();/*from   w w  w  . j  a v a2 s  . c  o  m*/
}

From source file:org.apache.nifi.authorization.FileUserGroupProvider.java

private void writeGroup(final XMLStreamWriter writer, final Group group) throws XMLStreamException {
    List<String> users = new ArrayList<>(group.getUsers());
    Collections.sort(users);/*from w  w w .  j  av  a  2  s  .c om*/

    writer.writeStartElement(GROUP_ELEMENT);
    writer.writeAttribute(IDENTIFIER_ATTR, group.getIdentifier());
    writer.writeAttribute(NAME_ATTR, group.getName());

    for (String user : users) {
        writer.writeStartElement(GROUP_USER_ELEMENT);
        writer.writeAttribute(IDENTIFIER_ATTR, user);
        writer.writeEndElement();
    }

    writer.writeEndElement();
}