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;
}
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);
}
}
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;
}
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;
}
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());
}
}
Aggregations