Search in sources :

Example 1 with RelatedOfferingXmlStreamWriter

use of org.n52.svalbard.write.RelatedOfferingXmlStreamWriter in project arctic-sea by 52North.

the class RelatedOfferingXmlStreamWriterTest method should_encode_relatedOfferings.

@Test
public void should_encode_relatedOfferings() throws XMLStreamException, EncodingException, XmlException, IOException {
    RelatedOfferings ro = new RelatedOfferings();
    ro.addValue("role_1", "offering_1");
    ro.addValue("role_2", "offering_2");
    try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
        new RelatedOfferingXmlStreamWriter(EncodingContext.of(EncoderFlags.ENCODER_REPOSITORY, new EncoderRepository()), out, ro).write();
        XmlObject.Factory.parse(new String(out.toByteArray()));
    }
}
Also used : EncoderRepository(org.n52.svalbard.encode.EncoderRepository) ByteArrayOutputStream(java.io.ByteArrayOutputStream) RelatedOfferings(org.n52.shetland.ogc.sos.ro.RelatedOfferings) Test(org.junit.Test)

Example 2 with RelatedOfferingXmlStreamWriter

use of org.n52.svalbard.write.RelatedOfferingXmlStreamWriter in project arctic-sea by 52North.

the class RelatedOfferingsEncoder method encode.

@Override
public XmlObject encode(RelatedOfferings objectToEncode, EncodingContext ctx) throws EncodingException {
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        EncodingContext context = ctx.with(EncoderFlags.ENCODER_REPOSITORY, getEncoderRepository()).with(XmlEncoderFlags.XML_OPTIONS, (Supplier<XmlOptions>) this::getXmlOptions);
        new RelatedOfferingXmlStreamWriter(context, baos, objectToEncode).write();
        return XmlObject.Factory.parse(baos.toString("UTF8"));
    } catch (XMLStreamException | XmlException | UnsupportedEncodingException ex) {
        String message = String.format("Error encoding %s", objectToEncode.getClass().getSimpleName());
        throw new EncodingException(message, ex);
    }
}
Also used : RelatedOfferingXmlStreamWriter(org.n52.svalbard.write.RelatedOfferingXmlStreamWriter) XMLStreamException(javax.xml.stream.XMLStreamException) EncodingException(org.n52.svalbard.encode.exception.EncodingException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) XmlException(org.apache.xmlbeans.XmlException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Supplier(java.util.function.Supplier) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Supplier (java.util.function.Supplier)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 XmlException (org.apache.xmlbeans.XmlException)1 Test (org.junit.Test)1 RelatedOfferings (org.n52.shetland.ogc.sos.ro.RelatedOfferings)1 EncoderRepository (org.n52.svalbard.encode.EncoderRepository)1 EncodingException (org.n52.svalbard.encode.exception.EncodingException)1 RelatedOfferingXmlStreamWriter (org.n52.svalbard.write.RelatedOfferingXmlStreamWriter)1