javax.xml.stream.XMLStreamWriter Java Examples

The following examples show how to use javax.xml.stream.XMLStreamWriter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: cxf   Author: apache   File: StaxUtilsTest.java    License: Apache License 2.0 7 votes vote down vote up
@Test
public void testCopyWithEmptyNamespace() throws Exception {
    StringBuilder in = new StringBuilder(128);
    in.append("<foo xmlns=\"http://example.com/\">");
    in.append("<bar xmlns=\"\"/>");
    in.append("</foo>");

    XMLStreamReader reader = StaxUtils.createXMLStreamReader(
         new ByteArrayInputStream(in.toString().getBytes()));

    Writer out = new StringWriter();
    XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(out);
    StaxUtils.copy(reader, writer);
    writer.close();

    assertEquals(in.toString(), out.toString());
}
 
Example #2
Source Project: java-client-api   Author: marklogic   File: DocumentMetadataHandle.java    License: Apache License 2.0 6 votes vote down vote up
private void sendPermissionsImpl(XMLStreamWriter serializer) throws XMLStreamException {
  if ( getPermissions() == null || getPermissions().size() == 0 ) return;
  serializer.writeStartElement("rapi", "permissions", REST_API_NS);

  for (Map.Entry<String, Set<Capability>> permission: getPermissions().entrySet()) {
    serializer.writeStartElement("rapi", "permission", REST_API_NS);

    serializer.writeStartElement("rapi", "role-name", REST_API_NS);
    if(permission.getKey() != null)
      serializer.writeCharacters(permission.getKey());
    serializer.writeEndElement();

    for (Capability capability: permission.getValue()) {
      serializer.writeStartElement("rapi", "capability", REST_API_NS);
      serializer.writeCharacters(capability.toString().toLowerCase());
      serializer.writeEndElement();
    }

    serializer.writeEndElement();
  }

  serializer.writeEndElement();
}
 
Example #3
Source Project: gate-core   Author: GateNLP   File: DocumentStaxUtils.java    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void writeDocument(Document doc, OutputStream outputStream, String namespaceURI) throws XMLStreamException, IOException {
  if(outputFactory == null) {
    outputFactory = XMLOutputFactory.newInstance();
  }

  XMLStreamWriter xsw = null;
  try {
    if(doc instanceof TextualDocument) {
      xsw = outputFactory.createXMLStreamWriter(outputStream,
              ((TextualDocument)doc).getEncoding());
      xsw.writeStartDocument(((TextualDocument)doc).getEncoding(), "1.0");
    }
    else {
      xsw = outputFactory.createXMLStreamWriter(outputStream);
      xsw.writeStartDocument("1.0");
    }
    newLine(xsw);

    writeDocument(doc, xsw, namespaceURI);
  }
  finally {
    if(xsw != null) {
      xsw.close();
    }
  }
}
 
Example #4
Source Project: cxf   Author: apache   File: CorbaStreamOutInterceptor.java    License: Apache License 2.0 6 votes vote down vote up
private void handleOutBoundMessage(CorbaMessage message, BindingOperationInfo boi) {
    boolean wrap = false;
    if (boi.isUnwrappedCapable()) {
        wrap = true;
    }
    OperationType opType = boi.getExtensor(OperationType.class);
    List<ParamType> paramTypes = opType.getParam();
    List<ArgType> params = new ArrayList<>();
    for (Iterator<ParamType> iter = paramTypes.iterator(); iter.hasNext();) {
        ParamType param = iter.next();
        if (!param.getMode().equals(ModeType.OUT)) {
            params.add(param);
        }
    }
    CorbaStreamWriter writer = new CorbaStreamWriter(orb, params, typeMap, service, wrap);
    message.setContent(XMLStreamWriter.class, writer);
}
 
