Example usage for javax.xml.stream XMLStreamWriter writeCData

List of usage examples for javax.xml.stream XMLStreamWriter writeCData

Introduction

In this page you can find the example usage for javax.xml.stream XMLStreamWriter writeCData.

Prototype

public void writeCData(String data) throws XMLStreamException;

Source Link

Document

Writes a CData section

Usage

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

@Override
protected void writeAdditionalChildElements(BaseElement element, BpmnModel model, XMLStreamWriter xtw)
        throws Exception {
    SequenceFlow sequenceFlow = (SequenceFlow) element;

    if (StringUtils.isNotEmpty(sequenceFlow.getConditionExpression())) {
        xtw.writeStartElement(ELEMENT_FLOW_CONDITION);
        xtw.writeAttribute(XSI_PREFIX, XSI_NAMESPACE, "type", "tFormalExpression");
        xtw.writeCData(sequenceFlow.getConditionExpression());
        xtw.writeEndElement();/*  ww w . j  a v  a2  s  .c  om*/
    }
}

From source file:org.activiti.designer.export.bpmn20.export.MailTaskExport.java

private static void writeCDataField(String name, String text, XMLStreamWriter xtw) throws Exception {
    xtw.writeStartElement(ACTIVITI_EXTENSIONS_PREFIX, "field", ACTIVITI_EXTENSIONS_NAMESPACE);
    xtw.writeAttribute("name", name);
    xtw.writeStartElement(ACTIVITI_EXTENSIONS_PREFIX, "expression", ACTIVITI_EXTENSIONS_NAMESPACE);
    xtw.writeCData(text);
    xtw.writeEndElement();/*from ww w .  ja v  a 2s. c  om*/
    xtw.writeEndElement();
}

From source file:org.activiti.designer.export.bpmn20.export.ScriptTaskExport.java

