Search in sources :

Example 1 with MappedXMLStreamWriter

use of org.codehaus.jettison.mapped.MappedXMLStreamWriter 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 MappedXMLStreamWriter

use of org.codehaus.jettison.mapped.MappedXMLStreamWriter in project opencast by opencast.

the class Group method toJSON.

@Override
public String toJSON() {
    try {
        if (context == null) {
            createJAXBContext();
        }
        Marshaller marshaller = Group.context.createMarshaller();
        Configuration config = new Configuration();
        config.setSupressAtAttributes(true);
        MappedNamespaceConvention con = new MappedNamespaceConvention(config);
        StringWriter writer = new StringWriter();
        XMLStreamWriter xmlStreamWriter = new MappedXMLStreamWriter(con, writer) {

            @Override
            public void writeStartElement(String prefix, String local, String uri) throws XMLStreamException {
                super.writeStartElement("", local, "");
            }

            @Override
            public void writeStartElement(String uri, String local) throws XMLStreamException {
                super.writeStartElement("", local, "");
            }

            @Override
            public void setPrefix(String pfx, String uri) throws XMLStreamException {
            }

            @Override
            public void setDefaultNamespace(String uri) throws XMLStreamException {
            }
        };
        marshaller.marshal(this, xmlStreamWriter);
        return writer.toString();
    } catch (JAXBException e) {
        throw new IllegalStateException(e.getLinkedException() != null ? e.getLinkedException() : e);
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) Configuration(org.codehaus.jettison.mapped.Configuration) StringWriter(java.io.StringWriter) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) MappedXMLStreamWriter(org.codehaus.jettison.mapped.MappedXMLStreamWriter) JAXBException(javax.xml.bind.JAXBException) MappedNamespaceConvention(org.codehaus.jettison.mapped.MappedNamespaceConvention) MappedXMLStreamWriter(org.codehaus.jettison.mapped.MappedXMLStreamWriter)

Example 3 with MappedXMLStreamWriter

use of org.codehaus.jettison.mapped.MappedXMLStreamWriter in project opencast by opencast.

the class Series method toJSON.

/**
 * Serializes the series.
 *
 * @return the serialized series
 */
@Override
public String toJSON() {
    try {
        if (context == null) {
            createJAXBContext();
        }
        Marshaller marshaller = Series.context.createMarshaller();
        Configuration config = new Configuration();
        config.setSupressAtAttributes(true);
        MappedNamespaceConvention con = new MappedNamespaceConvention(config);
        StringWriter writer = new StringWriter();
        XMLStreamWriter xmlStreamWriter = new MappedXMLStreamWriter(con, writer) {

            @Override
            public void writeStartElement(String prefix, String local, String uri) throws XMLStreamException {
                super.writeStartElement("", local, "");
            }

            @Override
            public void writeStartElement(String uri, String local) throws XMLStreamException {
                super.writeStartElement("", local, "");
            }

            @Override
            public void setPrefix(String pfx, String uri) throws XMLStreamException {
            }

            @Override
            public void setDefaultNamespace(String uri) throws XMLStreamException {
            }
        };
        marshaller.marshal(this, xmlStreamWriter);
        return writer.toString();
    } catch (JAXBException e) {
        throw new IllegalStateException(e.getLinkedException() != null ? e.getLinkedException() : e);
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) Configuration(org.codehaus.jettison.mapped.Configuration) StringWriter(java.io.StringWriter) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) MappedXMLStreamWriter(org.codehaus.jettison.mapped.MappedXMLStreamWriter) JAXBException(javax.xml.bind.JAXBException) MappedNamespaceConvention(org.codehaus.jettison.mapped.MappedNamespaceConvention) MappedXMLStreamWriter(org.codehaus.jettison.mapped.MappedXMLStreamWriter)

Example 4 with MappedXMLStreamWriter

use of org.codehaus.jettison.mapped.MappedXMLStreamWriter in project opencast by opencast.

the class Theme method toJSON.

/**
 * Serializes the theme.
 *
 * @return the serialized theme
 */