Example #5
Source Project: iaf   Author: ibissource   File: Wsdl.java    License: Apache License 2.0 6 votes vote down vote up
protected void jmsBinding(XMLStreamWriter w, String namePrefix) throws XMLStreamException, IOException, ConfigurationException {
    w.writeStartElement(WSDL_NAMESPACE, "binding");
    w.writeAttribute("name", namePrefix + "Binding_" + WsdlUtils.getNCName(getName()));
    w.writeAttribute("type", getTargetNamespacePrefix() + ":" + "PortType_" + getName()); {
        w.writeEmptyElement(wsdlSoapNamespace, "binding");
        w.writeAttribute("style", "document");
        if (esbSoap) {
            w.writeAttribute("transport", ESB_SOAP_JMS_NAMESPACE);
            w.writeEmptyElement(ESB_SOAP_JMS_NAMESPACE, "binding");
            w.writeAttribute("messageFormat", "Text");
            for (IListener listener : WsdlUtils.getListeners(pipeLine.getAdapter())) {
                if (listener instanceof JmsListener) {
                    writeSoapOperation(w, listener);
                }
            }
        } else {
            w.writeAttribute("transport", SOAP_JMS_NAMESPACE);
        }
    }
    w.writeEndElement();
}
 
Example #6
Source Project: phoebus   Author: ControlSystemStudio   File: ServletHelper.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/** Create XML content for scan server info
 *  @param writer {@link XMLStreamWriter}
 *  @param info {@link ScanServerInfo}
 *  @throws Exception on error
 */
public static void write(final XMLStreamWriter writer, final ScanServerInfo info) throws Exception
{
    writer.writeStartElement("server");

    write(writer, "version", info.getVersion());
    write(writer, "start_time", info.getStartTime());
    write(writer, "scan_config", info.getScanConfig());
    write(writer, "script_paths", PathUtil.joinPaths(info.getScriptPaths()));
    write(writer, "macros", info.getMacros());
    write(writer, "used_mem", info.getUsedMem());
    write(writer, "max_mem", info.getMaxMem());
    write(writer, "non_heap", info.getNonHeapUsedMem());

    writer.writeEndElement();
}
 
Example #7
Source Project: cxf   Author: apache   File: StaxUtils.java    License: Apache License 2.0 6 votes vote down vote up
private static void writeAttributeEvent(XMLEvent event, XMLStreamWriter writer)
    throws XMLStreamException {

    Attribute attr = (Attribute)event;
    QName name = attr.getName();
    String nsURI = name.getNamespaceURI();
    String localName = name.getLocalPart();
    String prefix = name.getPrefix();
    String value = attr.getValue();

    if (prefix != null) {
        writer.writeAttribute(prefix, nsURI, localName, value);
    } else if (nsURI != null) {
        writer.writeAttribute(nsURI, localName, value);
    } else {
        writer.writeAttribute(localName, value);
    }
}
 
Example #8
Source Project: flowable-engine   Author: flowable   File: BaseBpmnXMLConverter.java    License: Apache License 2.0 6 votes vote down vote up
protected void writeEventDefinitions(Event parentEvent, List<EventDefinition> eventDefinitions, BpmnModel model, XMLStreamWriter xtw) throws Exception {
    for (EventDefinition eventDefinition : eventDefinitions) {
        if (eventDefinition instanceof TimerEventDefinition) {
            writeTimerDefinition(parentEvent, (TimerEventDefinition) eventDefinition, model, xtw);
        } else if (eventDefinition instanceof SignalEventDefinition) {
            writeSignalDefinition(parentEvent, (SignalEventDefinition) eventDefinition, model, xtw);
        } else if (eventDefinition instanceof MessageEventDefinition) {
            writeMessageDefinition(parentEvent, (MessageEventDefinition) eventDefinition, model, xtw);
        } else if (eventDefinition instanceof ConditionalEventDefinition) {
            writeConditionalDefinition(parentEvent, (ConditionalEventDefinition) eventDefinition, model, xtw);
        } else if (eventDefinition instanceof ErrorEventDefinition) {
            writeErrorDefinition(parentEvent, (ErrorEventDefinition) eventDefinition, model, xtw);
        } else if (eventDefinition instanceof EscalationEventDefinition) {
            writeEscalationDefinition(parentEvent, (EscalationEventDefinition) eventDefinition, model, xtw);
        } else if (eventDefinition instanceof TerminateEventDefinition) {
            writeTerminateDefinition(parentEvent, (TerminateEventDefinition) eventDefinition, model, xtw);
        } else if (eventDefinition instanceof CancelEventDefinition) {
            writeCancelDefinition(parentEvent, (CancelEventDefinition) eventDefinition, model, xtw);
        } else if (eventDefinition instanceof CompensateEventDefinition) {
            writeCompensateDefinition(parentEvent, (CompensateEventDefinition) eventDefinition, model, xtw);
        }
    }
}
 
