Search in sources :

Example 1 with XmlString

use of org.apache.xmlbeans.XmlString 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 2 with XmlString

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

the class OmEncoderv100 method addSingleObservationToResult.

// FIXME String.equals(QName) !?
private void addSingleObservationToResult(XmlObject xbResult, OmObservation sosObservation) throws EncodingException {
    String observationType = sosObservation.getObservationConstellation().getObservationType();
    SingleObservationValue<?> observationValue = (SingleObservationValue<?>) sosObservation.getValue();
    if (observationValue.getValue() instanceof QuantityValue) {
        QuantityValue quantityValue = (QuantityValue) observationValue.getValue();
        xbResult.set(encodeObjectToXml(GmlConstants.NS_GML, quantityValue));
    } else if (observationValue.getValue() instanceof CountValue) {
        CountValue countValue = (CountValue) observationValue.getValue();
        XmlInteger xbInteger = XmlInteger.Factory.newInstance(getXmlOptions());
        if (countValue.getValue() != null && countValue.getValue() != Integer.MIN_VALUE) {
            xbInteger.setBigIntegerValue(new BigInteger(countValue.getValue().toString()));
        } else {
            xbInteger.setNil();
        }
        xbResult.set(xbInteger);
    } else if (observationValue.getValue() instanceof TextValue) {
        TextValue textValue = (TextValue) observationValue.getValue();
        XmlString xbString = XmlString.Factory.newInstance(getXmlOptions());
        if (textValue.getValue() != null && !textValue.getValue().isEmpty()) {
            xbString.setStringValue(textValue.getValue());
        } else {
            xbString.setNil();
        }
        xbResult.set(xbString);
    } else if (observationValue.getValue() instanceof BooleanValue) {
        BooleanValue booleanValue = (BooleanValue) observationValue.getValue();
        XmlBoolean xbBoolean = XmlBoolean.Factory.newInstance(getXmlOptions());
        if (booleanValue.getValue() != null) {
            xbBoolean.setBooleanValue(booleanValue.getValue());
        } else {
            xbBoolean.setNil();
        }
        xbResult.set(xbBoolean);
    } else if (observationValue.getValue() instanceof CategoryValue) {
        CategoryValue categoryValue = (CategoryValue) observationValue.getValue();
        if (categoryValue.getValue() != null && !categoryValue.getValue().isEmpty()) {
            xbResult.set(encodeObjectToXml(GmlConstants.NS_GML, categoryValue, EncodingContext.of(XmlBeansEncodingFlags.GMLID, SosConstants.OBS_ID_PREFIX + sosObservation.getObservationID())));
        } else {
            xbResult.setNil();
        }
    } else if (observationValue.getValue() instanceof GeometryValue) {
        GeometryValue geometryValue = (GeometryValue) observationValue.getValue();
        if (geometryValue.getValue() != null) {
            xbResult.set(encodeObjectToXml(GmlConstants.NS_GML, geometryValue.getValue(), EncodingContext.of(XmlBeansEncodingFlags.GMLID, SosConstants.OBS_ID_PREFIX + sosObservation.getObservationID())));
        } else {
            xbResult.setNil();
        }
    } else if (OmConstants.OBS_TYPE_SWE_ARRAY_OBSERVATION.equals(observationType) || OmConstants.RESULT_MODEL_OBSERVATION.getLocalPart().equals(observationType)) {
        SweDataArray dataArray = sweHelper.createSosSweDataArray(sosObservation);
        xbResult.set(encodeObjectToXml(SweConstants.NS_SWE_101, dataArray, EncodingContext.of(XmlBeansEncodingFlags.FOR_OBSERVATION)));
    }
}
Also used : XmlBoolean(org.apache.xmlbeans.XmlBoolean) XmlInteger(org.apache.xmlbeans.XmlInteger) XmlString(org.apache.xmlbeans.XmlString) XmlString(org.apache.xmlbeans.XmlString) SweDataArray(org.n52.shetland.ogc.swe.SweDataArray) GeometryValue(org.n52.shetland.ogc.om.values.GeometryValue) SingleObservationValue(org.n52.shetland.ogc.om.SingleObservationValue) CountValue(org.n52.shetland.ogc.om.values.CountValue) QuantityValue(org.n52.shetland.ogc.om.values.QuantityValue) TextValue(org.n52.shetland.ogc.om.values.TextValue) BooleanValue(org.n52.shetland.ogc.om.values.BooleanValue) BigInteger(java.math.BigInteger) CategoryValue(org.n52.shetland.ogc.om.values.CategoryValue)

Example 3 with XmlString

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

the class SweCommonEncoderv20 method createValues.

