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:nl.nn.adapterframework.soap.Wsdl.java

protected void jmsService(XMLStreamWriter w, JmsListener listener, String namePrefix)
        throws XMLStreamException, NamingException {
    w.writeStartElement(WSDL_NAMESPACE, "service");
    w.writeAttribute("name", "Service_" + WsdlUtils.getNCName(getName()));
    {// w w w .j a v  a 2s.  c o  m
        if (!esbSoap) {
            // Per example of https://docs.jboss.org/author/display/JBWS/SOAP+over+JMS
            w.writeStartElement(SOAP_JMS_NAMESPACE, "jndiConnectionFactoryName");
            w.writeCharacters(listener.getQueueConnectionFactoryName());
        }
        w.writeStartElement(WSDL_NAMESPACE, "port");
        w.writeAttribute("name", namePrefix + "Port_" + WsdlUtils.getNCName(getName()));
        w.writeAttribute("binding",
                getTargetNamespacePrefix() + ":" + namePrefix + "Binding_" + WsdlUtils.getNCName(getName()));
        {
            w.writeEmptyElement(soapNamespace, "address");
            String destinationName = listener.getDestinationName();
            if (destinationName != null) {
                w.writeAttribute("location", getLocation(destinationName));
            }
            if (esbSoap) {
                writeEsbSoapJndiContext(w, listener);
                w.writeStartElement(ESB_SOAP_JMS_NAMESPACE, "connectionFactory");
                {
                    w.writeCharacters("externalJndiName-for-" + listener.getQueueConnectionFactoryName()
                            + "-on-" + AppConstants.getInstance().getResolvedProperty("otap.stage"));
                    w.writeEndElement();
                }
                w.writeStartElement(ESB_SOAP_JMS_NAMESPACE, "targetAddress");
                {
                    w.writeAttribute("destination", listener.getDestinationType().toLowerCase());
                    String queueName = listener.getPhysicalDestinationShortName();
                    if (queueName == null) {
                        queueName = "queueName-for-" + listener.getDestinationName() + "-on-"
                                + AppConstants.getInstance().getResolvedProperty("otap.stage");
                    }
                    w.writeCharacters(queueName);
                    w.writeEndElement();
                }
            }
        }
        w.writeEndElement();
    }
    w.writeEndElement();
}

From source file:nl.nn.adapterframework.soap.Wsdl.java