Example #9
Source Project: SODS   Author: miachm   File: OdsWritter.java    License: Apache License 2.0 6 votes vote down vote up
private void writeBorderStyle(XMLStreamWriter out, Style style) throws XMLStreamException {
  	
Borders borders = style.getBorders();
if (borders.isBorder()) {
	out.writeAttribute("fo:border", borders.getBorderProperties());
}

if (borders.isBorderTop()) {
	out.writeAttribute("fo:border-top", borders.getBorderTopProperties());
}

if (borders.isBorderBottom()) {
	out.writeAttribute("fo:border-bottom", borders.getBorderBottomProperties());
}

if (borders.isBorderLeft()) {
	out.writeAttribute("fo:border-left", borders.getBorderLeftProperties());
}

if (borders.isBorderRight()) {
	out.writeAttribute("fo:border-right", borders.getBorderRightProperties());
}
  }
 
Example #10
Source Project: cloud-odata-java   Author: SAP   File: AtomEntryEntityProducer.java    License: Apache License 2.0 6 votes vote down vote up
private void appendProperties(final XMLStreamWriter writer, final EntityInfoAggregator eia, final Map<String, Object> data) throws EntityProviderException {
  try {
    List<String> propertyNames = eia.getSelectedPropertyNames();
    if (!propertyNames.isEmpty()) {
      writer.writeStartElement(Edm.NAMESPACE_M_2007_08, FormatXml.M_PROPERTIES);

      for (String propertyName : propertyNames) {
        EntityPropertyInfo propertyInfo = eia.getPropertyInfo(propertyName);

        if (isNotMappedViaCustomMapping(propertyInfo)) {
          Object value = data.get(propertyName);
          XmlPropertyEntityProducer aps = new XmlPropertyEntityProducer();
          aps.append(writer, propertyInfo.getName(), propertyInfo, value);
        }
      }

      writer.writeEndElement();
    }
  } catch (XMLStreamException e) {
    throw new EntityProviderException(EntityProviderException.COMMON, e);
  }
}
 
Example #11
Source Project: java-client-api   Author: marklogic   File: DocumentMetadataPatchBuilderImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void write(XMLOutputSerializer out) throws Exception {
  XMLStreamWriter serializer = out.getSerializer();
  writeStartReplace(out, "/rapi:metadata/rapi:quality", null);
  serializer.writeCharacters(String.valueOf(quality));
  serializer.writeEndElement();
}
 
Example #12
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: XMLStreamWriterFactory.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Fetchs an instance from the pool if available, otherwise null.
 */
private @Nullable XMLStreamWriter fetch() {
    XMLStreamWriter sr = pool.get();
    if(sr==null)    return null;
    pool.set(null);
    return sr;
}
 
Example #13
Source Project: micro-integrator   Author: wso2   File: XMLWriterHelper.java    License: Apache License 2.0 5 votes vote down vote up
public void startWrapperElement(XMLStreamWriter xmlWriter, String namespace,
		String name, int resultType) throws XMLStreamException {
       if (xmlWriter == null) {
           return;
       }
	String nsPrefix;
	boolean writeNS;
	switch (resultType) {
	case DBConstants.ResultTypes.XML:
		if (name != null) {
		    /* start result wrapper */
		    xmlWriter.writeStartElement(name);
		    /* write default namespace */
		    nsPrefix = xmlWriter.getNamespaceContext().getPrefix(this.getNamespace());
			writeNS = nsPrefix == null || !"".equals(nsPrefix);				
		    if (writeNS) {
		    	xmlWriter.setDefaultNamespace(namespace);
		        xmlWriter.writeDefaultNamespace(namespace);
		    }
		}
		break;
	case DBConstants.ResultTypes.RDF:
		xmlWriter.setDefaultNamespace(namespace);
		xmlWriter.writeStartElement(DBConstants.DEFAULT_RDF_PREFIX,
				DBConstants.DBSFields.RDF, DBConstants.RDF_NAMESPACE);
		xmlWriter.writeNamespace(DBConstants.DEFAULT_RDF_PREFIX, DBConstants.RDF_NAMESPACE);
		xmlWriter.writeDefaultNamespace(namespace);
		break;
	}
}
 
