Search in sources :

Example 31 with XmlException

use of org.apache.xmlbeans.XmlException in project arctic-sea by 52North.

the class OmDecoderv20 method getResult.

private ObservationValue<?> getResult(OMObservationType omObservation) throws DecodingException {
    XmlObject xbResult = omObservation.getResult();
    if (xbResult.schemaType() == XmlAnyTypeImpl.type) {
        // Template observation for InsertResultTemplate operation
        if (!xbResult.getDomNode().hasChildNodes()) {
            return new SingleObservationValue<>(new NilTemplateValue());
        } else {
            try {
                xbResult = XmlObject.Factory.parse(xbResult.xmlText().trim());
            } catch (XmlException e) {
                LOGGER.error("Error while parsing NamedValueValue", e);
            }
        }
    }
    if (xbResult.schemaType() == XmlBoolean.type) {
        // TruthObservation
        XmlBoolean xbBoolean = (XmlBoolean) xbResult;
        BooleanValue booleanValue = new BooleanValue(xbBoolean.getBooleanValue());
        return new SingleObservationValue<>(booleanValue);
    } else if (xbResult.schemaType() == XmlInteger.type) {
        // CountObservation
        XmlInteger xbInteger = (XmlInteger) xbResult;
        CountValue countValue = new CountValue(Integer.parseInt(xbInteger.getBigIntegerValue().toString()));
        return new SingleObservationValue<>(countValue);
    } else if (xbResult.schemaType() == XmlString.type) {
        // TextObservation
        XmlString xbString = (XmlString) xbResult;
        TextValue stringValue = new TextValue(xbString.getStringValue());
        return new SingleObservationValue<>(stringValue);
    } else {
        // result elements with other encoding like SWE_ARRAY_OBSERVATION
        Object decodedObject = decodeXmlObject(xbResult);
        if (decodedObject instanceof ObservationValue) {
            return (ObservationValue<?>) decodedObject;
        } else if (decodedObject instanceof GmlMeasureType) {
            GmlMeasureType measureType = (GmlMeasureType) decodedObject;
            QuantityValue quantitiyValue = new QuantityValue(measureType.getValue(), measureType.getUnit());
            return new SingleObservationValue<>(quantitiyValue);
        } else if (decodedObject instanceof ReferenceType) {
            if (omObservation.isSetType() && omObservation.getType().isSetHref() && omObservation.getType().getHref().equals(OmConstants.OBS_TYPE_REFERENCE_OBSERVATION)) {
                return new SingleObservationValue<>(new ReferenceValue((ReferenceType) decodedObject));
            }
            return new SingleObservationValue<>(new CategoryValue(((ReferenceType) decodedObject).getHref()));
        } else if (decodedObject instanceof Geometry) {
            return new SingleObservationValue<>(new GeometryValue((Geometry) decodedObject));
        } else if (decodedObject instanceof AbstractGeometry) {
            SingleObservationValue<Geometry> result = new SingleObservationValue<>();
            result.setValue(new GeometryValue(((AbstractGeometry) decodedObject).getGeometry()));
            return result;
        } else if (decodedObject instanceof SweDataArray) {
            return new SingleObservationValue<>(new SweDataArrayValue((SweDataArray) decodedObject));
        } else if (decodedObject instanceof SweDataRecord) {
            return new SingleObservationValue<>(new ComplexValue((SweDataRecord) decodedObject));
        }
        throw new DecodingException(Sos2Constants.InsertObservationParams.observation, "The requested result type '{}' is not supported by this service!", decodedObject.getClass().getSimpleName());
    }
}
Also used : AbstractGeometry(org.n52.shetland.ogc.gml.AbstractGeometry) XmlBoolean(org.apache.xmlbeans.XmlBoolean) ReferenceValue(org.n52.shetland.ogc.om.values.ReferenceValue) XmlInteger(org.apache.xmlbeans.XmlInteger) DecodingException(org.n52.svalbard.decode.exception.DecodingException) ReferenceType(org.n52.shetland.ogc.gml.ReferenceType) SweDataArrayValue(org.n52.shetland.ogc.om.values.SweDataArrayValue) SingleObservationValue(org.n52.shetland.ogc.om.SingleObservationValue) CountValue(org.n52.shetland.ogc.om.values.CountValue) BooleanValue(org.n52.shetland.ogc.om.values.BooleanValue) ComplexValue(org.n52.shetland.ogc.om.values.ComplexValue) XmlString(org.apache.xmlbeans.XmlString) SweDataArray(org.n52.shetland.ogc.swe.SweDataArray) Geometry(org.locationtech.jts.geom.Geometry) AbstractGeometry(org.n52.shetland.ogc.gml.AbstractGeometry) GeometryValue(org.n52.shetland.ogc.om.values.GeometryValue) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) XmlException(org.apache.xmlbeans.XmlException) TextValue(org.n52.shetland.ogc.om.values.TextValue) QuantityValue(org.n52.shetland.ogc.om.values.QuantityValue) CategoryValue(org.n52.shetland.ogc.om.values.CategoryValue) XmlObject(org.apache.xmlbeans.XmlObject) XmlObject(org.apache.xmlbeans.XmlObject) SingleObservationValue(org.n52.shetland.ogc.om.SingleObservationValue) ObservationValue(org.n52.shetland.ogc.om.ObservationValue) NilTemplateValue(org.n52.shetland.ogc.om.values.NilTemplateValue) GmlMeasureType(org.n52.shetland.ogc.gml.GmlMeasureType)

