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.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  ww  w.  j a  v  a  2 s .co 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;// ww  w.  j ava  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 writeDefaultAttribute(String attributeName, String value, XMLStreamWriter xtw)
        throws Exception {
    if (StringUtils.isNotEmpty(value) && "null".equalsIgnoreCase(value) == false) {
        xtw.writeAttribute(attributeName, value);
    }/*w w  w. j a v  a  2 s  . c  om*/
}

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

public byte[] convertToXML(DmnDefinition model, String encoding) {
    try {/*from  w w  w  .ja 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);

        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.chemistry.opencmis.server.impl.atompub.AtomDocumentBase.java

/**
 * Writes an Atom collection./* ww  w.j  a  v a2s. c o m*/
 */
public void writeCollection(String href, String collectionType, String text, String... accept)
        throws XMLStreamException {
    XMLStreamWriter xsw = getWriter();

    xsw.writeStartElement(Constants.NAMESPACE_APP, "collection");
    xsw.writeAttribute("href", href);

    if (collectionType != null) {
        xsw.writeStartElement(Constants.NAMESPACE_RESTATOM, "collectionType");
        xsw.writeCharacters(collectionType);
        xsw.writeEndElement();
    }

    xsw.writeStartElement(Constants.NAMESPACE_ATOM, "title");
    xsw.writeAttribute("type", "text");
    xsw.writeCharacters(text);
    xsw.writeEndElement();

    for (String ct : accept) {
        xsw.writeStartElement(Constants.NAMESPACE_APP, "accept");
        xsw.writeCharacters(ct);
        xsw.writeEndElement();
    }

    xsw.writeEndElement();
}

From source file:org.apache.chemistry.opencmis.server.impl.atompub.AtomDocumentBase.java

/**
 * Writes a link./*from w  w  w .  j a v  a  2 s  .c  o  m*/
 */
public void writeLink(String rel, String href, String type, String id) throws XMLStreamException {
    XMLStreamWriter xsw = getWriter();

    xsw.writeStartElement(Constants.NAMESPACE_ATOM, "link");

    xsw.writeAttribute("rel", rel);
    xsw.writeAttribute("href", href);

    if (type != null) {
        xsw.writeAttribute("type", type);
    }

    if (id != null) {
        xsw.writeAttribute(Constants.NAMESPACE_RESTATOM, "id", id);
    }

    xsw.writeEndElement();
}

From source file:org.apache.chemistry.opencmis.server.impl.atompub.AtomDocumentBase.java

public void writeAlternateLink(String href, String type, String kind, String title, BigInteger length)
        throws XMLStreamException {
    XMLStreamWriter xsw = getWriter();

    xsw.writeStartElement(Constants.NAMESPACE_ATOM, "link");

    xsw.writeAttribute("rel", Constants.REL_ALTERNATE);
    xsw.writeAttribute("href", href);

    if (type != null) {
        xsw.writeAttribute("type", type);
    }/*from   w ww .j  a v  a  2s  .c o m*/

    if (kind != null) {
        xsw.writeAttribute(Constants.NAMESPACE_RESTATOM, "renditionKind", kind);
    }

    if (title != null) {
        xsw.writeAttribute("title", title);
    }

    if (length != null) {
        xsw.writeAttribute("length", length.toString());
    }

    xsw.writeEndElement();
}

From source file:org.apache.flex.compiler.config.Configuration.java

/**
 * Write information about the compiler that compiled the swf.
 * //from  w  w  w  .  j ava2  s .  co m
 * @param writer
 * @throws XMLStreamException
 */
private void writeCompiledBy(XMLStreamWriter writer) throws XMLStreamException {
    writer.writeEmptyElement(VersionInfo.COMPILER_NAMESPACE_URI, VersionInfo.COMPILER_ELEMENT);
    writer.writeAttribute(VersionInfo.COMPILER_NAME_ATTRIBUTE, VersionInfo.getCompilerName());
    writer.writeAttribute(VersionInfo.COMPILER_VERSION_ATTRIBUTE, VersionInfo.getCompilerVersion());
    writer.writeAttribute(VersionInfo.COMPILER_BUILD_ATTRIBUTE, VersionInfo.getCompilerBuild());

    writer.writeEndElement(); // compiledBy
}

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();/*from  ww  w.  j  ava 2  s . c  om*/
    }

    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

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   ww  w .  j a  v a  2 s . co m
}