Search in sources :

Example 1 with SweAbstractEncoding

use of org.n52.shetland.ogc.swe.encoding.SweAbstractEncoding in project arctic-sea by 52North.

the class SweHelper method createTextEncoding.

/**
 * Create a TextEncoding object for token and tuple separators.
 *
 * @param tuple
 *            Token separator
 * @param token
 *            Tuple separator
 * @param decimal
 *            Decimal separator
 *
 * @return TextEncoding
 */
private SweAbstractEncoding createTextEncoding(String tuple, String token, String decimal) {
    SweTextEncoding sosTextEncoding = new SweTextEncoding();
    sosTextEncoding.setBlockSeparator(tuple);
    sosTextEncoding.setTokenSeparator(token);
    if (!Strings.isNullOrEmpty(decimal)) {
        sosTextEncoding.setDecimalSeparator(decimal);
    }
    return sosTextEncoding;
}
Also used : SweTextEncoding(org.n52.shetland.ogc.swe.encoding.SweTextEncoding)

Example 2 with SweAbstractEncoding

use of org.n52.shetland.ogc.swe.encoding.SweAbstractEncoding in project arctic-sea by 52North.

the class GetResultTemplateResponseEncoder method encodeSweTextEncoding.

private void encodeSweTextEncoding(SweAbstractEncoding encoding, ObjectNode node) {
    SweTextEncoding sweTextEncoding = (SweTextEncoding) encoding;
    String ts = sweTextEncoding.getTokenSeparator();
    if (ts != null && !ts.isEmpty()) {
        node.put(JSONConstants.TOKEN_SEPARATOR, ts);
    }
    String bs = sweTextEncoding.getBlockSeparator();
    if (bs != null && !bs.isEmpty()) {
        node.put(JSONConstants.BLOCK_SEPARATOR, bs);
    }
    String ds = sweTextEncoding.getDecimalSeparator();
    if (ds != null && !ds.isEmpty()) {
        node.put(JSONConstants.DECIMAL_SEPARATOR, ds);
    }
}
Also used : SweTextEncoding(org.n52.shetland.ogc.swe.encoding.SweTextEncoding)

Example 3 with SweAbstractEncoding

use of org.n52.shetland.ogc.swe.encoding.SweAbstractEncoding 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 SweAbstractEncoding

use of org.n52.shetland.ogc.swe.encoding.SweAbstractEncoding in project arctic-sea by 52North.

the class SweCommonDecoderV20 method parseValues.

private List<List<String>> parseValues(final SweCount elementCount, final SweAbstractDataComponent elementType, final SweAbstractEncoding encoding, final EncodedValuesPropertyType encodedValuesPropertyType) throws DecodingException {
    if (checkParameterTypes(elementType, encoding)) {
        // Get swe values String via cursor as String
        String values;
        // TODO replace XmlCursor
        /*
             * if (encodedValuesPropertyType.schemaType() == XmlString.type) {
             * XmlString xbString
             */
        // @see SosDecoderv20#parseResultValues
        XmlCursor xbCursor = encodedValuesPropertyType.newCursor();
        xbCursor.toFirstContentToken();
        if (xbCursor.isText()) {
            values = xbCursor.getTextValue().trim();
            xbCursor.dispose();
            if (values != null && !values.isEmpty()) {
                SweTextEncoding textEncoding = (SweTextEncoding) encoding;
                String[] blocks = values.split(textEncoding.getBlockSeparator());
                List<List<String>> resultValues = new ArrayList<>(blocks.length);
                for (String block : blocks) {
                    String[] tokens = block.split(textEncoding.getTokenSeparator());
                    List<String> tokenList = Arrays.asList(tokens);
                    resultValues.add(tokenList);
                }
                return resultValues;
            }
        }
    }
    return null;
}
Also used : ArrayList(java.util.ArrayList) SweTextEncoding(org.n52.shetland.ogc.swe.encoding.SweTextEncoding) List(java.util.List) ArrayList(java.util.ArrayList) XmlCursor(org.apache.xmlbeans.XmlCursor)

Example 5 with SweAbstractEncoding

use of org.n52.shetland.ogc.swe.encoding.SweAbstractEncoding 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

SweTextEncoding (org.n52.shetland.ogc.swe.encoding.SweTextEncoding)5 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Strings (com.google.common.base.Strings)1 Lists (com.google.common.collect.Lists)1 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)1 BigInteger (java.math.BigInteger)1 URI (java.net.URI)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors.joining (java.util.stream.Collectors.joining)1 AbstractDataComponentType (net.opengis.swe.x20.AbstractDataComponentType)1 AbstractEncodingDocument (net.opengis.swe.x20.AbstractEncodingDocument)1 AbstractEncodingType (net.opengis.swe.x20.AbstractEncodingType)1 AllowedTimesPropertyType (net.opengis.swe.x20.AllowedTimesPropertyType)1