Example 32 with XmlException

use of org.apache.xmlbeans.XmlException in project arctic-sea by 52North.

the class FesDecoderv20 method parsePropertyIsBetweenFilter.

/**
 * Parse XML propertyIsBetween element
 *
 * @param comparisonOpsType
 *            XML propertyIsBetween element
 * @return SOS comparison filter
 * @throws DecodingException
 *             If an error occurs of the filter is not supported
 */
private ComparisonFilter parsePropertyIsBetweenFilter(PropertyIsBetweenType comparisonOpsType) throws DecodingException {
    ComparisonFilter comparisonFilter = new ComparisonFilter();
    comparisonFilter.setOperator(ComparisonOperator.PropertyIsBetween);
    try {
        comparisonFilter.setValueReference(parseValueReference(comparisonOpsType.getExpression()));
    } catch (XmlException xmle) {
        throw valueReferenceParsingException(xmle);
    }
    if (comparisonOpsType.getLowerBoundary().getExpression() instanceof LiteralType) {
        comparisonFilter.setValue(parseLiteralValue((LiteralType) comparisonOpsType.getLowerBoundary().getExpression()));
    }
    if (comparisonOpsType.getUpperBoundary().getExpression() instanceof LiteralType) {
        comparisonFilter.setValueUpper(parseLiteralValue((LiteralType) comparisonOpsType.getUpperBoundary().getExpression()));
    }
    return comparisonFilter;
}
Also used : ComparisonFilter(org.n52.shetland.ogc.filter.ComparisonFilter) XmlException(org.apache.xmlbeans.XmlException) LiteralType(net.opengis.fes.x20.LiteralType)

Example 33 with XmlException

use of org.apache.xmlbeans.XmlException in project arctic-sea by 52North.

the class FesDecoderv20 method parseSpatialFilterType.

/**
 * Parses the spatial filter of a request.
 *
 * @param xbSpatialOpsType
 *            XmlBean representing the feature of interest parameter of the
 *            request
 * @return Returns SpatialFilter created from the passed foi request
 *         parameter
 *
 * @throws DecodingException
 *             * if creation of the SpatialFilter failed
 */
private SpatialFilter parseSpatialFilterType(SpatialOpsType xbSpatialOpsType) throws DecodingException {
    SpatialFilter spatialFilter = new SpatialFilter();
    try {
        if (xbSpatialOpsType instanceof BBOXType) {
            spatialFilter.setOperator(FilterConstants.SpatialOperator.BBOX);
            BBOXType xbBBOX = (BBOXType) xbSpatialOpsType;
            if (isValueReferenceExpression(xbBBOX.getExpression())) {
                spatialFilter.setValueReference(parseValueReference(xbBBOX.getExpression()));
            }
            XmlCursor geometryCursor = xbSpatialOpsType.newCursor();
            if (geometryCursor.toChild(GmlConstants.QN_ENVELOPE_32)) {
                Object sosGeometry = decodeXmlObject(Factory.parse(geometryCursor.getDomNode()));
                if (sosGeometry instanceof Geometry) {
                    spatialFilter.setGeometry((Geometry) sosGeometry);
                } else if (sosGeometry instanceof ReferencedEnvelope) {
                    spatialFilter.setGeometry((ReferencedEnvelope) sosGeometry);
                } else {
                    throw new UnsupportedDecoderXmlInputException(this, xbSpatialOpsType);
                }
            } else {
                throw new DecodingException(Sos2Constants.GetObservationParams.spatialFilter, "The requested spatial filter operand is not supported by this SOS!");
            }
            geometryCursor.dispose();
        } else {
            throw new DecodingException(Sos2Constants.GetObservationParams.spatialFilter, "The requested spatial filter is not supported by this SOS!");
        }
    } catch (XmlException xmle) {
        throw new DecodingException("Error while parsing spatial filter!", xmle);
    }
    return spatialFilter;
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) ReferencedEnvelope(org.n52.shetland.util.ReferencedEnvelope) BBOXType(net.opengis.fes.x20.BBOXType) XmlException(org.apache.xmlbeans.XmlException) SpatialFilter(org.n52.shetland.ogc.filter.SpatialFilter) XmlObject(org.apache.xmlbeans.XmlObject) UnsupportedDecoderXmlInputException(org.n52.svalbard.decode.exception.UnsupportedDecoderXmlInputException) DecodingException(org.n52.svalbard.decode.exception.DecodingException) XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 34 with XmlException

use of org.apache.xmlbeans.XmlException in project arctic-sea by 52North.

the class CapabilitiesTypeDecoder method parseOffering.