protected void writeEsbSoapJndiContext(XMLStreamWriter w, JmsListener listener)
        throws XMLStreamException, NamingException {
    w.writeStartElement(ESB_SOAP_JNDI_NAMESPACE, "context");
    {// ww  w  . j av a 2s  .c  o m
        w.writeStartElement(ESB_SOAP_JNDI_NAMESPACE, "property");
        {
            w.writeAttribute("name", "java.naming.factory.initial");
            w.writeAttribute("type", "java.lang.String");
            w.writeCharacters("com.tibco.tibjms.naming.TibjmsInitialContextFactory");
            w.writeEndElement();
        }
        w.writeStartElement(ESB_SOAP_JNDI_NAMESPACE, "property");
        {
            w.writeAttribute("name", "java.naming.provider.url");
            w.writeAttribute("type", "java.lang.String");
            String qcf = listener.getQueueConnectionFactoryName();
            if (StringUtils.isEmpty(qcf)) {
                warn("Attribute queueConnectionFactoryName empty for listener '" + listener.getName() + "'");
            } else {
                try {
                    qcf = URLEncoder.encode(qcf, "UTF-8");
                } catch (UnsupportedEncodingException e) {
                    warn("Could not encode queueConnectionFactoryName for listener '" + listener.getName()
                            + "'");
                }
            }
            String stage = AppConstants.getInstance().getResolvedProperty("otap.stage");
            if (StringUtils.isEmpty(stage)) {
                warn("Property otap.stage empty");
            } else {
                try {
                    stage = URLEncoder.encode(stage, "UTF-8");
                } catch (UnsupportedEncodingException e) {
                    warn("Could not encode property otap.stage");
                }
            }
            w.writeCharacters("tibjmsnaming://host-for-" + qcf + "-on-" + stage + ":37222");
            w.writeEndElement();
        }
        w.writeStartElement(ESB_SOAP_JNDI_NAMESPACE, "property");
        {
            w.writeAttribute("name", "java.naming.factory.object");
            w.writeAttribute("type", "java.lang.String");
            w.writeCharacters("com.tibco.tibjms.custom.CustomObjectFactory");
            w.writeEndElement();
        }
    }
    w.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();
    }/*www  .  j a  v a2s .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.BpmnXMLConverter.java

private void createXML(FlowElement flowElement, BpmnModel model, XMLStreamWriter xtw) throws Exception {

    if (flowElement instanceof SubProcess) {

        SubProcess subProcess = (SubProcess) flowElement;
        xtw.writeStartElement(ELEMENT_SUBPROCESS);
        xtw.writeAttribute(ATTRIBUTE_ID, subProcess.getId());
        if (StringUtils.isNotEmpty(subProcess.getName())) {
            xtw.writeAttribute(ATTRIBUTE_NAME, subProcess.getName());
        } else {//from   w w w. j a v  a  2 s.c  om
            xtw.writeAttribute(ATTRIBUTE_NAME, "subProcess");
        }

        if (subProcess instanceof EventSubProcess) {
            xtw.writeAttribute(ATTRIBUTE_TRIGGERED_BY, ATTRIBUTE_VALUE_TRUE);
        }

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

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

        boolean didWriteExtensionStartElement = ActivitiListenerExport.writeListeners(subProcess, false, xtw);

        didWriteExtensionStartElement = BpmnXMLUtil.writeExtensionElements(subProcess,
                didWriteExtensionStartElement, xtw);
        if (didWriteExtensionStartElement) {
            // closing extensions element
            xtw.writeEndElement();
        }

        MultiInstanceExport.writeMultiInstance(subProcess, xtw);

        for (FlowElement subElement : subProcess.getFlowElements()) {
            createXML(subElement, model, xtw);
        }

        for (Artifact artifact : subProcess.getArtifacts()) {
            createXML(artifact, model, xtw);
        }

        xtw.writeEndElement();

    } else {

        BaseBpmnXMLConverter converter = convertersToXMLMap.get(flowElement.getClass());

        if (converter == null) {
            throw new XMLException("No converter for " + flowElement.getClass() + " found");
        }

        converter.convertToXML(xtw, flowElement, model);
    }
}

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

@Override
protected void writeAdditionalAttributes(BaseElement element, BpmnModel model, XMLStreamWriter xtw)
        throws Exception {
    CallActivity callActivity = (CallActivity) element;
    if (StringUtils.isNotEmpty(callActivity.getCalledElement())) {
        xtw.writeAttribute(ATTRIBUTE_CALL_ACTIVITY_CALLEDELEMENT, callActivity.getCalledElement());
    }//www. jav  a2 s. c o m
}

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

@Override
protected void writeAdditionalAttributes(BaseElement element, BpmnModel model, XMLStreamWriter xtw)
        throws Exception {
    DataStoreReference dataStoreRef = (DataStoreReference) element;
    if (StringUtils.isNotEmpty(dataStoreRef.getDataStoreRef())) {
        xtw.writeAttribute(ATTRIBUTE_DATA_STORE_REF, dataStoreRef.getDataStoreRef());
    }/*from   w ww  .j  av a2 s.c  o m*/

    if (StringUtils.isNotEmpty(dataStoreRef.getItemSubjectRef())) {
        xtw.writeAttribute(ATTRIBUTE_ITEM_SUBJECT_REF, dataStoreRef.getItemSubjectRef());
    }
}

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

