use of org.n52.svalbard.encode.EncodingContext in project arctic-sea by 52North.
the class AqdGetObservationResponseEncoder method create.
@Override
protected void create(GetObservationResponse response, OutputStream outputStream, EncodingContext ctx) throws EncodingException {
FeatureCollection featureCollection = createFeatureCollection(response);
EReportingHeader eReportingHeader;
TimePeriod timePeriod;
try {
eReportingHeader = getEReportingHeader(getReportObligationType(response));
featureCollection.addMember(eReportingHeader);
timePeriod = addToFeatureCollectionAndGetTimePeriod(featureCollection, response, eReportingHeader);
} catch (OwsExceptionReport ex) {
throw new EncodingException(ex);
}
if (!timePeriod.isEmpty()) {
eReportingHeader.setReportingPeriod(Referenceable.of((Time) timePeriod));
}
try {
EncodingContext context = ctx.with(EncoderFlags.ENCODER_REPOSITORY, getEncoderRepository()).with(XmlEncoderFlags.XML_OPTIONS, (Supplier<XmlOptions>) this::getXmlOptions).with(XmlEncoderFlags.ENCODE_NAMESPACE, OmConstants.NS_OM_2).with(XmlBeansEncodingFlags.DOCUMENT);
new AqdGetObservationResponseXmlStreamWriter(context, outputStream, featureCollection).write();
} catch (XMLStreamException xmlse) {
throw new EncodingException("Error while writing element to stream!", xmlse);
}
}
use of org.n52.svalbard.encode.EncodingContext in project arctic-sea by 52North.
the class EnvironmentalMonitoringFaciltityDocumentEncoder method encode.
@Override
public XmlObject encode(AbstractFeature abstractFeature, EncodingContext context) throws EncodingException {
if (abstractFeature instanceof EnvironmentalMonitoringFacility) {
EnvironmentalMonitoringFacilityDocument emfpd = EnvironmentalMonitoringFacilityDocument.Factory.newInstance();
emfpd.setEnvironmentalMonitoringFacility(createEnvironmentalMonitoringFaciltityType((EnvironmentalMonitoringFacility) abstractFeature));
return emfpd;
}
throw new UnsupportedEncoderInputException(this, abstractFeature);
}
use of org.n52.svalbard.encode.EncodingContext in project arctic-sea by 52North.
the class InspireXmlEncoder method encodeObject.
private XmlObject encodeObject(InspireObject objectToEncode, EncodingContext ctx) throws EncodingException {
try {
checkIfSupported(objectToEncode);
ByteArrayOutputStream out = new ByteArrayOutputStream();
EncodingContext context = ctx.with(EncoderFlags.ENCODER_REPOSITORY, getEncoderRepository()).with(XmlEncoderFlags.XML_OPTIONS, (Supplier<XmlOptions>) this::getXmlOptions);
new InspireXmlStreamWriter(context, out, objectToEncode).write();
String s = out.toString("UTF8");
return XmlObject.Factory.parse(s);
} catch (XMLStreamException | DateTimeFormatException | XmlException | UnsupportedEncodingException ex) {
throw new EncodingException("Error encoding Inspire extended capabilities!", ex);
}
}
use of org.n52.svalbard.encode.EncodingContext in project arctic-sea by 52North.
the class SamplingEncoderv20 method addSampledFeatures.
protected void addSampledFeatures(SFSamplingFeatureType sfsft, AbstractSamplingFeature sampFeat) throws EncodingException {
if (sampFeat.isSetSampledFeatures()) {
for (AbstractFeature sampledFeature : sampFeat.getSampledFeatures()) {
XmlObject encodeObjectToXml = encodeObjectToXml(GmlConstants.NS_GML_32, sampledFeature, new EncodingContext().with(XmlBeansEncodingFlags.REFERENCED));
sfsft.addNewSampledFeature().set(encodeObjectToXml);
}
} else {
sfsft.addNewSampledFeature().setHref(OGCConstants.UNKNOWN);
}
}
use of org.n52.svalbard.encode.EncodingContext in project arctic-sea by 52North.
the class SamplingEncoderv20 method createFeature.
@Override
protected XmlObject createFeature(FeaturePropertyType featurePropertyType, AbstractFeature abstractFeature, EncodingContext context) throws EncodingException {
if (abstractFeature instanceof AbstractSamplingFeature) {
final AbstractSamplingFeature samplingFeature = (AbstractSamplingFeature) abstractFeature;
String namespace;
if (context.has(XmlEncoderFlags.ENCODE_NAMESPACE) && context.get(XmlEncoderFlags.ENCODE_NAMESPACE).isPresent() && context.get(XmlEncoderFlags.ENCODE_NAMESPACE).get() instanceof String) {
namespace = (String) context.get(XmlEncoderFlags.ENCODE_NAMESPACE).get();
} else {
namespace = OMHelper.getNamespaceForFeatureType(samplingFeature.getFeatureType());
}
final XmlObject encodedXmlObject = encodeObjectToXml(namespace, samplingFeature);
if (encodedXmlObject != null) {
return encodedXmlObject;
} else {
if (samplingFeature.isSetXml()) {
try {
// XmlDescription? <-- XmlCursor
return XmlObject.Factory.parse(samplingFeature.getXml());
} catch (final XmlException xmle) {
throw new EncodingException("Error while encoding featurePropertyType!", xmle);
}
} else {
featurePropertyType.setHref(samplingFeature.getIdentifierCodeWithAuthority().getValue());
if (samplingFeature.isSetName()) {
featurePropertyType.setTitle(samplingFeature.getFirstName().getValue());
}
return featurePropertyType;
}
}
}
return featurePropertyType;
}
Aggregations