private XmlString createValues(List<List<String>> values, SweAbstractEncoding encoding) {
    // TODO How to deal with the decimal separator - is it an issue here?
    SweTextEncoding textEncoding = (SweTextEncoding) encoding;
    String valueString = values.stream().map(block -> String.join(textEncoding.getTokenSeparator(), block)).collect(joining(textEncoding.getBlockSeparator()));
    // create XB result object
    XmlString xmlString = XmlString.Factory.newInstance(getXmlOptions());
    xmlString.setStringValue(valueString);
    return xmlString;
}
Also used : OGCConstants(org.n52.shetland.ogc.OGCConstants) SweAllowedValues(org.n52.shetland.ogc.swe.simpleType.SweAllowedValues) CategoryPropertyType(net.opengis.swe.x20.CategoryPropertyType) CategoryRangeDocument(net.opengis.swe.x20.CategoryRangeDocument) Arrays(java.util.Arrays) VectorType(net.opengis.swe.x20.VectorType) CountPropertyType(net.opengis.swe.x20.CountPropertyType) SosConstants(org.n52.shetland.ogc.sos.SosConstants) CountRangeType(net.opengis.swe.x20.CountRangeType) TimeDocument(net.opengis.swe.x20.TimeDocument) VectorPropertyType(net.opengis.swe.x20.VectorPropertyType) Show(org.n52.shetland.w3c.xlink.Show) Map(java.util.Map) BigInteger(java.math.BigInteger) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) VectorDocument(net.opengis.swe.x20.VectorDocument) SweAllowedTokens(org.n52.shetland.ogc.swe.simpleType.SweAllowedTokens) EncodingException(org.n52.svalbard.encode.exception.EncodingException) TimeRangePropertyType(net.opengis.swe.x20.TimeRangePropertyType) TimeRangeType(net.opengis.swe.x20.TimeRangeType) DataArrayPropertyType(net.opengis.swe.x20.DataArrayPropertyType) Actuate(org.n52.shetland.w3c.xlink.Actuate) Set(java.util.Set) Encoding(net.opengis.swe.x20.DataArrayType.Encoding) Collectors.joining(java.util.stream.Collectors.joining) BooleanDocument(net.opengis.swe.x20.BooleanDocument) SweAllowedTimes(org.n52.shetland.ogc.swe.simpleType.SweAllowedTimes) NcName(org.n52.janmayen.NcName) TextEncodingType(net.opengis.swe.x20.TextEncodingType) SchemaLocation(org.n52.shetland.w3c.SchemaLocation) QuantityRangeDocument(net.opengis.swe.x20.QuantityRangeDocument) CategoryRangePropertyType(net.opengis.swe.x20.CategoryRangePropertyType) TimeType(net.opengis.swe.x20.TimeType) RangeValue(org.n52.shetland.ogc.swe.RangeValue) TimePropertyType(net.opengis.swe.x20.TimePropertyType) SmlPosition(org.n52.shetland.ogc.sensorML.elements.SmlPosition) SweQuantity(org.n52.shetland.ogc.swe.simpleType.SweQuantity) SweQuantityRange(org.n52.shetland.ogc.swe.simpleType.SweQuantityRange) CountType(net.opengis.swe.x20.CountType) TextDocument(net.opengis.swe.x20.TextDocument) SwesConstants(org.n52.shetland.ogc.swes.SwesConstants) XmlHelper(org.n52.svalbard.util.XmlHelper) ArrayList(java.util.ArrayList) SweCategoryRange(org.n52.shetland.ogc.swe.simpleType.SweCategoryRange) QuantityType(net.opengis.swe.x20.QuantityType) DateTimeHelper(org.n52.shetland.util.DateTimeHelper) Strings(com.google.common.base.Strings) Lists(com.google.common.collect.Lists) QuantityRangePropertyType(net.opengis.swe.x20.QuantityRangePropertyType) SweCount(org.n52.shetland.ogc.swe.simpleType.SweCount) DataChoicePropertyType(net.opengis.swe.x20.DataChoicePropertyType) MatrixDocument(net.opengis.swe.x20.MatrixDocument) QuantityRangeType(net.opengis.swe.x20.QuantityRangeType) MatrixPropertyType(net.opengis.swe.x20.MatrixPropertyType) Sos2Constants(org.n52.shetland.ogc.sos.Sos2Constants) SweDataComponentVisitor(org.n52.shetland.ogc.swe.SweDataComponentVisitor) SweCountRange(org.n52.shetland.ogc.swe.simpleType.SweCountRange) DataRecordPropertyType(net.opengis.swe.x20.DataRecordPropertyType) Coordinate(net.opengis.swe.x20.VectorType.Coordinate) UnitReference(net.opengis.swe.x20.UnitReference) SweText(org.n52.shetland.ogc.swe.simpleType.SweText) ShowType(org.w3.x1999.xlink.ShowType) SweField(org.n52.shetland.ogc.swe.SweField) XmlException(org.apache.xmlbeans.XmlException) SweSimpleDataRecord(org.n52.shetland.ogc.swe.SweSimpleDataRecord) AbstractDataComponentType(net.opengis.swe.x20.AbstractDataComponentType) SweDataArray(org.n52.shetland.ogc.swe.SweDataArray) BooleanType(net.opengis.swe.x20.BooleanType) XmlString(org.apache.xmlbeans.XmlString) DataChoiceType(net.opengis.swe.x20.DataChoiceType) AllowedTokensPropertyType(net.opengis.swe.x20.AllowedTokensPropertyType) SweTimeRange(org.n52.shetland.ogc.swe.simpleType.SweTimeRange) LoggerFactory(org.slf4j.LoggerFactory) DataArrayType(net.opengis.swe.x20.DataArrayType) TextEncodingDocument(net.opengis.swe.x20.TextEncodingDocument) SweAbstractEncoding(org.n52.shetland.ogc.swe.encoding.SweAbstractEncoding) SweVector(org.n52.shetland.ogc.swe.SweVector) DataRecordType(net.opengis.swe.x20.DataRecordType) SweBoolean(org.n52.shetland.ogc.swe.simpleType.SweBoolean) AllowedTimesType(net.opengis.swe.x20.AllowedTimesType) CountRangePropertyType(net.opengis.swe.x20.CountRangePropertyType) ActuateType(org.w3.x1999.xlink.ActuateType) UoM(org.n52.shetland.ogc.UoM) URI(java.net.URI) ConformanceClass(org.n52.svalbard.ConformanceClass) AllowedTokensType(net.opengis.swe.x20.AllowedTokensType) SweCategory(org.n52.shetland.ogc.swe.simpleType.SweCategory) CategoryType(net.opengis.swe.x20.CategoryType) SweCoordinate(org.n52.shetland.ogc.swe.SweCoordinate) AllowedValuesType(net.opengis.swe.x20.AllowedValuesType) Collection(java.util.Collection) CategoryRangeType(net.opengis.swe.x20.CategoryRangeType) ConformanceClasses(org.n52.svalbard.ConformanceClasses) List(java.util.List) QualityPropertyType(net.opengis.swe.x20.QualityPropertyType) BooleanPropertyType(net.opengis.swe.x20.BooleanPropertyType) AllowedValuesPropertyType(net.opengis.swe.x20.AllowedValuesPropertyType) SmlFeatureOfInterest(org.n52.shetland.ogc.sensorML.v20.SmlFeatureOfInterest) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) AbstractEncodingType(net.opengis.swe.x20.AbstractEncodingType) DataRecordDocument(net.opengis.swe.x20.DataRecordDocument) QuantityDocument(net.opengis.swe.x20.QuantityDocument) NotYetSupportedEncodingException(org.n52.svalbard.encode.exception.NotYetSupportedEncodingException) Nillable(org.n52.shetland.w3c.Nillable) SweTextEncoding(org.n52.shetland.ogc.swe.encoding.SweTextEncoding) StreamingSweDataArray(org.n52.shetland.ogc.swe.stream.StreamingSweDataArray) SmlDataInterface(org.n52.shetland.ogc.sensorML.v20.SmlDataInterface) SweTime(org.n52.shetland.ogc.swe.simpleType.SweTime) QuantityPropertyType(net.opengis.swe.x20.QuantityPropertyType) TypeType(org.w3.x1999.xlink.TypeType) Type(org.n52.shetland.w3c.xlink.Type) HashSet(java.util.HashSet) Referenceable(org.n52.shetland.w3c.xlink.Referenceable) AllowedTimesPropertyType(net.opengis.swe.x20.AllowedTimesPropertyType) SweQuality(org.n52.shetland.ogc.swe.simpleType.SweQuality) TextPropertyType(net.opengis.swe.x20.TextPropertyType) SweConstants(org.n52.shetland.ogc.swe.SweConstants) UnsupportedEncoderInputException(org.n52.svalbard.encode.exception.UnsupportedEncoderInputException) XmlObject(org.apache.xmlbeans.XmlObject) TextType(net.opengis.swe.x20.TextType) SweAbstractDataComponent(org.n52.shetland.ogc.swe.SweAbstractDataComponent) SweObservableProperty(org.n52.shetland.ogc.swe.simpleType.SweObservableProperty) CountDocument(net.opengis.swe.x20.CountDocument) TimeRangeDocument(net.opengis.swe.x20.TimeRangeDocument) Logger(org.slf4j.Logger) DataChoiceDocument(net.opengis.swe.x20.DataChoiceDocument) DateTime(org.joda.time.DateTime) MatrixType(net.opengis.swe.x20.MatrixType) CategoryDocument(net.opengis.swe.x20.CategoryDocument) CountRangeDocument(net.opengis.swe.x20.CountRangeDocument) AbstractEncodingDocument(net.opengis.swe.x20.AbstractEncodingDocument) CodingHelper(org.n52.svalbard.util.CodingHelper) SweEnvelope(org.n52.shetland.ogc.swe.SweEnvelope) Field(net.opengis.swe.x20.DataRecordType.Field) Collections(java.util.Collections) DataArrayDocument(net.opengis.swe.x20.DataArrayDocument) XmlString(org.apache.xmlbeans.XmlString) SweTextEncoding(org.n52.shetland.ogc.swe.encoding.SweTextEncoding) XmlString(org.apache.xmlbeans.XmlString)

