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:nl.nn.adapterframework.extensions.svn.ScanTibcoSolutionPipe.java

private void skipDir(XMLStreamWriter xmlStreamWriter, String token) throws XMLStreamException {
    xmlStreamWriter.writeStartElement("dir");
    xmlStreamWriter.writeAttribute("name", skipLastCharacter(token));
    xmlStreamWriter.writeAttribute("skip", "true");
    xmlStreamWriter.writeEndElement();//from w  ww  .j  a v a  2  s  . c  o  m
}

From source file:nl.nn.adapterframework.extensions.svn.ScanTibcoSolutionPipe.java

private void addCommit(XMLStreamWriter xmlStreamWriter, String urlString) throws XMLStreamException {
    xmlStreamWriter.writeStartElement("commit");
    try {//from   w ww .ja v a2s .c  om
        String logReport = SvnUtils.getLogReport(urlString);
        String creator = XmlUtils.evaluateXPathNodeSetFirstElement(logReport,
                "log-report/log-item/creator-displayname");
        xmlStreamWriter.writeAttribute("creator", creator);
        String date = XmlUtils.evaluateXPathNodeSetFirstElement(logReport, "log-report/log-item/date");
        xmlStreamWriter.writeAttribute("date", date);
    } catch (Exception e) {
        error(xmlStreamWriter, "error occured during adding commit info", e, false);
    }
    xmlStreamWriter.writeEndElement();
}

From source file:nl.nn.adapterframework.extensions.svn.ScanTibcoSolutionPipe.java