public static void createScriptTask(Object object, XMLStreamWriter xtw) throws Exception {
    ScriptTask scriptTask = (ScriptTask) object;
    // start ScriptTask element
    xtw.writeStartElement("scriptTask");
    xtw.writeAttribute("id", scriptTask.getId());
    if (scriptTask.getName() != null) {
        xtw.writeAttribute("name", scriptTask.getName());
    }/*from   w  w  w  .  j  ava2 s .com*/
    DefaultFlowExport.createDefaultFlow(scriptTask, xtw);
    AsyncActivityExport.createAsyncAttribute(scriptTask, xtw);
    if (StringUtils.isNotEmpty(scriptTask.getScriptFormat())) {
        xtw.writeAttribute("scriptFormat", scriptTask.getScriptFormat());
    }

    ExecutionListenerExport.createExecutionListenerXML(scriptTask.getExecutionListeners(), true, xtw);

    xtw.writeStartElement("script");
    if (StringUtils.isNotEmpty(scriptTask.getScript())) {
        xtw.writeCData(scriptTask.getScript());
    }
    xtw.writeEndElement();

    MultiInstanceExport.createMultiInstance(object, xtw);

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

From source file:org.activiti.designer.export.bpmn20.export.SequenceFlowExport.java

public static void createSequenceFlow(Object object, XMLStreamWriter xtw) throws Exception {
    SequenceFlow sequenceFlow = (SequenceFlow) object;
    // start SequenceFlow element
    xtw.writeStartElement("sequenceFlow");
    xtw.writeAttribute("id", sequenceFlow.getId());
    if (sequenceFlow.getName() == null) {
        xtw.writeAttribute("name", "");
    } else {//from   www.  ja  va  2 s. co  m
        xtw.writeAttribute("name", sequenceFlow.getName());
    }
    xtw.writeAttribute("sourceRef", sequenceFlow.getSourceRef().getId());
    xtw.writeAttribute("targetRef", sequenceFlow.getTargetRef().getId());

    ExecutionListenerExport.createExecutionListenerXML(sequenceFlow.getExecutionListeners(), true, xtw);

    if (StringUtils.isNotEmpty(sequenceFlow.getConditionExpression())) {

        String condition = sequenceFlow.getConditionExpression();
        // start conditionExpression element
        xtw.writeStartElement("conditionExpression");
        xtw.writeAttribute("xsi", XSI_NAMESPACE, "type", "tFormalExpression");
        xtw.writeCData(condition);

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

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

From source file:org.apache.axiom.om.impl.serialize.StreamingOMSerializer.java

/**
 * Method serializeCData./*from w  w w  . j a v  a 2 s . com*/
 *
 * @param reader
 * @param writer
 * @throws XMLStreamException
 */
protected void serializeCData(XMLStreamReader reader, XMLStreamWriter writer) throws XMLStreamException {
    writer.writeCData(reader.getText());
}

From source file:org.apache.synapse.commons.json.JsonDataSource.java

public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException {
    XMLStreamReader reader = getReader();
    xmlWriter.writeStartDocument();//from w w  w .  j a  v a  2s  . c o  m
    while (reader.hasNext()) {
        int x = reader.next();
        switch (x) {
        case XMLStreamConstants.START_ELEMENT:
            xmlWriter.writeStartElement(reader.getPrefix(), reader.getLocalName(), reader.getNamespaceURI());
            int namespaceCount = reader.getNamespaceCount();
            for (int i = namespaceCount - 1; i >= 0; i--) {
                xmlWriter.writeNamespace(reader.getNamespacePrefix(i), reader.getNamespaceURI(i));
            }
            int attributeCount = reader.getAttributeCount();
            for (int i = 0; i < attributeCount; i++) {
                xmlWriter.writeAttribute(reader.getAttributePrefix(i), reader.getAttributeNamespace(i),
                        reader.getAttributeLocalName(i), reader.getAttributeValue(i));
            }
            break;
        case XMLStreamConstants.START_DOCUMENT:
            break;
        case XMLStreamConstants.CHARACTERS:
            xmlWriter.writeCharacters(reader.getText());
            break;
        case XMLStreamConstants.CDATA:
            xmlWriter.writeCData(reader.getText());
            break;
        case XMLStreamConstants.END_ELEMENT:
            xmlWriter.writeEndElement();
            break;
        case XMLStreamConstants.END_DOCUMENT:
            xmlWriter.writeEndDocument();
            break;
        case XMLStreamConstants.SPACE:
            break;
        case XMLStreamConstants.COMMENT:
            xmlWriter.writeComment(reader.getText());
            break;
        case XMLStreamConstants.DTD:
            xmlWriter.writeDTD(reader.getText());
            break;
        case XMLStreamConstants.PROCESSING_INSTRUCTION:
            xmlWriter.writeProcessingInstruction(reader.getPITarget(), reader.getPIData());
            break;
        case XMLStreamConstants.ENTITY_REFERENCE:
            xmlWriter.writeEntityRef(reader.getLocalName());
            break;
        default:
            throw new OMException();
        }
    }
    xmlWriter.writeEndDocument();
    xmlWriter.flush();
    xmlWriter.close();
}

From source file:org.deegree.services.csw.exporthandling.GetCapabilitiesHelper.java

private void writeTemplateElement(XMLStreamWriter writer, XMLStreamReader inStream,
        Map<String, String> varToValue) throws XMLStreamException {

    if (inStream.getEventType() != XMLStreamConstants.START_ELEMENT) {
        throw new XMLStreamException("Input stream does not point to a START_ELEMENT event.");
    }/* w ww .j a va 2s  .  co  m*/
    int openElements = 0;
    boolean firstRun = true;
    while (firstRun || openElements > 0) {
        firstRun = false;
        int eventType = inStream.getEventType();

        switch (eventType) {
        case CDATA: {
            writer.writeCData(inStream.getText());
            break;
        }
        case CHARACTERS: {
            String s = new String(inStream.getTextCharacters(), inStream.getTextStart(),
                    inStream.getTextLength());
            // TODO optimize
            for (String param : varToValue.keySet()) {
                String value = varToValue.get(param);
                s = s.replace(param, value);
            }
            writer.writeCharacters(s);

            break;
        }
        case END_ELEMENT: {
            writer.writeEndElement();
            openElements--;
            break;
        }
        case START_ELEMENT: {
            if (inStream.getNamespaceURI() == "" || inStream.getPrefix() == DEFAULT_NS_PREFIX
                    || inStream.getPrefix() == null) {
                writer.writeStartElement(inStream.getLocalName());
            } else {
                if (writer.getNamespaceContext().getPrefix(inStream.getPrefix()) == "") {
                    // TODO handle special cases for prefix binding, see
                    // http://download.oracle.com/docs/cd/E17409_01/javase/6/docs/api/javax/xml/namespace/NamespaceContext.html#getNamespaceURI(java.lang.String)
                    writer.setPrefix(inStream.getPrefix(), inStream.getNamespaceURI());
                }
                writer.writeStartElement(inStream.getPrefix(), inStream.getLocalName(),
                        inStream.getNamespaceURI());
            }
            // copy all namespace bindings
            for (int i = 0; i < inStream.getNamespaceCount(); i++) {
                String nsPrefix = inStream.getNamespacePrefix(i);
                String nsURI = inStream.getNamespaceURI(i);
                writer.writeNamespace(nsPrefix, nsURI);
            }

            // copy all attributes
            for (int i = 0; i < inStream.getAttributeCount(); i++) {
                String localName = inStream.getAttributeLocalName(i);
                String nsPrefix = inStream.getAttributePrefix(i);
                String value = inStream.getAttributeValue(i);
                String nsURI = inStream.getAttributeNamespace(i);
                if (nsURI == null) {
                    writer.writeAttribute(localName, value);
                } else {
                    writer.writeAttribute(nsPrefix, nsURI, localName, value);
                }
            }

            openElements++;
            break;
        }
        default: {
            break;
        }
        }
        if (openElements > 0) {
            inStream.next();
        }
    }
}

From source file:org.eclipse.gyrex.logback.config.model.LogbackConfig.java

private void writeJulLevelChangePropagator(final XMLStreamWriter writer) throws XMLStreamException {
    writer.writeComment("propagate log level changes to JUL");
    writer.writeStartElement("contextListener");
    writer.writeAttribute("class", LevelChangePropagator.class.getName());
    {/*from www .ja v a 2 s .  c  o m*/
        writer.writeStartElement("resetJUL");
        writer.writeCData("true");
        writer.writeEndElement();
    }
    writer.writeEndElement();
}

From source file:org.flowable.bpmn.converter.BpmnXMLConverter.java

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

    if (flowElement instanceof SubProcess) {

        SubProcess subProcess = (SubProcess) flowElement;
        if (flowElement instanceof Transaction) {
            xtw.writeStartElement(ELEMENT_TRANSACTION);
        } else if (flowElement instanceof AdhocSubProcess) {
            xtw.writeStartElement(ELEMENT_ADHOC_SUBPROCESS);
        } else {//from   w w  w .  j a va  2s.com
            xtw.writeStartElement(ELEMENT_SUBPROCESS);
        }

        xtw.writeAttribute(ATTRIBUTE_ID, subProcess.getId());
        if (StringUtils.isNotEmpty(subProcess.getName())) {
            xtw.writeAttribute(ATTRIBUTE_NAME, subProcess.getName());
        } else {
            xtw.writeAttribute(ATTRIBUTE_NAME, "subProcess");
        }

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

        } else if (subProcess instanceof Transaction == false) {
            if (subProcess.isAsynchronous()) {
                BpmnXMLUtil.writeQualifiedAttribute(ATTRIBUTE_ACTIVITY_ASYNCHRONOUS, ATTRIBUTE_VALUE_TRUE, xtw);
                if (subProcess.isNotExclusive()) {
                    BpmnXMLUtil.writeQualifiedAttribute(ATTRIBUTE_ACTIVITY_EXCLUSIVE, ATTRIBUTE_VALUE_FALSE,
                            xtw);
                }
            }

        } else if (subProcess instanceof AdhocSubProcess) {
            AdhocSubProcess adhocSubProcess = (AdhocSubProcess) subProcess;
            BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_CANCEL_REMAINING_INSTANCES,
                    String.valueOf(adhocSubProcess.isCancelRemainingInstances()), xtw);
            if (StringUtils.isNotEmpty(adhocSubProcess.getOrdering())) {
                BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_ORDERING, adhocSubProcess.getOrdering(), xtw);
            }
        }

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

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

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

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

        MultiInstanceExport.writeMultiInstance(subProcess, xtw);

        if (subProcess instanceof AdhocSubProcess) {
            AdhocSubProcess adhocSubProcess = (AdhocSubProcess) subProcess;
            if (StringUtils.isNotEmpty(adhocSubProcess.getCompletionCondition())) {
                xtw.writeStartElement(ELEMENT_COMPLETION_CONDITION);
                xtw.writeCData(adhocSubProcess.getCompletionCondition());
                xtw.writeEndElement();
            }
        }

        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.flowable.bpmn.converter.export.FieldExtensionExport.java

public static boolean writeFieldExtensions(List<FieldExtension> fieldExtensionList,
        boolean didWriteExtensionStartElement, XMLStreamWriter xtw) throws Exception {

    for (FieldExtension fieldExtension : fieldExtensionList) {

        if (StringUtils.isNotEmpty(fieldExtension.getFieldName())) {

            if (StringUtils.isNotEmpty(fieldExtension.getStringValue())
                    || StringUtils.isNotEmpty(fieldExtension.getExpression())) {

                if (didWriteExtensionStartElement == false) {
                    xtw.writeStartElement(ELEMENT_EXTENSIONS);
                    didWriteExtensionStartElement = true;
                }/*from  w ww.j a v a 2  s. c o m*/

                xtw.writeStartElement(FLOWABLE_EXTENSIONS_PREFIX, ELEMENT_FIELD, FLOWABLE_EXTENSIONS_NAMESPACE);
                BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_FIELD_NAME, fieldExtension.getFieldName(), xtw);

                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());
                }
                xtw.writeEndElement();
                xtw.writeEndElement();
            }
        }
    }
    return didWriteExtensionStartElement;
}