Search in sources :

Example 81 with XMLStreamWriter

use of javax.xml.stream.XMLStreamWriter in project dhis2-core by dhis2.

the class JacksonOrganisationUnitChildrenSerializer method serialize.

@Override
public void serialize(OrganisationUnit value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
    if (ToXmlGenerator.class.isAssignableFrom(jgen.getClass())) {
        ToXmlGenerator xmlGenerator = (ToXmlGenerator) jgen;
        try {
            XMLStreamWriter staxWriter = xmlGenerator.getStaxWriter();
            staxWriter.writeStartElement(DxfNamespaces.DXF_2_0, "child");
            staxWriter.writeAttribute("id", value.getUid());
            staxWriter.writeAttribute("name", value.getName());
            staxWriter.writeAttribute("created", DATE_FORMAT.format(value.getCreated()));
            staxWriter.writeAttribute("lastUpdated", DATE_FORMAT.format(value.getLastUpdated()));
            if (value.getHref() != null) {
                staxWriter.writeAttribute("href", value.getHref());
            }
            staxWriter.writeAttribute("hasChildren", String.valueOf(value.hasChild()));
            staxWriter.writeEndElement();
        } catch (XMLStreamException e) {
            //TODO fix
            e.printStackTrace();
        }
    } else {
        jgen.writeStartObject();
        jgen.writeStringField("id", value.getUid());
        jgen.writeStringField("name", value.getName());
        jgen.writeFieldName("created");
        provider.defaultSerializeDateValue(value.getCreated(), jgen);
        jgen.writeFieldName("lastUpdated");
        provider.defaultSerializeDateValue(value.getLastUpdated(), jgen);
        if (value.getHref() != null) {
            jgen.writeStringField("href", value.getHref());
        }
        jgen.writeBooleanField("hasChildren", value.hasChild());
        jgen.writeEndObject();
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) ToXmlGenerator(com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator)

Example 82 with XMLStreamWriter

use of javax.xml.stream.XMLStreamWriter in project dhis2-core by dhis2.

the class JacksonOrganisationUnitGroupSymbolSerializer method serialize.

@Override
public void serialize(OrganisationUnitGroup value, JsonGenerator jgen, SerializerProvider provider) throws IOException {
    if (ToXmlGenerator.class.isAssignableFrom(jgen.getClass())) {
        ToXmlGenerator xmlGenerator = (ToXmlGenerator) jgen;
        try {
            XMLStreamWriter staxWriter = xmlGenerator.getStaxWriter();
            staxWriter.writeStartElement(DxfNamespaces.DXF_2_0, "organisationUnitGroup");
            staxWriter.writeAttribute("id", value.getUid());
            staxWriter.writeAttribute("name", value.getName());
            staxWriter.writeAttribute("created", DATE_FORMAT.format(value.getCreated()));
            staxWriter.writeAttribute("lastUpdated", DATE_FORMAT.format(value.getLastUpdated()));
            if (value.getHref() != null) {
                staxWriter.writeAttribute("href", value.getHref());
            }
            staxWriter.writeAttribute("symbol", String.valueOf(value.getSymbol()));
            staxWriter.writeEndElement();
        } catch (XMLStreamException e) {
            //TODO fix
            e.printStackTrace();
        }
    } else {
        jgen.writeStartObject();
        jgen.writeStringField("id", value.getUid());
        jgen.writeStringField("name", value.getName());
        jgen.writeFieldName("created");
        provider.defaultSerializeDateValue(value.getCreated(), jgen);
        jgen.writeFieldName("lastUpdated");
        provider.defaultSerializeDateValue(value.getLastUpdated(), jgen);
        if (value.getHref() != null) {
            jgen.writeStringField("href", value.getHref());
        }
        jgen.writeStringField("symbol", value.getSymbol());
        jgen.writeEndObject();
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) ToXmlGenerator(com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator)

Aggregations

XMLStreamWriter (javax.xml.stream.XMLStreamWriter)82 XMLStreamException (javax.xml.stream.XMLStreamException)36 XMLOutputFactory (javax.xml.stream.XMLOutputFactory)28 StringWriter (java.io.StringWriter)15 ByteArrayOutputStream (java.io.ByteArrayOutputStream)14 IOException (java.io.IOException)12 XmlWriter (org.apache.aries.blueprint.plugin.spi.XmlWriter)7 OutputStream (java.io.OutputStream)6 StAXResult (javax.xml.transform.stax.StAXResult)6 Test (org.junit.Test)6 OutputStreamWriter (java.io.OutputStreamWriter)5 JAXBException (javax.xml.bind.JAXBException)5 StreamResult (javax.xml.transform.stream.StreamResult)5 ZipEntry (java.util.zip.ZipEntry)4 XMLStreamReader (javax.xml.stream.XMLStreamReader)4 PcrManifest (com.intel.mountwilson.manifest.data.PcrManifest)3 StringReader (java.io.StringReader)3 ToXmlGenerator (com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator)2 IManifest (com.intel.mountwilson.manifest.data.IManifest)2 Headers (com.sun.net.httpserver.Headers)2