private SosObservationOffering parseOffering(AbstractContentsType.Offering offering) {
    SosObservationOffering observationOffering = new SosObservationOffering();
    if (offering.getDomNode().hasChildNodes()) {
        final Node node = XmlHelper.getNodeFromNodeList(offering.getDomNode().getChildNodes());
        try {
            ObservationOfferingPropertyType offeringType = ObservationOfferingPropertyType.Factory.parse(node);
            ObservationOfferingType obsOffPropType = offeringType.getObservationOffering();
            observationOffering.setOffering(parseOffering(obsOffPropType));
            observationOffering.setProcedures(parseProcedure(obsOffPropType));
            observationOffering.setProcedureDescriptionFormat(parseProcedureDescriptionFormat(obsOffPropType));
            observationOffering.setObservableProperties(parseObservableProperties(obsOffPropType));
            observationOffering.setRelatedFeatures(parseRelatedFeatures(obsOffPropType));
            observationOffering.setObservedArea(parseObservedArea(obsOffPropType));
            observationOffering.setPhenomenonTime(parsePhenomenonTime(obsOffPropType));
            observationOffering.setResultTime(parseResultTime(obsOffPropType));
            observationOffering.setResponseFormats(parseResponseFormats(obsOffPropType));
            observationOffering.setObservationTypes(parseObservationTypes(obsOffPropType));
            observationOffering.setFeatureOfInterestTypes(parseFeatureOfInterestTypes(obsOffPropType));
            observationOffering.setExtensions(parseOfferingExtension(obsOffPropType));
        } catch (XmlException | DecodingException ex) {
            LOGGER.error(ex.getLocalizedMessage(), ex);
        }
    }
    return observationOffering;
}
Also used : ObservationOfferingPropertyType(net.opengis.sos.x20.ObservationOfferingPropertyType) ObservationOfferingType(net.opengis.sos.x20.ObservationOfferingType) XmlException(org.apache.xmlbeans.XmlException) Node(org.w3c.dom.Node) DecodingException(org.n52.svalbard.decode.exception.DecodingException) SosObservationOffering(org.n52.shetland.ogc.sos.SosObservationOffering)

Example 35 with XmlException

use of org.apache.xmlbeans.XmlException in project arctic-sea by 52North.

the class OgcDecoderv100 method parseSpatialOperatorType.

private Object parseSpatialOperatorType(BinarySpatialOpType xbSpatialOpsType) throws DecodingException {
    SpatialFilter spatialFilter = new SpatialFilter();
    try {
        if (xbSpatialOpsType instanceof BBOXTypeImpl) {
            spatialFilter.setOperator(FilterConstants.SpatialOperator.BBOX);
            BBOXTypeImpl xbBBOX = (BBOXTypeImpl) xbSpatialOpsType;
            spatialFilter.setOperator(FilterConstants.SpatialOperator.BBOX);
            XmlCursor geometryCursor = xbBBOX.newCursor();
            if (geometryCursor.toChild(GmlConstants.QN_ENVELOPE)) {
                Object sosGeometry = decodeXmlElement(XmlObject.Factory.parse(geometryCursor.getDomNode()));
                if (sosGeometry instanceof Geometry) {
                    spatialFilter.setGeometry((Geometry) sosGeometry);
                }
            } else {
                throw unsupportedSpatialFilter();
            }
            geometryCursor.dispose();
        } else {
            throw unsupportedSpatialFilter();
        }
    } catch (XmlException xmle) {
        throw errorParsingSpatialFilter(xmle);
    }
    return spatialFilter;
}
Also used : Geometry(org.locationtech.jts.geom.Geometry) XmlException(org.apache.xmlbeans.XmlException) SpatialFilter(org.n52.shetland.ogc.filter.SpatialFilter) XmlObject(org.apache.xmlbeans.XmlObject) BBOXTypeImpl(net.opengis.ogc.impl.BBOXTypeImpl) XmlCursor(org.apache.xmlbeans.XmlCursor)

Aggregations

XmlException (org.apache.xmlbeans.XmlException)112 XmlObject (org.apache.xmlbeans.XmlObject)45 IOException (java.io.IOException)35 DecodingException (org.n52.svalbard.decode.exception.DecodingException)19 EncodingException (org.n52.svalbard.encode.exception.EncodingException)17 POIXMLException (org.apache.poi.POIXMLException)15 InputStream (java.io.InputStream)11 ArrayList (java.util.ArrayList)10 XmlCursor (org.apache.xmlbeans.XmlCursor)10 XmlOptions (org.apache.xmlbeans.XmlOptions)10 OpenXML4JException (org.apache.poi.openxml4j.exceptions.OpenXML4JException)8 POIXMLDocumentPart (org.apache.poi.POIXMLDocumentPart)7 AbstractFeature (org.n52.shetland.ogc.gml.AbstractFeature)7 Geometry (org.locationtech.jts.geom.Geometry)6 Document (org.w3c.dom.Document)6 Node (org.w3c.dom.Node)6 DataAccessException (com.centurylink.mdw.common.exception.DataAccessException)5 ByteArrayInputStream (java.io.ByteArrayInputStream)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 File (java.io.File)5