private void addFileContent(XMLStreamWriter xmlStreamWriter, String urlString, String type)
        throws XMLStreamException {
    xmlStreamWriter.writeStartElement("content");
    xmlStreamWriter.writeAttribute("type", type);
    String content;//w  w  w .j  a v a2  s  . com
    try {
        content = getHtml(urlString);
    } catch (Exception e) {
        error(xmlStreamWriter, "error occured during getting file content", e, true);
        content = null;
    }
    if (content != null) {
        Vector<String> warnMessage = new Vector<String>();
        try {
            if (type.equals("jmsDest") || type.equals("jmsDestConf")) {
                // AMX - receive (for jmsInboundDest)
                Collection<String> c1 = XmlUtils.evaluateXPathNodeSet(content, "namedResource/@name");
                if (c1 != null && c1.size() > 0) {
                    if (c1.size() > 1) {
                        warnMessage.add("more then one resourceName found");
                    }
                    String resourceName = (String) c1.iterator().next();
                    xmlStreamWriter.writeStartElement("resourceName");
                    xmlStreamWriter.writeCharacters(resourceName);
                    xmlStreamWriter.writeEndElement();
                } else {
                    warnMessage.add("no resourceName found");
                }
                Collection<String> c2 = XmlUtils.evaluateXPathNodeSet(content,
                        "namedResource/configuration/@jndiName");
                if (c2 != null && c2.size() > 0) {
                    if (c2.size() > 1) {
                        warnMessage.add("more then one resourceJndiName found");
                    }
                    String resourceJndiName = (String) c2.iterator().next();
                    xmlStreamWriter.writeStartElement("resourceJndiName");
                    xmlStreamWriter.writeCharacters(resourceJndiName);
                    xmlStreamWriter.writeEndElement();
                } else {
                    warnMessage.add("no resourceJndiName found");
                }
            } else if (type.equals("composite")) {
                // AMX - receive
                Collection<String> c1 = XmlUtils.evaluateXPathNodeSet(content,
                        "composite/service/bindingAdjunct/property[@name='JmsInboundDestinationConfig']/@simpleValue");
                if (c1 != null && c1.size() > 0) {
                    for (Iterator<String> c1it = c1.iterator(); c1it.hasNext();) {
                        xmlStreamWriter.writeStartElement("jmsInboundDest");
                        xmlStreamWriter.writeCharacters(c1it.next());
                        xmlStreamWriter.writeEndElement();
                    }
                } else {
                    warnMessage.add("no jmsInboundDest found");
                }
                // AMX - send
                Collection<String> c2 = XmlUtils.evaluateXPathNodeSet(content,
                        "composite/reference/interface.wsdl/@wsdlLocation");
                if (c2 != null && c2.size() > 0) {
                    for (Iterator<String> c2it = c2.iterator(); c2it.hasNext();) {
                        String itn = c2it.next();
                        String wsdl = null;
                        try {
                            URL url = new URL(urlString);
                            URL wsdlUrl = new URL(url, itn);
                            wsdl = getHtml(wsdlUrl.toString());
                        } catch (Exception e) {
                            error(xmlStreamWriter, "error occured during getting wsdl file content", e, true);
                            wsdl = null;
                        }
                        if (wsdl != null) {
                            Collection<String> c3 = XmlUtils.evaluateXPathNodeSet(wsdl,
                                    // "definitions/service/port/targetAddress",
                                    // "concat(.,';',../../@name)");
                                    "definitions/service/port/targetAddress");
                            if (c3 != null && c3.size() > 0) {
                                for (Iterator<String> c3it = c3.iterator(); c3it.hasNext();) {
                                    xmlStreamWriter.writeStartElement("targetAddr");
                                    xmlStreamWriter.writeCharacters(c3it.next());
                                    xmlStreamWriter.writeEndElement();
                                }
                            } else {
                                warnMessage.add("no targetAddr found");
                            }
                        } else {
                            warnMessage.add("wsdl [" + itn + "] not found");
                        }
                    }
                } else {
                    warnMessage.add("no wsdlLocation found");
                }
            } else if (type.equals("process")) {
                // BW - receive
                Double d1 = XmlUtils.evaluateXPathNumber(content,
                        "count(ProcessDefinition/starter[type='com.tibco.plugin.soap.SOAPEventSource']/config)");
                if (d1 > 0) {
                    Collection<String> c1 = XmlUtils.evaluateXPathNodeSet(content,
                            "ProcessDefinition/starter[type='com.tibco.plugin.soap.SOAPEventSource']/config/sharedChannels/jmsChannel/JMSTo");
                    if (c1 != null && c1.size() > 0) {
                        for (Iterator<String> c1it = c1.iterator(); c1it.hasNext();) {
                            xmlStreamWriter.writeStartElement("jmsTo");
                            xmlStreamWriter.writeAttribute("type", "soapEventSource");
                            xmlStreamWriter.writeCharacters(c1it.next());
                            xmlStreamWriter.writeEndElement();
                        }
                    } else {
                        warnMessage.add("no jmsTo found for soapEventSource");
                    }
                } else {
                    warnMessage.add("no soapEventSource found");
                }
                // BW - send
                Double d2 = XmlUtils.evaluateXPathNumber(content,
                        "count(ProcessDefinition/activity[type='com.tibco.plugin.soap.SOAPSendReceiveActivity']/config)");
                if (d2 > 0) {
                    Collection<String> c2 = XmlUtils.evaluateXPathNodeSet(content,
                            "ProcessDefinition/activity[type='com.tibco.plugin.soap.SOAPSendReceiveActivity']/config/sharedChannels/jmsChannel/JMSTo");
                    if (c2 != null && c2.size() > 0) {
                        for (Iterator<String> c2it = c2.iterator(); c2it.hasNext();) {
                            xmlStreamWriter.writeStartElement("jmsTo");
                            xmlStreamWriter.writeAttribute("type", "soapSendReceiveActivity");
                            xmlStreamWriter.writeCharacters(c2it.next());
                            xmlStreamWriter.writeEndElement();
                        }
                    } else {
                        warnMessage.add("no jmsTo found for soapSendReceiveActivity");
                    }
                } else {
                    warnMessage.add("no soapSendReceiveActivity found");
                }
            } else if (type.equals("substVar")) {
                String path = StringUtils
                        .substringBeforeLast(StringUtils.substringAfterLast(urlString, "/defaultVars/"), "/");
                Map<String, String> m1 = XmlUtils.evaluateXPathNodeSet(content,
                        "repository/globalVariables/globalVariable", "name", "value");
                if (m1 != null && m1.size() > 0) {
                    for (Iterator<String> m1it = m1.keySet().iterator(); m1it.hasNext();) {
                        Object key = m1it.next();
                        Object value = m1.get(key);
                        xmlStreamWriter.writeStartElement("globalVariable");
                        xmlStreamWriter.writeAttribute("name", (String) key);
                        xmlStreamWriter.writeAttribute("ref", "%%" + path + "/" + key + "%%");
                        xmlStreamWriter.writeCharacters((String) value);
                        xmlStreamWriter.writeEndElement();
                    }
                } else {
                    warnMessage.add("no globalVariable found");
                }
                /*
                 * } else { content = XmlUtils.removeNamespaces(content);
                 * xmlStreamWriter.writeCharacters(content);
                 */
            }
        } catch (Exception e) {
            error(xmlStreamWriter, "error occured during processing " + type + " file", e, true);
        }
        if (warnMessage.size() > 0) {
            xmlStreamWriter.writeStartElement("warnMessages");
            for (int i = 0; i < warnMessage.size(); i++) {
                xmlStreamWriter.writeStartElement("warnMessage");
                xmlStreamWriter.writeCharacters(warnMessage.elementAt(i));
                xmlStreamWriter.writeEndElement();
            }
            xmlStreamWriter.writeEndElement();
        }
    }
    xmlStreamWriter.writeEndElement();
}

From source file:nl.nn.adapterframework.extensions.svn.ScanTibcoSolutionPipe.java

private void error(XMLStreamWriter xmlStreamWriter, String msg, Throwable t, boolean printStackTrace)
        throws XMLStreamException {
    log.warn(msg, t);// ww  w.  j  av  a2 s.  co m
    xmlStreamWriter.writeStartElement("errorMessage");
    String errorMsg;
    if (printStackTrace) {
        StringWriter trace = new StringWriter();
        t.printStackTrace(new PrintWriter(trace));
        errorMsg = msg + ": " + trace;
    } else {
        errorMsg = msg + ": " + t.getMessage();
    }
    xmlStreamWriter.writeCharacters(errorMsg);
    xmlStreamWriter.writeEndElement();
}

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.  j  a  v a  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 ww w.ja  v 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();//from   ww  w. jav a2s. 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.  ja  va  2s  .  c om
    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  . j  ava 2s.  c  om
    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  v a 2s.  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();
}