use of org.n52.svalbard.encode.EncodingContext in project arctic-sea by 52North.
the class AbstractXmlResponseEncoder method create.
/**
* Override this method in concrete response encoder if streaming is supported for this operations.
*
* @param response Implementation of {@link OwsServiceResponse}
* @param outputStream {@link OutputStream} to write
* @param encodingValues {@link EncodingValues} with additional indicators for encoding
*
* @throws EncodingException If an error occurs during encoding/writing to stream
*/
protected void create(T response, OutputStream outputStream, EncodingContext encodingValues) throws EncodingException {
try {
XmlOptions xmlOptions;
if (encodingValues.has(StreamingEncoderFlags.EMBEDDED)) {
xmlOptions = new XmlOptions(getXmlOptions());
xmlOptions.setSaveNoXmlDecl();
} else {
xmlOptions = getXmlOptions();
}
XmlObject xmlObject = create(response);
setSchemaLocations(xmlObject);
xmlObject.save(outputStream, xmlOptions);
} catch (IOException ioe) {
throw new EncodingException("Error while writing element to stream!", ioe);
}
}
use of org.n52.svalbard.encode.EncodingContext in project arctic-sea by 52North.
the class AbstractXmlResponseEncoder method encode.
@Override
public XmlObject encode(T response, EncodingContext additionalValues) throws EncodingException {
if (response == null) {
throw new UnsupportedEncoderInputException(this, (String) null);
}
XmlObject xml = create(response);
setSchemaLocations(xml);
if (validate) {
XmlHelper.validateDocument(xml, EncodingException::new);
}
return xml;
}
use of org.n52.svalbard.encode.EncodingContext in project arctic-sea by 52North.
the class AqdEncoder method encodeGetObservationResponse.
private XmlObject encodeGetObservationResponse(GetObservationResponse response, EncodingContext ctx) throws EncodingException {
try {
FeatureCollection featureCollection = getFeatureCollection(response);
// TODO get FLOW from response
EReportingHeader eReportingHeader = getEReportingHeader(getReportObligationType(response));
featureCollection.addMember(eReportingHeader);
TimePeriod timePeriod = new TimePeriod();
TimeInstant resultTime = new TimeInstant(new DateTime(DateTimeZone.UTC));
int counter = 1;
ObservationStream observationCollection = response.getObservationCollection();
while (observationCollection.hasNext()) {
OmObservation observation = observationCollection.next();
if (observation.getValue() instanceof ObservationStream) {
ObservationStream value = (ObservationStream) observation.getValue();
if (value instanceof StreamingValue) {
value = value.merge();
}
while (value.hasNext()) {
processObservation(value.next(), timePeriod, resultTime, featureCollection, eReportingHeader, counter++);
}
} else {
processObservation(observation, timePeriod, resultTime, featureCollection, eReportingHeader, counter++);
}
}
if (!timePeriod.isEmpty()) {
eReportingHeader.setReportingPeriod(Referenceable.of((Time) timePeriod));
}
return encodeObjectToXml(GmlConstants.NS_GML_32, featureCollection, ctx.with(XmlEncoderFlags.ENCODE_NAMESPACE, OmConstants.NS_OM_2).with(XmlBeansEncodingFlags.DOCUMENT));
} catch (OwsExceptionReport ex) {
throw new EncodingException(ex);
}
}
use of org.n52.svalbard.encode.EncodingContext in project arctic-sea by 52North.
the class AqdEncoder method encodeEReportingHeader.
private XmlObject encodeEReportingHeader(EReportingHeader element, 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 EReportingHeaderEncoder(context, baos, element).write();
if (context.has(XmlStreamEncoderFlags.XML_WRITER)) {
return null;
}
return XmlObject.Factory.parse(baos.toString("UTF8"));
} catch (XMLStreamException | XmlException | UnsupportedEncodingException xmlse) {
throw new EncodingException("Error encoding response", xmlse);
}
}
use of org.n52.svalbard.encode.EncodingContext in project arctic-sea by 52North.
the class AqdGetObservationResponseEncoder method create.
@Override
protected XmlObject create(GetObservationResponse response) throws EncodingException {
try {
FeatureCollection featureCollection = createFeatureCollection(response);
// TODO get FLOW from response
EReportingHeader eReportingHeader = getEReportingHeader(getReportObligationType(response));
featureCollection.addMember(eReportingHeader);
TimePeriod timePeriod = new TimePeriod();
TimeInstant resultTime = new TimeInstant(new DateTime(DateTimeZone.UTC));
int counter = 1;
while (response.getObservationCollection().hasNext()) {
OmObservation observation = response.getObservationCollection().next();
processObservation(observation, timePeriod, resultTime, featureCollection, eReportingHeader, counter++);
}
if (!timePeriod.isEmpty()) {
eReportingHeader.setReportingPeriod(Referenceable.of((Time) timePeriod));
}
EncodingContext ctx = EncodingContext.empty().with(XmlEncoderFlags.ENCODE_NAMESPACE, OmConstants.NS_OM_2).with(XmlBeansEncodingFlags.DOCUMENT);
return encodeGml(ctx, featureCollection);
} catch (OwsExceptionReport ex) {
throw new EncodingException(ex);
}
}
Aggregations