Search in sources :

Example 96 with XmlException

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

the class AbstractWmlEncoderv20 method createObservationProcess.

/**
 * Creates an WaterML 2.0 ObservationProcess XML object from SOS
 * ObservationProcess object
 *
 * @param procedure
 *            SOS ObservationProcess
 * @param context
 *            Additional values
 * @return WaterML 2.0 ObservationProcess XML object
 * @throws EncodingException
 *             If an error occurs
 */
protected ObservationProcessDocument createObservationProcess(ObservationProcess procedure, EncodingContext context) throws EncodingException {
    XmlObject encodedObject = null;
    try {
        if (procedure.isSetXml()) {
            encodedObject = XmlObject.Factory.parse(procedure.getXml());
            checkAndAddIdentifier(procedure, ((ObservationProcessDocument) encodedObject).getObservationProcess());
        } else {
            encodedObject = ObservationProcessDocument.Factory.newInstance();
            ObservationProcessType observationProcess = ((ObservationProcessDocument) encodedObject).addNewObservationProcess();
            if (context.has(XmlBeansEncodingFlags.GMLID)) {
                observationProcess.setId(PROCESS_ID_PREFIX + context.get(XmlBeansEncodingFlags.GMLID));
            } else {
                observationProcess.setId(PROCESS_ID_PREFIX + JavaHelper.generateID(procedure.toString()));
            }
            if (procedure.isSetIdentifier()) {
                observationProcess.addNewIdentifier().set(encodeGML(procedure.getIdentifierCodeWithAuthority()));
            }
            if (procedure.isSetName()) {
                for (final CodeType sosName : procedure.getName()) {
                    observationProcess.addNewName().set(encodeGML(sosName));
                }
            }
            addProcessType(observationProcess, procedure);
            addOriginatingProcess(observationProcess, procedure);
            addAggregatingDuration(observationProcess, procedure);
            addVerticalDatum(observationProcess, procedure);
            addComment(observationProcess, procedure);
            addProcessReference(observationProcess, procedure);
            addInput(observationProcess, procedure);
            addParameter(observationProcess, procedure);
        }
    } catch (final XmlException xmle) {
        throw new EncodingException(xmle);
    }
    try {
        LOGGER.debug("Encoded object {} is valid: {}", encodedObject.schemaType().toString(), XmlHelper.validateDocument(encodedObject));
    } catch (DecodingException e) {
        throw new EncodingException(e);
    }
    return (ObservationProcessDocument) encodedObject;
}
Also used : EncodingException(org.n52.svalbard.encode.exception.EncodingException) ObservationProcessType(net.opengis.waterml.x20.ObservationProcessType) XmlException(org.apache.xmlbeans.XmlException) ObservationProcessDocument(net.opengis.waterml.x20.ObservationProcessDocument) CodeType(org.n52.shetland.ogc.gml.CodeType) XmlObject(org.apache.xmlbeans.XmlObject) DecodingException(org.n52.svalbard.decode.exception.DecodingException)

Example 97 with XmlException

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

the class ProcessTypeEncoder method createProcess.

protected ProcessType createProcess(Process process) throws EncodingException {
    if (process.isSetXml()) {
        XmlObject encodedObject = null;
        try {
            encodedObject = XmlObject.Factory.parse(process.getXml());
            if (encodedObject instanceof ProcessType) {
                ProcessType pt = (ProcessType) encodedObject;
                checkForInspireId(pt, process);
                return pt;
            } else if (encodedObject instanceof ProcessDocument) {
                return ((ProcessDocument) encodedObject).getProcess();
            } else if (encodedObject instanceof ProcessPropertyType) {
                return ((ProcessPropertyType) encodedObject).getProcess();
            } else {
                throw new UnsupportedEncoderInputException(this, process);
            }
        } catch (final XmlException xmle) {
            throw new EncodingException(xmle);
        }
    } else {
        ProcessType pt = ProcessType.Factory.newInstance();
        if (!process.isSetGmlID()) {
            process.setGmlId("p_" + JavaHelper.generateID(process.toString()));
        }
        pt.setId(process.getGmlId());
        addInspireId(pt, process);
        addName(pt, process);
        addType(pt, process);
        addDocumentation(pt, process);
        addProcessParameter(pt, process);
        addResponsibleParty(pt, process);
        return pt;
    }
}
Also used : ProcessType(eu.europa.ec.inspire.schemas.ompr.x30.ProcessType) EncodingException(org.n52.svalbard.encode.exception.EncodingException) XmlException(org.apache.xmlbeans.XmlException) ProcessPropertyType(eu.europa.ec.inspire.schemas.ompr.x30.ProcessPropertyType) XmlObject(org.apache.xmlbeans.XmlObject) ProcessDocument(eu.europa.ec.inspire.schemas.ompr.x30.ProcessDocument) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException)

