use of org.apache.xmlbeans.XmlException in project arctic-sea by 52North.
the class OgcDecoderv100 method parseTemporalOperatorType.
/**
* parses a single temporal filter of the requests and returns SOS temporal filter
*
* @param xbBinaryTemporalOp XmlObject representing the temporal filter
*
* @return Returns SOS representation of temporal filter
*
* @throws DecodingException if parsing of the element failed
*/
private Object parseTemporalOperatorType(BinaryTemporalOpType xbBinaryTemporalOp) throws DecodingException {
TemporalFilter temporalFilter = new TemporalFilter();
// FIXME local workaround against SOSHelper check value reference
String valueRef = "phenomenonTime";
try {
NodeList nodes = xbBinaryTemporalOp.getDomNode().getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
if (nodes.item(i).getNamespaceURI() != null && !nodes.item(i).getLocalName().equals(FilterConstants.EN_VALUE_REFERENCE)) {
// GML decoder will return TimeInstant or TimePriod
Object timeObject = decodeXmlElement(XmlObject.Factory.parse(nodes.item(i)));
if (timeObject instanceof PropertyNameType) {
PropertyNameType propType = (PropertyNameType) timeObject;
// TODO here apply logic for ogc property
// om:samplingTime etc
// valueRef = propType.getDomNode().getNodeValue();
}
if (timeObject instanceof Time) {
TimeOperator operator;
Time time = (Time) timeObject;
String localName = XmlHelper.getLocalName(xbBinaryTemporalOp);
// change to SOS 1.0. TMDuring kind of
if (localName.equals(TimeOperator.TM_During.name()) && time instanceof TimePeriod) {
operator = TimeOperator.TM_During;
} else if (localName.equals(TimeOperator.TM_Equals.name()) && time instanceof TimeInstant) {
operator = TimeOperator.TM_Equals;
} else if (localName.equals(TimeOperator.TM_After.name()) && time instanceof TimeInstant) {
operator = TimeOperator.TM_After;
} else if (localName.equals(TimeOperator.TM_Before.name()) && time instanceof TimeInstant) {
operator = TimeOperator.TM_Before;
} else {
throw unsupportedTemporalFilterOperand();
}
temporalFilter.setOperator(operator);
temporalFilter.setTime(time);
// actually it should be eg om:samplingTime
temporalFilter.setValueReference(valueRef);
break;
}
}
}
} catch (XmlException xmle) {
throw new DecodingException("Error while parsing temporal filter!", xmle);
}
return temporalFilter;
}
use of org.apache.xmlbeans.XmlException in project arctic-sea by 52North.
the class AbstractSoapDecoder method getSOAPBodyContent.
/**
* Parses the SOAPBody content to a text representation
*
* @param message
* SOAP message
*
* @return SOAPBody content as text
*
* @throws DecodingException
* * if an error occurs.
*/
protected OwsServiceRequest getSOAPBodyContent(SOAPMessage message) throws DecodingException {
try {
Document bodyRequestDoc = message.getSOAPBody().extractContentAsDocument();
String xmlString = W3cHelper.nodeToXmlString(bodyRequestDoc.getDocumentElement());
return decodeXmlElement(XmlObject.Factory.parse(xmlString, getXmlOptions()));
} catch (SOAPException | XmlException | IOException e) {
throw new DecodingException("Error while parsing SOAPMessage body content!", e);
}
}
use of org.apache.xmlbeans.XmlException in project arctic-sea by 52North.
the class GetResultTemplateResponseEncoder method createResultStructure.
private ResultStructure createResultStructure(SosResultStructure resultStructure) throws EncodingException {
// TODO move encoding to SWECommonEncoder
final DataRecordDocument dataRecordDoc;
if (resultStructure.isEncoded()) {
try {
dataRecordDoc = DataRecordDocument.Factory.parse(resultStructure.getXml().get());
} catch (XmlException ex) {
throw unsupportedResultStructure(ex);
}
} else {
XmlObject xml = encodeSwe(EncodingContext.of(XmlBeansEncodingFlags.DOCUMENT), resultStructure.get().get());
if (xml instanceof DataRecordDocument) {
dataRecordDoc = (DataRecordDocument) xml;
} else {
throw unsupportedResultStructure();
}
}
ResultStructure xbResultStructure = ResultStructure.Factory.newInstance(getXmlOptions());
xbResultStructure.addNewAbstractDataComponent().set(dataRecordDoc.getDataRecord());
XmlHelper.substituteElement(xbResultStructure.getAbstractDataComponent(), dataRecordDoc.getDataRecord());
return xbResultStructure;
}
use of org.apache.xmlbeans.XmlException in project arctic-sea by 52North.
the class GmlEncoderv321 method createFeature.
private XmlObject createFeature(AbstractFeature feature, EncodingContext ctx) throws EncodingException {
FeaturePropertyType featurePropertyType = FeaturePropertyType.Factory.newInstance(getXmlOptions());
if (isNotSamplingFeature(feature) || ctx.has(XmlBeansEncodingFlags.REFERENCED)) {
featurePropertyType.setHref(feature.getIdentifierCodeWithAuthority().getValue());
return featurePropertyType;
} else {
AbstractSamplingFeature samplingFeature = (AbstractSamplingFeature) feature;
if (samplingFeature.isSetGmlID()) {
featurePropertyType.setHref("#" + samplingFeature.getGmlId());
return featurePropertyType;
} else {
if (ctx.has(XmlBeansEncodingFlags.ENCODE) && !ctx.getBoolean(XmlBeansEncodingFlags.ENCODE) || !samplingFeature.isEncode()) {
featurePropertyType.setHref(feature.getIdentifierCodeWithAuthority().getValue());
if (feature instanceof SamplingFeature && samplingFeature.isSetName()) {
featurePropertyType.setTitle(samplingFeature.getFirstName().getValue());
}
return featurePropertyType;
}
if (!samplingFeature.isSetGeometry()) {
featurePropertyType.setHref(samplingFeature.getIdentifierCodeWithAuthority().getValue());
if (samplingFeature.isSetName()) {
featurePropertyType.setTitle(samplingFeature.getFirstName().getValue());
}
return featurePropertyType;
}
if (samplingFeature.isSetUrl()) {
featurePropertyType.setHref(samplingFeature.getUrl());
if (samplingFeature.isSetName()) {
featurePropertyType.setTitle(samplingFeature.getFirstName().getValue());
}
return featurePropertyType;
} else {
String namespace = ctx.getString(XmlEncoderFlags.ENCODE_NAMESPACE).orElseGet(() -> OMHelper.getNamespaceForFeatureType(samplingFeature.getFeatureType()));
XmlObject encodedXmlObject = encodeObjectToXml(namespace, samplingFeature);
if (encodedXmlObject != null) {
return encodedXmlObject;
} else {
if (feature.isSetXml()) {
try {
// XmlDescription? <-- XmlCursor
return XmlObject.Factory.parse(feature.getXml());
} catch (XmlException xmle) {
throw new EncodingException("Error while encoding featurePropertyType!", xmle);
}
} else {
featurePropertyType.setHref(feature.getIdentifierCodeWithAuthority().getValue());
if (samplingFeature.isSetName()) {
featurePropertyType.setTitle(feature.getFirstName().getValue());
}
return featurePropertyType;
}
}
}
}
}
}
use of org.apache.xmlbeans.XmlException in project arctic-sea by 52North.
the class GetCapabilitiesResponseEncoder method create.
@Override
protected XmlObject create(GetCapabilitiesResponse response) throws EncodingException {
CapabilitiesDocument doc = CapabilitiesDocument.Factory.newInstance(getXmlOptions());
CapabilitiesType xbCaps = doc.addNewCapabilities();
if (response.isStatic()) {
String xml = response.getXmlString();
LOGGER.trace("Response is static. XML-String:\n{}\n", xml);
try {
doc.set(XmlObject.Factory.parse(xml));
return doc;
} catch (XmlException ex) {
throw new EncodingException("Error encoding static capabilities", ex);
}
}
// set version.
if (response.getCapabilities().getVersion() != null) {
xbCaps.setVersion(response.getCapabilities().getVersion());
} else {
xbCaps.setVersion(response.getVersion());
}
encodeServiceIdentification(response.getCapabilities(), xbCaps);
encodeServiceProvider(response.getCapabilities(), xbCaps);
encodeOperationsMetadata(response.getCapabilities(), xbCaps);
if (response.getCapabilities() instanceof SosCapabilities) {
SosCapabilities caps = (SosCapabilities) response.getCapabilities();
encodeFilterCapabilities(caps, xbCaps);
encodeContents(caps, xbCaps, response.getVersion());
encodeExtensions(caps, xbCaps);
}
return doc;
}
Aggregations