Search in sources :

Example 1 with MappedNamespaceConvention

use of org.codehaus.jettison.mapped.MappedNamespaceConvention in project jersey by jersey.

the class Stax2JettisonFactory method createWriter.

public static XMLStreamWriter createWriter(final Writer writer, final JettisonConfig config) throws IOException {
    switch(config.getNotation()) {
        case BADGERFISH:
            return new BadgerFishXMLStreamWriter(writer);
        case MAPPED_JETTISON:
            Configuration jmConfig;
            if (null == config.getXml2JsonNs()) {
                jmConfig = new Configuration();
            } else {
                jmConfig = new Configuration(config.getXml2JsonNs());
            }
            final MappedXMLStreamWriter result = new MappedXMLStreamWriter(new MappedNamespaceConvention(jmConfig), writer);
            for (String array : config.getArrayElements()) {
                result.serializeAsArray(array);
            }
            return result;
        default:
            return null;
    }
}
Also used : Configuration(org.codehaus.jettison.mapped.Configuration) MappedXMLStreamWriter(org.codehaus.jettison.mapped.MappedXMLStreamWriter) MappedNamespaceConvention(org.codehaus.jettison.mapped.MappedNamespaceConvention) BadgerFishXMLStreamWriter(org.codehaus.jettison.badgerfish.BadgerFishXMLStreamWriter)

Example 2 with MappedNamespaceConvention

use of org.codehaus.jettison.mapped.MappedNamespaceConvention in project GeoGig by boundlessgeo.

the class JettisonRepresentation method createWriter.

private XMLStreamWriter createWriter(Writer writer) {
    final MediaType mediaType = getMediaType();
    XMLStreamWriter xml;
    if (mediaType.getSubType().equalsIgnoreCase("xml")) {
        try {
            xml = XMLOutputFactory.newFactory().createXMLStreamWriter(writer);
        } catch (XMLStreamException ex) {
            throw new RuntimeException(ex);
        }
    } else if (mediaType == MediaType.APPLICATION_JSON) {
        xml = new MappedXMLStreamWriter(new MappedNamespaceConvention(), writer);
    } else {
        throw new RuntimeException("mediatype not handled " + mediaType);
    }
    return xml;
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) MappedXMLStreamWriter(org.codehaus.jettison.mapped.MappedXMLStreamWriter) MediaType(org.restlet.data.MediaType) MappedXMLStreamWriter(org.codehaus.jettison.mapped.MappedXMLStreamWriter) MappedNamespaceConvention(org.codehaus.jettison.mapped.MappedNamespaceConvention)

Example 3 with MappedNamespaceConvention

use of org.codehaus.jettison.mapped.MappedNamespaceConvention in project cxf by apache.

the class JSONUtils method createStreamWriter.

// CHECKSTYLE:OFF
public static XMLStreamWriter createStreamWriter(OutputStream os, QName qname, boolean writeXsiType, Configuration config, boolean serializeAsArray, List<String> arrayKeys, boolean dropRootElement, String enc) throws Exception {
    // CHECKSTYLE:ON
    MappedNamespaceConvention convention = new MappedNamespaceConvention(config);
    AbstractXMLStreamWriter xsw = new MappedXMLStreamWriter(convention, new OutputStreamWriter(os, enc));
    if (serializeAsArray) {
        if (arrayKeys != null) {
            for (String key : arrayKeys) {
                xsw.serializeAsArray(key);
            }
        } else if (qname != null) {
            String key = getKey(convention, qname);
            xsw.serializeAsArray(key);
        }
    }
    return !writeXsiType || dropRootElement ? new IgnoreContentJettisonWriter(xsw, writeXsiType, dropRootElement) : xsw;
}
Also used : AbstractXMLStreamWriter(org.codehaus.jettison.AbstractXMLStreamWriter) MappedNamespaceConvention(org.codehaus.jettison.mapped.MappedNamespaceConvention) MappedXMLStreamWriter(org.codehaus.jettison.mapped.MappedXMLStreamWriter) OutputStreamWriter(java.io.OutputStreamWriter)

Aggregations

MappedNamespaceConvention (org.codehaus.jettison.mapped.MappedNamespaceConvention)3 MappedXMLStreamWriter (org.codehaus.jettison.mapped.MappedXMLStreamWriter)3 OutputStreamWriter (java.io.OutputStreamWriter)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)1 AbstractXMLStreamWriter (org.codehaus.jettison.AbstractXMLStreamWriter)1 BadgerFishXMLStreamWriter (org.codehaus.jettison.badgerfish.BadgerFishXMLStreamWriter)1 Configuration (org.codehaus.jettison.mapped.Configuration)1 MediaType (org.restlet.data.MediaType)1