Example 98 with XmlException

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

the class FesDecoderv20 method parseTemporalFilterType.

/**
 * parses a single temporal filter of the requests and returns SOS temporal
 * filter
 *
 * @param xbTemporalOpsType
 *            XmlObject representing the temporal filter
 * @return Returns SOS representation of temporal filter
 *
 * @throws DecodingException
 *             * if parsing of the element failed
 */
private TemporalFilter parseTemporalFilterType(TemporalOpsType xbTemporalOpsType) throws DecodingException {
    TemporalFilter temporalFilter = new TemporalFilter();
    try {
        if (xbTemporalOpsType instanceof BinaryTemporalOpType) {
            BinaryTemporalOpType btot = (BinaryTemporalOpType) xbTemporalOpsType;
            if (btot.getValueReference() != null && !btot.getValueReference().isEmpty()) {
                temporalFilter.setValueReference(btot.getValueReference().trim());
            }
            NodeList nodes = btot.getDomNode().getChildNodes();
            for (int i = 0; i < nodes.getLength(); i++) {
                if (nodes.item(i).getNamespaceURI() != null && !nodes.item(i).getLocalName().equals(FilterConstants.EN_VALUE_REFERENCE)) {
                    Object timeObject = decodeXmlObject(Factory.parse(nodes.item(i)));
                    if (timeObject instanceof Time) {
                        TimeOperator operator;
                        Time time = (Time) timeObject;
                        String localName = XmlHelper.getLocalName(xbTemporalOpsType);
                        if (localName.equals(TimeOperator2.After.name())) {
                            operator = TimeOperator.TM_After;
                        } else if (localName.equals(TimeOperator2.Before.name())) {
                            operator = TimeOperator.TM_Before;
                        } else if (localName.equals(TimeOperator2.Begins.name())) {
                            operator = TimeOperator.TM_Begins;
                        } else if (localName.equals(TimeOperator2.BegunBy.name())) {
                            operator = TimeOperator.TM_BegunBy;
                        } else if (localName.equals(TimeOperator2.TContains.name())) {
                            operator = TimeOperator.TM_Contains;
                        } else if (localName.equals(TimeOperator2.During.name())) {
                            operator = TimeOperator.TM_During;
                        } else if (localName.equals(TimeOperator2.EndedBy.name())) {
                            operator = TimeOperator.TM_EndedBy;
                        } else if (localName.equals(TimeOperator2.Ends.name())) {
                            operator = TimeOperator.TM_Ends;
                        } else if (localName.equals(TimeOperator2.TEquals.name())) {
                            operator = TimeOperator.TM_Equals;
                        } else if (localName.equals(TimeOperator2.Meets.name())) {
                            operator = TimeOperator.TM_Meets;
                        } else if (localName.equals(TimeOperator2.MetBy.name())) {
                            operator = TimeOperator.TM_MetBy;
                        } else if (localName.equals(TimeOperator2.TOverlaps.name())) {
                            operator = TimeOperator.TM_Overlaps;
                        } else if (localName.equals(TimeOperator2.OverlappedBy.name())) {
                            operator = TimeOperator.TM_OverlappedBy;
                        } else {
                            throw unsupportedTemporalOperator();
                        }
                        temporalFilter.setOperator(operator);
                        temporalFilter.setTime(time);
                        break;
                    } else {
                        throw new DecodingException(Sos2Constants.GetObservationParams.temporalFilter, "The requested temporal filter value is not supported by this SOS!");
                    }
                }
            }
        } else {
            throw unsupportedTemporalOperator();
        }
    } catch (XmlException xmle) {
        throw new DecodingException("Error while parsing temporal filter!", xmle);
    }
    return temporalFilter;
}
Also used : TimeOperator(org.n52.shetland.ogc.filter.FilterConstants.TimeOperator) TemporalFilter(org.n52.shetland.ogc.filter.TemporalFilter) XmlException(org.apache.xmlbeans.XmlException) NodeList(org.w3c.dom.NodeList) XmlObject(org.apache.xmlbeans.XmlObject) Time(org.n52.shetland.ogc.gml.time.Time) DecodingException(org.n52.svalbard.decode.exception.DecodingException) BinaryTemporalOpType(net.opengis.fes.x20.BinaryTemporalOpType)

Example 99 with XmlException

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

the class AbstractGmlDecoderv321 method parseNamedValueValue.