public static void writeBPMNDI(BpmnModel model, XMLStreamWriter xtw) throws Exception {
    // BPMN DI information
    xtw.writeStartElement(BPMNDI_PREFIX, ELEMENT_DI_DIAGRAM, BPMNDI_NAMESPACE);

    String processId = null;//from   www  .j  av a 2 s  .  c  o m
    if (model.getPools().size() > 0) {
        processId = "Collaboration";
    } else {
        processId = model.getMainProcess().getId();
    }

    xtw.writeAttribute(ATTRIBUTE_ID, "BPMNDiagram_" + processId);

    xtw.writeStartElement(BPMNDI_PREFIX, ELEMENT_DI_PLANE, BPMNDI_NAMESPACE);
    xtw.writeAttribute(ATTRIBUTE_DI_BPMNELEMENT, processId);
    xtw.writeAttribute(ATTRIBUTE_ID, "BPMNPlane_" + processId);

    for (String elementId : model.getLocationMap().keySet()) {

        if (model.getFlowElement(elementId) != null || model.getArtifact(elementId) != null
                || model.getPool(elementId) != null || model.getLane(elementId) != null) {

            xtw.writeStartElement(BPMNDI_PREFIX, ELEMENT_DI_SHAPE, BPMNDI_NAMESPACE);
            xtw.writeAttribute(ATTRIBUTE_DI_BPMNELEMENT, elementId);
            xtw.writeAttribute(ATTRIBUTE_ID, "BPMNShape_" + elementId);

            GraphicInfo graphicInfo = model.getGraphicInfo(elementId);
            FlowElement flowElement = model.getFlowElement(elementId);
            if (flowElement instanceof SubProcess && graphicInfo.getExpanded() != null) {
                xtw.writeAttribute(ATTRIBUTE_DI_IS_EXPANDED, String.valueOf(graphicInfo.getExpanded()));
            }

            xtw.writeStartElement(OMGDC_PREFIX, ELEMENT_DI_BOUNDS, OMGDC_NAMESPACE);
            xtw.writeAttribute(ATTRIBUTE_DI_HEIGHT, "" + graphicInfo.getHeight());
            xtw.writeAttribute(ATTRIBUTE_DI_WIDTH, "" + graphicInfo.getWidth());
            xtw.writeAttribute(ATTRIBUTE_DI_X, "" + graphicInfo.getX());
            xtw.writeAttribute(ATTRIBUTE_DI_Y, "" + graphicInfo.getY());
            xtw.writeEndElement();

            xtw.writeEndElement();
        }
    }

    for (String elementId : model.getFlowLocationMap().keySet()) {

        if (model.getFlowElement(elementId) != null || model.getArtifact(elementId) != null) {

            xtw.writeStartElement(BPMNDI_PREFIX, ELEMENT_DI_EDGE, BPMNDI_NAMESPACE);
            xtw.writeAttribute(ATTRIBUTE_DI_BPMNELEMENT, elementId);
            xtw.writeAttribute(ATTRIBUTE_ID, "BPMNEdge_" + elementId);

            List<GraphicInfo> graphicInfoList = model.getFlowLocationGraphicInfo(elementId);
            for (GraphicInfo graphicInfo : graphicInfoList) {
                xtw.writeStartElement(OMGDI_PREFIX, ELEMENT_DI_WAYPOINT, OMGDI_NAMESPACE);
                xtw.writeAttribute(ATTRIBUTE_DI_X, "" + graphicInfo.getX());
                xtw.writeAttribute(ATTRIBUTE_DI_Y, "" + graphicInfo.getY());
                xtw.writeEndElement();
            }

            GraphicInfo labelGraphicInfo = model.getLabelGraphicInfo(elementId);
            FlowElement flowElement = model.getFlowElement(elementId);
            if (labelGraphicInfo != null && flowElement != null
                    && StringUtils.isNotEmpty(flowElement.getName())) {
                xtw.writeStartElement(BPMNDI_PREFIX, ELEMENT_DI_LABEL, BPMNDI_NAMESPACE);
                xtw.writeStartElement(OMGDC_PREFIX, ELEMENT_DI_BOUNDS, OMGDC_NAMESPACE);
                xtw.writeAttribute(ATTRIBUTE_DI_HEIGHT, "" + labelGraphicInfo.getHeight());
                xtw.writeAttribute(ATTRIBUTE_DI_WIDTH, "" + labelGraphicInfo.getWidth());
                xtw.writeAttribute(ATTRIBUTE_DI_X, "" + labelGraphicInfo.getX());
                xtw.writeAttribute(ATTRIBUTE_DI_Y, "" + labelGraphicInfo.getY());
                xtw.writeEndElement();
                xtw.writeEndElement();
            }

            xtw.writeEndElement();
        }
    }

    // end BPMN DI elements
    xtw.writeEndElement();
    xtw.writeEndElement();
}

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