Example #14
Source Project: cxf   Author: apache   File: WrappedOutInterceptor.java    License: Apache License 2.0 5 votes vote down vote up
public void handleMessage(Message message) {
    BindingOperationInfo bop = message.getExchange().getBindingOperationInfo();

    if (bop != null && bop.isUnwrapped()) {
        XMLStreamWriter xmlWriter = message.getContent(XMLStreamWriter.class);

        MessageInfo messageInfo;
        if (isRequestor(message)) {
            messageInfo = bop.getWrappedOperation().getOperationInfo().getInput();
        } else {
            messageInfo = bop.getWrappedOperation().getOperationInfo().getOutput();
        }

        QName name = messageInfo.getFirstMessagePart().getConcreteName();

        try {
            String pfx = null;
            Service service = message.getExchange().getService();
            if (service.getDataBinding().getDeclaredNamespaceMappings() != null) {
                pfx = service.getDataBinding().getDeclaredNamespaceMappings().get(name.getNamespaceURI());
            }
            if (pfx == null) {
                pfx = StaxUtils.getUniquePrefix(xmlWriter, name.getNamespaceURI(), false);
            }
            xmlWriter.setPrefix(pfx, name.getNamespaceURI());
            xmlWriter.writeStartElement(pfx, name.getLocalPart(), name.getNamespaceURI());
            if (StringUtils.isEmpty(pfx)) {
                xmlWriter.writeDefaultNamespace(name.getNamespaceURI());
            } else {
                xmlWriter.writeNamespace(pfx, name.getNamespaceURI());
            }
        } catch (XMLStreamException e) {
            throw new Fault(new org.apache.cxf.common.i18n.Message("STAX_WRITE_EXC", BUNDLE), e);
        }

        // Add a final interceptor to write end element
        message.getInterceptorChain().add(ending);
    }
}
 
Example #15
Source Project: hottub   Author: dsrg-uoft   File: SourceUtils.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * sets undeclared prefixes on the writer
 * @param prefix
 * @param writer
 * @throws XMLStreamException
 */
private static void setUndeclaredPrefix(String prefix, String readerURI, XMLStreamWriter writer) throws XMLStreamException {
    String writerURI = null;
    if (writer.getNamespaceContext() != null) {
        writerURI = writer.getNamespaceContext().getNamespaceURI(prefix);
    }

    if (writerURI == null) {
        writer.setPrefix(prefix, readerURI != null ? readerURI : "");
        writer.writeNamespace(prefix, readerURI != null ? readerURI : "");
    }
}
 
Example #16
Source Project: syndesis   Author: syndesisio   File: ResponseSoapPayloadConverter.java    License: Apache License 2.0 5 votes vote down vote up
protected static void writeStartEnvelopeAndHeaders(SoapVersion soapVersion, List<?> headers, XMLStreamWriter writer) throws XMLStreamException {
    writer.writeStartDocument();
    writer.writeStartElement(SOAP_PREFIX,  soapVersion.getEnvelope().getLocalPart(), soapVersion.getNamespace());
    if (headers != null && !headers.isEmpty()) {
        writeHeaders(writer, headers, soapVersion);
    }
}
 
Example #17
Source Project: jdk8u60   Author: chenghanpeng   File: XMLStreamWriterUtil.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Gives the encoding with which XMLStreamWriter is created.
 *
 * @param writer XMLStreamWriter for which encoding is required
 * @return null if cannot be found, else the encoding
 */