protected NamedValue<?> parseNamedValueValue(XmlObject xml) throws DecodingException {
    XmlObject xmlObject = xml;
    if (xmlObject.schemaType() == XmlAnyTypeImpl.type) {
        try {
            xmlObject = XmlObject.Factory.parse(xml.xmlText().trim());
        } catch (XmlException e) {
            LOGGER.error("Error while parsing NamedValueValue", e);
        }
    }
    Object value;
    if (XmlBoolean.Factory.newInstance().schemaType().equals(xmlObject.schemaType())) {
        value = ((XmlBoolean) xmlObject).getBooleanValue();
    } else if (XmlString.Factory.newInstance().schemaType().equals(xmlObject.schemaType())) {
        value = ((XmlString) xmlObject).getStringValue();
    } else if (XmlInt.Factory.newInstance().schemaType().equals(xmlObject.schemaType())) {
        value = ((XmlInt) xmlObject).getIntValue();
    } else if (XmlInteger.Factory.newInstance().schemaType().equals(xmlObject.schemaType())) {
        value = ((XmlInteger) xmlObject).getBigIntegerValue().intValue();
    } else if (XmlDouble.Factory.newInstance().schemaType().equals(xmlObject.schemaType())) {
        value = ((XmlDouble) xmlObject).getDoubleValue();
    } else {
        value = decodeXmlObject(xmlObject);
    }
    if (value instanceof BooleanValue) {
        NamedValue<Boolean> namedValue = new NamedValue<>();
        namedValue.setValue((BooleanValue) value);
        return namedValue;
    } else if (value instanceof SweBoolean) {
        NamedValue<Boolean> namedValue = new NamedValue<>();
        namedValue.setValue(new BooleanValue(((SweBoolean) value).getValue()));
        return namedValue;
    } else if (value instanceof Boolean) {
        NamedValue<Boolean> namedValue = new NamedValue<>();
        namedValue.setValue(new BooleanValue((Boolean) value));
        return namedValue;
    } else if (value instanceof CategoryValue) {
        NamedValue<String> namedValue = new NamedValue<>();
        namedValue.setValue((CategoryValue) value);
        return namedValue;
    } else if (value instanceof SweCategory) {
        NamedValue<String> namedValue = new NamedValue<>();
        namedValue.setValue(new CategoryValue(((SweCategory) value).getValue(), ((SweCategory) value).getCodeSpace()));
        return namedValue;
    } else if (value instanceof CountValue) {
        NamedValue<Integer> namedValue = new NamedValue<>();
        namedValue.setValue((CountValue) value);
        return namedValue;
    } else if (value instanceof SweCount) {
        NamedValue<Integer> namedValue = new NamedValue<>();
        namedValue.setValue(new CountValue(((SweCount) value).getValue()));
        return namedValue;
    } else if (value instanceof Integer) {
        NamedValue<Integer> namedValue = new NamedValue<>();
        namedValue.setValue(new CountValue((Integer) value));
        return namedValue;
    } else if (value instanceof GeometryValue) {
        NamedValue<Geometry> namedValue = new NamedValue<>();
        namedValue.setValue((GeometryValue) value);
        return namedValue;
    } else if (value instanceof QuantityValue) {
        NamedValue<BigDecimal> namedValue = new NamedValue<>();
        namedValue.setValue((QuantityValue) value);
        return namedValue;
    } else if (value instanceof GmlMeasureType) {
        NamedValue<BigDecimal> namedValue = new NamedValue<>();
        namedValue.setValue(new QuantityValue(((GmlMeasureType) value).getValue(), ((GmlMeasureType) value).getUnit()));
        return namedValue;
    } else if (value instanceof SweQuantity) {
        NamedValue<BigDecimal> namedValue = new NamedValue<>();
        namedValue.setValue(new QuantityValue(((SweQuantity) value).getValue(), ((SweQuantity) value).getUom()));
        return namedValue;
    } else if (value instanceof Double) {
        NamedValue<BigDecimal> namedValue = new NamedValue<>();
        namedValue.setValue(new QuantityValue((Double) value));
        return namedValue;
    } else if (value instanceof TextValue) {
        NamedValue<String> namedValue = new NamedValue<>();
        namedValue.setValue((TextValue) value);
        return namedValue;
    } else if (value instanceof SweText) {
        NamedValue<String> namedValue = new NamedValue<>();
        namedValue.setValue(new TextValue(((SweText) value).getValue()));
        return namedValue;
    } else if (value instanceof String) {
        NamedValue<String> namedValue = new NamedValue<>();
        namedValue.setValue(new TextValue((String) value));
        return namedValue;
    } else if (value instanceof AbstractGeometry) {
        NamedValue<Geometry> namedValue = new NamedValue<>();
        namedValue.setValue(new GeometryValue((AbstractGeometry) value));
        return namedValue;
    } else if (value instanceof org.n52.shetland.ogc.gml.ReferenceType) {
        NamedValue<org.n52.shetland.ogc.gml.ReferenceType> namedValue = new NamedValue<>();
        namedValue.setValue(new ReferenceValue((org.n52.shetland.ogc.gml.ReferenceType) value));
        return namedValue;
    } else if (value instanceof W3CHrefAttribute) {
        NamedValue<W3CHrefAttribute> namedValue = new NamedValue<>();
        namedValue.setValue(new HrefAttributeValue((W3CHrefAttribute) value));
        return namedValue;
    } else {
        throw new UnsupportedDecoderInputException(this, xmlObject);
    }
}
Also used : SweQuantity(org.n52.shetland.ogc.swe.simpleType.SweQuantity) SweText(org.n52.shetland.ogc.swe.simpleType.SweText) AbstractGeometry(org.n52.shetland.ogc.gml.AbstractGeometry) ReferenceValue(org.n52.shetland.ogc.om.values.ReferenceValue) NamedValue(org.n52.shetland.ogc.om.NamedValue) XmlString(org.apache.xmlbeans.XmlString) SweBoolean(org.n52.shetland.ogc.swe.simpleType.SweBoolean) CountValue(org.n52.shetland.ogc.om.values.CountValue) BooleanValue(org.n52.shetland.ogc.om.values.BooleanValue) SweCategory(org.n52.shetland.ogc.swe.simpleType.SweCategory) SweBoolean(org.n52.shetland.ogc.swe.simpleType.SweBoolean) XmlBoolean(org.apache.xmlbeans.XmlBoolean) HrefAttributeValue(org.n52.shetland.ogc.om.values.HrefAttributeValue) XmlString(org.apache.xmlbeans.XmlString) SweCount(org.n52.shetland.ogc.swe.simpleType.SweCount) W3CHrefAttribute(org.n52.shetland.w3c.xlink.W3CHrefAttribute) XmlDouble(org.apache.xmlbeans.XmlDouble) UnsupportedDecoderInputException(org.n52.svalbard.decode.exception.UnsupportedDecoderInputException) BigDecimal(java.math.BigDecimal) XmlInteger(org.apache.xmlbeans.XmlInteger) Geometry(org.locationtech.jts.geom.Geometry) AbstractGeometry(org.n52.shetland.ogc.gml.AbstractGeometry) GeometryValue(org.n52.shetland.ogc.om.values.GeometryValue) XmlException(org.apache.xmlbeans.XmlException) QuantityValue(org.n52.shetland.ogc.om.values.QuantityValue) TextValue(org.n52.shetland.ogc.om.values.TextValue) CategoryValue(org.n52.shetland.ogc.om.values.CategoryValue) XmlObject(org.apache.xmlbeans.XmlObject) XmlObject(org.apache.xmlbeans.XmlObject) GmlMeasureType(org.n52.shetland.ogc.gml.GmlMeasureType)