public static void writePools(BpmnModel model, XMLStreamWriter xtw) throws Exception {
    if (!model.getPools().isEmpty()) {
        xtw.writeStartElement(ELEMENT_COLLABORATION);
        xtw.writeAttribute(ATTRIBUTE_ID, "Collaboration");
        for (Pool pool : model.getPools()) {
            xtw.writeStartElement(ELEMENT_PARTICIPANT);
            xtw.writeAttribute(ATTRIBUTE_ID, pool.getId());
            if (StringUtils.isNotEmpty(pool.getName())) {
                xtw.writeAttribute(ATTRIBUTE_NAME, pool.getName());
            }/*from  w  w w . ja va 2  s  .com*/
            if (StringUtils.isNotEmpty(pool.getProcessRef())) {
                xtw.writeAttribute(ATTRIBUTE_PROCESS_REF, pool.getProcessRef());
            }
            xtw.writeEndElement();
        }

        for (MessageFlow messageFlow : model.getMessageFlows().values()) {
            xtw.writeStartElement(ELEMENT_MESSAGE_FLOW);
            xtw.writeAttribute(ATTRIBUTE_ID, messageFlow.getId());
            if (StringUtils.isNotEmpty(messageFlow.getName())) {
                xtw.writeAttribute(ATTRIBUTE_NAME, messageFlow.getName());
            }
            if (StringUtils.isNotEmpty(messageFlow.getSourceRef())) {
                xtw.writeAttribute(ATTRIBUTE_FLOW_SOURCE_REF, messageFlow.getSourceRef());
            }
            if (StringUtils.isNotEmpty(messageFlow.getTargetRef())) {
                xtw.writeAttribute(ATTRIBUTE_FLOW_TARGET_REF, messageFlow.getTargetRef());
            }
            if (StringUtils.isNotEmpty(messageFlow.getMessageRef())) {
                xtw.writeAttribute(ATTRIBUTE_MESSAGE_REF, messageFlow.getMessageRef());
            }
            xtw.writeEndElement();
        }

        xtw.writeEndElement();
    }
}

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

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

    // start definitions root element
    xtw.writeStartElement(ELEMENT_DEFINITIONS);
    xtw.setDefaultNamespace(BPMN2_NAMESPACE);
    xtw.writeDefaultNamespace(BPMN2_NAMESPACE);
    xtw.writeNamespace(XSI_PREFIX, XSI_NAMESPACE);
    xtw.writeNamespace(XSD_PREFIX, SCHEMA_NAMESPACE);
    xtw.writeNamespace(ACTIVITI_EXTENSIONS_PREFIX, ACTIVITI_EXTENSIONS_NAMESPACE);
    xtw.writeNamespace(BPMNDI_PREFIX, BPMNDI_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 .  j ava  2  s .  c  om*/
    xtw.writeAttribute(TYPE_LANGUAGE_ATTRIBUTE, SCHEMA_NAMESPACE);
    xtw.writeAttribute(EXPRESSION_LANGUAGE_ATTRIBUTE, XPATH_NAMESPACE);
    if (StringUtils.isNotEmpty(model.getTargetNamespace())) {
        xtw.writeAttribute(TARGET_NAMESPACE_ATTRIBUTE, model.getTargetNamespace());
    } else {
        xtw.writeAttribute(TARGET_NAMESPACE_ATTRIBUTE, PROCESS_NAMESPACE);
    }

    BpmnXMLUtil.writeCustomAttributes(model.getDefinitionsAttributes().values(), xtw, model.getNamespaces(),
            defaultAttributes);
}

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());
            }/*  w  w  w.j  a  v a 2 s  .co  m*/

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

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