public static @Nullable String getEncoding(XMLStreamWriter writer) {
    /*
     * TODO Add reflection logic to handle woodstox writer
     * as it implements XMLStreamWriter2#getEncoding()
     * It's not that important since woodstox writer is typically wrapped
     * in a writer with HasEncoding
     */
    return (writer instanceof HasEncoding)
            ? ((HasEncoding)writer).getEncoding()
            : null;
}
 
Example #18
Source Project: steady   Author: eclipse   File: RequiredParts.java    License: Apache License 2.0 5 votes vote down vote up
public void serialize(XMLStreamWriter writer) throws XMLStreamException {
    String localName = getRealName().getLocalPart();
    String namespaceURI = getRealName().getNamespaceURI();

    String prefix = writer.getPrefix(namespaceURI);

    if (prefix == null) {
        prefix = getRealName().getPrefix();
        writer.setPrefix(prefix, namespaceURI);
    }

    // <sp:RequiredParts>
    writer.writeStartElement(prefix, localName, namespaceURI);

    // xmlns:sp=".."
    writer.writeNamespace(prefix, namespaceURI);

    Header header;
    for (Iterator<Header> iterator = headers.iterator(); iterator.hasNext();) {
        header = iterator.next();
        // <sp:Header Name=".." Namespace=".." />
        writer.writeStartElement(prefix, SPConstants.HEADER, namespaceURI);
        // Name attribute is optional
        if (!StringUtils.isEmpty(header.getName())) {
            writer.writeAttribute("Name", header.getName());
        }
        writer.writeAttribute("Namespace", header.getNamespace());

        writer.writeEndElement();
    }

    // </sp:RequiredParts>
    writer.writeEndElement();
}
 
Example #19
Source Project: micro-integrator   Author: wso2   File: SPARQLQuery.java    License: Apache License 2.0 5 votes vote down vote up
private void processPostQuery(Object result, XMLStreamWriter xmlWriter,
                              InternalParamCollection params, int queryLevel) throws DataServiceFault {
    try {
        ResultSet results = (ResultSet) result;
        DataEntry dataEntry;
        while (results != null && results.hasNext()) {
            dataEntry = this.getDataEntryFromRS(results);
            this.writeResultEntry(xmlWriter, dataEntry, params, queryLevel);
        }
    } catch (Exception e) {
        throw new DataServiceFault(e, "Error in 'SPARQLQuery.processQuery'");
    }
}
 
Example #20
Source Project: java-technology-stack   Author: codeEngraver   File: StaxUtils.java    License: MIT License 5 votes vote down vote up
/**
 * Return the {@link XMLStreamWriter} for the given StAX Result.
 * @param result a JAXP 1.4 {@link StAXResult}
 * @return the {@link XMLStreamReader}
 * @throws IllegalArgumentException if {@code source} isn't a JAXP 1.4 {@link StAXResult}
 * or custom StAX Result
 */
@Nullable
public static XMLStreamWriter getXMLStreamWriter(Result result) {
	if (result instanceof StAXResult) {
		return ((StAXResult) result).getXMLStreamWriter();
	}
	else if (result instanceof StaxResult) {
		return ((StaxResult) result).getXMLStreamWriter();
	}
	else {
		throw new IllegalArgumentException("Result '" + result + "' is neither StaxResult nor StAXResult");
	}
}
 
Example #21
Source Project: java-client-api   Author: marklogic   File: DocumentMetadataPatchBuilderImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void write(XMLOutputSerializer out) throws Exception {
  XMLStreamWriter serializer = out.getSerializer();
  writeStartInsert(out, "/rapi:metadata/rapi:metadata-values", "last-child", null);

  serializer.writeStartElement("rapi", "metadata-value", REST_API_NS);
  serializer.writeAttribute("key", key);
  if(value != null)
    serializer.writeCharacters(value);
  serializer.writeEndElement();

  serializer.writeEndElement();
}
 
