use of org.n52.shetland.ogc.swe.encoding.SweTextEncoding in project arctic-sea by 52North.
the class SweCommonDecoderV20 method decode.
@Override
public Object decode(Object element) throws DecodingException {
if (element instanceof DataArrayPropertyType) {
final DataArrayPropertyType dataArrayPropertyType = (DataArrayPropertyType) element;
return parseAbstractDataComponent(dataArrayPropertyType.getDataArray1());
} else if (element instanceof DataRecordPropertyType) {
final DataRecordPropertyType dataRecordPropertyType = (DataRecordPropertyType) element;
return parseAbstractDataComponent(dataRecordPropertyType.getDataRecord());
} else if (element instanceof AbstractDataComponentDocument) {
return parseAbstractDataComponentDocument((AbstractDataComponentDocument) element);
} else if (element instanceof AbstractDataComponentType) {
return parseAbstractDataComponent((AbstractDataComponentType) element);
} else if (element instanceof Coordinate[]) {
return parseCoordinates((Coordinate[]) element);
} else if (element instanceof AnyScalarPropertyType[]) {
return parseAnyScalarPropertyTypeArray((AnyScalarPropertyType[]) element);
} else if (element instanceof TextEncodingDocument) {
final TextEncodingDocument textEncodingDoc = (TextEncodingDocument) element;
final SweTextEncoding sosTextEncoding = parseTextEncoding(textEncodingDoc.getTextEncoding());
sosTextEncoding.setXml(textEncodingDoc.xmlText(getXmlOptions()));
return sosTextEncoding;
} else if (element instanceof TextEncodingType) {
TextEncodingDocument textEncodingDoc = TextEncodingDocument.Factory.newInstance(getXmlOptions());
TextEncodingType textEncoding = (TextEncodingType) element;
textEncodingDoc.setTextEncoding(textEncoding);
SweTextEncoding sosTextEncoding = parseTextEncoding(textEncoding);
sosTextEncoding.setXml(textEncodingDoc.xmlText(getXmlOptions()));
return sosTextEncoding;
} else if (element instanceof TextPropertyType) {
return parseAbstractDataComponent(((TextPropertyType) element).getText());
} else if (element instanceof CountPropertyType) {
return parseAbstractDataComponent(((CountPropertyType) element).getCount());
} else if (element instanceof BooleanPropertyType) {
return parseAbstractDataComponent(((BooleanPropertyType) element).getBoolean());
} else if (element instanceof CategoryPropertyType) {
return parseAbstractDataComponent(((CategoryPropertyType) element).getCategory());
} else if (element instanceof QuantityPropertyType) {
return parseAbstractDataComponent(((QuantityPropertyType) element).getQuantity());
} else if (element instanceof DataStreamPropertyType) {
return parseDataStream(((DataStreamPropertyType) element).getDataStream());
} else if (element instanceof DataStreamType) {
return parseDataStream((DataStreamType) element);
} else if (element instanceof DataStreamDocument) {
return parseDataStream(((DataStreamDocument) element).getDataStream());
} else if (element instanceof XmlObject) {
throw new UnsupportedDecoderXmlInputException(this, (XmlObject) element);
} else {
throw new UnsupportedDecoderInputException(this, element);
}
}
use of org.n52.shetland.ogc.swe.encoding.SweTextEncoding 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.SweTextEncoding in project arctic-sea by 52North.
the class InsertResultTemplateRequestEncoderTest method setup.
@Before
public void setup() throws InvalidSridException, ParseException {
SensorML procedure = new SensorML();
procedure.setIdentifier(procedureIdentifier);
SamplingFeature featureOfInterest = new SamplingFeature(new CodeWithAuthority(featureIdentifier));
featureOfInterest.setIdentifier(featureIdentifier);
featureOfInterest.setName(new CodeType(featureName));
featureOfInterest.setFeatureType(SfConstants.SAMPLING_FEAT_TYPE_SF_SAMPLING_POINT);
featureOfInterest.setGeometry(JTSHelper.createGeometryFromWKT("POINT(30 10)", 4326));
observationTemplate = new OmObservationConstellation();
observationTemplate.addOffering(offering);
observationTemplate.setObservationType(OmConstants.OBS_TYPE_MEASUREMENT);
observationTemplate.setProcedure(procedure);
observationTemplate.setObservableProperty(new OmObservableProperty(observedProperty));
observationTemplate.setFeatureOfInterest(featureOfInterest);
SweTextEncoding textEncoding = new SweTextEncoding();
textEncoding.setBlockSeparator(blockSeparator);
textEncoding.setTokenSeparator(tokenSeparator);
SweDataRecord resultStructure = new SweDataRecord();
SweTime sweTime = new SweTime();
sweTime.setDefinition(field1Definition);
sweTime.setUom(field1Uom);
resultStructure.addField(new SweField(field1Name, sweTime));
request = new InsertResultTemplateRequest(SosConstants.SOS, Sos2Constants.SERVICEVERSION, Sos2Constants.Operations.InsertResultTemplate.name());
request.setResultEncoding(new SosResultEncoding(textEncoding));
request.setResultStructure(new SosResultStructure(resultStructure));
request.setIdentifier(templateIdentifier);
request.setObservationTemplate(observationTemplate);
Supplier<XmlOptions> xmlOptions = () -> new XmlOptions();
encoder = new InsertResultTemplateRequestEncoder();
encoder.setXmlOptions(xmlOptions);
OmEncoderv20 omEncoder = new OmEncoderv20();
omEncoder.setXmlOptions(xmlOptions);
SamplingEncoderv20 samsEncoder = new SamplingEncoderv20();
samsEncoder.setXmlOptions(xmlOptions);
GmlEncoderv321 gml32Encoder = new GmlEncoderv321();
gml32Encoder.setXmlOptions(xmlOptions);
SweCommonEncoderv20 sweEncoderv20 = new SweCommonEncoderv20();
sweEncoderv20.setXmlOptions(xmlOptions);
EncoderRepository encoderRepository = new EncoderRepository();
encoderRepository.setEncoders(Arrays.asList(encoder, omEncoder, samsEncoder, gml32Encoder, sweEncoderv20));
encoderRepository.init();
encoderRepository.getEncoders().stream().forEach(e -> ((AbstractDelegatingEncoder<?, ?>) e).setEncoderRepository(encoderRepository));
}
use of org.n52.shetland.ogc.swe.encoding.SweTextEncoding in project arctic-sea by 52North.
the class SweCommonDecoderV20 method parseTextEncoding.
private SweTextEncoding parseTextEncoding(final TextEncodingType textEncoding) {
final SweTextEncoding sosTextEncoding = new SweTextEncoding();
sosTextEncoding.setBlockSeparator(textEncoding.getBlockSeparator());
sosTextEncoding.setTokenSeparator(textEncoding.getTokenSeparator());
if (textEncoding.isSetDecimalSeparator()) {
sosTextEncoding.setDecimalSeparator(textEncoding.getDecimalSeparator());
}
if (textEncoding.isSetCollapseWhiteSpaces()) {
sosTextEncoding.setCollapseWhiteSpaces(textEncoding.getCollapseWhiteSpaces());
}
return sosTextEncoding;
}
use of org.n52.shetland.ogc.swe.encoding.SweTextEncoding 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;
}
Aggregations