Example 4 with XmlString

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

the class InsertResultRequestEncoderTest method shouldEncodeInsertResultRequest.

@Test
public void shouldEncodeInsertResultRequest() throws EncodingException {
    String version = Sos2Constants.SERVICEVERSION;
    String service = SosConstants.SOS;
    String templateIdentifier = "test-template-identifier";
    String resultValues = "test-result-values";
    InsertResultRequest request = new InsertResultRequest(service, version);
    request.setTemplateIdentifier(templateIdentifier);
    request.setResultValues(resultValues);
    XmlObject encodedRequest = encoder.create(request);
    Assert.assertThat(encodedRequest, Matchers.instanceOf(InsertResultDocument.class));
    Assert.assertThat(((InsertResultDocument) encodedRequest).getInsertResult(), Matchers.notNullValue());
    InsertResultType xbRequest = ((InsertResultDocument) encodedRequest).getInsertResult();
    Assert.assertThat(xbRequest.getService(), Is.is(service));
    Assert.assertThat(xbRequest.getVersion(), Is.is(version));
    Assert.assertThat(xbRequest.getTemplate(), Is.is(templateIdentifier));
    Assert.assertThat(xbRequest.getResultValues(), Matchers.instanceOf(XmlString.class));
    Assert.assertThat(((XmlString) xbRequest.getResultValues()).getStringValue(), Is.is(resultValues));
}
Also used : InsertResultRequest(org.n52.shetland.ogc.sos.request.InsertResultRequest) XmlString(org.apache.xmlbeans.XmlString) XmlObject(org.apache.xmlbeans.XmlObject) XmlString(org.apache.xmlbeans.XmlString) InsertResultType(net.opengis.sos.x20.InsertResultType) InsertResultDocument(net.opengis.sos.x20.InsertResultDocument) Test(org.junit.Test)

