use of org.n52.shetland.ogc.swe.encoding.SweTextEncoding 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());
}
}
use of org.n52.shetland.ogc.swe.encoding.SweTextEncoding in project arctic-sea by 52North.
the class SweCommonEncoderv20Test method shouldEncodeTextEncoding.
@Test
public void shouldEncodeTextEncoding() throws EncodingException {
String tokenSeparator = "@";
String blockSeparator = ";";
SweTextEncoding textEncoding = new SweTextEncoding();
textEncoding.setBlockSeparator(blockSeparator);
textEncoding.setTokenSeparator(tokenSeparator);
XmlObject encodedEncoding = sweCommonEncoderv20.encode(textEncoding);
Assert.assertThat(encodedEncoding, Matchers.instanceOf(TextEncodingType.class));
TextEncodingType xbTextEncoding = (TextEncodingType) encodedEncoding;
Assert.assertThat(xbTextEncoding.getBlockSeparator(), Is.is(blockSeparator));
Assert.assertThat(xbTextEncoding.getTokenSeparator(), Is.is(tokenSeparator));
}
use of org.n52.shetland.ogc.swe.encoding.SweTextEncoding in project arctic-sea by 52North.
the class SweCommonEncoderv101 method createValues.
private XmlString createValues(SweTextEncoding textEncoding, List<List<String>> values) {
// TODO How to deal with the decimal separator - is it an issue here?
// textEncoding.getDecimalSeparator();
String tokenSeparator = textEncoding.getTokenSeparator();
String blockSeparator = textEncoding.getBlockSeparator();
String valueString = values.stream().map(block -> String.join(tokenSeparator, block)).collect(joining(blockSeparator));
// create XB result object
XmlString xbValueString = XmlString.Factory.newInstance();
xbValueString.setStringValue(valueString);
return xbValueString;
}
Aggregations