use of org.apache.xmlbeans.XmlException in project arctic-sea by 52North.
the class GetDataAvailabilityXmlEncoder method create.
@Override
protected XmlObject create(GetDataAvailabilityResponse response) throws EncodingException {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
EncodingContext ctx = EncodingContext.empty().with(EncoderFlags.ENCODER_REPOSITORY, getEncoderRepository()).with(XmlEncoderFlags.XML_OPTIONS, (Supplier<XmlOptions>) this::getXmlOptions);
if (GetDataAvailabilityConstants.NS_GDA.equals(response.getResponseFormat())) {
new GetDataAvailabilityStreamWriter(ctx, baos, response.getDataAvailabilities()).write();
} else if (GetDataAvailabilityConstants.NS_GDA_20.equals(response.getResponseFormat())) {
new GetDataAvailabilityV20StreamWriter(ctx, baos, response.getDataAvailabilities()).write();
}
XmlObject encodedObject = XmlObject.Factory.parse(baos.toString("UTF8"));
XmlHelper.validateDocument(encodedObject, EncodingException::new);
return encodedObject;
} catch (XMLStreamException | XmlException | UnsupportedEncodingException ex) {
throw new EncodingException("Error encoding response", ex);
}
}
use of org.apache.xmlbeans.XmlException in project arctic-sea by 52North.
the class AqdEncoder method encodeEReportingHeader.
private XmlObject encodeEReportingHeader(EReportingHeader element, EncodingContext ctx) throws EncodingException {
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
EncodingContext context = ctx.with(EncoderFlags.ENCODER_REPOSITORY, getEncoderRepository()).with(XmlEncoderFlags.XML_OPTIONS, (Supplier<XmlOptions>) this::getXmlOptions);
new EReportingHeaderEncoder(context, baos, element).write();
if (context.has(XmlStreamEncoderFlags.XML_WRITER)) {
return null;
}
return XmlObject.Factory.parse(baos.toString("UTF8"));
} catch (XMLStreamException | XmlException | UnsupportedEncodingException xmlse) {
throw new EncodingException("Error encoding response", xmlse);
}
}
use of org.apache.xmlbeans.XmlException in project arctic-sea by 52North.
the class InspireXmlEncoder method encodeObject.
private XmlObject encodeObject(InspireObject objectToEncode, EncodingContext ctx) throws EncodingException {
try {
checkIfSupported(objectToEncode);
ByteArrayOutputStream out = new ByteArrayOutputStream();
EncodingContext context = ctx.with(EncoderFlags.ENCODER_REPOSITORY, getEncoderRepository()).with(XmlEncoderFlags.XML_OPTIONS, (Supplier<XmlOptions>) this::getXmlOptions);
new InspireXmlStreamWriter(context, out, objectToEncode).write();
String s = out.toString("UTF8");
return XmlObject.Factory.parse(s);
} catch (XMLStreamException | DateTimeFormatException | XmlException | UnsupportedEncodingException ex) {
throw new EncodingException("Error encoding Inspire extended capabilities!", ex);
}
}
use of org.apache.xmlbeans.XmlException in project arctic-sea by 52North.
the class SamplingEncoderv20 method createFeature.
@Override
protected XmlObject createFeature(FeaturePropertyType featurePropertyType, AbstractFeature abstractFeature, EncodingContext context) throws EncodingException {
if (abstractFeature instanceof AbstractSamplingFeature) {
final AbstractSamplingFeature samplingFeature = (AbstractSamplingFeature) abstractFeature;
String namespace;
if (context.has(XmlEncoderFlags.ENCODE_NAMESPACE) && context.get(XmlEncoderFlags.ENCODE_NAMESPACE).isPresent() && context.get(XmlEncoderFlags.ENCODE_NAMESPACE).get() instanceof String) {
namespace = (String) context.get(XmlEncoderFlags.ENCODE_NAMESPACE).get();
} else {
namespace = OMHelper.getNamespaceForFeatureType(samplingFeature.getFeatureType());
}
final XmlObject encodedXmlObject = encodeObjectToXml(namespace, samplingFeature);
if (encodedXmlObject != null) {
return encodedXmlObject;
} else {
if (samplingFeature.isSetXml()) {
try {
// XmlDescription? <-- XmlCursor
return XmlObject.Factory.parse(samplingFeature.getXml());
} catch (final XmlException xmle) {
throw new EncodingException("Error while encoding featurePropertyType!", xmle);
}
} else {
featurePropertyType.setHref(samplingFeature.getIdentifierCodeWithAuthority().getValue());
if (samplingFeature.isSetName()) {
featurePropertyType.setTitle(samplingFeature.getFirstName().getValue());
}
return featurePropertyType;
}
}
}
return featurePropertyType;
}
use of org.apache.xmlbeans.XmlException in project arctic-sea by 52North.
the class SpecimenEncoderv20 method createSpecimen.
private XmlObject createSpecimen(SfSpecimen specimen) throws EncodingException {
SFSpecimenDocument sfsd = SFSpecimenDocument.Factory.newInstance(getXmlOptions());
if (specimen.isSetXml()) {
try {
final XmlObject feature = XmlObject.Factory.parse(specimen.getXml(), getXmlOptions());
XmlHelper.updateGmlIDs(feature.getDomNode().getFirstChild(), specimen.getGmlId(), null);
if (XmlHelper.getNamespace(feature).equals(SfConstants.NS_SPEC) && feature instanceof SFSpecimenType) {
sfsd.setSFSpecimen((SFSpecimenType) feature);
addName(sfsd.getSFSpecimen(), specimen);
addDescription(sfsd.getSFSpecimen(), specimen);
return sfsd;
}
addName(((SFSpecimenDocument) feature).getSFSpecimen(), specimen);
addDescription(((SFSpecimenDocument) feature).getSFSpecimen(), specimen);
return feature;
} catch (final XmlException xmle) {
throw new EncodingException("Error while encoding GetFeatureOfInterest response, invalid specimen description!", xmle);
}
}
final SFSpecimenType sfst = sfsd.addNewSFSpecimen();
// TODO: CHECK for all fields set gml:id
addId(sfst, specimen);
addIdentifier(sfst, specimen);
// set type
addFeatureType(sfst, specimen);
addName(sfst, specimen);
addDescription(sfst, specimen);
// set sampledFeatures
addSampledFeatures(sfst, specimen);
addParameter(sfst, specimen);
// set specimen specific data
addMaterialClass(sfst, specimen);
addSamplingTime(sfst, specimen);
addSamplingMethod(sfst, specimen);
addSamplingLocation(sfst, specimen);
addProcessingDetails(sfst, specimen);
addSize(sfst, specimen);
addCurrentLocation(sfst, specimen);
addSpecimenType(sfst, specimen);
specimen.wasEncoded();
return sfsd;
}
Aggregations