Example 5 with XmlString

use of org.apache.xmlbeans.XmlString in project poi by apache.

the class XWPFRun method preserveSpaces.

/**
     * Add the xml:spaces="preserve" attribute if the string has leading or trailing white spaces
     *
     * @param xs the string to check
     */
static void preserveSpaces(XmlString xs) {
    String text = xs.getStringValue();
    if (text != null && (text.startsWith(" ") || text.endsWith(" "))) {
        XmlCursor c = xs.newCursor();
        c.toNextToken();
        c.insertAttributeWithValue(new QName("http://www.w3.org/XML/1998/namespace", "space"), "preserve");
        c.dispose();
    }
}
Also used : QName(javax.xml.namespace.QName) XmlString(org.apache.xmlbeans.XmlString) XmlCursor(org.apache.xmlbeans.XmlCursor)

Aggregations

XmlString (org.apache.xmlbeans.XmlString)12 XmlObject (org.apache.xmlbeans.XmlObject)6 XmlException (org.apache.xmlbeans.XmlException)4 BigInteger (java.math.BigInteger)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 SweDataArray (org.n52.shetland.ogc.swe.SweDataArray)3 Lists (com.google.common.collect.Lists)2 URI (java.net.URI)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 List (java.util.List)2 Set (java.util.Set)2 Collectors.joining (java.util.stream.Collectors.joining)2 QName (javax.xml.namespace.QName)2 XmlBoolean (org.apache.xmlbeans.XmlBoolean)2 XmlCursor (org.apache.xmlbeans.XmlCursor)2 XmlInteger (org.apache.xmlbeans.XmlInteger)2 SingleObservationValue (org.n52.shetland.ogc.om.SingleObservationValue)2 BooleanValue (org.n52.shetland.ogc.om.values.BooleanValue)2