Example #22
Source Project: openjdk-8   Author: bpupadhyaya   File: FastInfosetStreamSOAPCodec.java    License: GNU General Public License v2.0 5 votes vote down vote up
private XMLStreamWriter getXMLStreamWriter(OutputStream out) {
    if (_serializer != null) {
        _serializer.setOutputStream(out);
        return _serializer;
    } else {
        return _serializer = FastInfosetCodec.createNewStreamWriter(out, _retainState);
    }
}
 
Example #23
Source Project: nifi   Author: apache   File: HtmlDocumentationWriter.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Write the description of the Restricted annotation if provided in this component.
 *
 * @param configurableComponent the component to describe
 * @param xmlStreamWriter the stream writer to use
 * @throws XMLStreamException thrown if there was a problem writing the XML
 */
private void writeRestrictedInfo(ConfigurableComponent configurableComponent, XMLStreamWriter xmlStreamWriter)
        throws XMLStreamException {
    final Restricted restricted = configurableComponent.getClass().getAnnotation(Restricted.class);

    writeSimpleElement(xmlStreamWriter, "h3", "Restricted: ");

    if(restricted != null) {
        final String value = restricted.value();

        if (!StringUtils.isBlank(value)) {
            xmlStreamWriter.writeCharacters(restricted.value());
        }

        final Restriction[] restrictions = restricted.restrictions();
        if (restrictions != null && restrictions.length > 0) {
            xmlStreamWriter.writeStartElement("table");
            xmlStreamWriter.writeAttribute("id", "restrictions");
            xmlStreamWriter.writeStartElement("tr");
            writeSimpleElement(xmlStreamWriter, "th", "Required Permission");
            writeSimpleElement(xmlStreamWriter, "th", "Explanation");
            xmlStreamWriter.writeEndElement();

            for (Restriction restriction : restrictions) {
                xmlStreamWriter.writeStartElement("tr");
                writeSimpleElement(xmlStreamWriter, "td", restriction.requiredPermission().getPermissionLabel());
                writeSimpleElement(xmlStreamWriter, "td", restriction.explanation());
                xmlStreamWriter.writeEndElement();
            }

            xmlStreamWriter.writeEndElement();
        } else {
            xmlStreamWriter.writeCharacters("This component requires access to restricted components regardless of restriction.");
        }
    } else {
        xmlStreamWriter.writeCharacters("This component is not restricted.");
    }
}
 
Example #24
Source Project: jeka   Author: jerkar   File: JkPomTemplateGenerator.java    License: Apache License 2.0 5 votes vote down vote up
private static void writeElement(String indent, XMLStreamWriter writer, String elementName,
        String text) throws XMLStreamException {
    if (text == null) {
        return;
    }
    writer.writeCharacters(indent);
    writeElement(writer, elementName, text);
}
 
Example #25
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: DOMUtil.java    License: GNU General Public License v2.0 5 votes vote down vote up
private static boolean isPrefixDeclared(XMLStreamWriter writer, String nsUri, String prefix) {
    boolean prefixDecl = false;
    NamespaceContext nscontext = writer.getNamespaceContext();
    Iterator prefixItr = nscontext.getPrefixes(nsUri);
    while (prefixItr.hasNext()) {
        if (prefix.equals(prefixItr.next())) {
            prefixDecl = true;
            break;
        }
    }
    return prefixDecl;
}
 
Example #26
Source Project: jboss-logmanager-ext   Author: jamezp   File: XmlFormatter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected Generator createGenerator(final Writer writer) throws Exception {
    final XMLStreamWriter xmlWriter;
    if (prettyPrint) {
        xmlWriter = new IndentingXmlWriter(factory.createXMLStreamWriter(writer));
    } else {
        xmlWriter = factory.createXMLStreamWriter(writer);
    }
    return new XmlGenerator(xmlWriter);
}
 
