Search in sources :

Example 21 with EncodingContext

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);
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) FeatureCollection(org.n52.shetland.ogc.om.features.FeatureCollection) EncodingException(org.n52.svalbard.encode.exception.EncodingException) EReportingHeader(org.n52.shetland.aqd.EReportingHeader) TimePeriod(org.n52.shetland.ogc.gml.time.TimePeriod) AqdGetObservationResponseXmlStreamWriter(org.n52.svalbard.write.AqdGetObservationResponseXmlStreamWriter) Time(org.n52.shetland.ogc.gml.time.Time) DateTime(org.joda.time.DateTime) Supplier(java.util.function.Supplier) OwsExceptionReport(org.n52.shetland.ogc.ows.exception.OwsExceptionReport)

Example 22 with EncodingContext

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);
}
Also used : EnvironmentalMonitoringFacilityDocument(eu.europa.ec.inspire.schemas.ef.x40.EnvironmentalMonitoringFacilityDocument) EnvironmentalMonitoringFacility(org.n52.shetland.inspire.ef.EnvironmentalMonitoringFacility) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException)

Example 23 with EncodingContext

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);
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) EncodingException(org.n52.svalbard.encode.exception.EncodingException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) XmlException(org.apache.xmlbeans.XmlException) InspireXmlStreamWriter(org.n52.svalbard.write.InspireXmlStreamWriter) DateTimeFormatException(org.n52.shetland.util.DateTimeFormatException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Supplier(java.util.function.Supplier) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 24 with EncodingContext

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);
    }
}
Also used : AbstractFeature(org.n52.shetland.ogc.gml.AbstractFeature) XmlObject(org.apache.xmlbeans.XmlObject)

Example 25 with EncodingContext

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;
}
Also used : AbstractSamplingFeature(org.n52.shetland.ogc.om.features.samplingFeatures.AbstractSamplingFeature) EncodingException(org.n52.svalbard.encode.exception.EncodingException) XmlException(org.apache.xmlbeans.XmlException) XmlObject(org.apache.xmlbeans.XmlObject) MultiLineString(org.locationtech.jts.geom.MultiLineString) LineString(org.locationtech.jts.geom.LineString)

Aggregations

EncodingException (org.n52.svalbard.encode.exception.EncodingException)26 XmlObject (org.apache.xmlbeans.XmlObject)24 UnsupportedEncoderInputException (org.n52.svalbard.encode.exception.UnsupportedEncoderInputException)15 XmlException (org.apache.xmlbeans.XmlException)9 XMLStreamException (javax.xml.stream.XMLStreamException)6 OmObservation (org.n52.shetland.ogc.om.OmObservation)6 Supplier (java.util.function.Supplier)5 Time (org.n52.shetland.ogc.gml.time.Time)5 OwsExceptionReport (org.n52.shetland.ogc.ows.exception.OwsExceptionReport)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 AbstractCRSType (net.opengis.gml.x32.AbstractCRSType)4 CodeType (net.opengis.gml.x32.CodeType)4 FeaturePropertyType (net.opengis.gml.x32.FeaturePropertyType)4 DateTime (org.joda.time.DateTime)4 AbstractFeature (org.n52.shetland.ogc.gml.AbstractFeature)4 TimePeriod (org.n52.shetland.ogc.gml.time.TimePeriod)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 IOException (java.io.IOException)3 AbstractGeometryType (net.opengis.gml.x32.AbstractGeometryType)3 GeometryPropertyType (net.opengis.gml.x32.GeometryPropertyType)3