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);
}
}
Aggregations