Example #27
Source Project: activiti6-boot2   Author: dingziyang   File: FieldExtensionExport.java    License: Apache License 2.0 5 votes vote down vote up
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;
          }

          xtw.writeStartElement(ACTIVITI_EXTENSIONS_PREFIX, ELEMENT_FIELD, ACTIVITI_EXTENSIONS_NAMESPACE);
          BpmnXMLUtil.writeDefaultAttribute(ATTRIBUTE_FIELD_NAME, fieldExtension.getFieldName(), xtw);

          if (StringUtils.isNotEmpty(fieldExtension.getStringValue())) {
            xtw.writeStartElement(ACTIVITI_EXTENSIONS_PREFIX, ELEMENT_FIELD_STRING, ACTIVITI_EXTENSIONS_NAMESPACE);
            xtw.writeCData(fieldExtension.getStringValue());
          } else {
            xtw.writeStartElement(ACTIVITI_EXTENSIONS_PREFIX, ATTRIBUTE_FIELD_EXPRESSION, ACTIVITI_EXTENSIONS_NAMESPACE);
            xtw.writeCData(fieldExtension.getExpression());
          }
          xtw.writeEndElement();
          xtw.writeEndElement();
        }
      }
    }
    return didWriteExtensionStartElement;
  }
 
Example #28
Source Project: olingo-odata4   Author: apache   File: AtomSerializer.java    License: Apache License 2.0 5 votes vote down vote up
private void collection(final XMLStreamWriter writer,
    final ValueType valueType, final EdmPrimitiveTypeKind kind, final List<?> value)
        throws XMLStreamException, EdmPrimitiveTypeException {
  for (Object item : value) {
    writer.writeStartElement(Constants.PREFIX_METADATA, Constants.ELEM_ELEMENT, Constants.NS_METADATA);
    value(writer, valueType, kind, item);
    writer.writeEndElement();
  }
}
 
Example #29
Source Project: steady   Author: eclipse   File: RecipientSignatureToken.java    License: Apache License 2.0 5 votes vote down vote up
public void serialize(XMLStreamWriter writer) throws XMLStreamException {
    String localName = getRealName().getLocalPart();
    String namespaceURI = getRealName().getNamespaceURI();

    String prefix = writer.getPrefix(namespaceURI);

    if (prefix == null) {
        prefix = getRealName().getPrefix();
        writer.setPrefix(prefix, namespaceURI);
    }

    // <sp:RecipientSignatureToken>
    writer.writeStartElement(prefix, localName, namespaceURI);

    String pPrefix = writer.getPrefix(SPConstants.POLICY.getNamespaceURI());
    if (pPrefix == null) {
        pPrefix = SPConstants.POLICY.getPrefix();
        writer.setPrefix(pPrefix, SPConstants.POLICY.getNamespaceURI());
    }

    // <wsp:Policy>
    writer.writeStartElement(pPrefix, SPConstants.POLICY.getLocalPart(), SPConstants.POLICY
        .getNamespaceURI());

    Token token = getRecipientSignatureToken();
    if (token == null) {
        throw new RuntimeException("RecipientSignatureToken doesn't contain any token assertions");
    }
    token.serialize(writer);

    // </wsp:Policy>
    writer.writeEndElement();

    // </sp:RecipientSignatureToken>
    writer.writeEndElement();
}
 
Example #30
Source Project: openjdk-8-source   Author: keerath   File: SAAJMessage.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void writeTo(XMLStreamWriter writer) throws XMLStreamException {
    try {
        writer.writeStartDocument();
        if (!parsedMessage) {
            DOMUtil.serializeNode(sm.getSOAPPart().getEnvelope(), writer);
        } else {
            SOAPEnvelope env = sm.getSOAPPart().getEnvelope();
            DOMUtil.writeTagWithAttributes(env, writer);
            if (hasHeaders()) {
                if(env.getHeader() != null) {
                    DOMUtil.writeTagWithAttributes(env.getHeader(), writer);
                } else {
                    writer.writeStartElement(env.getPrefix(), "Header", env.getNamespaceURI());
                }
                for (Header h : headers.asList()) {
                    h.writeTo(writer);
                }
                writer.writeEndElement();
            }

            DOMUtil.serializeNode(sm.getSOAPBody(), writer);
            writer.writeEndElement();
        }
        writer.writeEndDocument();
        writer.flush();
    } catch (SOAPException ex) {
        throw new XMLStreamException2(ex);
        //for now. ask jaxws team what to do.
    }
}