Search in sources :

Example 1 with GetDataAvailabilityStreamWriter

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

the class GetDataAvailabilityXmlEncoder method create.

@Override
protected XmlObject create(GetDataAvailabilityResponse response) throws EncodingException {
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        EncodingContext ctx = EncodingContext.empty().with(EncoderFlags.ENCODER_REPOSITORY, getEncoderRepository()).with(XmlEncoderFlags.XML_OPTIONS, (Supplier<XmlOptions>) this::getXmlOptions);
        if (GetDataAvailabilityConstants.NS_GDA.equals(response.getResponseFormat())) {
            new GetDataAvailabilityStreamWriter(ctx, baos, response.getDataAvailabilities()).write();
        } else if (GetDataAvailabilityConstants.NS_GDA_20.equals(response.getResponseFormat())) {
            new GetDataAvailabilityV20StreamWriter(ctx, baos, response.getDataAvailabilities()).write();
        }
        XmlObject encodedObject = XmlObject.Factory.parse(baos.toString("UTF8"));
        XmlHelper.validateDocument(encodedObject, EncodingException::new);
        return encodedObject;
    } catch (XMLStreamException | XmlException | UnsupportedEncodingException ex) {
        throw new EncodingException("Error encoding response", ex);
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) EncodingException(org.n52.svalbard.encode.exception.EncodingException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) XmlException(org.apache.xmlbeans.XmlException) GetDataAvailabilityV20StreamWriter(org.n52.svalbard.write.GetDataAvailabilityV20StreamWriter) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Supplier(java.util.function.Supplier) XmlObject(org.apache.xmlbeans.XmlObject) ByteArrayOutputStream(java.io.ByteArrayOutputStream) GetDataAvailabilityStreamWriter(org.n52.svalbard.write.GetDataAvailabilityStreamWriter)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Supplier (java.util.function.Supplier)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 XmlException (org.apache.xmlbeans.XmlException)1 XmlObject (org.apache.xmlbeans.XmlObject)1 EncodingException (org.n52.svalbard.encode.exception.EncodingException)1 GetDataAvailabilityStreamWriter (org.n52.svalbard.write.GetDataAvailabilityStreamWriter)1 GetDataAvailabilityV20StreamWriter (org.n52.svalbard.write.GetDataAvailabilityV20StreamWriter)1