Example 100 with XmlException

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

the class GetResultTemplateResponseEncoder method encodeResultEncoding.

private void encodeResultEncoding(GetResultTemplateResponse t, ObjectNode json) throws EncodingException {
    ObjectNode jre = json.putObject(JSONConstants.RESULT_ENCODING);
    SweAbstractEncoding encoding = null;
    SosResultEncoding re = t.getResultEncoding();
    if (re.isDecoded()) {
        encoding = t.getResultEncoding().get().get();
    } else {
        try {
            XmlNamespaceDecoderKey key = new XmlNamespaceDecoderKey(SweConstants.NS_SWE_20, SweAbstractEncoding.class);
            Decoder<SweAbstractEncoding, XmlObject> decoder = this.decoderRepository.getDecoder(key);
            if (decoder == null) {
                throw new NoDecoderForKeyException(key);
            }
            encoding = decoder.decode(XmlObject.Factory.parse(re.getXml().get()));
        } catch (XmlException | DecodingException ex) {
            throw new EncodingException(ex);
        }
    }
    if (encoding instanceof SweTextEncoding) {
        encodeSweTextEncoding(encoding, jre);
    } else {
        LOG.warn("Unsupported encoding: {}", encoding == null ? null : encoding.getClass());
    }
}
Also used : NoDecoderForKeyException(org.n52.svalbard.decode.exception.NoDecoderForKeyException) XmlNamespaceDecoderKey(org.n52.svalbard.decode.XmlNamespaceDecoderKey) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) EncodingException(org.n52.svalbard.encode.exception.EncodingException) SweAbstractEncoding(org.n52.shetland.ogc.swe.encoding.SweAbstractEncoding) XmlException(org.apache.xmlbeans.XmlException) XmlObject(org.apache.xmlbeans.XmlObject) DecodingException(org.n52.svalbard.decode.exception.DecodingException) SweTextEncoding(org.n52.shetland.ogc.swe.encoding.SweTextEncoding) SosResultEncoding(org.n52.shetland.ogc.sos.SosResultEncoding)

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