@Override
public String toJSON() {
    try {
        if (context == null) {
            createJAXBContext();
        }
        Marshaller marshaller = Theme.context.createMarshaller();
        Configuration config = new Configuration();
        config.setSupressAtAttributes(true);
        MappedNamespaceConvention con = new MappedNamespaceConvention(config);
        StringWriter writer = new StringWriter();
        XMLStreamWriter xmlStreamWriter = new MappedXMLStreamWriter(con, writer) {

            @Override
            public void writeStartElement(String prefix, String local, String uri) throws XMLStreamException {
                super.writeStartElement("", local, "");
            }

            @Override
            public void writeStartElement(String uri, String local) throws XMLStreamException {
                super.writeStartElement("", local, "");
            }

            @Override
            public void setPrefix(String pfx, String uri) throws XMLStreamException {
            }

            @Override
            public void setDefaultNamespace(String uri) throws XMLStreamException {
            }
        };
        marshaller.marshal(this, xmlStreamWriter);
        return writer.toString();
    } catch (JAXBException e) {
        throw new IllegalStateException(e.getLinkedException() != null ? e.getLinkedException() : e);
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) Configuration(org.codehaus.jettison.mapped.Configuration) StringWriter(java.io.StringWriter) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) MappedXMLStreamWriter(org.codehaus.jettison.mapped.MappedXMLStreamWriter) JAXBException(javax.xml.bind.JAXBException) MappedNamespaceConvention(org.codehaus.jettison.mapped.MappedNamespaceConvention) MappedXMLStreamWriter(org.codehaus.jettison.mapped.MappedXMLStreamWriter)

Example 5 with MappedXMLStreamWriter

use of org.codehaus.jettison.mapped.MappedXMLStreamWriter in project opencast by opencast.

the class MediaPackageParser method getAsJSON.

/**
 * Serializes the media package to a JSON string.
 *
 * @param mediaPackage
 *          the media package
 * @return the serialized media package
 */
public static String getAsJSON(MediaPackage mediaPackage) {
    if (mediaPackage == null) {
        throw new IllegalArgumentException("Mediapackage must not be null");
    }
    try {
        Marshaller marshaller = MediaPackageImpl.context.createMarshaller();
        Configuration config = new Configuration();
        config.setSupressAtAttributes(true);
        MappedNamespaceConvention con = new MappedNamespaceConvention(config);
        StringWriter writer = new StringWriter();
        XMLStreamWriter xmlStreamWriter = new MappedXMLStreamWriter(con, writer) {

            @Override
            public void writeStartElement(String prefix, String local, String uri) throws XMLStreamException {
                super.writeStartElement("", local, "");
            }

            @Override
            public void writeStartElement(String uri, String local) throws XMLStreamException {
                super.writeStartElement("", local, "");
            }

            @Override
            public void setPrefix(String pfx, String uri) throws XMLStreamException {
            }

            @Override
            public void setDefaultNamespace(String uri) throws XMLStreamException {
            }
        };
        marshaller.marshal(mediaPackage, xmlStreamWriter);
        return writer.toString();
    } catch (JAXBException e) {
        throw new IllegalStateException(e.getLinkedException() != null ? e.getLinkedException() : e);
    }
}
Also used : Marshaller(javax.xml.bind.Marshaller) Configuration(org.codehaus.jettison.mapped.Configuration) StringWriter(java.io.StringWriter) MappedXMLStreamWriter(org.codehaus.jettison.mapped.MappedXMLStreamWriter) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) JAXBException(javax.xml.bind.JAXBException) MappedNamespaceConvention(org.codehaus.jettison.mapped.MappedNamespaceConvention) MappedXMLStreamWriter(org.codehaus.jettison.mapped.MappedXMLStreamWriter)

Aggregations

MappedNamespaceConvention (org.codehaus.jettison.mapped.MappedNamespaceConvention)8 MappedXMLStreamWriter (org.codehaus.jettison.mapped.MappedXMLStreamWriter)8 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)6 Configuration (org.codehaus.jettison.mapped.Configuration)6 StringWriter (java.io.StringWriter)5 JAXBException (javax.xml.bind.JAXBException)5 Marshaller (javax.xml.bind.Marshaller)5 OutputStreamWriter (java.io.OutputStreamWriter)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 AbstractXMLStreamWriter (org.codehaus.jettison.AbstractXMLStreamWriter)1 BadgerFishXMLStreamWriter (org.codehaus.jettison.badgerfish.BadgerFishXMLStreamWriter)1 MediaType (org.restlet.data.MediaType)1